drag the application window (mainstack)

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ninetrees
Posts: 7
Joined: Thu Apr 22, 2010 6:54 am

drag the application window (mainstack)

Post by ninetrees » Sat May 01, 2010 5:43 am

I'd like to be able to drag the stack around like I would any window by moving the titlebar.
a) How do I make a titlebar visible? If I do get a titlebar does it also have a closebox to quit the app? When I compiled this stack, I discovered there was no Quit/Exit! Do I have to explicitly write a Quit handler?

b) I thought I'd try to make it draggable by adding an object with the following code; it tries to work, but the window jumps rapidly back and forth, as though another msg was trying to put it back where it was while this script is moving it. Ideas for a better way?

Code: Select all

on mouseDown
    -- store the window location
    put the location of this stack into L -- x,y
    put item 1 of L into locH
    put item 2 of L into locV
    -- store the mouse location
    put the mouseH into mH
    put the mouseV into mV
    repeat while the mouse is Down -- add delta mouseloc to window loc
        put locH + (the mouseH - mH) into item 1 of newStackLoc
        put locV + (the mouseV - mV) into item 2 of newStackLoc
        set the location of this stack to  newStackLoc
        put newStackLoc
    end repeat
end mouseDown

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: drag the application window (mainstack)

Post by bn » Sat May 01, 2010 11:09 am

ninetree,
a stacks coordinates are given in global coordinates with respect to the screen. Look at globalLoc / localLoc in the dictionary. You can see this if you put this into the script of a new stack

Code: Select all

on mouseUp
  put "rect of stack in global coordinates: " & the rect of this stack & " rect of card: "& the rect of card 1 of this stack
end mouseUp
the card coordinates are relative to the stack, they are local coordinates.

If you want to use your script I changed it accordingly

Code: Select all

on mouseDown
    -- store the window location
   put the location of this stack into L -- x,y
   put localloc (L) into L
    put item 1 of L into locH
    put item 2 of L into locV
    -- store the mouse location
    put the mouseH into mH
    put the mouseV into mV
    repeat while the mouse is Down -- add delta mouseloc to window loc
        put locH + (the mouseH - mH) into item 1 of newStackLoc
        put locV + (the mouseV - mV) into item 2 of newStackLoc
        set the location of this stack to  globalLoc (newStackLoc)
        put newStackLoc
    end repeat
end mouseDown
What are your decoration settings? In the property inspector for your stack -> basic properties you can set the decorations. The default is that you have a title bar and clicking into the title bar you can drag the stack around.

On a Mac if you dont make any menus you still get the quit menu that quits your application. If you add menus you have to script them, but even without scripting any of the menus there is still the option to quit the app built in.
regards
Bernd

Post Reply