using ProjectCatamaran.Drawnings; using ProjectCatamaran.Entities; 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 ProjectCatamaran; public partial class FormBoatConfig : Form { /// /// Объект - прорисовка лодки /// private DrawningBoat? _boat; /// /// Событие для передачи объекта /// private event Action? BoatDelegate; public FormBoatConfig() { InitializeComponent(); panelRed.MouseDown += Panel_MouseDown; panelGreen.MouseDown += Panel_MouseDown; panelBlue.MouseDown += Panel_MouseDown; panelYellow.MouseDown += Panel_MouseDown; panelWhite.MouseDown += Panel_MouseDown; panelGray.MouseDown += Panel_MouseDown; panelBlack.MouseDown += Panel_MouseDown; panelPurple.MouseDown += Panel_MouseDown; buttonCancel.Click += (sender, e) => Close(); } /// /// Привязка внешнего метода к событию /// /// public void AddEvent(Action boatDelegate) { if (BoatDelegate != null) { BoatDelegate = boatDelegate; } else { BoatDelegate += boatDelegate; } } /// /// Прорисовка объекта /// private void DrawObject() { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Graphics gr = Graphics.FromImage(bmp); _boat?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height); _boat?.SetPosition(15, 15); _boat?.DrawTransport(gr); pictureBoxObject.Image = bmp; } /// /// Передаем информацию при нажатии на Label /// /// /// private void LabelObject_MouseDown(object sender, MouseEventArgs e) { (sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy); } /// /// Проверка получаемой информации (ее типа на соответствие требуемому) /// /// /// private void PanelObject_DragEnter(object sender, DragEventArgs e) { e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None; } /// /// Действия при приеме перетаскиваемой информации /// /// /// private void PanelObject_DragDrop(object sender, DragEventArgs e) { switch (e.Data?.GetData(DataFormats.Text)?.ToString()) { case "labelSimpleObject": _boat = new DrawningBoat((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White); break; case "labelModifiedObject": _boat = new DrawningCatamaran((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxLeftfloater.Checked, checkBoxRightfloater.Checked, checkBoxSail.Checked); break; } DrawObject(); } /// /// Передаем информацию при нажатии на Panel /// /// /// private void Panel_MouseDown(object? sender, MouseEventArgs e) { (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy); } private void labelBodyColor_DragDrop(object sender, DragEventArgs e) { if (_boat != null) { _boat.EntityBoat.SetBodyColor((Color)e.Data.GetData(typeof(Color))); DrawObject(); } } private void labelBodyColor_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 (_boat.EntityBoat is EntityCatamaran catamaran) { catamaran.SetAdditionalColor((Color)e.Data.GetData(typeof(Color))); DrawObject(); } } private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e) { if (_boat is DrawningCatamaran) { if (e.Data.GetDataPresent(typeof(Color))) { e.Effect = DragDropEffects.Copy; } else { e.Effect = DragDropEffects.None; } } } /// /// Передача объекта /// /// /// private void ButtonAdd_Click(object sender, EventArgs e) { if (_boat != null) { BoatDelegate?.Invoke(_boat); Close(); } } }