Notifications
Clear all

[Closed] How can I drag the dialog window?

Hello everyone!

How can I drag the dialog, I mean click down left button on the title bar then move mouse to change the position of the dialog, via moving the mouse within the dialog client window?

This is my Script but that doesn’t work.

 
rollout posChangeTest "Pos Change"
(
	button bt1 "Button1"
	button bt2 "Button2"
 
	local mouseDown
 
	fn moveRollout =
	(
		SetDialogPos posChangeTest ((mouse.screenpos) - pos)
	)
 
	on posChangeTest lbuttondown pos do
		mouseDown = true
 
	on posChangeTest lbuttonup pos do
		mouseDown = false
 
	on posChangeTest mousemove pos do
		if mouseDown = true do
			moveRollout()	
)
 
createDialog posChangeTest style:#()

9 Replies

well for one thing you should send the mouse move pos to the function as it is erroring on pos not being in scope.
And maybe set mouseDown to false initially.
Still dosent work too well though!

try (destroydialog posChangeTest) catch()
rollout posChangeTest "Pos Change"
(
	button bt1 "Button1"
	button bt2 "Button2"
 
	local mouseDown = false
 
	fn moveRollout pos =
	(
		SetDialogPos posChangeTest ((mouse.screenpos) - pos)
	)
 
	on posChangeTest lbuttondown pos do
		mouseDown = true
 
	on posChangeTest lbuttonup pos do
		mouseDown = false
 
	on posChangeTest mousemove pos do
		if mouseDown = true do
			moveRollout pos
)
 
createDialog posChangeTest style:#()

I found it still didn’t work.

So how shall we do?

My friend SITT have fixed my script to the following:

 
try(destroyDialog posChangeTest) catch()
rollout posChangeTest "Pos Change"
(
	button bt1 "Close"
 
	local mouseIsDown = false,thePos = [0,0]
 
	on posChangeTest lbuttondown pos do
		(mouseIsDown = true ; thePos = pos)
	on posChangeTest lbuttonup pos do
		mouseIsDown = false
	on posChangeTest mousemove pos do if mouseIsDown do 
		setDialogPos posChangeTest (mouse.screenpos - thePos)
 
	on bt1 pressed do destroyDialog posChangeTest
)
createDialog posChangeTest style:#()
 

This time it works perfectly.
But why? Why my first script didn’t work? I see that he just created a new variable named thePos and set thePos = pos, and what’s the difference?

he did a bit more than that, but Im not sure why it worked… Something to do with getting rid of the function maybe?

I use the same for my scripts, The pos of the mouse must be saved once to get it relative to the dialog

1 Reply
(@jausn)
Joined: 11 months ago

Posts: 0

I’ve thought about it much and I agree with you!

Also in your original script you had written:

if mouseDown = true do

when it should be

if mouseDown == true do
 -- note the double equals sign!
2 Replies
(@jausn)
Joined: 11 months ago

Posts: 0

Thank you!
Yeah,you were right.But what you said seems not to be the big issue.

(@gravey)
Joined: 11 months ago

Posts: 0

yea just thought i’d throw it in there anyway for future reference