Scrolling around

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: Klaus, FourthWorld, heatherlaine, kevinmiller

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

Scrolling around

Post by richmond62 » Thu Jul 11, 2019 10:56 am

I have a socking great image (about 3000 x 3000 pixels) grouped with scroll bars to a usable size
of 880 x 620 pixels (this is also called "coping with a 1024 x 768 display") . . .

NOW . . . I should like things to be in such a way that when I mouseClick anywhere in that image
the scrollbars will set things so that that position (i.e where I clicked) is slap, bang in the centre
of the visible part of the image).

So far, mouseLoc doesn't help, mainly as what I require is the mouseLoc relative to the image
in which I have clicked.

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

Re: Scrolling around

Post by dunbarx » Thu Jul 11, 2019 1:51 pm

Richmond.

Try this experiment. Make a scrolling field with lots of lines in it, many more than can be displayed, so the scrollbar does a lot of work. Lock the field, and place this in its script;

Code: Select all

on mouseUp
      answer (the top of me - the mouseV) / (the bot of me - the top of me) 
end mouseUp
Click anywhere in the field. You will get a percentage of the distance from the top to the bottom of the field. Use this to set your scroll.

Craig

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

Re: Scrolling around

Post by richmond62 » Thu Jul 11, 2019 7:27 pm

That got me started, although I feel there is something a bit wrong with your numbers.

Here's what I did:

Code: Select all

on mouseUp
   put (((the mouseV) - (top of me)) / 24.84)  into fld "fVERT"
   put (((the mouseH) - (the left of me)) / 24.48 )  into fld "fHORZ"
end mouseUp
Where 2484 is the height of my image, and 2448 is its width: this gives me 2 "tidy" percentages.

If one does something even simpler:

Code: Select all

on mouseUp
   put ((the mouseV) - (top of me))  into fld "fVERT"
   put ((the mouseH) - (the left of me))  into fld "fHORZ"
end mouseUp
one gets the exact pixel position of the mouse position within the grouped image.

Then one can do this:

Code: Select all

on mouseUp
   put ((the mouseV) - (top of me))  into VERT
   put ((the mouseH) - (the left of me))  into HORZ
   set the vScroll of group "map" to (VERT - ((the height of group "map") / 2))
   set the hScroll of group "map" to (HORZ - ((the width of group "map") / 2))
end mouseUp
and it's "So long, and thanks for all the fish." 8)

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

Re: Scrolling around

Post by dunbarx » Thu Jul 11, 2019 9:04 pm

...although I feel there is something a bit wrong with your numbers.
All my quick and dirty ditty did was find the vertical percentage of the mouseClick in the vertical height of the control. That value has to be scaled to make the scroll of the control react properly.

Craig

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

Re: Scrolling around

Post by richmond62 » Thu Jul 11, 2019 9:18 pm

Your
quick and dirty ditty
was wonderful as it set me off in the right direction, and for that I am extremely grateful. :D

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6833
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Scrolling around

Post by FourthWorld » Fri Jul 12, 2019 2:24 am

Small detail, but sometimes helpful: the mouseH and mouseV will reflect the current position of the mouse, so if the user is somewhat active it by the time those values are obtained they may be a few pixels off from the location they clicked at. ClickH and ClickV will give you the last "down" location.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

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

Re: Scrolling around

Post by dunbarx » Fri Jul 12, 2019 5:15 am

Richard is spot on with that tweak.

I am spot off in two ways.

1- There is no "bot" abbreviation for "bottom". That is what made Richmond doubt my "numbers".
2- I should have thought more about the signs.

Code: Select all

on mouseUp
    answer (the clickV - the top of me) / the height of me
end mouseUp
Well, the bridge almost stayed up. Do NOT program while driving. Test your ditties on an actual computer.

Craig
Last edited by dunbarx on Fri Jul 12, 2019 5:37 am, edited 1 time in total.

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

Re: Scrolling around

Post by dunbarx » Fri Jul 12, 2019 5:35 am

I only mention this because I cannot remember if there is a property that indicates the number of vertical "pixels" of the contents of a field. In other words, one solution to Richmond's post is:

Code: Select all

on mouseUp
   set the scroll of me to ((the clickV - the top of me) / the height of me) * (the number of lines of me * the textHeight of me)
end mouseUp
Is there no property that is "the number of lines of me * the textHeight of me"? In other words, the number of vertical pixels of the contents of a field, given its textHeight and the number of lines it holds?

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5105
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Scrolling around

Post by jacque » Fri Jul 12, 2019 4:19 pm

The formattedHeight?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Scrolling around

Post by richmond62 » Fri Jul 12, 2019 4:45 pm

The initial post was anent an large image inwith a group.

Now, while formattedheight might be useful for a textField is will
be of no use for an image.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5105
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Scrolling around

Post by jacque » Fri Jul 12, 2019 6:07 pm

Images have formattedHeight. Is the image used as an imagesource? If so, get the formattedHeight of the original. Imagesource is the only way I can think of to embed an image in a field.

If you want the height of the entire field including the image then formattedHeight should also still work.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Scrolling around

Post by richmond62 » Fri Jul 12, 2019 7:04 pm

Images have formattedHeight.
Thanks for that corrective. :D

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

Re: Scrolling around

Post by dunbarx » Fri Jul 12, 2019 7:38 pm

Jacque nailed it. The "formattedHeight" is just the ticket, since it is a property of images, and the limitation of lines is then moot.

I did just a couple of tests; graphics and scrollbars do not have that property. But groups do.

Craig

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

Re: Scrolling around

Post by richmond62 » Fri Jul 12, 2019 8:25 pm

Jacque nailed it.
No, I don't think she nailed "it."

What she did do is nail one way of achieving the goal.

As you can see, I nailed another way.

This is one of the marvellous features of LiveCode; many roads leading to, err, Rome? :D
-
screw.jpg
Alternative nail?
screw.jpg (3.85 KiB) Viewed 402 times

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”