diff --git a/base/Catamaran/Catamaran/CatamaranDelegate.cs b/base/Catamaran/Catamaran/CatamaranDelegate.cs deleted file mode 100644 index f7a67f5..0000000 --- a/base/Catamaran/Catamaran/CatamaranDelegate.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Catamaran -{ - internal class CatamaranDelegate - { - } -} diff --git a/base/Catamaran/Catamaran/FormCatamaranCollection.cs b/base/Catamaran/Catamaran/FormCatamaranCollection.cs index 663127d..d8aa776 100644 --- a/base/Catamaran/Catamaran/FormCatamaranCollection.cs +++ b/base/Catamaran/Catamaran/FormCatamaranCollection.cs @@ -94,17 +94,17 @@ namespace Catamaran } /// - /// Добавление объекта в набор + /// Добавление объекта /// /// /// private void ButtonAddCatamaran_Click(object sender, EventArgs e) { - var formCatamaranConfig = new FormCatamaranConfig(); - // TODO Call method AddEvent from formCatamaranConfig - formCatamaranConfig.Show(); - + var formCarConfig = new FormCatamaranConfig(); + // TODO Call method AddEvent from formCarConfig + formCarConfig.Show(); } + /// /// Удаление объекта из набора /// listBoxStorages diff --git a/base/Catamaran/Catamaran/FormCatamaranConfig.Designer.cs b/base/Catamaran/Catamaran/FormCatamaranConfig.Designer.cs index 153eb9b..9c57666 100644 --- a/base/Catamaran/Catamaran/FormCatamaranConfig.Designer.cs +++ b/base/Catamaran/Catamaran/FormCatamaranConfig.Designer.cs @@ -47,8 +47,8 @@ this.labelWeight = new System.Windows.Forms.Label(); this.labelSpeed = new System.Windows.Forms.Label(); this.panel1 = new System.Windows.Forms.Panel(); - this.button2 = new System.Windows.Forms.Button(); - this.button1 = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonOk = new System.Windows.Forms.Button(); this.labelAddColor = new System.Windows.Forms.Label(); this.labelBodyColor = new System.Windows.Forms.Label(); this.pictureBoxObject = new System.Windows.Forms.PictureBox(); @@ -90,6 +90,7 @@ this.labelModifiedObject.TabIndex = 8; this.labelModifiedObject.Text = "Продвинутый"; this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown); // // labelSimpleObject // @@ -101,6 +102,7 @@ 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); // // groupBoxColor // @@ -123,30 +125,33 @@ // // panelRed // - this.panelRed.BackColor = System.Drawing.Color.Red; + this.panelRed.BackColor = System.Drawing.Color.Tomato; this.panelRed.Location = new System.Drawing.Point(6, 29); this.panelRed.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.panelRed.Name = "panelRed"; this.panelRed.Size = new System.Drawing.Size(40, 40); this.panelRed.TabIndex = 1; + this.panelRed.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelBlue // - this.panelBlue.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192))))); + this.panelBlue.BackColor = System.Drawing.Color.CornflowerBlue; this.panelBlue.Location = new System.Drawing.Point(125, 29); this.panelBlue.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.panelBlue.Name = "panelBlue"; this.panelBlue.Size = new System.Drawing.Size(40, 40); this.panelBlue.TabIndex = 1; + this.panelBlue.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelYellow // - this.panelYellow.BackColor = System.Drawing.Color.Yellow; + this.panelYellow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); this.panelYellow.Location = new System.Drawing.Point(187, 29); this.panelYellow.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.panelYellow.Name = "panelYellow"; this.panelYellow.Size = new System.Drawing.Size(40, 40); this.panelYellow.TabIndex = 1; + this.panelYellow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelWhite // @@ -156,6 +161,7 @@ this.panelWhite.Name = "panelWhite"; this.panelWhite.Size = new System.Drawing.Size(40, 40); this.panelWhite.TabIndex = 1; + this.panelWhite.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelGray // @@ -165,6 +171,7 @@ this.panelGray.Name = "panelGray"; this.panelGray.Size = new System.Drawing.Size(40, 40); this.panelGray.TabIndex = 1; + this.panelGray.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelBlack // @@ -174,24 +181,27 @@ this.panelBlack.Name = "panelBlack"; this.panelBlack.Size = new System.Drawing.Size(40, 40); this.panelBlack.TabIndex = 1; + this.panelBlack.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelPurple // - this.panelPurple.BackColor = System.Drawing.Color.Purple; + this.panelPurple.BackColor = System.Drawing.Color.Violet; this.panelPurple.Location = new System.Drawing.Point(187, 86); this.panelPurple.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.panelPurple.Name = "panelPurple"; this.panelPurple.Size = new System.Drawing.Size(40, 40); this.panelPurple.TabIndex = 1; + this.panelPurple.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // panelGreen // - this.panelGreen.BackColor = System.Drawing.Color.Green; + this.panelGreen.BackColor = System.Drawing.Color.LightGreen; this.panelGreen.Location = new System.Drawing.Point(65, 29); this.panelGreen.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.panelGreen.Name = "panelGreen"; this.panelGreen.Size = new System.Drawing.Size(40, 40); this.panelGreen.TabIndex = 0; + this.panelGreen.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PanelColor_MouseDown); // // checkBoxSail // @@ -282,8 +292,8 @@ // panel1 // this.panel1.AllowDrop = true; - this.panel1.Controls.Add(this.button2); - this.panel1.Controls.Add(this.button1); + this.panel1.Controls.Add(this.buttonCancel); + this.panel1.Controls.Add(this.buttonOk); this.panel1.Controls.Add(this.labelAddColor); this.panel1.Controls.Add(this.labelBodyColor); this.panel1.Controls.Add(this.pictureBoxObject); @@ -292,26 +302,28 @@ this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(312, 263); this.panel1.TabIndex = 0; + this.panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); + this.panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); // - // button2 + // buttonCancel // - this.button2.Location = new System.Drawing.Point(175, 223); - this.button2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(108, 24); - this.button2.TabIndex = 12; - this.button2.Text = "Отмена"; - this.button2.UseVisualStyleBackColor = true; + this.buttonCancel.Location = new System.Drawing.Point(175, 223); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(108, 24); + this.buttonCancel.TabIndex = 12; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; // - // button1 + // buttonOk // - this.button1.Location = new System.Drawing.Point(38, 223); - this.button1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(108, 24); - this.button1.TabIndex = 11; - this.button1.Text = "Добавить"; - this.button1.UseVisualStyleBackColor = true; + this.buttonOk.Location = new System.Drawing.Point(38, 223); + this.buttonOk.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(108, 24); + this.buttonOk.TabIndex = 11; + this.buttonOk.Text = "Добавить"; + this.buttonOk.UseVisualStyleBackColor = true; // // labelAddColor // @@ -386,10 +398,10 @@ private Label labelModifiedObject; private Label labelSimpleObject; private Panel panel1; - private Button button1; + private Button buttonOk; private Label labelAddColor; private Label labelBodyColor; private PictureBox pictureBoxObject; - private Button button2; + private Button buttonCancel; } } \ No newline at end of file diff --git a/base/Catamaran/Catamaran/FormCatamaranConfig.cs b/base/Catamaran/Catamaran/FormCatamaranConfig.cs index ded0876..817e361 100644 --- a/base/Catamaran/Catamaran/FormCatamaranConfig.cs +++ b/base/Catamaran/Catamaran/FormCatamaranConfig.cs @@ -8,13 +8,132 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Catamaran.DrawningObjects; +using Catamaran.Entities; namespace Catamaran { + /// + /// Форма создания объекта + /// public partial class FormCatamaranConfig : Form { + /// + /// Переменная-выбранная машина + /// + DrawningCatamaran? _catamaran = null; + /// + /// Событие + /// + private event CatamaranDelegate? EventAddCatamaran; + /// + /// Конструктор + /// public FormCatamaranConfig() { InitializeComponent(); + panelBlack.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelGray.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelRed.MouseDown += PanelColor_MouseDown; + panelWhite.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + // TODO buttonCancel.Click with lambda + buttonCancel.Click += (s, e) => Close(); } + /// + /// Отрисовать машину + /// + private void DrawCatamaran() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _catamaran?.SetPosition(5, 5); + _catamaran?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); + } + + /// + /// Добавление события + /// + /// Привязанный метод + internal void AddEvent(CatamaranDelegate ev) + { + if (EventAddCatamaran == null) + { + EventAddCatamaran = ev; + } + else + { + EventAddCatamaran += ev; + } + } + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (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) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + /// + /// Действия при приеме перетаскиваемой информации + /// + /// + /// + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text).ToString()) + { + case "labelSimpleObject": + _catamaran = new DrawningCatamaran((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + case "labelModifiedObject": + _catamaran = new DrawningSailCatamaran((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxSail.Checked, + checkBoxFloatDetails.Checked, pictureBoxObject.Width, + pictureBoxObject.Height); + break; + } + DrawCatamaran(); + } + // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) + /// + /// Добавление машины + /// + /// + /// + private void ButtonOk_Click(object sender, EventArgs e) + { + EventAddCatamaran?.Invoke(_catamaran); + Close(); + } + } } diff --git a/base/Catamaran/Catamaran/FormCatamaranConfig.resx b/base/Catamaran/Catamaran/FormCatamaranConfig.resx index 1af7de1..f298a7b 100644 --- a/base/Catamaran/Catamaran/FormCatamaranConfig.resx +++ b/base/Catamaran/Catamaran/FormCatamaranConfig.resx @@ -1,64 +1,4 @@ - - - +