Create RectangleFigure.cs
This commit is contained in:
34
DrawFigureLibrary/Figures/RectangleFigure.cs
Normal file
34
DrawFigureLibrary/Figures/RectangleFigure.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace DrawFigureLibrary.Figures
|
||||
{
|
||||
public class RectangleFigure : Figure
|
||||
{
|
||||
public RectangleFigure(string name, int x, int y, int w, int h) : base(name, x, y, w, h) { }
|
||||
|
||||
public override void Draw(DrawingContext drawingContext)
|
||||
{
|
||||
var rect = new Rect(x, y, w, h);
|
||||
drawingContext.DrawRectangle(null, Init.pen, rect);
|
||||
}
|
||||
|
||||
public void Resize(int newW, int newH)
|
||||
{
|
||||
if (newW <= 0 || newH <= 0) throw new ArgumentException("Размеры должны быть > 0");
|
||||
w = newW;
|
||||
h = newH;
|
||||
}
|
||||
|
||||
public override void MoveBy(int deltaX, int deltaY)
|
||||
{
|
||||
if (Init.DrawingImage == null) return;
|
||||
|
||||
if (Figure.Check(this, deltaX, deltaY, Init.DrawingImage))
|
||||
{
|
||||
x += deltaX;
|
||||
y += deltaY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user