[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:#()
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:#()
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 didnt work? I see that he just created a new variable named thePos and set thePos = pos, and whats 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
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!