From d6acb857ab0349321fbe0c4dd362dbdf5b7cf4c6 Mon Sep 17 00:00:00 2001 From: insideq Date: Mon, 5 Feb 2024 17:11:53 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20SetPictureSize()=20=D0=B8=20SetPosition()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectExcavator/DrawningExcavator.cs | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs b/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs index 7fbcc3f..102e984 100644 --- a/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs +++ b/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs @@ -70,21 +70,24 @@ public class DrawningExcavator { //TODO проверка, что объект "влезает" в размеры поля //если влезает, сохраняем границы и корректируем позицию объекта, если она уже была установлена - _pictureWidth = width; - _pictureHeight = height; - if (_pictureWidth <= _drawingExcWidth || _pictureHeight <= _drawingExcHeight) - { - _pictureHeight = null; - _pictureWidth = null; + if(_drawingExcWidth > width || _drawingExcHeight > height) { return false; } - if (_startPosX + _drawingExcWidth > _pictureWidth) + + _pictureWidth = width; + _pictureHeight = height; + if (_startPosX.HasValue || _startPosY.HasValue) { - _startPosX = _pictureWidth.Value - _drawingExcWidth; - } - if (_startPosY + _drawingExcHeight > _pictureHeight) - { - _startPosY = _pictureHeight.Value - _drawingExcHeight; + if (_startPosX + _drawingExcWidth > _pictureWidth) + { + _startPosX = _pictureWidth - _drawingExcWidth; + } + else if (_startPosX < 0) _startPosX = 0; + if (_startPosY + _drawingExcHeight > _pictureHeight) + { + _startPosY = _pictureHeight - _drawingExcHeight; + } + else if (_startPosY < 0) _startPosY = 0; } return true; } @@ -96,15 +99,26 @@ public class DrawningExcavator /// Координата Y public void SetPosition(int x, int y, int width, int height) { + if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) + { + return; + } + //TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы //то надо изменить координаты, чтобы он оставался в этих границах - if (x >= 0 && x + _drawingExcWidth <= width && y >= 0 && y + _drawingExcWidth <= height) + if (x + _drawingExcWidth > _pictureWidth) { - _startPosX = x; - _startPosY = y; - _pictureWidth = width; - _pictureHeight = height; + _startPosX = _pictureWidth - _drawingExcWidth; } + else if (x < 0) _startPosX = 0; + else _startPosX = x; + + if (y + _drawingExcHeight > _pictureHeight) + { + _startPosY = _pictureHeight - _drawingExcHeight; + } + else if (y < 0) _startPosY = 0; + else _startPosY = y; } ///