From 8b930c99d4b477ba145f8f6bccd70ead95e0a14a Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Tue, 27 Feb 2024 13:55:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BE?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectSeaplane/DrawningSeaplane.cs | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/ProjectSeaplane/ProjectSeaplane/DrawningSeaplane.cs b/ProjectSeaplane/ProjectSeaplane/DrawningSeaplane.cs index 72eba68..fddee39 100644 --- a/ProjectSeaplane/ProjectSeaplane/DrawningSeaplane.cs +++ b/ProjectSeaplane/ProjectSeaplane/DrawningSeaplane.cs @@ -66,10 +66,19 @@ public class DrawningSeaplane /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах public bool SetPictureSize(int width, int height) { - // TODO проверка, что объект "влезает" в размеры поля - // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена + + + if (height < _drawningSeaplaneHeight || width < _drawningSeaplaneWidth) + { + return false; + } + + _pictureWidth = width; _pictureHeight = height; + + if (_startPosX.HasValue && _drawningSeaplaneWidth + _startPosX > width) _startPosX = _pictureWidth - _drawningSeaplaneWidth; + if (_startPosY.HasValue && _drawningSeaplaneHeight + _startPosY > height) _startPosY = _pictureHeight - _drawningSeaplaneHeight; return true; } @@ -84,8 +93,22 @@ public class DrawningSeaplane { return; } - // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы - // то надо изменить координаты, чтобы он оставался в этих границах + if (x < 0) + { + x = 0; + } + if (x + _drawningSeaplaneWidth > _pictureWidth.Value) + { + x = _pictureWidth.Value - _drawningSeaplaneWidth; + } + if (y < 0) + { + y = 0; + } + if (y + _drawningSeaplaneHeight > _pictureHeight.Value) + { + y = _pictureHeight.Value - _drawningSeaplaneHeight; + } _startPosX = x; _startPosY = y;