127 lines
4.4 KiB
C#
127 lines
4.4 KiB
C#
using lab1.Drawnings;
|
||
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 lab1;
|
||
/// <summary>
|
||
/// Форма конфигурации объекта
|
||
/// </summary>
|
||
public partial class FormTrackedVehicleConfig : Form
|
||
|
||
{
|
||
/// <summary>
|
||
/// Объект - прорисовка гусеничной машины
|
||
/// </summary>
|
||
private DrawningTrackedVehicle _trackedVehicle = null;
|
||
|
||
/// <summary>
|
||
/// Конструктор
|
||
/// </summary>
|
||
public FormTrackedVehicleConfig()
|
||
{
|
||
|
||
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;
|
||
//TODO buttonCancel.Click with lambda с закрытием формы
|
||
buttonCancel.Click += (object sender, EventArgs e) => Close();
|
||
InitializeComponent();
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// Прорисовка объекта
|
||
/// </summary>
|
||
private void DrawObject()
|
||
{
|
||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||
Graphics gr = Graphics.FromImage(bmp);
|
||
_trackedVehicle?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height);
|
||
_trackedVehicle?.SetPosition(25, 25);
|
||
_trackedVehicle?.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 PanelObject1_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 panelObject1_DragDrop(object sender, DragEventArgs e)
|
||
{
|
||
switch (e.Data?.GetData(DataFormats.Text)?.ToString())
|
||
{
|
||
|
||
case "labelSimpleObject":
|
||
_trackedVehicle = new DrawningTrackedVehicle((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White);
|
||
break;
|
||
case "LabelModifiedObject":
|
||
_trackedVehicle = new DrawningEntityFighter((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value,
|
||
Color.White,
|
||
Color.Black, checkBoxKovsh.Checked,
|
||
checkBoxOtval.Checked);
|
||
break;
|
||
}
|
||
DrawObject();
|
||
|
||
}
|
||
|
||
private void FormTrackedVehicleConfig_Load(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
/// <summary>
|
||
/// Передаём информацию при нажатии на Panel
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void Panel_MouseDown(object sender, MouseEventArgs e)
|
||
{
|
||
//TODO отправка цвета в Drag&Drop
|
||
(sender as Control)?.DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||
}
|
||
//TODO реализовать логику смены цветов: основного и дополнительного ( для продвинутого объекта)
|
||
private void LabelBodyColor_DragEnter(object? sender, DragEventArgs e)
|
||
{
|
||
if (e.Data.GetDataPresent(typeof(Color)))
|
||
{
|
||
e.Effect = DragDropEffects.Copy;
|
||
}
|
||
else
|
||
{
|
||
e.Effect = DragDropEffects.None;
|
||
}
|
||
}
|
||
}
|