Maybe this is a noob question...

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Cyberqat
Posts: 24
Joined: Thu Jun 10, 2010 5:38 pm

Maybe this is a noob question...

Post by Cyberqat » Wed Apr 01, 2015 3:00 am

But, how do I set the location on the screen of a stack? The code below creates the stack, and if I examine the size and position properties I can see that the Location property gets set to 0,0. But the stack stays where it was created on screen. Do i need to call some form of refresh? This is on OSX.

Code: Select all

on dragStart
   set the dragData["files"] to empty
   set the dragImage to the id of me
   set the allowableDragActions to "copy"
   set the dragAction to "copy"
   pass dragStart
end dragStart



on dragEnd
  CreateNewDBStack("New Databse Stack", "Default.sdb")
end dragEnd

command CreateNewDBStack  pNewStackName, pDBname
      #create stack
   create stack pNewStackName
   put it into tTheNewStack
   #put the screenMouseLoc into gMousePos
   put 0,0 into gMousePos
   set the loc of tTheNewStack to  gMousePos
   #set the loc of tTheNewStack to the screenLoc
   set the DBPath of tTheNewStack to pDBName
   #create DBscript on stack
   #local tScript
   #put "global gDBConnectionID"&cr into tScript
   #put "command onPreOpenStack"&cr after tScript
   #put "   library stack "&quote&"DatabaseLibrary.livecode"&quote&cr  after tScript
   #put "   put the DBPath of me into tDBPath"&cr after tScript
   #put "   put databaseConnect(tDBPath) into gDBConnectionID" &cr after tScript
   #put "end onPreOpenStack" after tScript
   #set the script of tTheNewStack to tScript
end CreateNewDBStack

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

Re: Maybe this is a noob question...

Post by dunbarx » Wed Apr 01, 2015 4:14 am

Hi.

The loc of a stack on the screen, is, er, the loc of the stack on the screen.

Just set it. Try it.

Craig Newman

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Maybe this is a noob question...

Post by Klaus » Wed Apr 01, 2015 2:04 pm

Hi Cyberqat,

what Craig said!

But you do not want to set the loc of your stack to 0,0! 8)

"the loc" of an object means the CENTER POINT of an object, so if you set your stack to 0,0 ypou will only see the bottomright quarter of the stack!
AND setting the loc of a stack will use GLOBAL (monitor!) and not LOCAL (stack!) coordinates!

Know what I mean?

Maybe you want to center the stack on the monitor:

Code: Select all

command CreateNewDBStack  pNewStackName, pDBname
   create stack pNewStackName
   put it into tTheNewStack
   ## put 0,0 into gMousePos
   set the loc of tTheNewStack to the screenloc
...
And remember that you can also set -> the left, the right, the top, the bottom of a stack if that will fit better in the current situation.


Best

Klaus

Cyberqat
Posts: 24
Joined: Thu Jun 10, 2010 5:38 pm

Re: Maybe this is a noob question...

Post by Cyberqat » Thu Apr 02, 2015 4:16 am

So... 0,0 just fails, apparently you cannot set it to offscreen on the mac

HOWEVER the screenLoc works for centering.

So, i *think* my problem in my code that tries to put it where the mouse is, is that Im getting the mouse position in the
wrong coordinate system. How do I get the current mouse position in screen coordinates?

Cyberqat
Posts: 24
Joined: Thu Jun 10, 2010 5:38 pm

Re: Maybe this is a noob question...

Post by Cyberqat » Thu Apr 02, 2015 4:30 am

Okay... after some playing around I think the answer is that I can't read the mouse location on screen when the cursor is outside of any stack.

Is there a lower level way around this to get the real mouse cursor location when its not ontop of a stack?

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Maybe this is a noob question...

Post by Dixie » Thu Apr 02, 2015 9:12 am

No, but there is a trick to try...

I have attached a stack for you to look at... the stack has a substack. On opening, the rect of the main stack is set to the screenRect and its blendLevel is set to 95 so that you don't notice it... the second stack is then opened... Now if you move the mouse you are able to get the mouse coords of anywhere on the screen... out side of the second stack, but within the main stack that you can't see...:-)

the script is in the stack script of the main stack... hope it helps !...:-)
Attachments
globalLoc.livecode.zip
(1.27 KiB) Downloaded 276 times

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Maybe this is a noob question...

Post by jacque » Thu Apr 02, 2015 5:44 pm

Cyberqat wrote:Okay... after some playing around I think the answer is that I can't read the mouse location on screen when the cursor is outside of any stack.
I don't have any trouble when I do this from the message box: put the mouseloc. Does that fail for you? For converting local coordinates to global screen coordinates, see "globalLoc" in the dictionary.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

PBH
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 132
Joined: Sun Feb 20, 2011 4:26 pm
Contact:

Re: Maybe this is a noob question...

Post by PBH » Fri Apr 03, 2015 2:21 am

If you haven't cracked this yet, it looks to me like you were very close with your original script. I just made a couple of small changes and this works fine as far as I can see…

Code: Select all

      #create stack
   create invisible stack pNewStackName
   put it into tTheNewStack
   put the screenMouseLoc into gMousePos
   set the topLeft of tTheNewStack to gMousePos
   set the DBPath of tTheNewStack to pDBName
   set the visible of stack tTheNewStack to true

The changes I made are; setting the topLeft instead of the loc (just because it seems more logical to me) and creating the stack invisibly to avoid seeing it move from the default position to the screenMouseLoc.

HTH

Paul

Post Reply