@@ -10,6 +10,7 @@ namespace ContextCircleMenu.Editor
1010 /// </summary>
1111 public class ContextCircleMenu : VisualElement , IMenuControllable
1212 {
13+ private const float IndicatorSizeDegrees = 70.0f ;
1314 private static readonly Color AnnulusColor = new ( 0.02f , 0.02f , 0.02f , 0.8f ) ;
1415 private static readonly Color MouseAngleIndicatorBackgroundColor = new ( 0.01f , 0.01f , 0.01f , 1.0f ) ;
1516 private static readonly Color MouseAngleIndicatorForegroundColor = Color . white ;
@@ -128,12 +129,10 @@ private void UpdateMousePosition(MouseMoveEvent evt)
128129 if ( ! IsVisible ) return ;
129130 var referenceVector = new Vector2 ( 0f , - 1f ) ;
130131 var mouseVector = new Vector2 (
131- evt . mousePosition . x - _position . x ,
132- - evt . mousePosition . y + _position . y ) . normalized ;
133- var angle = ( float ) ( Math . Atan2 ( referenceVector . y , referenceVector . x ) -
134- Math . Atan2 ( mouseVector . y , mouseVector . x ) ) * ( float ) ( 180 / Math . PI ) ;
135- if ( angle < 0 ) angle += 360.0f ;
136- _currentMouseAngle = angle ;
132+ _mousePosition . x - _position . x ,
133+ - _mousePosition . y + _position . y ) . normalized ;
134+ _currentMouseAngle = Vector2 . SignedAngle ( mouseVector , referenceVector ) ;
135+
137136 MarkDirtyRepaint ( ) ;
138137 }
139138
@@ -163,35 +162,18 @@ private void OnGenerateVisualContent(MeshGenerationContext context)
163162 {
164163 var position = new Vector2 ( _width * 0.5f , _height * 0.5f ) ;
165164 var radius = _width * 0.1f ;
166- const float indicatorSizeDegrees = 70.0f ;
165+
166+ var startAngle = _currentMouseAngle + 90.0f - IndicatorSizeDegrees * 0.5f ;
167+ var endAngle = _currentMouseAngle + 90.0f + IndicatorSizeDegrees * 0.5f ;
167168
168169 var painter = context . painter2D ;
169170 painter . lineCap = LineCap . Butt ;
170171
171- painter . lineWidth = 8.0f ;
172- painter . strokeColor = AnnulusColor ;
173- painter . BeginPath ( ) ;
174- painter . Arc ( new Vector2 ( position . x , position . y ) , radius , 0.0f , 360.0f ) ;
175- painter . Stroke ( ) ;
176-
177- painter . lineWidth = 8.0f ;
178- painter . strokeColor = MouseAngleIndicatorBackgroundColor ;
179- painter . BeginPath ( ) ;
180- painter . Arc ( new Vector2 ( position . x , position . y ) , radius ,
181- _currentMouseAngle + 90.0f - indicatorSizeDegrees * 0.5f ,
182- _currentMouseAngle + 90.0f + indicatorSizeDegrees * 0.5f ) ;
183- painter . Stroke ( ) ;
184-
185- painter . lineWidth = 4.0f ;
186- painter . strokeColor = MouseAngleIndicatorForegroundColor ;
187- painter . BeginPath ( ) ;
188- painter . Arc ( new Vector2 ( position . x , position . y ) , radius ,
189- _currentMouseAngle + 90.0f - indicatorSizeDegrees * 0.5f ,
190- _currentMouseAngle + 90.0f + indicatorSizeDegrees * 0.5f ) ;
191- painter . Stroke ( ) ;
172+ painter . DrawCircle ( position , radius , 0f , 360.0f , 8.0f , AnnulusColor ) ;
173+ painter . DrawCircle ( position , radius , startAngle , endAngle , 8.0f , MouseAngleIndicatorBackgroundColor ) ;
174+ painter . DrawCircle ( position , radius , startAngle , endAngle , 4.0f , MouseAngleIndicatorForegroundColor ) ;
192175 }
193176
194-
195177 /// <summary>
196178 /// Configures and builds the menu based on a provided configuration action.
197179 /// </summary>
0 commit comments