October 19, 2021, 09:55:28

Author Topic: [bmx] Gadget Helper by JoshK [ 1+ years ago ]  (Read 729 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] Gadget Helper by JoshK [ 1+ years ago ]
« on: June 29, 2017, 00:28:40 »
Title : Gadget Helper
Author : JoshK
Posted : 1+ years ago

Description : Transforms screen coordinates from one gadget to another, or to the screen

Code :
Code: BlitzMax
  1. Strict
  2.  
  3. Import pub.win32
  4. Import brl.maxgui
  5.  
  6. Extern "win32"
  7.         Function ScreenToClient:Int(hwnd,lpPoint:Byte Ptr)="ScreenToClient@8"
  8.         Function ClientToScreen:Int(hwnd,lpPoint:Byte Ptr)="ClientToScreen@8"
  9.         Function SetCursorPos:Int(x,y)="SetCursorPos@8"
  10.         Function GetCursorPos:Int(lpPoint:Byte Ptr)="GetCursorPos@4"
  11. EndExtern
  12.  
  13. Function coord:TCoord(x,y)
  14.         Local screencoord:TCoord=New TCoord
  15.         screencoord.x=x
  16.         screencoord.y=y
  17.         Return screencoord
  18. EndFunction
  19.  
  20. Type TCoord
  21.         Field x,y
  22.        
  23.         Method pointer:Byte Ptr()
  24.                 Return Varptr x
  25.         EndMethod
  26.        
  27.         Method copy:TCoord()
  28.                 Return Coord(x,y)
  29.         EndMethod
  30.        
  31. EndType
  32.  
  33. Function GetGadgetCoord:TCoord(gadget:TGadget,glob=0)
  34.         If glob
  35.                 Return TFormCoord( Coord(GadgetX(gadget),GadgetY(gadget)),GadgetGroup(gadget),Null )
  36.         Else
  37.                 Return Coord(GadgetX(gadget),GadgetY(gadget))
  38.         EndIf
  39. EndFunction
  40.  
  41. Function SetMouseCoord(c:TCoord,gadget:TGadget=Null)
  42.         If gadget c=TFormCoord(c,gadget,Null)
  43.         setcursorpos c.x,c.y
  44. EndFunction
  45.  
  46. Function TFormCoord:TCoord(c:TCoord,src:TGadget,dst:TGadget)
  47.         c=c.copy()
  48.         If src ClientToScreen QueryGadget(src,QUERY_HWND),c.pointer()
  49.         If dst ScreenToClient QueryGadget(dst,QUERY_HWND),c.pointer()
  50.         Return c
  51. EndFunction


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal