Problem with eventX()
BlitzMax Forums/MaxGUI Module/Problem with eventX()
| ||
| Hi can someone explain me what's wrong with this? I really think that is a bug with EventX() but it's can be me that don't understand how it's work .. here the code the problem is when I try to position the panel in the window with the mouse I got strange thing the panel sometime don't position where the mouse is.
' createwindow.bmx
Strict
Global MouseXEndPosi:Int
Global MouseYEndPosi:Int
Global selected:Int
Global window:TGadget=CreateWindow("My Window",40,40,320,240)
Global panelwindow:TGadget=CreatePanel(0,0,GadgetWidth(window),GadgetHeight(window),window,PANEL_ACTIVE)
Global SelectPan:TGadget=CreatePanel(20,20,30,30,panelwindow,PANEL_ACTIVE)
SetPanelColor( SelectPan,50,120,10 )
While True
WaitEvent
Select EventID()
Case EVENT_WINDOWCLOSE
End
Case EVENT_MOUSEDOWN
If EventSource() = SelectPan Then selected = 1
Case EVENT_MOUSEMOVE
MouseXEndPosi = EventX()
MouseYEndPosi = EventY()
Print MouseXEndPosi + "," + MouseYEndPosi
Delay 100
Case EVENT_MOUSEUP
Local MouseXEndPosi = EventX()
Local MouseYEndPosi = EventY()
Print "Before gadgetshape" + MouseXEndPosi + "," + MouseXEndPosi
SetGadgetShape( SelectPan,MouseXEndPosi,MouseYEndPosi,30,30 )
Print "After gadgetshape" + MouseXEndPosi + "," + MouseXEndPosi
Delay 100
End Select
Wend
|
| ||
| I see two cases in which the panel isn't placed where the mouse cursor is when the button is clicked: 1. There's some lag caused by the two "Delay 100" statements, so that if the mouse is moved rapidly while clicking quickly, sometimes the green panel is placed at the position of the last click instead of the current one. Reducing the value of the Delay statements below 100 helps reduce this. 2. If the mouse is over the green, SelectPan, panel (30,30), it gets the coordinates within it, rather than within the usual panelwindow (320,240). This is because SelectPan is set to PANEL_ACTIVE. However, because the mouse events don't check the EventSource(), they treat these coordinates as if they were relative to the panelwindow and position SelectPanel somewhere between 0 and 29. This can be fixed by adding "If EventSource() = panelwindow Then" (or "If Not selected Then") before "SetGadgetShape( SelectPan,MouseXEndPosi,MouseYEndPosi,30,30 )". I'm not certain that either of these is what you meant, but they're just what caught my eye. |
| ||
| Works better, but if I double click on the panel, it reports 0,0 oddly... |
| ||
| WendellM What it suppost to do is if you click on SelectPan it set the var selected to 1 then I know that the mouse was click for this panel then I have another panel that cover the entire window then if the mouse move, it update the var MouseXendPosi then for the case mouseup I just try to position the panel you clicked at the new position. remember that the SelectPan is only there for detecting if the mouse is click or not. I use EVENT_MOUSEUP to position the SelectPan where I want it to be and the EVENT_MOUSEMOVE will be there to move in real time the SelectPan panel. SelectPan is set ACTIVE because I want to move it when I click on it.... if I set it to PANEL_BORDER it's work but it work all the time event if I don't click on it. |
| ||
| You don't need panelwindow active, once a mouse has clicked down on a panel it is captured and all mousemove until mouseup events will come only from SelectPan. Here's how I would do it:
Strict
' offsets so pointer drag is relative to position panel was grabbed
Global selected:Int
Global selectx:Int
Global selecty:Int
Global window:TGadget=CreateWindow("My Window",40,40,320,240)
Global panelwindow:TGadget=CreatePanel(0,0,GadgetWidth(window),GadgetHeight(window),window,PANEL_ACTIVE)
Global SelectPan:TGadget=CreatePanel(20,20,30,30,panelwindow,PANEL_ACTIVE)
SetPanelColor( SelectPan,50,120,10 )
While True
WaitEvent
Select EventID()
Case EVENT_WINDOWCLOSE
End
Case EVENT_MOUSEDOWN
If EventSource() = SelectPan
selected=True
selectx=EventX()
selecty=EventY()
EndIf
Case EVENT_MOUSEMOVE
If selected
Local x=GadgetX(SelectPan)+EventX()-selectx
Local y=GadgetY(SelectPan)+EventY()-selecty
Local w=GadgetWidth(SelectPan)
Local h=GadgetHeight(SelectPan)
SetGadgetShape( SelectPan,x,y,w,h)
EndIf
Case EVENT_MOUSEUP
selected=False
End Select
Wend
|
| ||
| It's working :) I did't know about the panel thing thanks skid btw it's there a way to capture the mouse move event if I pass over a gadget without having to press the mouse button? |