using ProjectBus.Drawnings;
using System;
using ProjectBus.Entities;
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 ProjectBus;
///
/// Форма конфигурации объекта
///
public partial class FormSimpleBusConfig : Form
{
///
/// Объект - прорисовка автобуса
///
private DrawningSimpleBus _simpleBus = null;
private object _busDelegate;
private event Action _simpleBusDelegate;
///
/// Конструктор
///
public FormSimpleBusConfig()
{
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;
panelHotPink.MouseDown += Panel_MouseDown;
buttonCancel.Click += (sender, e) => Close();
}
public void AddEvent(Action simpleBusDelegate)
{
_simpleBusDelegate += simpleBusDelegate;
}
///
/// Отрисовка объекта
///
private void DrawObject()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_simpleBus?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
_simpleBus?.SetPosition(35, 35);
_simpleBus?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
///
/// Передаем информацию при нажатии на Labe
///
///
///
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)
{
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":
_simpleBus = new DrawningSimpleBus((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
break;
case "labelModifiedObject":
_simpleBus = new DrawningBus((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxAdditionalCompartment.Checked, checkBoxAccordion.Checked);
break;
}
DrawObject();
}
///
/// Передаем информацию при нажатии на Panel
///
///
///
private void Panel_MouseDown(object? sender, MouseEventArgs e)
{
(sender as Control)?.DoDragDrop((sender as Control)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
///
/// Проверка получаемой информации по основному цвету
///
///
///
private void LabelBodyColor_DragEnter_1(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
///
/// действия при приеме перетаскиваемого основного цвета
///
///
///
private void LabelBodyColor_DragDrop(object sender, DragEventArgs e)
{
if (_simpleBus != null)
{
_simpleBus.EntitySimpleBus.setBodyColor((Color)e.Data.GetData(typeof(Color)));
DrawObject();
}
}
///
/// проверка получаемой информации по доп. цвету
///
///
///
private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e)
{
if (_simpleBus is DrawningBus)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
///
/// действия при перетаскивании доп. цвета
///
///
///
private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
if (_simpleBus is DrawningBus bus)
{
labelAdditionalColor.BackColor = (Color)e.Data.GetData(typeof(Color));
bus.SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
}
DrawObject();
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
if (_simpleBus != null)
{
_simpleBusDelegate?.Invoke(_simpleBus);
Close();
}
}
}