From c6c43262f90e1b9c81486e611cf3afae87dbbf70 Mon Sep 17 00:00:00 2001 From: Debug_pro Date: Thu, 26 Feb 2026 01:09:06 +0300 Subject: [PATCH] Create RectangleFigure.cs --- DrawFigureLibrary/Figures/RectangleFigure.cs | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 DrawFigureLibrary/Figures/RectangleFigure.cs diff --git a/DrawFigureLibrary/Figures/RectangleFigure.cs b/DrawFigureLibrary/Figures/RectangleFigure.cs new file mode 100644 index 0000000..e5e1610 --- /dev/null +++ b/DrawFigureLibrary/Figures/RectangleFigure.cs @@ -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; + } + } + } +}