mouse position inside canvas
BlitzMax Forums/MaxGUI Module/mouse position inside canvas
| ||
| Hi ! Is there a method to have the mouse position inside a canvas if you not move the mouse or interact with it. (the mouse pointer is just on the canvas) ? Thanks ! |
| ||
| I'm at the work at the moment, but if I remember a canvas should emitt (if setted with EVENT_MOUSEMOVE) an event, and then you can read the result with EventX() EventY() |
| ||
| i'm ok with this, it's maybe a stupid question. But do you must store the mouse coord in you own variables (for example mx = eventx() and my=eventy()). Because if the mouse not move, not event is generated for the mouse so you can't check eventx() or eventy() !?! in fact to move an object on the screen i need to determine deltax and deltay, (how many pixels mouse moved from last position) |
| ||
| yes, store them. I typically use ex and ey. |
| ||
How to determine dx and dy ? (how many pixels mouse moved from last position) Where reinit dx=0,dy=0 when the mouse doesn't move ? Thanks to help me !
Strict
Global Win2:TGadget = CreateWindow("",(GadgetWidth(Desktop())-540)/2,(GadgetHeight(Desktop())-650)/2,540,650,Null,WINDOW_MENU|WINDOW_TITLEBAR)
Global Panel_choix_map : Tgadget = CreatePanel (0,0,700,40, Win2)
Global Canvas2:TGadget= CreateCanvas(10,50,512,512,Win2)
' -------------------------------------------------------------------------------------------
Global mx, my
Global dx, dy
Global Timer:TTimer = CreateTimer(60)
While WaitEvent()
Select EventID()
Case EVENT_MOUSEMOVE
dx = mx - EventX()
dy = my = EventY()
mx = EventX()
my = EventY()
Case EVENT_TIMERTICK
SetGraphics CanvasGraphics(Canvas2)
Cls
SetColor 255,255,255
DrawOval mx-2,my-2,2,2
DrawText String Int(mx) + "," + String (Int(my)), mx,my
DrawText "dx=" + String Int(dx) + ",dy=" + String (Int(dy)), mx,my + 16
Flip
Case EVENT_WINDOWCLOSE
Exit
End Select
Wend
|
| ||
Thanks for your help. Finaly i have coded this. It's ok for my game editor.
Strict
Global Win2:TGadget = CreateWindow("",(GadgetWidth(Desktop())-540)/2,(GadgetHeight(Desktop())-650)/2,540,650,Null,WINDOW_MENU|WINDOW_TITLEBAR)
Global Panel_choix_map : Tgadget = CreatePanel (0,0,700,40, Win2)
Global Canvas2:TGadget= CreateCanvas(10,50,512,512,Win2)
Global cerclex=100
Global Cercley=100
' -------------------------------------------------------------------------------------------
Global mx, my
Global dx, dy
Global ox, oy
Global bDeplacer = False
Global Timer:TTimer = CreateTimer(60)
While WaitEvent()
Select EventID()
Case EVENT_MOUSEDOWN
ox = mx
oy = my
Case EVENT_MOUSEUP
ox = 0
oy = 0
Case EVENT_MOUSEMOVE
mx = EventX()
my = EventY()
If ox <> 0 And oy <> 0 Then
dx = ox - mx
dy = oy - my
ox = mx
oy = my
Else
dx = 0
dy = 0
End If
CercleX = CercleX - dx
CercleY = CercleY - dy
Case EVENT_TIMERTICK
SetGraphics CanvasGraphics(Canvas2)
Cls
SetColor 255,255,255
DrawOval mx-2,my-2,2,2
DrawText String Int(mx) + "," + String (Int(my)), mx,my
DrawText "dx=" + String Int(dx) + ",dy=" + String (Int(dy)), mx,my + 16
DrawOval CercleX - 50, CercleY - 50,100,100
Flip 0
Case EVENT_WINDOWCLOSE
Exit
End Select
Wend
|