Scrolling around
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Scrolling around
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.
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.
Re: Scrolling around
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;
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
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
Craig
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Re: Scrolling around
That got me started, although I feel there is something a bit wrong with your numbers.
Here's what I did:
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:
one gets the exact pixel position of the mouse position within the grouped image.
Then one can do this:
and it's "So long, and thanks for all the fish." 
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
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
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

Re: Scrolling around
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....although I feel there is something a bit wrong with your numbers.
Craig
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Re: Scrolling around
Your

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

-
- VIP Livecode Opensource Backer
- Posts: 10049
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Scrolling around
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Scrolling around
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.
Well, the bridge almost stayed up. Do NOT program while driving. Test your ditties on an actual computer.
Craig
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
Craig
Last edited by dunbarx on Fri Jul 12, 2019 5:37 am, edited 1 time in total.
Re: Scrolling around
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:
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
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
Craig
Re: Scrolling around
The formattedHeight?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Re: Scrolling around
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.
Now, while formattedheight might be useful for a textField is will
be of no use for an image.
Re: Scrolling around
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.
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
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Re: Scrolling around
Thanks for that corrective.Images have formattedHeight.

Re: Scrolling around
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
I did just a couple of tests; graphics and scrollbars do not have that property. But groups do.
Craig
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Re: Scrolling around
No, I don't think she nailed "it."Jacque 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?

-