Page 1 of 1
Scrolling around
Posted: Thu Jul 11, 2019 10:56 am
by richmond62
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.
Re: Scrolling around
Posted: Thu Jul 11, 2019 1:51 pm
by dunbarx
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
Re: Scrolling around
Posted: Thu Jul 11, 2019 7:27 pm
by richmond62
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."

Re: Scrolling around
Posted: Thu Jul 11, 2019 9:04 pm
by dunbarx
...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
Re: Scrolling around
Posted: Thu Jul 11, 2019 9:18 pm
by richmond62
Your
quick and dirty ditty
was wonderful as it set me off in the right direction, and for that I am extremely grateful.

Re: Scrolling around
Posted: Fri Jul 12, 2019 2:24 am
by FourthWorld
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.
Re: Scrolling around
Posted: Fri Jul 12, 2019 5:15 am
by dunbarx
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
Re: Scrolling around
Posted: Fri Jul 12, 2019 5:35 am
by dunbarx
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
Re: Scrolling around
Posted: Fri Jul 12, 2019 4:19 pm
by jacque
The formattedHeight?
Re: Scrolling around
Posted: Fri Jul 12, 2019 4:45 pm
by richmond62
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.
Re: Scrolling around
Posted: Fri Jul 12, 2019 6:07 pm
by jacque
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.
Re: Scrolling around
Posted: Fri Jul 12, 2019 7:04 pm
by richmond62
Images have formattedHeight.
Thanks for that corrective.

Re: Scrolling around
Posted: Fri Jul 12, 2019 7:38 pm
by dunbarx
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
Re: Scrolling around
Posted: Fri Jul 12, 2019 8:25 pm
by richmond62
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?
-

- Alternative nail?
- screw.jpg (3.85 KiB) Viewed 6214 times