Resize/move line graph?

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
Summertime01
Posts: 11
Joined: Thu Aug 23, 2018 2:14 pm

Resize/move line graph?

Post by Summertime01 » Tue Sep 18, 2018 10:00 am

Hi all,

For a new project I would like to make it possible for the user to minimize or enlarge a line graph and even drag it to a different location. The panel shows different tables with values and buttons and the idea is that the user may drag the diagram to a place where it's most suitable for his needs. Some of the values or buttons might not be relevant for him and may be hidden by the diagram.

Any ideas how to do this?

Thanks four your help.

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

Re: Resize/move line graph?

Post by [-hh] » Tue Sep 18, 2018 10:40 am

Try the following (line must be thick enough to enable the user to hit the line).
Script of the graphic:

Code: Select all

on mouseDown
    if the topleft of me is not (0,0)
    then set the savedRect of me to the rect of me
    grab me
end mouseDown

on mouseUp b
  if b=3 then -- rightClick
    lock screen
    if the topleft of me is (0,0) then
      set the rect of me to the savedRect of me
    else
      put the savedRect of me into R
      put item 3 of R-item 1 of R into W
      put item 4 of R-item 2 of R into H
      set the width of me to 32
      -- proportional
      set the height of me to 32/W*H
      set the topleft of me to (0,0)
    end if
  end if
end mouseUp
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Resize/move line graph?

Post by dunbarx » Tue Sep 18, 2018 1:50 pm

Hi.

Do I assume you are speaking of a line graph widget?

If so, what is the issue? The widget is simple to drag and resize. What Hermann has offered seems suited more to a polygon graphic.

Craig Newman

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

Re: Resize/move line graph?

Post by [-hh] » Tue Sep 18, 2018 3:02 pm

Craig.

Yes, you are right, he means that (I overlooked it because the word "widget" is missing).

But there is possibly no simple solution because the line graph widget has no mouse events implemented to use for the LC Script side (the user), I looked into the source code: mouseEvents don't reach the widget, they are all captured by the widget.

I have a solution that uses an overlayed blendLevel 99 graphic and timed messages, but that's not simple ...

Hermann
shiftLock happens

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

Re: Resize/move line graph?

Post by [-hh] » Tue Sep 18, 2018 3:13 pm

Sorry, forgot to give my recipe, here it is, should work with any widget (except those that have a native layer, as the browser widget).
  • make a rectangle graphic OVER the widget (bring to front)
  • set its opaque to true
  • set its backColor to white (or whatever, this is the color for the minimized state)
  • set the script of the graphic as follows (updated!)
The rest is done by that script.
Minimize/Maximize by rightClick, drag by grabbing (mouseDown).

Code: Select all

local LG="line graph"

on mouseDown b
  if the topleft of me is not (0,0)
  then set the savedRect of me to the rect of widget LG
  set the rect of me to the rect of widget LG
  set the name of me to LG
  if b=3 or the topleft of me is (0,0) then pass mouseDown
  put the loc of me into lc
  grabMe the mouseH-item 1 of lc,the mouseV-item 2 of lc
end mouseDown

on mouseUp b
  if b <> 3 then pass mouseUp
  -- for rightClick only
  lock screen; lock messages
  if the topleft of me is (0,0) then
    set the rect of me to the savedRect of me
    set the showName of me to false
    set the blendLevel of me to 99
  else
    put the savedRect of me into R
    put item 3 of R-item 1 of R into W
    put item 4 of R-item 2 of R into H
    put 80 into W0 -- or whatever
    set the width of me to W0
    -- proportional
    set the height of me to W0/W*H -- or constant size, say W0/2
    set the topleft of me to (0,0)
    set the blendLevel of me to 0
    set the showName of me to true
  end if
  set the rect of widget LG to the rect of me
end mouseUp

on grabMe dx,dy
  if the mouse is up then exit grabMe
  put (the mouseH-dx,the mouseV-dy) into LC
  set the loc of widget LG to LC
  set the loc of me to LC
  send "grabMe dx,dy" to me in 1 tick
end grabMe
Edit.
Of course you can, instead of changing the rect, simply
  • hide the two objects (graphic and widget) and show a button that on click hides itself and shows again the two objects
    _OR_
  • hide the two objects (graphic and widget), make a snapshot of minimized size of the widget and show this image that on click hides itself and shows again the two objects.
Last edited by [-hh] on Tue Sep 18, 2018 6:32 pm, edited 2 times in total.
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Resize/move line graph?

Post by dunbarx » Tue Sep 18, 2018 4:43 pm

Hermann.

I have never used a widget, but you are right. Messages seem to be blocked in a widget. Even rawKeyDown.

So there is no communication between the LC script and LC builder worlds???

Anyone? Does this seem reasonable? I am not able to determine if the cursor simply enters the widget rect itself? The widget has a script, but that is rather limited in usefulness if no messages can be trapped.

Is it inherent in the nature of widgets?

Craig

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

Re: Resize/move line graph?

Post by [-hh] » Tue Sep 18, 2018 5:11 pm

As I use to say: A widget is not an ordinary control ...

But the author of the widget can implement to pass some messages to LC Script. But this is also a question of functionality and performance of the widget.

Handling mouse messages in widgets:
http://forums.livecode.com/viewtopic.ph ... 46#p126346
shiftLock happens

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

Re: Resize/move line graph?

Post by [-hh] » Wed Sep 19, 2018 4:43 pm

I wrote a utility that lets you resize or grab and move around ANY widget.
And also hide it by rightClick on the drag-handles.

If hidden you have to select it in the contained menu button.

It is all in that single menu button, just copy it to your stack.
More info:
shiftLock happens

Summertime01
Posts: 11
Joined: Thu Aug 23, 2018 2:14 pm

Re: Resize/move line graph?

Post by Summertime01 » Thu Oct 04, 2018 3:20 pm

Thank you so much, Hermann! That's amazing! :D

Summertime01
Posts: 11
Joined: Thu Aug 23, 2018 2:14 pm

Re: Resize/move line graph?

Post by Summertime01 » Mon Oct 08, 2018 10:54 am

There's one question that came up when using the line graph with controls in a standalone:
When I use
## 9,10,11,12: Grab
## __+Cmd- or RightClick: Hide Poly
## __+Shift: Hide Control and Poly
I hide the line graph and/or controls. Is there any simple way of showing them again without restarting the standalone?

Thanks in advance for your ideas.

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

Re: Resize/move line graph?

Post by [-hh] » Thu Oct 18, 2018 4:44 pm

Sorry, I saw this late. You could use, for example, the escapeKey.
Add to your card's script:

Code: Select all

on escapeKey
  do "show " & the label of btn "controlsMenu" --> = the widget
  send "mouseUp" to btn "controlsMenu" --> the handles appear
end escapeKey
shiftLock happens

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”