diff --git a/HoistingCrane/HoistingCrane/DirectionType.cs b/HoistingCrane/HoistingCrane/DirectionType.cs index b1cd6d6..f7b59b9 100644 --- a/HoistingCrane/HoistingCrane/DirectionType.cs +++ b/HoistingCrane/HoistingCrane/DirectionType.cs @@ -4,7 +4,6 @@ namespace HoistingCrane { public enum DirectionType { - /// Вверх Up = 1, /// Вниз @@ -13,6 +12,5 @@ namespace HoistingCrane Left = 3, /// Вправо Right = 4 - } } diff --git a/HoistingCrane/HoistingCrane/DrawingHoistingCrane.cs b/HoistingCrane/HoistingCrane/DrawingHoistingCrane.cs index 1f7b8df..0e80a4b 100644 --- a/HoistingCrane/HoistingCrane/DrawingHoistingCrane.cs +++ b/HoistingCrane/HoistingCrane/DrawingHoistingCrane.cs @@ -46,6 +46,24 @@ namespace HoistingCrane { // TODO проверка, что объект "влезает" в размеры поля // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена + if (_drawningCarWidth > width || _drawningCarHeight > height) + { + return false; + } + + if (_pictureWidth.HasValue && width != _pictureWidth || _pictureHeight.HasValue && height != _pictureHeight) + { + if (_startPosX + _drawningCarWidth > width) + { + _startPosX -= _drawningCarWidth; + } + + if (_startPosY + _drawningCarHeight > height) + { + _startPosY -= _drawningCarHeight; + } + } + _pictureWidth = width; _pictureHeight = height; return true; @@ -59,9 +77,27 @@ namespace HoistingCrane { return; } + + if (x < 0) + { + x = 0; + } + if (x + _drawningCarWidth > _pictureWidth) + { + x = (int)_pictureWidth - _drawningCarWidth; + } + if (y < 0) + { + y = 0; + } + if (y + _drawningCarHeight > _pictureHeight) + { + y = (int)_pictureHeight - _drawningCarHeight; + + } // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы - // то надо изменить координаты, чтобы он оставался в этих границах - _startPosX = x; + // то надо изменить координаты, чтобы он оставался в этих границах + _startPosX = x; _startPosY = y; } /// Изменение направления перемещения @@ -92,11 +128,17 @@ namespace HoistingCrane return true; // вправо case DirectionType.Right: - //TODO прописать логику сдвига в право + if (_startPosX.Value - EntityHoistingCrane.Step > _pictureWidth) + { + _startPosX += (int)EntityHoistingCrane.Step; + } return true; //вниз case DirectionType.Down: - //TODO прописать логику сдвига в вниз + if (_startPosY.Value - EntityHoistingCrane.Step > _pictureHeight) + { + _startPosY += (int)EntityHoistingCrane.Step; + } return true; default: return false; @@ -114,7 +156,14 @@ namespace HoistingCrane { return; } - } + + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(EntityHoistingCrane.AdditionalColor); + + //границы крана + + + } } diff --git a/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs b/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs index d659046..63845eb 100644 --- a/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs +++ b/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs @@ -4,26 +4,18 @@ namespace HoistingCrane { public class EntityHoistingCrane { - - /// Скорость public int Speed { get; private set; } - /// Вес public double Weight { get; private set; } - /// Основной цвет public Color BodyColor { get; private set; } - /// Дополнительный цвет (для опциональных элементов) public Color AdditionalColor { get; private set; } - /// Признак (опция) наличия крана public bool Crane { get; private set; } - /// Признак (опция) наличия противовеса public bool Counterweight { get; private set; } - /// Шаг перемещения автомобиля public double Step => Speed * 100 / Weight; @@ -45,7 +37,5 @@ namespace HoistingCrane Counterweight = counterweight; } - - } } diff --git a/HoistingCrane/HoistingCrane/Form1.Designer.cs b/HoistingCrane/HoistingCrane/Form1.Designer.cs deleted file mode 100644 index 32cdcd8..0000000 --- a/HoistingCrane/HoistingCrane/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace HoistingCrane -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/Form1.cs b/HoistingCrane/HoistingCrane/Form1.cs deleted file mode 100644 index 3820d41..0000000 --- a/HoistingCrane/HoistingCrane/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace HoistingCrane -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs b/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs new file mode 100644 index 0000000..dac4d39 --- /dev/null +++ b/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs @@ -0,0 +1,129 @@ +namespace HoistingCrane +{ + partial class FormHoistingCrane + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + pictureBoxHoistingCrane = new PictureBox(); + buttonLeft = new Button(); + buttonRight = new Button(); + buttonUp = new Button(); + buttonDown = new Button(); + buttonCreate = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxHoistingCrane).BeginInit(); + SuspendLayout(); + // + // pictureBoxHoistingCrane + // + pictureBoxHoistingCrane.Dock = DockStyle.Fill; + pictureBoxHoistingCrane.Location = new Point(0, 0); + pictureBoxHoistingCrane.Name = "pictureBoxHoistingCrane"; + pictureBoxHoistingCrane.Size = new Size(800, 462); + pictureBoxHoistingCrane.TabIndex = 0; + pictureBoxHoistingCrane.TabStop = false; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; + buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; + buttonLeft.Location = new Point(668, 415); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(35, 35); + buttonLeft.TabIndex = 2; + buttonLeft.UseVisualStyleBackColor = true; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.arrowRight; + buttonRight.BackgroundImageLayout = ImageLayout.Stretch; + buttonRight.Location = new Point(750, 415); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(35, 35); + buttonRight.TabIndex = 3; + buttonRight.UseVisualStyleBackColor = true; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.arrowUp; + buttonUp.BackgroundImageLayout = ImageLayout.Stretch; + buttonUp.Location = new Point(709, 374); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(35, 35); + buttonUp.TabIndex = 4; + buttonUp.UseVisualStyleBackColor = true; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.arrowDown; + buttonDown.BackgroundImageLayout = ImageLayout.Stretch; + buttonDown.Location = new Point(709, 415); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(35, 35); + buttonDown.TabIndex = 5; + buttonDown.UseVisualStyleBackColor = true; + // + // buttonCreate + // + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(12, 427); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(75, 23); + buttonCreate.TabIndex = 6; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + // + // FormHoistingCrane + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 462); + Controls.Add(buttonCreate); + Controls.Add(buttonDown); + Controls.Add(buttonUp); + Controls.Add(buttonRight); + Controls.Add(buttonLeft); + Controls.Add(pictureBoxHoistingCrane); + Name = "FormHoistingCrane"; + Text = "Подъёмный кран"; + ((System.ComponentModel.ISupportInitialize)pictureBoxHoistingCrane).EndInit(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureBoxHoistingCrane; + private Button buttonLeft; + private Button buttonRight; + private Button buttonUp; + private Button buttonDown; + private Button buttonCreate; + } +} \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/FormHoistingCrane.cs b/HoistingCrane/HoistingCrane/FormHoistingCrane.cs new file mode 100644 index 0000000..155dc4c --- /dev/null +++ b/HoistingCrane/HoistingCrane/FormHoistingCrane.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HoistingCrane +{ + public partial class FormHoistingCrane : Form + { + private DrawingHoistingCrane? _drawingHoistingCrane; + + public FormHoistingCrane() + { + InitializeComponent(); + } + + private void pictureBoxHoistingCrane_Click(object sender, EventArgs e) + { + + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawingHoistingCrane = new DrawingHoistingCrane(); + _drawingHoistingCrane.Init(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + + Bitmap bmp = new(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawingHoistingCrane.DrawTransport(gr); + pictureBoxHoistingCrane.Image = bmp; + + } + } +} diff --git a/HoistingCrane/HoistingCrane/FormHoistingCrane.resx b/HoistingCrane/HoistingCrane/FormHoistingCrane.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/HoistingCrane/HoistingCrane/FormHoistingCrane.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/HoistingCrane.csproj b/HoistingCrane/HoistingCrane/HoistingCrane.csproj index e1a0735..244387d 100644 --- a/HoistingCrane/HoistingCrane/HoistingCrane.csproj +++ b/HoistingCrane/HoistingCrane/HoistingCrane.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/Program.cs b/HoistingCrane/HoistingCrane/Program.cs index 315551e..fbb985e 100644 --- a/HoistingCrane/HoistingCrane/Program.cs +++ b/HoistingCrane/HoistingCrane/Program.cs @@ -11,7 +11,7 @@ namespace HoistingCrane // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new FormHoistingCrane()); } } } \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/Properties/Resources.Designer.cs b/HoistingCrane/HoistingCrane/Properties/Resources.Designer.cs new file mode 100644 index 0000000..efc3ea7 --- /dev/null +++ b/HoistingCrane/HoistingCrane/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace HoistingCrane.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("HoistingCrane.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowDown { + get { + object obj = ResourceManager.GetObject("arrowDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowLeft { + get { + object obj = ResourceManager.GetObject("arrowLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowRight { + get { + object obj = ResourceManager.GetObject("arrowRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowUp { + get { + object obj = ResourceManager.GetObject("arrowUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/HoistingCrane/HoistingCrane/Properties/Resources.resx b/HoistingCrane/HoistingCrane/Properties/Resources.resx new file mode 100644 index 0000000..293419e --- /dev/null +++ b/HoistingCrane/HoistingCrane/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\arrowDown.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowLeft.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowRight.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowUp.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/Resources/arrowDown.jpg b/HoistingCrane/HoistingCrane/Resources/arrowDown.jpg new file mode 100644 index 0000000..f21002e Binary files /dev/null and b/HoistingCrane/HoistingCrane/Resources/arrowDown.jpg differ diff --git a/HoistingCrane/HoistingCrane/Resources/arrowLeft.jpg b/HoistingCrane/HoistingCrane/Resources/arrowLeft.jpg new file mode 100644 index 0000000..61b8dae Binary files /dev/null and b/HoistingCrane/HoistingCrane/Resources/arrowLeft.jpg differ diff --git a/HoistingCrane/HoistingCrane/Resources/arrowRight.jpg b/HoistingCrane/HoistingCrane/Resources/arrowRight.jpg new file mode 100644 index 0000000..b440197 Binary files /dev/null and b/HoistingCrane/HoistingCrane/Resources/arrowRight.jpg differ diff --git a/HoistingCrane/HoistingCrane/Resources/arrowUp.jpg b/HoistingCrane/HoistingCrane/Resources/arrowUp.jpg new file mode 100644 index 0000000..e630cea Binary files /dev/null and b/HoistingCrane/HoistingCrane/Resources/arrowUp.jpg differ