Forum

> > Off Topic > How to properly update whilst window dragging?
Forums overviewOff Topic overviewLog in to reply

English How to properly update whilst window dragging?

11 replies
To the start Previous 1 Next To the start

old How to properly update whilst window dragging?

Rainoth
Moderator Off Offline

Quote
Good day everyone,

I've tried searching but it seems nobody had a problem like mine.
Alright so here's the deal:
• In the game I'm making I've created a window (like a gadget)
• My game is set to update 100 times per second
• There's an area for dragging the window with which I can drag my window
• If I drag the window faster than 1/100th of a second, my mouse moves out of "draggable" area (the top of the window) and my window is no longer being dragged.
• If I put the mouse back to draggable area again (mouse held all the time) I can drag again
• I do not want to speed up the update rate

Is there any way I could still drag the window even if I move the mouse out of the draggable are?
Any ideas and or solutions are welcome.
Thank you in advance.

old Re: How to properly update whilst window dragging?

Hurri04
Super User Off Offline

Quote
user Rainoth has written
• If I drag the window faster than 1/100th of a second, [...]
not sure how to read this since "faster" implies a speed which additionally needs some measurement of distance, not only time.

user Rainoth has written
[...] my mouse moves out of "draggable" area (the top of the window) and my window is no longer being dragged.
what does "moves out of draggable area" mean? in which direction does it move? or does the cursor actually even stay still and only the window moves?

posting screenshots, a video and/or code snippets would help.

old Re: How to properly update whilst window dragging?

VADemon
User Off Offline

Quote
1
2
3
4
5
6
7
8
--pseudocode
onMouseDown event:
if CursorPos in the draggable area:
repeat

setWindowPos to CursorPos

until mouseUp
I couldn't really understand you, but is the stuff above what you need?

old Re: How to properly update whilst window dragging?

Rainoth
Moderator Off Offline

Quote
@user Hurri04: If I move the mouse within draggable area (every window has the rectangle u can click and drag the window with) my check which happens 100 times per second will notice that and the window will be dragged. The problem is that if I move it out of draggeable area before the check occurs again, it no longer drags. I'm guessing that on windows the check is so frequent that it's impossible to move a mouse faster than how fast the check happens.

@user VADemon: That's essentially what I've written except "repeat until" would mean I'd check it thousands of times per second instead of 100.

Guess I've got no choice but to use faster update in this case

old Re: How to properly update whilst window dragging?

Rainoth
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
Case EVENT_MOUSEMOVE
				For Local Window:TWindow = EachIn ObjectList
					If Window.ID = 21
						If MouseIsDown And MX >= Window.DragX And MX <= Window.DragX + Window.DragW And MY >= Window.DragY And MY <= Window.DragY + 30
							Window.Drag()
						EndIf
					EndIf		
				Next

The thing is, most checks are run inside an if
1
If WaitTimer(GameTimer)
and that timer ticks 100 times per second (it's more than enough for everything but the mouse)

old Re: How to properly update whilst window dragging?

Hurri04
Super User Off Offline

Quote
• simply safe the x and y values of where the cursor is upon pressing down the button (if it happens in the dragging area)
• then in the next update check if the button is still pressed
• if yes, calculate the difference between the current cursor position and the saved one
• move the window by that difference (if the difference is 0 the window will simply stay at the same position)
• safe the new position values into the variables for the old position

old Re: How to properly update whilst window dragging?

Hurri04
Super User Off Offline

Quote
is there a chance that you are checking whether the cursor is still within the dragging area at the update? because that would explain why the window stops moving once you move the cursor outside, like you wrote before.

old Re: How to properly update whilst window dragging?

Rainoth
Moderator Off Offline

Quote
Yes, that's exactly what I'm doing.
By that question, I take it that you're suggesting I check only on the initial click and then drag the window forever until mouse button is released. Is that it?

old Re: How to properly update whilst window dragging?

DannyDeth
User Off Offline

Quote
1
If MouseIsDown
That is your problem. Use mouse down events instead of a final-state for buttons/. Go over the event loop instead of checking final state and this problem will go away.

psuedocode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
dragging_window = value_from_previous_frame
for event in events() do
	if event == mouse_down then
		if over_window then
			dragging_window = window_id
		else
			dragging_window = NULL
		end
	elif event == mouse_up then
		dragging_window = NUL
	elif event == mouse_move then
		if dragging_window != NULL then
			move_window( dragging_window, move_x_amount, move_y_amount )
		end
	end
	/* any other event handling stuff */
end

Remember that a query to the mouse state will always be the state after all events are processed up to the time it was called.
To the start Previous 1 Next To the start
Log in to replyOff Topic overviewForums overview