dunbarx wrote: ↑Mon Sep 20, 2021 2:27 pm
MoveAlongOval.livecode.zip
Craig
Thanks Craig - i appreciate it but it was not quite what i was looking for.
I can make the graphic move programmatically along predefined points, but that's not the question.
The question is that is the users grabs the maker graphic and moves it, how to make sure it stays on the circle and just moves around it's circumference while the user is dragging it. More like a radial dial?
Or am i missing the obvious? (fully possible)
Anyway it occurred to me that i had already figured out above how to position the marker based on the arcAngle of the circle. Then it dawned on me that all i needed to do was calculate the angle between the marker (mouseLoc) and the x axis, in the same fashion arcAngle would work and pass that angle to my previous handler.
This solution works.
It works fantastically in 9.6.2 RC2 - super quick.
Unfortunately from 9.6.2 RC3 onwards, including the illustrious and premium priced 9.6.4, there has been a significant slowing of anything involving graphics (bug reported). This can be mitigated with frivolous use of 'lock screen' but doesn't quite make it as good as on 9.6.2 RC2.
This means that using LC more recent that 9.6.2 RC2 is slower, and a slight 'ghost' of the marker appears
transiently as the user is dragging the marker.
Not sure what to do about that...
For the curious, to calculate the angle between the dragged marker and the horizontal plane in the same way as an arcAngle, i found helpful advice on
StackOverflow
The handler is to calculate the angle is:
Code: Select all
function getAngleFromMouselocForCircle pCircle
local x1, y1, x2, y2, x3, y3, tAngle
put item 1 of the loc of pCircle into x1
put item 2 of the loc of pCircle into y1
put item 1 of the loc of pCircle + the width of pCircle/2 into x2
put item 2 of the loc of pCircle into y2
put item 1 of the mouseLoc into x3
put item 2 of the mouseLoc into y3
put atan2(y3- y1, x3 - x1) - atan2(y2 - y1, x2 - x1) into tAngle // in radians, needs transform
put 180 + round ( tAngle * (180 / pi), 0) into tAngle // 1st transform to make it suitable for arcAngle
if tAngle <= 180 then // 2nd transform to make it suitable for arcAngle
put 180 - tAngle into tAngle
else
put 360 - (tAngle - 180) into tAngle
end if
return tAngle
end getAngleFromMouselocForCircle
in the script for the marker graphic ("knob"), i calculate the angle of the centre of the graphic the user is dragging to the x-axis of the circle, assign this to the arcAngle of the circle and then change it's location based on this:
Code: Select all
on mouseDown
lock screen
grab me
end mouseDown
on mouseMove
if the mouse is up then pass mouseMove
lock screen
setMarkerPosition
end mouseMove
on mouseUp
setMarkerPosition
end mouseUp
command setMarkerPosition
lock screen
set the arcAngle of grc "circle" to getAngleFromMouselocForCircle(the long id of grc "circle")
set the loc of me to getXYfromAngleOfCircle(the long id of grc "circle")
set the thumbPosition of scrollbar "scrollbar" to the arcAngle of graphic "circle" // cosmetic
end setMarkerPosition
It's quite possible i've gone about this the wrong way - please do point out if there are easier/simpler/faster ways! (i'm sure there are...).
My test stack is attached - drag the little blue circle
