|
@@ -1,23 +1,22 @@
|
|
using Avalonia;
|
|
using Avalonia;
|
|
using Avalonia.Media;
|
|
using Avalonia.Media;
|
|
-using Drawie.Backend.Core.Numerics;
|
|
|
|
using Drawie.Backend.Core.Surfaces;
|
|
using Drawie.Backend.Core.Surfaces;
|
|
|
|
+using Drawie.Backend.Core.Surfaces.PaintImpl;
|
|
|
|
+using Drawie.Backend.Core.Text;
|
|
using Drawie.Numerics;
|
|
using Drawie.Numerics;
|
|
|
|
+using PixiEditor.UI.Common.Fonts;
|
|
|
|
+using Colors = Drawie.Backend.Core.ColorsImpl.Colors;
|
|
|
|
|
|
namespace PixiEditor.Views.Overlays.Handles;
|
|
namespace PixiEditor.Views.Overlays.Handles;
|
|
|
|
|
|
-public class HandleGlyph
|
|
|
|
|
|
+public abstract class HandleGlyph
|
|
{
|
|
{
|
|
- public DrawingGroup Glyph { get; set; }
|
|
|
|
-
|
|
|
|
public VecD Size { get; set; }
|
|
public VecD Size { get; set; }
|
|
|
|
|
|
- private Rect originalBounds;
|
|
|
|
|
|
+ public VecD Offset { get; set; }
|
|
|
|
|
|
- public HandleGlyph(DrawingGroup glyph)
|
|
|
|
|
|
+ public HandleGlyph()
|
|
{
|
|
{
|
|
- Glyph = glyph;
|
|
|
|
- originalBounds = glyph.GetBounds();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public void Draw(Canvas context, double zoomboxScale, VecD position)
|
|
public void Draw(Canvas context, double zoomboxScale, VecD position)
|
|
@@ -25,26 +24,33 @@ public class HandleGlyph
|
|
VecD scale = NormalizeGlyph(zoomboxScale);
|
|
VecD scale = NormalizeGlyph(zoomboxScale);
|
|
VecD offset = CalculateOffset(zoomboxScale, position);
|
|
VecD offset = CalculateOffset(zoomboxScale, position);
|
|
|
|
|
|
- Glyph.Transform = new MatrixTransform(
|
|
|
|
- new Matrix(
|
|
|
|
- scale.X, 0,
|
|
|
|
- 0, scale.Y,
|
|
|
|
- offset.X, offset.Y)
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- // TODO: Implement
|
|
|
|
- //Glyph.Draw(context);
|
|
|
|
|
|
+ int saved = context.Save();
|
|
|
|
+
|
|
|
|
+ context.Translate((float)offset.X, (float)offset.Y);
|
|
|
|
+ context.Scale((float)scale.X, (float)scale.Y);
|
|
|
|
+
|
|
|
|
+ DrawHandle(context);
|
|
|
|
+
|
|
|
|
+ context.RestoreToCount(saved);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ protected abstract void DrawHandle(Canvas context);
|
|
|
|
+ protected abstract RectD GetBounds();
|
|
|
|
|
|
private VecD CalculateOffset(double zoomboxScale, VecD position)
|
|
private VecD CalculateOffset(double zoomboxScale, VecD position)
|
|
{
|
|
{
|
|
- return new VecD(position.X - Size.X / (zoomboxScale * 2) - originalBounds.Position.X / (zoomboxScale * 2), position.Y - Size.Y / (zoomboxScale * 2) - originalBounds.Position.Y / (zoomboxScale * 2));
|
|
|
|
|
|
+ RectD bounds = GetBounds();
|
|
|
|
+ VecD scaledPosition = position + new VecD(-Size.X / 2f / zoomboxScale, Size.Y / 2f / zoomboxScale);
|
|
|
|
+ VecD scaledOffset = Offset / zoomboxScale;
|
|
|
|
+
|
|
|
|
+ return new VecD(scaledPosition.X, scaledPosition.Y) + scaledOffset;
|
|
}
|
|
}
|
|
|
|
|
|
private VecD NormalizeGlyph(double scale)
|
|
private VecD NormalizeGlyph(double scale)
|
|
{
|
|
{
|
|
- double scaleX = Size.X / originalBounds.Width / scale;
|
|
|
|
- double scaleY = Size.Y / originalBounds.Height / scale;
|
|
|
|
|
|
+ RectD bounds = GetBounds();
|
|
|
|
+ double scaleX = Size.X / bounds.Width / scale;
|
|
|
|
+ double scaleY = Size.Y / bounds.Height / scale;
|
|
|
|
|
|
return new VecD(scaleX, scaleY);
|
|
return new VecD(scaleX, scaleY);
|
|
}
|
|
}
|