Moving window glitchy
BlitzMax Forums/MaxGUI Module/Moving window glitchy
| ||
| I have used this simple idea for moving windows or controls in multiple languages and never had a problem. When you click down on the control, the app remembers that location, so when you move the mouse it moves the control depending on the difference. In blitzmax the control seems to go crazy lol.
Global ItemWindow:TGadget
Global Panela:TGadget
Global X1:Int
Global Y1:Int
ItemWindow = CreateWindow("Test Window", 100, 100, 600, 450, Null, Null)
Panela= CreatePanel(0, 0, 600, 450, ItemWindow,PANEL_ACTIVE)
Repeat
WaitEvent()
Select EventID()
Case event_mousedown
If EventData() = 1
If EventSource() = Panela
x1 = CurrentEvent.x
y1 = CurrentEvent.y
End If
Else
End
End If
Case event_mousemove
If EventData() = 1
If EventSource() = panela
SetGadgetShape(ItemWindow,Int(GadgetX(ItemWindow)) - (X1-CurrentEvent.x),Int(GadgetY(ItemWindow)) - (y1-CurrentEvent.y),GadgetWidth(ItemWindow),GadgetHeight(ItemWindow))
x1 = CurrentEvent.x
y1 = CurrentEvent.y
End If
End If
End Select
Forever
What am I missing? This code works fine for me in other languages. ps. Right click to close. Time |
| ||
| You might need to use an EventHook. Search the forums for more details :-) |
| ||
| I figured as much. It seems like the event is lagged and getting the events out of order. |
| ||
| There is no order in events ... if you rely on an order, then your code is procedural, not event based. |
| ||
| I don't think an EventHook will help, the problem is the event coordinates are relative to the panel so the act of moving it's parent window is effectively moving the mouse (window moves left mouse has effectively moved right in relation to the windows contents). Taking this into account:
Import maxgui.drivers
Global ItemWindow:TGadget
Global Panela:TGadget
Global X1:Int
Global Y1:Int
ItemWindow = CreateWindow("Test Window", 100, 100, 600, 450, Null, Null)
Panela= CreatePanel(0, 0, 600, 450, ItemWindow,PANEL_ACTIVE)
Repeat
WaitEvent()
Select EventID()
Case event_mousedown
If EventData() = 1
If EventSource() = Panela
x1 = CurrentEvent.x
y1 = CurrentEvent.y
End If
Else
End
End If
Case event_mousemove
If EventData() = 1
If EventSource() = panela
dx= CurrentEvent.x-x1
dy= CurrentEvent.y-y1
SetGadgetShape(ItemWindow,GadgetX(ItemWindow)+dx,GadgetY(ItemWindow)+dy,GadgetWidth(ItemWindow),GadgetHeight(ItemWindow))
x1 = CurrentEvent.x-dx
y1 = CurrentEvent.y-dy
End If
End If
End Select
Forever
|
| ||
| Ahhh! Thanks a lot skid. The event hook worked, but the scaling of the mouse coordinates was strange, forcing me to move the mouse almost twice as much as the window would move. But this source works flawlessly. Cheers. |