Expanding one's mind

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
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Expanding one's mind

Post by richmond62 » Sat Sep 21, 2019 11:31 am

Resizer.png
-
The idea behind this stack is to be able to resize it (and, ultimately,
and objects on the card that might need resizing and/or repositioning)
via grabbing and dragging the brown graphic circle in the bottom, right hand corner.

The 'only' problem is that there is a considerable lag between a grab-N-drag
and the mouseStillDown script firing to perform a resize.

Code: Select all

on mouseDown
   grab me
end mouseDown

on mouseStillDown
   put the bottom of grc "DRAGGER" into BUM
   put the right of grc "DRAGGER" into RITE
   if RITE < 400 then
      set the width of stack "RESIZER" to 400
   else
      set the width of stack "RESIZER" to RITE
   end if
   if BUM < 400 then
      set the height of stack "RESIZER" to 400
   else
      set the height of stack "RESIZER" to BUM
   end if
   set the top of stack "RESIZER" to 150
end mouseStillDown

on mouseUp
   put the bottom of grc "DRAGGER" into BUM
   put the right of grc "DRAGGER" into RITE
   if RITE < 400 then
      set the width of stack "RESIZER" to 400
      set the right of grc "DRAGGER" to 400
   else
      set the width of stack "RESIZER" to RITE
   end if
   if BUM < 400 then
      set the height of stack "RESIZER" to 400
      set the bottom of grc "DRAGGER" to 400
   else
      set the height of stack "RESIZER" to BUM
   end if
   set the top of stack "RESIZER" to 150
end mouseUp
Attachments
RESIZER.livecode.zip
Here's the stack.
(15.76 KiB) Downloaded 166 times

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

Re: Expanding one's mind

Post by [-hh] » Sat Sep 21, 2019 12:30 pm

This will not work as "grab" eats the movements.
Instead you could use an own resizing routine with a button only, for example:

Code: Select all

on resizeMe dx,dy
  if the mouse is up then exit resizeMe
  lock screen; put the screenMouseLoc into smL
  put item 1 of smL+dx into x; put item 2 of smL+dy into y
  set rect of this stack to (the topleft of this stack,x,y)
  set bottomRight of me to localLoc((x-1,y-1))
  send "resizeMe dx,dy" to me in 3 ticks
end resizeMe

on mouseDown
  put the right of me - the mouseH into dx
  put the bottom of me - the mouseV into dy
  resizeMe dx,dy
end mouseDown
Then adjust object sizes using resizeStack or the (buggy) geometry manager.
shiftLock happens

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Expanding one's mind

Post by richmond62 » Sat Sep 21, 2019 12:34 pm

the (buggy) geometry manager
Quite: worth avoiding.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Expanding one's mind

Post by richmond62 » Sat Sep 21, 2019 12:48 pm

Instead you could use an own resizing routine with a button only
Looks marvellous, BUT how am I to enable the mouse so it can be moved in the first place?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Expanding one's mind

Post by richmond62 » Sat Sep 21, 2019 1:14 pm

Harrumph . . .

So, I got something sorted out 'just' by keeping the stack resizeable, and resizing via
either the bottom, the right or the bottom-right of the stack, but could not
quite sort out how to have minimal size restraints that worked:
-
Resizer2.png
-

Code: Select all

on resizeStack RITE, BUM
   put BUM into fld "fBUM"
   put RITE into fld "fRITE"
   --if RITE < 400 then
      --set the width of stack "RESIZER2" to 400
   --end if
   --if BUM < 400 then
      --set the height of stack "RESIZER2" to 400
   --end if
   set the width of grc "rr2" to RITE
   set the loc of grc "rr2" to (RITE / 2), (BUM / 2)
   set the height of grc "rr1" to BUM
   set the loc of grc "rr1" to (RITE / 2), (BUM / 2)
end resizeStack
My attempts at constraints are commented out because
ALL they seemed to do was stop the scaling of the graphics on the stack.
Attachments
RESIZER2.livecode.zip
Here's the stack.
(1.14 KiB) Downloaded 135 times
Last edited by richmond62 on Sat Sep 21, 2019 1:16 pm, edited 1 time in total.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Expanding one's mind

