diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningBulldoser.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningBulldoser.cs index ca3eb8a..42d7618 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningBulldoser.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningBulldoser.cs @@ -95,5 +95,10 @@ namespace ProjectTractor.DrawningObjects } } + public void ChangeAdditionalColor(Color color) + { + ((EntityBulldoser)EntityTractor).AdditionalColor = color; + } + } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs index 99015c2..39e7239 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs @@ -6,13 +6,11 @@ using System.Threading.Tasks; using ProjectTractor.Entities; using ProjectTractor.MovementStrategy; -namespace ProjectTractor.DrawningObjects { - -/// -/// Класс, отвечающий за прорисовку и перемещение объекта-сущности -/// - public class DrawningTractor -{ +namespace ProjectTractor.DrawningObjects { + /// + /// Класс, отвечающий за прорисовку и перемещение объекта-сущности + /// + public class DrawningTractor { /// /// Класс-сущность /// @@ -41,15 +39,16 @@ namespace ProjectTractor.DrawningObjects { /// Высота прорисовки автомобиля /// protected readonly int _tractorHeight = 60; - /// - /// Конструктор - /// - /// Скорость - /// Вес - /// Основной цвет - /// Ширина картинки - /// Высота картинки - public DrawningTractor(int speed, double weight, Color bodyColor, int + + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Ширина картинки + /// Высота картинки + public DrawningTractor(int speed, double weight, Color bodyColor, int width, int height) { if (width <= _tractorWidth || height <= _tractorHeight) @@ -228,7 +227,22 @@ namespace ProjectTractor.DrawningObjects { g.DrawRectangle(pen, _startPosX + 60, _startPosY, 10, 20); g.DrawRectangle(pen, _startPosX, _startPosY, 40, 20); } -} + + public void ChangeColor(Color color) + { + if (EntityTractor == null) + { + return; + } + EntityTractor.BodyColor = color; + } + + public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight) + { + _pictureWidth = pictureBoxWidth; + _pictureHeight = pictureBoxHeight; + } + } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityBulldoser.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityBulldoser.cs index b71fcd3..c0e5211 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityBulldoser.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityBulldoser.cs @@ -14,7 +14,7 @@ namespace ProjectTractor.Entities /// /// Дополнительный цвет (для опциональных элементов) /// - public Color AdditionalColor { get; private set; } + public Color AdditionalColor { get; set; } /// /// Признак (опция) наличия обвеса /// diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityTractor.cs index 17d046f..0de2fbe 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/EntityTractor.cs @@ -22,7 +22,7 @@ namespace ProjectTractor.Entities /// /// Основной цвет /// - public Color BodyColor { get; private set; } + public Color BodyColor { get; set; } /// /// Шаг перемещения автомобиля /// @@ -39,6 +39,5 @@ namespace ProjectTractor.Entities Weight = weight; BodyColor = bodyColor; } - } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index cd9a7e9..58ac92d 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -113,19 +113,24 @@ namespace ProjectTractor { return; } - FormTractor form = new(); - if (form.ShowDialog() == DialogResult.OK) + + FormTractorConfig form = new(); + form.Show(); + Action? tractorDelegate = new((m) => { - if (obj + form.SelectedTractor) + bool isAdditionSuccessful = (obj + m); + if (isAdditionSuccessful) { MessageBox.Show("Объект добавлен"); + m.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height); pictureBoxCollection.Image = obj.ShowTractors(); } else { MessageBox.Show("Не удалось добавить объект"); } - } + }); + form.AddEvent(tractorDelegate); } /// @@ -180,7 +185,6 @@ namespace ProjectTractor } pictureBoxCollection.Image = obj.ShowTractors(); } - private void InitializeComponent() { this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.Designer.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.Designer.cs index 786aa34..31df060 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.Designer.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.Designer.cs @@ -30,7 +30,7 @@ { this.groupBoxConfig = new System.Windows.Forms.GroupBox(); this.labelModifiedObject = new System.Windows.Forms.Label(); - this.labelSimleObject = new System.Windows.Forms.Label(); + this.labelSimpleObject = new System.Windows.Forms.Label(); this.groupBoxColors = new System.Windows.Forms.GroupBox(); this.panelPurpule = new System.Windows.Forms.Panel(); this.panelBlack = new System.Windows.Forms.Panel(); @@ -46,11 +46,11 @@ this.label1 = new System.Windows.Forms.Label(); this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown(); this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown(); - this.buttonAddCar = new System.Windows.Forms.Button(); - this.button6 = new System.Windows.Forms.Button(); + this.buttonOk = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); this.pictureBoxObject = new System.Windows.Forms.PictureBox(); - this.label5 = new System.Windows.Forms.Label(); - this.label6 = new System.Windows.Forms.Label(); + this.labelColor = new System.Windows.Forms.Label(); + this.labelAdditionalColor = new System.Windows.Forms.Label(); this.panelObject = new System.Windows.Forms.Panel(); this.groupBoxConfig.SuspendLayout(); this.groupBoxColors.SuspendLayout(); @@ -63,7 +63,7 @@ // groupBoxConfig // this.groupBoxConfig.Controls.Add(this.labelModifiedObject); - this.groupBoxConfig.Controls.Add(this.labelSimleObject); + this.groupBoxConfig.Controls.Add(this.labelSimpleObject); this.groupBoxConfig.Controls.Add(this.groupBoxColors); this.groupBoxConfig.Controls.Add(this.checkBoxBlade); this.groupBoxConfig.Controls.Add(this.checkBoxWheelsOrnament); @@ -73,7 +73,7 @@ this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed); this.groupBoxConfig.Location = new System.Drawing.Point(12, 0); this.groupBoxConfig.Name = "groupBoxConfig"; - this.groupBoxConfig.Size = new System.Drawing.Size(585, 341); + this.groupBoxConfig.Size = new System.Drawing.Size(585, 256); this.groupBoxConfig.TabIndex = 0; this.groupBoxConfig.TabStop = false; this.groupBoxConfig.Text = "Параметры"; @@ -82,7 +82,6 @@ // this.labelModifiedObject.BackColor = System.Drawing.SystemColors.ButtonHighlight; this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelModifiedObject.Enabled = false; this.labelModifiedObject.Location = new System.Drawing.Point(449, 171); this.labelModifiedObject.Name = "labelModifiedObject"; this.labelModifiedObject.Size = new System.Drawing.Size(114, 42); @@ -91,17 +90,17 @@ this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); // - // labelSimleObject + // labelSimpleObject // - this.labelSimleObject.BackColor = System.Drawing.SystemColors.ButtonHighlight; - this.labelSimleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelSimleObject.Location = new System.Drawing.Point(369, 171); - this.labelSimleObject.Name = "labelSimleObject"; - this.labelSimleObject.Size = new System.Drawing.Size(74, 42); - this.labelSimleObject.TabIndex = 7; - this.labelSimleObject.Text = "Простой"; - this.labelSimleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.labelSimleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); + this.labelSimpleObject.BackColor = System.Drawing.SystemColors.ButtonHighlight; + this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelSimpleObject.Location = new System.Drawing.Point(369, 171); + this.labelSimpleObject.Name = "labelSimpleObject"; + this.labelSimpleObject.Size = new System.Drawing.Size(74, 42); + this.labelSimpleObject.TabIndex = 7; + this.labelSimpleObject.Text = "Простой"; + this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); // // groupBoxColors // @@ -128,6 +127,7 @@ this.panelPurpule.Name = "panelPurpule"; this.panelPurpule.Size = new System.Drawing.Size(40, 40); this.panelPurpule.TabIndex = 1; + this.panelPurpule.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop); this.panelPurpule.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown); // // panelBlack @@ -138,6 +138,7 @@ this.panelBlack.Name = "panelBlack"; this.panelBlack.Size = new System.Drawing.Size(40, 40); this.panelBlack.TabIndex = 1; + this.panelBlack.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop); this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown); // // panelGrey @@ -148,6 +149,7 @@ this.panelGrey.Name = "panelGrey"; this.panelGrey.Size = new System.Drawing.Size(40, 40); this.panelGrey.TabIndex = 1; + this.panelGrey.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop); this.panelGrey.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown); // // panelYellow @@ -158,6 +160,7 @@ this.panelYellow.Name = "panelYellow"; this.panelYellow.Size = new System.Drawing.Size(40, 40); this.panelYellow.TabIndex = 1; + this.panelYellow.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop); this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown); // // panelBlue @@ -168,6 +171,7 @@ this.panelBlue.Name = "panelBlue"; this.panelBlue.Size = new System.Drawing.Size(40, 40); this.panelBlue.TabIndex = 1; + this.panelBlue.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop); this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown); // // panelWhite @@ -178,6 +182,7 @@ this.panelWhite.Name = "panelWhite"; this.panelWhite.Size = new System.Drawing.Size(40, 40); this.panelWhite.TabIndex = 1; + this.panelWhite.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop); this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown); // // panelGreen @@ -188,6 +193,7 @@ this.panelGreen.Name = "panelGreen"; this.panelGreen.Size = new System.Drawing.Size(40, 40); this.panelGreen.TabIndex = 0; + this.panelGreen.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop); this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown); // // panelRed @@ -198,12 +204,13 @@ this.panelRed.Name = "panelRed"; this.panelRed.Size = new System.Drawing.Size(40, 40); this.panelRed.TabIndex = 0; + this.panelRed.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop); this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panelColor_MouseDown); // // checkBoxBlade // this.checkBoxBlade.AutoSize = true; - this.checkBoxBlade.Location = new System.Drawing.Point(32, 227); + this.checkBoxBlade.Location = new System.Drawing.Point(32, 154); this.checkBoxBlade.Name = "checkBoxBlade"; this.checkBoxBlade.Size = new System.Drawing.Size(205, 24); this.checkBoxBlade.TabIndex = 5; @@ -213,7 +220,7 @@ // checkBoxWheelsOrnament // this.checkBoxWheelsOrnament.AutoSize = true; - this.checkBoxWheelsOrnament.Location = new System.Drawing.Point(32, 286); + this.checkBoxWheelsOrnament.Location = new System.Drawing.Point(32, 189); this.checkBoxWheelsOrnament.Name = "checkBoxWheelsOrnament"; this.checkBoxWheelsOrnament.Size = new System.Drawing.Size(305, 24); this.checkBoxWheelsOrnament.TabIndex = 4; @@ -282,67 +289,71 @@ 0, 0}); // - // buttonAddCar + // buttonOk // - this.buttonAddCar.Location = new System.Drawing.Point(631, 305); - this.buttonAddCar.Name = "buttonAddCar"; - this.buttonAddCar.Size = new System.Drawing.Size(94, 29); - this.buttonAddCar.TabIndex = 2; - this.buttonAddCar.Text = "Добавить"; - this.buttonAddCar.UseVisualStyleBackColor = true; - this.buttonAddCar.Click += new System.EventHandler(this.buttonAddCar_Click); + this.buttonOk.Location = new System.Drawing.Point(631, 227); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(94, 29); + this.buttonOk.TabIndex = 2; + this.buttonOk.Text = "Добавить"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click); // - // button6 + // buttonCancel // - this.button6.Location = new System.Drawing.Point(744, 305); - this.button6.Name = "button6"; - this.button6.Size = new System.Drawing.Size(94, 29); - this.button6.TabIndex = 3; - this.button6.Text = "Отмена"; - this.button6.UseVisualStyleBackColor = true; + this.buttonCancel.Location = new System.Drawing.Point(746, 227); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; // // pictureBoxObject // this.pictureBoxObject.Location = new System.Drawing.Point(3, 50); this.pictureBoxObject.Name = "pictureBoxObject"; - this.pictureBoxObject.Size = new System.Drawing.Size(259, 232); + this.pictureBoxObject.Size = new System.Drawing.Size(259, 150); this.pictureBoxObject.TabIndex = 2; this.pictureBoxObject.TabStop = false; // - // label5 + // labelColor // - this.label5.AllowDrop = true; - this.label5.BackColor = System.Drawing.SystemColors.ButtonHighlight; - this.label5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.label5.Location = new System.Drawing.Point(2, 15); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(119, 32); - this.label5.TabIndex = 3; - this.label5.Text = "Цвет"; - this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelColor.AllowDrop = true; + this.labelColor.BackColor = System.Drawing.SystemColors.ButtonHighlight; + this.labelColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelColor.Location = new System.Drawing.Point(2, 15); + this.labelColor.Name = "labelColor"; + this.labelColor.Size = new System.Drawing.Size(119, 32); + this.labelColor.TabIndex = 3; + this.labelColor.Text = "Цвет"; + this.labelColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.labelColor_DragDrop); + this.labelColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter); // - // label6 + // labelAdditionalColor // - this.label6.AllowDrop = true; - this.label6.BackColor = System.Drawing.SystemColors.ButtonHighlight; - this.label6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.label6.Location = new System.Drawing.Point(142, 15); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(120, 32); - this.label6.TabIndex = 4; - this.label6.Text = "Доп. цвет"; - this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAdditionalColor.AllowDrop = true; + this.labelAdditionalColor.BackColor = System.Drawing.SystemColors.ButtonHighlight; + this.labelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.labelAdditionalColor.Location = new System.Drawing.Point(142, 15); + this.labelAdditionalColor.Name = "labelAdditionalColor"; + this.labelAdditionalColor.Size = new System.Drawing.Size(120, 32); + this.labelAdditionalColor.TabIndex = 4; + this.labelAdditionalColor.Text = "Доп. цвет"; + this.labelAdditionalColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelAdditionalColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAdditionalColor_DragDrop); + this.labelAdditionalColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.labelColor_DragEnter); // // panelObject // this.panelObject.AllowDrop = true; this.panelObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.panelObject.Controls.Add(this.label6); - this.panelObject.Controls.Add(this.label5); + this.panelObject.Controls.Add(this.labelAdditionalColor); + this.panelObject.Controls.Add(this.labelColor); this.panelObject.Controls.Add(this.pictureBoxObject); this.panelObject.Location = new System.Drawing.Point(603, 12); this.panelObject.Name = "panelObject"; - this.panelObject.Size = new System.Drawing.Size(267, 287); + this.panelObject.Size = new System.Drawing.Size(267, 208); this.panelObject.TabIndex = 4; this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelObject_DragDrop); this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelObject_DragEnter); @@ -351,10 +362,10 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(882, 353); + this.ClientSize = new System.Drawing.Size(882, 271); this.Controls.Add(this.panelObject); - this.Controls.Add(this.button6); - this.Controls.Add(this.buttonAddCar); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOk); this.Controls.Add(this.groupBoxConfig); this.Name = "FormTractorConfig"; this.Text = "FormTractorConfig"; @@ -388,12 +399,12 @@ private Panel panelBlue; private Panel panelWhite; private Label labelModifiedObject; - private Label labelSimleObject; - private Button buttonAddCar; - private Button button6; + private Label labelSimpleObject; + private Button buttonOk; + private Button buttonCancel; private PictureBox pictureBoxObject; - private Label label5; - private Label label6; + private Label labelColor; + private Label labelAdditionalColor; private Panel panelObject; } } \ No newline at end of file diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.cs index 4c11d33..a4f5ff3 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorConfig.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ProjectTractor.DrawningObjects; +using ProjectTractor.Entities; namespace ProjectTractor; @@ -17,19 +18,13 @@ namespace ProjectTractor; public partial class FormTractorConfig : Form { /// - /// Переменная-выбранная машина + /// Переменная-выбранный трактор /// DrawningTractor? _tractor = null; /// - /// Делегат для передачи объекта-автомобиля - /// - /// - public delegate void TractorDelegate(DrawningTractor tractor); - /// /// Событие /// - private event TractorDelegate? EventAddTractor; - + private event Action? EventAddTractor; /// /// Конструктор /// @@ -45,14 +40,28 @@ public partial class FormTractorConfig : Form panelWhite.MouseDown += panelColor_MouseDown; panelYellow.MouseDown += panelColor_MouseDown; panelBlue.MouseDown += panelColor_MouseDown; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + labelModifiedObject.MouseDown += LabelObject_MouseDown; - // TODO buttonCancel.Click with lambda + buttonCancel.Click += (s, e) => Close(); + } + + /// + /// Отрисовать трактор + /// + private void DrawTractor() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _tractor?.SetPosition(5, 5); + _tractor?.DrawTransport(gr); + pictureBoxObject.Image = bmp; } /// /// Добавление события /// /// Привязанный метод - public void AddEvent(TractorDelegate ev) + public void AddEvent(Action ev) { if (EventAddTractor == null) { @@ -64,38 +73,19 @@ public partial class FormTractorConfig : Form } } /// - /// Добавление машины - /// - /// - /// - private void ButtonOk_Click(object sender, EventArgs e) - { - EventAddTractor?.Invoke(_tractor); - Close(); - } - - /// - /// Отрисовать машину - /// - private void DrawTractor() - { - Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); - Graphics gr = Graphics.FromImage(bmp); - _tractor?.SetPosition(5, 5); - _tractor?.DrawTransport(gr); - pictureBoxObject.Image = bmp; - } - /// /// Передаем информацию при нажатии на Label /// /// /// private void LabelObject_MouseDown(object sender, MouseEventArgs e) { - (sender as Label)?.DoDragDrop((sender as Label)?.Name, - DragDropEffects.Move | DragDropEffects.Copy); + (sender as Label)?.DoDragDrop((sender as Label)?.Name, DragDropEffects.Move | DragDropEffects.Copy); } - + /// + /// Проверка получаемой информации (ее типа на соответствие требуемому) + /// + /// + /// private void panelObject_DragEnter(object sender, DragEventArgs e) { if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) @@ -107,7 +97,11 @@ public partial class FormTractorConfig : Form e.Effect = DragDropEffects.None; } } - + /// + /// Действия при приеме перетаскиваемой информации + /// + /// + /// private void panelObject_DragDrop(object sender, DragEventArgs e) { switch (e.Data?.GetData(DataFormats.Text).ToString()) @@ -119,31 +113,68 @@ public partial class FormTractorConfig : Form break; case "labelModifiedObject": _tractor = new DrawningBulldoser((int)numericUpDownSpeed.Value, - (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxBlade.Checked, - checkBoxWheelsOrnament.Checked, pictureBoxObject.Width, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxWheelsOrnament.Checked, + checkBoxBlade.Checked, pictureBoxObject.Width, pictureBoxObject.Height); break; } + labelColor.BackColor = Color.Empty; + labelAdditionalColor.BackColor = Color.Empty; + DrawTractor(); + } + /// + /// Смена цвета + /// + private void panelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + private void labelColor_DragDrop(object sender, DragEventArgs e) + { + if (_tractor == null) + { + return; + } + labelColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + _tractor.ChangeColor(labelColor.BackColor); DrawTractor(); } - private void panelColor_MouseDown(object sender, MouseEventArgs e) + private void labelColor_DragEnter(object sender, DragEventArgs e) { - + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } } + + private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if ((_tractor == null) || (_tractor is DrawningBulldoser == false)) + { + return; + } + labelAdditionalColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + ((DrawningBulldoser)_tractor).ChangeAdditionalColor(labelAdditionalColor.BackColor); + DrawTractor(); + } + + /// - /// Добавление объекта + /// Добавление трактора /// /// /// - private void buttonAddCar_Click(object sender, EventArgs e) + private void ButtonOk_Click(object sender, EventArgs e) { - var formTractorConfig = new FormTractorConfig(); - // TODO Call method AddEvent from formCarConfig - formTractorConfig.Show(); - + if (_tractor == null) + return; + EventAddTractor?.Invoke(_tractor); + Close(); } - - - // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) }