Pibd_13_Fathutdinov_A.I._Si.../ProjectLiner/ProjectLiner/FormLinerConfig.cs

190 lines
6.0 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 ProjectLiner.Drawnings;
using ProjectLiner.Entities;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;
namespace ProjectLiner;
/// <summary>
/// Форма конфигурации объекта
/// </summary>
public partial class FormLinerConfig : Form
{
/// <summary>
/// Объект - прорисовка самолета
/// </summary>
private DrawningCommonLiner? _commonLiner;
/// <summary>
/// Событие для передачи объекта
/// </summary>
private event Action<DrawningCommonLiner>? linerDelegate;
public FormLinerConfig()
{
InitializeComponent();
panelBlueViolet.MouseDown += Panel_MouseDown;
panelMediumBlue.MouseDown += Panel_MouseDown;
panelAqua.MouseDown += Panel_MouseDown;
panelCrimson.MouseDown += Panel_MouseDown;
panelDarkOliveGreen.MouseDown += Panel_MouseDown;
panelPaleGreen.MouseDown += Panel_MouseDown;
panelSeaGreen.MouseDown += Panel_MouseDown;
panelDeepPink.MouseDown += Panel_MouseDown;
buttonCancel.Click += (sender, e) => Close();
}
/// <summary>
/// Привязка внешнего метода к событию
/// </summary>
/// <param name="commonlinerDelegate"></param>
public void AddEvent(Action<DrawningCommonLiner> commonlinerDelegate)
{
linerDelegate += commonlinerDelegate;
}
/// <summary>
/// Прорисовка объекта
/// </summary>
private void DrawObject()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_commonLiner?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
_commonLiner?.SetPosition(5, 5);
_commonLiner?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Передаем информацию при нажатии на Label
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : 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 "labelSimpleObject":
_commonLiner = new DrawningCommonLiner((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
break;
case "labelModifiedObject":
_commonLiner = new DrawningLiner((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White,
Color.Black, checkBoxAnchor.Checked, checkBoxBoats.Checked, checkBoxPipe.Checked);
break;
}
DrawObject();
}
/// <summary>
/// Передаем информацию при нажатии на Panel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Panel_MouseDown(object? sender, MouseEventArgs e)
{
(sender as Control)?.DoDragDrop((sender as Control)?.BackColor!, DragDropEffects.Move | DragDropEffects.Copy);
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
if (_commonLiner != null)
{
linerDelegate?.Invoke(_commonLiner);
Close();
}
}
/// <summary>
/// Передача основного цвета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelBodyColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Прорисовка основным цветом
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelBodyColor_DragDrop(object sender, DragEventArgs e)
{
if (_commonLiner != null)
{
_commonLiner.EntityCommonLiner?.SetBodyColor((Color)e.Data.GetData(typeof(Color)));
DrawObject();
}
}
/// <summary>
/// Прорисовка дополнительным цветом
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
if (_commonLiner?.EntityCommonLiner is EntityLiner _liner)
{
_liner.SetAdditionalColor((Color)e.Data.GetData(typeof(Color)));
}
DrawObject();
}
/// <summary>
/// Передача дополнительного цвета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e)
{
if (_commonLiner is DrawningLiner)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
}