Create Figure.cs
This commit is contained in:
44
DrawFigureLibrary/Figure.cs
Normal file
44
DrawFigureLibrary/Figure.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace DrawFigureLibrary
|
||||
{
|
||||
public abstract class Figure
|
||||
{
|
||||
public string? Name { get; }
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
public int w;
|
||||
public int h;
|
||||
|
||||
public Figure(string name, int x, int y, int w, int h)
|
||||
{
|
||||
this.Name = name;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
public abstract void Draw(DrawingContext ctx);
|
||||
|
||||
public abstract void MoveBy(int dX, int dY);
|
||||
|
||||
public override string ToString() => Name ?? "";
|
||||
|
||||
public static bool Check(Figure fig, int dX, int dY, Image img) => fig.x + dX >= 0 && fig.y + dY >= 0 && fig.x + dX + fig.w <= img.ActualWidth && fig.y + dY + fig.h <= img.ActualHeight;
|
||||
|
||||
public virtual bool HitTest(Point p) => p.X >= x && p.X <= x + w && p.Y >= y && p.Y <= y + h;
|
||||
|
||||
public virtual bool MoveByChecked(int dX, int dY)
|
||||
{
|
||||
if (Init.DrawingImage == null) return false;
|
||||
if (!Check(this, dX, dY, Init.DrawingImage)) return false;
|
||||
|
||||
MoveBy(dX, dY);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user