How to move a widget panel when I press the mouse button, and follow the mouse cursor

I try to move a widget when I press the mouse button down. It do move hut it can’t follow the mouse cursor and when I release the mouse button the widget will still move. the code is set up to stop moving the widget when the mouse button is released.

Can someone help me?

screenshot from codes
alt text

Is it safe to assume this is for moving windows, like in, eh, Windows?

Here’s the thing - we can’t have the player controller do anything here; widgets and the controller do not like talking to each other and often don’t know what the other is doing with the input.


Here are my wWindow’s Up / Down events for left mouse button:

Above, the Grab Offset is where we clicked in that window - it’s later on used when we move it around. When grabbed, the window calls an event dispatcher that is picked up by main canvas where we drag the windows.

Below, onMouseUp calls the dispatcher, informing the main canvas that we no longer wish to drag the window.


Here’s my main canvas - wScreen - where the windows are added and the dragging happens:

The top bit creates a bunch of windows and registers the above-mentioned event dispatcher. That event tells the main canvas (wScreen) that a new windows needs dragging. A reference to that window is created and we give it higher Z so it stays on top of other windows.

We need to know where the cursor is in the main canvas as well. For this, I’m overriding onMouseMove:

Tick will move the window using its reference. The final location is calculated by subtracting the Grab Offset from the Local Screen Position produced by the override above.

Image from Gyazo

6 Likes

Yes, that is what I try to do

How do you get the “Call ED Grabbed window” node?

It’s an Event Dispatcher you create yourself and add inputs to.

the widget to move, but it wont stop folowing the mouse cursor when I relses the left mouse button, Can you help me?

Are you sure you’re not running some old code in the controller? The script above looks good.

Thank you for the help, it works now.

I made a new empty project to test this

Put a print string in the mouse up after the dispatcher. Does it print when you release the button?

Ok, I see it now. You have reversed True | False of Unhandled | Handled in the onMouseDown. It should be other way round - compare it with mine.

This means the up can never execute since the widget does not know the key went down.

It do it at random if I double click the button

  1. Is there a reason to do the position setting in the container widget? I have done it directly in the MouseMove event of the window class. It doesnt seem to make any difference. The move event is for my case actually only picked up when hovering above some ui element of the container class anyways.
  2. Also there seems to be a lag for the event tick (for dragging the window) and the actual mouse position on the screen. So if I drag quite fast then the mouse will leave the bounds of the window and the event is not going to be picked up. Is there a way to do this better? Preferably not having this “lag”.
    Maybe someone knowlageble still picks up this thread! Thanks in advance.
1 Like

I added OnMouseButtonUp to canvas widget to clear DraggableWindow variable
Seems to stop fine now
Also did the same thing when mouse leaves canvas widget