Post by Klaus » Sat Sep 21, 2019 1:15 pm

richmond62 wrote:
Sat Sep 21, 2019 12:48 pm
Instead you could use an own resizing routine with a button only
Looks marvellous, BUT how am I to enable the mouse so it can be moved in the first place?
It is all in the script, why not just ry it out?
Hermann knows what he is doing! :D

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Expanding one's mind

Post by richmond62 » Sat Sep 21, 2019 1:23 pm

It is all in the script
Well, indeed, but we have arrived at 2 solutions,
neither of which seem to allow one to have some constraints.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Expanding one's mind

Post by Klaus » Sat Sep 21, 2019 1:25 pm

You can "hook" into Hermanns "resizeme" script to add your constraints right before setting the stacks rect.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Expanding one's mind

Post by richmond62 » Sat Sep 21, 2019 1:35 pm

Perhaps I'm missing something . . .

Wonder why, If I put:

Code: Select all

set the width of stack "STRANGEFRUIT" to 700
in the massageBox, or in a button that does exactly what I want it to,

But this:

Code: Select all

if the width of stack "STRANGEFRUIT" < 400 then
set the width of stack "STRANGEFRUIT" to 400
end if
nothing happens.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Expanding one's mind

Post by richmond62 » Sat Sep 21, 2019 2:27 pm

Oddly enough this works:

Code: Select all

on mouseUp
   put the width of stack "RESIZER2" into WIDD
   put the height of stack "RESIZER2" into HITE
   if WIDD < 400 then 
      set the width of stack "RESIZER2" to 400
      set the width of grc "rr2" to 400
      set the loc of grc "rr2" to 200,200
   end if
   if HITE < 400 then 
      set the height of stack "RESIZER2" to 400
      set the height of grc "rr1" to 400
      set the loc of grc "rr1" to 200,200
   end if
end mouseUp
BUT send "mouseUp" to button "Constrain" does NOT work inside an on resizeStack statement.

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

Re: Expanding one's mind

Post by [-hh] » Sat Sep 21, 2019 3:10 pm

Klaus wrote:add your constraints right before setting the stacks rect.
This is one way to do that:

Code: Select all

-- script for a button "Resize"
on resizeMe dx,dy,L,T,minW,minH,maxW,maxH
  if the mouse is up then exit resizeMe
  lock screen; put the screenMouseLoc into smL
  put min(L+maxW,max(L+minW,dx+item 1 of smL)) into W
  put min(T+maxH,max(T+minH,dy+item 2 of smL)) into H
  set rect of this stack to (L,T,W,H)
  set bottomRight of me to localLoc((W-1,H-1)) -- 1=borderWidth
  send "resizeMe dx,dy,L,T,minW,minH,maxW,maxH" to me in 2 ticks
end resizeMe

on mouseDown
  put the right of me - the mouseH into dx
  put the bottom of me - the mouseV into dy
  put the left of this stack into L
  put the top of this stack into T
  ##-- set numbers for minW,minH or use minWidth,minHeight
  --  put the minWidth of this stack into minW
  --  put the minHeight of this stack into minH
  put 280 into minW
  put 210 into minH
  ##-- set numbers for maxW,maxH or use maxWidth,maxHeight
  --  put the maxWidth of this stack into minW
  --  put the maxHeight of this stack into minH
  put 800 into maxW
  put 600 into maxH
  resizeMe dx,dy,L,T,minW,minH,maxW,maxH
end mouseDown
This is a possible resizeStack handler, works also when the user resizes with usual handles:

Code: Select all

-- put into card script or stack script
on resizeStack newW,newH,oldW,oldH
  put newW-oldW into dW; put newH-oldH into dH
  put newW/2,newH/2 into lc
  set width of grc "rr1"  to dW+the width of grc "rr1" -- the horizontal graphic
  set height of grc "rr2" to dH+the height of grc "rr2" -- the vertical graphic
  # graphics are centered:
  set loc of grc "rr1" to lc; set loc of grc "rr2" to lc
  set bottomRight of button "Resize" to newW-1,newH-1 -- 1=borderWidth
