PIbd-22_Kurbanova_A.A.Warml.../WarmlyLocomotive/FormWarmlyLocomotiveConfig.cs
2023-12-01 23:01:57 +04:00

169 lines
6.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using WarmlyLocomotive.DrawningObjects;
using WarmlyLocomotive.Entities;
namespace WarmlyLocomotive
{
/// <summary>
/// Делегат для передачи объекта-тепловоза
/// </summary>
/// <param name="warmlylocomotive"></param>
public partial class FormWarmlyLocomotiveConfig : Form
{
public int _pictureWidth { get; private set; }
public int _pictureHeight { get; private set; }
/// <summary>
/// Переменная
/// </summary>
DrawningWarmlyLocomotive? _warmlylocomotive = null;
/// <summary>
/// Событие
/// </summary>
public event Action<DrawningWarmlyLocomotive>? EventAddWarmlyLocomotive;
public FormWarmlyLocomotiveConfig(int pictureWidth, int pictureHeight)
{
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
InitializeComponent();
panelRed.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelGray.MouseDown += PanelColor_MouseDown;
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
}
private void DrawWarmlyLocomotive()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_warmlylocomotive?.SetPosition(5, 5);
_warmlylocomotive?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
public void AddEvent(Action<DrawningWarmlyLocomotive> ev)
{
if (EventAddWarmlyLocomotive == null)
{
EventAddWarmlyLocomotive = ev;
}
else
{
EventAddWarmlyLocomotive += ev;
}
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Действия при приеме перетаскиваемой информации
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelBasic":
_warmlylocomotive = new DrawningWarmlyLocomotive((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, _pictureWidth, _pictureHeight);
break;
case "labelAdvanced":
_warmlylocomotive = new DrawningWarmlyLocomotiveWithTrumpet((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxTrumpet.Checked,
checkBoxLuggage.Checked, _pictureWidth, _pictureHeight);
break;
}
DrawWarmlyLocomotive();
}
private void PanelColor_MouseDown(object? sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Добавление
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAdd_Click(object sender, EventArgs e)
{
if (_warmlylocomotive == null)
return;
EventAddWarmlyLocomotive?.Invoke(_warmlylocomotive);
Close();
}
private void labelColor_DragDrop(object sender, DragEventArgs e)
{
if (_warmlylocomotive?.EntityWarmlyLocomotive == null)
return;
switch (((Label)sender).Name)
{
case "labelMainColor":
_warmlylocomotive?.EntityWarmlyLocomotive?.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "labelAdditionalColor":
if (!(_warmlylocomotive is DrawningWarmlyLocomotiveWithTrumpet))
return;
(_warmlylocomotive.EntityWarmlyLocomotive as EntityWarmlyLocomotiveWithTrumpet)?.setAdditionalColor(color: (Color)e.Data.GetData(typeof(Color)));
break;
}
DrawWarmlyLocomotive();
}
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 labelAddColor_DragDrop(object sender, DragEventArgs e)
{
if ((_warmlylocomotive?.EntityWarmlyLocomotive == null) || (_warmlylocomotive is DrawningWarmlyLocomotiveWithTrumpet == false))
return;
Color additionalColor = (Color)e.Data.GetData(typeof(Color));
_warmlylocomotive = new DrawningWarmlyLocomotiveWithTrumpet((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, _warmlylocomotive.EntityWarmlyLocomotive.BodyColor, additionalColor, checkBoxTrumpet.Checked,
checkBoxLuggage.Checked, _pictureWidth, _pictureHeight);
DrawWarmlyLocomotive();
}
private void labelAddColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void ButtonAdd()
{
throw new NotImplementedException();
}
}
}