Skip to content

Commit c1a8f95

Browse files
authored
Merge pull request #6 from Garume/v0.3.1
V0.3.1
2 parents 1f5ed26 + ee7f413 commit c1a8f95

File tree

4 files changed

+37
-29
lines changed

4 files changed

+37
-29
lines changed

Assets/ContextCircleMenu/Editor/Core/ContextCircleMenu.cs

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

Assets/ContextCircleMenu/Editor/Extensions.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Runtime.CompilerServices;
2+
using UnityEngine;
3+
using UnityEngine.UIElements;
4+
5+
namespace ContextCircleMenu.Editor
6+
{
7+
public static class Painter2DExtension
8+
{
9+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
10+
public static void DrawCircle(this Painter2D painter, Vector2 center, float radius, float startAngle,
11+
float endAngle, float lineWidth, Color color)
12+
{
13+
painter.lineWidth = lineWidth;
14+
painter.strokeColor = color;
15+
painter.BeginPath();
16+
painter.Arc(center, radius, startAngle, endAngle);
17+
painter.Stroke();
18+
}
19+
}
20+
}

Assets/ContextCircleMenu/Editor/Extensions/Painter2DExtension.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)