B4J Question B4XPath - InitializeArc at the top point the direction changes

Alexander Stolte

Expert
Licensed User
Longtime User
With this Code:
B4X:
Dim p As B4XPath
Dim angle1 As Int = (mValue1 - mMin) / (mMax - mMin) * 360
Dim angle2 As Int = (mValue2 - mMin) / (mMax - mMin) * 360

If TouchedPanel1 = True Then
    p.InitializeArc(CircleRect.CenterX, CircleRect.CenterY, mBase.Width/2, angle2-90,angle1-angle2)
Else
    p.InitializeArc(CircleRect.CenterX, CircleRect.CenterY, mBase.Width/2, angle1-90,angle2-angle1)
End If
cvs.DrawPath(p, mReachedColor, True, 40dip)
comes the following behavior:

Every time a button enters the top point, the direction of the line is changed, how to prevent this?

Example Project is attached.
Line 157-170
 

Attachments

  • AS RangeRoundSlider.zip
    183.3 KB · Views: 193

klaus

Expert
Licensed User
Longtime User
The problem comes from the calculation of of angle1 and angle2 based on mValue1 and mValue2.
When you calculate mValue you set its limits to 0 = 0° and 100 = 360°.
When you move over the top, the angle you calculate goes from positive values to negative values, no jump.
But then, when you calculate mValue, the small negative angle is converted to a value just below 100 which means a bit less than 360° in the calculaton of the angles for the arc.
When you move over the top, the left part means negative values, but you do not allow negative values.
So, what value do you expect ?
 
Upvote 1

klaus

Expert
Licensed User
Longtime User
You need to check this in the SetValueBasedOn and the Draw routines and depending on the mRollOver property.
Maybe, instead of checking which thumb was activated, check only the two values and draw the thumbs accordingly to these and always roll over
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
How to calculate the degree between the 2 points
Which two points ?
You could memorize the angles, between 0 and 259°, of the two thumbs.
Then when you move, you calculate, in the SetValueBasedOn routine, the angle of the cursor.
Then you can check if the cursor angle is closer to angle1 or angle2 and set it to the cursor angle.
Then check if angle1 > angle2, and if yes, swap the two values.
Just some thoughts.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…