end resizeStack
And here is a short script (I use) for grabbing the stack window, so you can use all that with a window without titlebar (for example if using a windowshape):

Code: Select all

-- Put into stack script. If it should arrive here then
-- pass mouseDown where used before in the message path
on mouseDown b
  put the width of this stack into w
  put the height of this stack into h
  dragMe the clickH,the clickV,w,h
end mouseDown

on dragMe x,y,w,h -- x,y = the loc of dragging cursor
  if the mouse is up then
    killDrags; exit dragMe
  end if
  put item 1 of the screenMouseloc into sx
  put item 2 of the screenMouseloc into sy
  set rect of this stack to (sx-x,sy-y,w+sx-x,h+sy-y)
  send "dragMe x,y,w,h" to me in 2 ticks
end dragMe

on killDrags
  repeat 2
    repeat for each line L in the pendingMessages
      if "dragMe" is item 3 of L then cancel item 1 of L
    end repeat
  end repeat
end killDrags

Have fun, and keep making fine education stacks!
shiftLock happens

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Expanding one's mind

Post by richmond62 » Sat Sep 21, 2019 6:34 pm

Thanks -hh . . .
-
Screenshot 2019-09-21 at 20.31.21.png
-
I used your initial script and modified it, along with a mouseUp statement to constrain the maximum resize
(I also renamed your variable so I will be able to remember what they are meant to do in 5 years time) 8)

All in the button "RESIZE":

Code: Select all

on resizeMe RITE, BUM
   if the mouse is up then exit resizeMe
   lock screen; put the screenMouseLoc into smL
   put item 1 of smL+ RITE into x; put item 2 of smL+ BUM into y
   set rect of this stack to (the topleft of this stack,x,y)
   put the width of this stack into WIDD
   put the height of this stack into HITE
   set bottomRight of me to localLoc((x-1,y-1))
   set the height of grc "rr1" to HITE
   set the top of grc "rr1" to 0
   set the left of grc "rr1" to ((WIDD /2 ) - 40)
   set the width of grc "rr2" to WIDD
   set the left of grc "rr2" to 0
   set the top of grc "rr2" to ((HITE /2) - 40)
   send "resizeMe RITE, BUM" to me in 3 ticks
end resizeMe

on mouseDown
   put the right of me - the mouseH into RITE
   put the bottom of me - the mouseV into BUM
   resizeMe RITE, BUM
end mouseDown

on mouseUp
   if the width of stack "RESIZER3" < 400 then
      set the width of stack "RESIZER3" to 400
      set the right of me to 400
      set the top of grc "rr2" to 160
      set the width of grc "rr2" to 400
      set the left of grc "rr2" to 0
   end if
   if the height of stack "RESIZER3" < 400 then
      set the height of stack "RESIZER3" to 400
      set the bottom of me to 400
      set the left of grc "rr1" to 160
      set the height of grc "rr1" to 400
      set the top of grc "rr1" to 0
   end if
   set the top of stack "RESIZER3" to 100
   set the left of stack "RESIZER3" to 100
end mouseUp
-
Resizer3.png
Attachments
RESIZER3.livecode.zip
Here's the stack.
(1.3 KiB) Downloaded 133 times

bwmilby
Posts: 439
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Expanding one's mind

Post by bwmilby » Sun Sep 22, 2019 1:04 am

Why not use the min/max width/height properties of the stack?
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9387
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Expanding one's mind

Post by richmond62 » Sun Sep 22, 2019 9:21 pm

Why not use the min/max width/height properties of the stack?
Not for any obvious reason beyond what a temperature of 103 degrees Fahrenheit did
to my brain when I was working that out. :D

Unlike the rumours flying around about Bill "someone" and HyperCard
I get my hallucinations free of charge. 8)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”