Dragging windows with windowShape?

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
thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 383
Joined: Mon Mar 01, 2010 7:13 pm
Contact:

Dragging windows with windowShape?

Post by thatkeith » Mon Jan 06, 2014 3:37 pm

I'm having lots of fun with windowShape – reminds me of the old RadWindow trick from back in the day. But I'm stumped over the (I hope) simple task of dragging the window.

How do I script the process of the user dragging the window around when it's in a custom windowShape and has no title bar?

(I've tried searching here, but it's a bit difficult when the forum won't let me search for "window"! :D )

k
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Dragging windows with windowShape?

Post by FourthWorld » Mon Jan 06, 2014 4:22 pm

When making a custom window, you're making a truly custom window: you can have any controls you like, but you'll need to script their behaviors yourself.

The mouseMove message is an ideal way to handle mouse tracking on drags, but you'll have to keep a flag noting when the mouse is down and when it's not.

T?his may help, from a custom window I'm using in a new version of my devolution tool palette, which not only handles the dragging but also prevents dragging below the top visible bounds of the monitor (accounting for the menu bar on OS X and the top panel on Ubuntu and most other Linux distros) - just put this script in whatever graphic, button, or other object you're using for your drag region:

Code: Select all

local sDownDelta

on mouseDown
   put the clickloc into sDownDelta
end mouseDown

on mouseMove
   if sDownDelta is not empty then
      put item 1 of the screenMouseLoc into x
      put item 2 of the screenMouseLoc into y
      
      switch the platform 
         case "MacOS"
            put item 2 of the windowBoundingRect into tMinY
            break
         case "Linux"
            put 24+ item 2 of the screenRect into tMinY
            break
         case "Win32"
            put 0 into tMinY
      end switch
      put item 1 of the windowBoundingRect into tMinX
      --
      set the topleft of this stack to \
            max(tMinX, (x-item 1 of sDownDelta)),\
      max(tMinY, (y-item 2 of sDownDelta) ) 
   end if
end mouseMove


on mouseRelease
      put empty into sDownDelta
end mouseRelease

on mouseUp
   put empty into sDownDelta
end mouseUp
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10332
Joined: Wed May 06, 2009 2:28 pm

Re: Dragging windows with windowShape?

Post by dunbarx » Mon Jan 06, 2014 4:28 pm

Try this in the card script:

Code: Select all

local tOffset
on mouseDown
   put the mouseLoc into tOffset
end mouseDown

on mouseMove
   put the loc of this stack into tScreen
   put the mouseLoc into tMouse
      set the loc of  this stack to item 1 of tScreen + item 1 of tMouse - item 1 of tOffset & "," & item 2 of tScreen + item 2 of tMouse - item 2 of tOffset
end mouseMove
EDIT. Per Richard, I keep forgetting to go Modern. "MouseMove" is smoother than mouseStillDown

I originally placed this in the stack script.

Try it. It does not work, because neither "mousemove" nor "mouseStillDown" is received by the stack script handler. Why?

Craig Newman
Last edited by dunbarx on Mon Jan 06, 2014 5:08 pm, edited 2 times in total.

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

Re: Dragging windows with windowShape?

Post by bn » Mon Jan 06, 2014 4:47 pm

Hi Keith,

a sample stack that shows some windowShape stuff including moving the stack around can be found here:

http://forums.runrev.com/phpBB2/viewtop ... =15#p82157

Kind regards
Bernd

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

Re: Dragging windows with windowShape?

Post by bn » Mon Jan 06, 2014 5:23 pm

Hi,
@Keith,
apparently Windows 7 and higher does not like the stack size to be larger than the skinning image, the non-skinned part shines through
http://forums.runrev.com/phpBB2/viewtop ... =9&t=18047

Kind regards
Bernd

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 383
Joined: Mon Mar 01, 2010 7:13 pm
Contact:

Re: Dragging windows with windowShape?

Post by thatkeith » Tue Jan 07, 2014 9:50 am

@Richard, @Craig, @Bernd, thanks very much for the responses! This looks logical and useful, I'll give it a whirl as soon as I'm done with teaching today.

k
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

Post Reply