ex-inh-03-shapes/Shapes/Shapes/Shape.cs
2025-03-16 23:21:14 +01:00

54 lines
2.3 KiB
C#

using Avalonia;
using Avalonia.Media;
namespace Shapes.Shapes;
public abstract class Shape
{
private static int _nextId = 1;
// Ripped from https://github.com/haslingerm/simple-xplat-drawing/blob/master/SimpleDrawing/LeoCanvas.cs#L26
protected const double DefaultLineThickness = 1D;
public int Id { get; }
protected Point Scale;
protected Point Position;
protected double? LineThickness;
protected IBrush? LineColor;
protected IBrush? FillColor;
/// <summary>
/// The base constructor for all shapes
/// </summary>
/// <param name="position">The position of the shape</param>
/// <param name="scale">The scale of the shape</param>
/// <param name="lineThickness">The thickness of the line (optional)</param>
/// <param name="lineColor">The color of the line (optional)</param>
/// <param name="fillColor">The color of the fill (optional)</param>
protected Shape(Point position, Point scale, double? lineThickness = null, IBrush? lineColor = null, IBrush? fillColor = null)
{
Id = _nextId++;
Position = position;
Scale = scale;
LineThickness = lineThickness;
LineColor = lineColor;
FillColor = fillColor;
}
/// <summary>
/// Draws the shape
/// Not specified values will use the stored ones at the instance creation
/// </summary>
/// <param name="position">The position of the shape (optional)</param>
/// <param name="scale">The scale of the shape (optional)</param>
/// <param name="lineThickness">The thickness of the line (optional)</param>
/// <param name="lineColor">The color of the line (optional)</param>
/// <param name="fillColor">The color of the fill (optional)</param>
/// <returns>True if the drawing was successful, false otherwise</returns>
public abstract bool DrawSelf(Point position = default, Point scale = default, double? lineThickness = null, IBrush? lineColor = null, IBrush? fillColor = null);
/// <summary>
/// Checks if the <see cref="mousePoint"/> is inside the shape
/// </summary>
/// <param name="mousePoint">The mouse point</param>
/// <returns>True if the mouse point is inside the shape, false otherwise</returns>
public abstract bool PointInShape(Point mousePoint);
}