Skip to content

Commit

Permalink
Merge pull request #6 from Garume/v0.3.1
Browse files Browse the repository at this point in the history
V0.3.1
  • Loading branch information
Garume authored May 7, 2024
2 parents 1f5ed26 + ee7f413 commit c1a8f95
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
40 changes: 11 additions & 29 deletions Assets/ContextCircleMenu/Editor/Core/ContextCircleMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace ContextCircleMenu.Editor
/// </summary>
public class ContextCircleMenu : VisualElement, IMenuControllable
{
private const float IndicatorSizeDegrees = 70.0f;
private static readonly Color AnnulusColor = new(0.02f, 0.02f, 0.02f, 0.8f);
private static readonly Color MouseAngleIndicatorBackgroundColor = new(0.01f, 0.01f, 0.01f, 1.0f);
private static readonly Color MouseAngleIndicatorForegroundColor = Color.white;
Expand Down Expand Up @@ -128,12 +129,10 @@ private void UpdateMousePosition(MouseMoveEvent evt)
if (!IsVisible) return;
var referenceVector = new Vector2(0f, -1f);
var mouseVector = new Vector2(
evt.mousePosition.x - _position.x,
-evt.mousePosition.y + _position.y).normalized;
var angle = (float)(Math.Atan2(referenceVector.y, referenceVector.x) -
Math.Atan2(mouseVector.y, mouseVector.x)) * (float)(180 / Math.PI);
if (angle < 0) angle += 360.0f;
_currentMouseAngle = angle;
_mousePosition.x - _position.x,
-_mousePosition.y + _position.y).normalized;
_currentMouseAngle = Vector2.SignedAngle(mouseVector, referenceVector);

MarkDirtyRepaint();
}

Expand Down Expand Up @@ -163,35 +162,18 @@ private void OnGenerateVisualContent(MeshGenerationContext context)
{
var position = new Vector2(_width * 0.5f, _height * 0.5f);
var radius = _width * 0.1f;
const float indicatorSizeDegrees = 70.0f;

var startAngle = _currentMouseAngle + 90.0f - IndicatorSizeDegrees * 0.5f;
var endAngle = _currentMouseAngle + 90.0f + IndicatorSizeDegrees * 0.5f;

var painter = context.painter2D;
painter.lineCap = LineCap.Butt;

painter.lineWidth = 8.0f;
painter.strokeColor = AnnulusColor;
painter.BeginPath();
painter.Arc(new Vector2(position.x, position.y), radius, 0.0f, 360.0f);
painter.Stroke();

painter.lineWidth = 8.0f;
painter.strokeColor = MouseAngleIndicatorBackgroundColor;
painter.BeginPath();
painter.Arc(new Vector2(position.x, position.y), radius,
_currentMouseAngle + 90.0f - indicatorSizeDegrees * 0.5f,
_currentMouseAngle + 90.0f + indicatorSizeDegrees * 0.5f);
painter.Stroke();

painter.lineWidth = 4.0f;
painter.strokeColor = MouseAngleIndicatorForegroundColor;
painter.BeginPath();
painter.Arc(new Vector2(position.x, position.y), radius,
_currentMouseAngle + 90.0f - indicatorSizeDegrees * 0.5f,
_currentMouseAngle + 90.0f + indicatorSizeDegrees * 0.5f);
painter.Stroke();
painter.DrawCircle(position, radius, 0f, 360.0f, 8.0f, AnnulusColor);
painter.DrawCircle(position, radius, startAngle, endAngle, 8.0f, MouseAngleIndicatorBackgroundColor);
painter.DrawCircle(position, radius, startAngle, endAngle, 4.0f, MouseAngleIndicatorForegroundColor);
}


/// <summary>
/// Configures and builds the menu based on a provided configuration action.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions Assets/ContextCircleMenu/Editor/Extensions.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Assets/ContextCircleMenu/Editor/Extensions/Painter2DExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.UIElements;

namespace ContextCircleMenu.Editor
{
public static class Painter2DExtension
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void DrawCircle(this Painter2D painter, Vector2 center, float radius, float startAngle,
float endAngle, float lineWidth, Color color)
{
painter.lineWidth = lineWidth;
painter.strokeColor = color;
painter.BeginPath();
painter.Arc(center, radius, startAngle, endAngle);
painter.Stroke();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c1a8f95

Please sign in to comment.