Page 1 of 1

Maybe this is a noob question...

Posted: Wed Apr 01, 2015 3:00 am
by Cyberqat
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

Re: Maybe this is a noob question...

Posted: Wed Apr 01, 2015 4:14 am
by dunbarx
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

Re: Maybe this is a noob question...

Posted: Wed Apr 01, 2015 2:04 pm
by Klaus
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

Re: Maybe this is a noob question...

Posted: Thu Apr 02, 2015 4:16 am
by Cyberqat
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?

Re: Maybe this is a noob question...

Posted: Thu Apr 02, 2015 4:30 am
by Cyberqat
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?

Re: Maybe this is a noob question...

Posted: Thu Apr 02, 2015 9:12 am
by Dixie
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 !...:-)

Re: Maybe this is a noob question...

Posted: Thu Apr 02, 2015 5:44 pm
by jacque
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.

Re: Maybe this is a noob question...

Posted: Fri Apr 03, 2015 2:21 am
by PBH
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