How keep the loc of stack after scalefactor ?

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
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

How keep the loc of stack after scalefactor ?

Post by jmburnod » Mon Nov 17, 2014 2:04 pm

Hi All,
I begin to use scalefactor but I don't found the way to set the loc of stack to the screenLoc after I have used scalefactor.

Code: Select all

   put the scaleFactor of this stack into tCurScale
   add 0.1 to tCurScale
   set the scaleFactor of this stack to tCurScale
   set the loc of this stack to the screenloc
Is there someone have a trick ?
Best regards
Jean-Marc
https://alternatic.ch

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: How keep the loc of stack after scalefactor ?

Post by dave.kilroy » Mon Nov 17, 2014 3:38 pm

Hi Jean-marc

This is how I did it (basically you have to apply your scalefactor to the stack's loc)

Code: Select all

      --finding out about the screen
      put the screenRect into tScreenRectRaw
      put the working screenRect into tScreenRect
      put item 3 of tScreenRect into tScreenW
      put item 2 of tScreenRect - item 2 of tScreenRectRaw into tMenuBarHeight
      put item 4 of tScreenRectRaw - item 4 of tScreenRect into tTaskBarHeight
      put item 4 of tScreenRect - tMenuBarHeight into tScreenH

      --elsewhere I calculate what scaleFactor I need for the app, then I set the stack to it
      set the scaleFactor of stack "Rewind" to tScaleFactor

      --loc for positioning the stack (before scaleFactor)
      put round(tScreenW/2,0) into tAppLocH 
      put 13 into tTitleBarHeight
      put tMenuBarHeight + tTitleBarHeight + round(tScreenH/2,0) into tAppLocV         
      
      --loc for positioning the stack (including scaleFactor)
      put round(tAppLocH / tScaleFactor) into tAppLocH
      put round(tAppLocV / tScaleFactor) into tAppLocV
      set the loc of stack "Rewind" to tAppLocH & comma & tAppLocV
Kind regards
"...this is not the code you are looking for..."

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: How keep the loc of stack after scalefactor ?

Post by [-hh] » Mon Nov 17, 2014 7:23 pm

[Sorry I had to rewrite this, had some copy/paste errors when editing and pasting from scripts.]

Hi all,

Dave's technique is not only good for the screenloc (what he elaborates in more detail), but also when using any *globalLoc* with a scaled stack.

Scale back the globalValue via *dividing* by the scaleFactor:

Code: Select all

-- For example in card script
function globalScaledBack gLoc
  put the scalefactor of this stack into sf
  return  ( round(item 1 of gLoc/sf), round(item 2 of gLoc/sf) ) 
end globalScaledBack

on mouseUp
  set the loc of this stack to \
       globalScaledBack (the screenmouseLoc)
  set loc of btn 1 to localLoc (the screenmouseLoc)
end mouseUp
Note for beginners. If you need the globalLoc converted to a localLoc, the localLoc function works correctly with a scaled stack (7.0.1), you don't have to 'scale back' the globalLoc for such a conversion (see above mouseUp).

I used such scale-back-computations for determining several sizes in the "nixieStack" (Raspi Collection), that can be scaled by rightClick and moved by dragging (uses 'converted' screenMouseLoc).

My opinion is, that it is a "bug", when we have to use our own globalLoc computations. That is, the scalefactor shouldn't change *global* coordinates, because a screen cannot be scaled, it's a physical unit. Certainly it should change, as it does, change the globalToLocal computations.

I already reported this as a bug without success, now it is at least a documentation bug ...
This (hidden) changing of global coordinates by the engine is also the reason why currently a scaled stack can leave the screen if one is changing the scalefactor and tries to "pin up" the stack at it's current topleft or bottomright or loc, but as I said, no success ...

Hermann
shiftLock happens

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: How keep the loc of stack after scalefactor ?

Post by dave.kilroy » Mon Nov 17, 2014 8:54 pm

Nice function Hermann! Focused, to-the-point and elegant :)
"...this is not the code you are looking for..."

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: How keep the loc of stack after scalefactor ?

Post by jmburnod » Mon Nov 17, 2014 11:00 pm

Hi Dave and Hermann,
Thanks for help
I tried to use your ways and both work fine.
In my context (a btn ZoomIn at topleft of cd) Dave's ways works better than Hermann's way. In Hermann's way I understand the mouse must be to the screenLoc. Am I right ?
Anyway, I can now zoom the time line that I build with my students who have a visual deficit
Kind regards
Jean-Marc
https://alternatic.ch

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: How keep the loc of stack after scalefactor ?

Post by [-hh] » Tue Nov 18, 2014 2:03 am

Hi Jean-Marc.
Jean-Marc wrote:I understand the mouse must be to the screenLoc. Am I right ?
Yes, of course. But it's both the same technique. I wanted just give a different example to Dave's one. He uses a perfectly "elaborated" screenloc respecting also other things. If you use

set loc of this stack to globalScaledBack(the screenloc)

you get the same as you awaited to have (and have if the scalefactor is 1) with

set loc of this stack to the screenloc.

I tested this for example with an option button that makes several scalefactors available (say 0.5 in steps of 0.25 to 2.0). Setting it's script to the following will hold your stack always at the screenloc:

Code: Select all

on menuPick pN
  lock screen; lock messages
  set scalefactor of this stack to pN
  put the screenLoc into sL
  set loc of this stack to \
        (round(item 1 of sL / pN), round(item 2 of sl / pN))
  unlock screen; unlock messages
end menuPick
Also you see a current 'property' (I already reported this, some may call it a 'bug'): The textSize of the option button's content is *not* scaled.

[Edit. WARNING for all crazy testers (like me). Don't set scalefactor to 10 or 20, so that it exceeds the screenrect. Yes, this looks great, but LC will forever refuse to reopen your stack after you closed it at this scaled size. If you report this as bug, don't blame me, please ...]
shiftLock happens

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: How keep the loc of stack after scalefactor ?

Post by jmburnod » Tue Nov 18, 2014 9:30 am

Hi Hermann,
Thanks again.
I have confused screenLoc and loc of stack. :shock:
It work fine if we have in our head your alert about limits
https://alternatic.ch

Post Reply