Pibd-22_Presnyakova.V.V_Cat.../Catamaran/FormBoatConfig.cs

202 lines
7.0 KiB
C#
Raw Normal View History

2022-11-07 01:27:11 +04:00
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 Catamaran
{
/// <summary>
/// Форма создания объекта
/// </summary>
public partial class FormBoatConfig : Form
{
/// <summary>
/// Переменная-выбранная машина
/// </summary>
DrawingBoat _boat = null;
/// <summary>
/// Событие
/// </summary>
private event Action<DrawingBoat> EventAddBoat;
2022-11-07 01:27:11 +04:00
/// <summary>
/// Конструктор
2022-11-07 10:54:56 +04:00
/// </summary>
public FormBoatConfig()
2022-11-07 01:27:11 +04:00
{
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelGray.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelRed.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
// TODO buttonCancel.Click with lambda
}
/// <summary>
/// Отрисовать машину
/// </summary>
2022-11-07 10:54:56 +04:00
private void DrawCatamaran()
2022-11-07 01:27:11 +04:00
{
Bitmap bmp = new Bitmap(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_boat?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
_boat?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// <summary>
/// Добавление события
/// </summary>
/// <param name="ev"></param>
public void AddEvent(Action<DrawingBoat> ev)
2022-11-07 01:27:11 +04:00
{
if (EventAddBoat == null)
{
EventAddBoat = new Action<DrawingBoat>(ev);
2022-11-07 01:27:11 +04:00
}
else
{
EventAddBoat += ev;
}
}
/// <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, 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))
{
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 "labelSimpleObject":
_boat = new DrawingBoat((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
break;
case "labelModifiedObject":
_boat = new DrawingCatamaran((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
checkBoxFloats.Checked, checkBoxSail.Checked);
break;
}
2022-11-07 10:54:56 +04:00
DrawCatamaran();
2022-11-07 01:27:11 +04:00
}
/// <summary>
/// Отправляем цвет с панели
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
/// <summary>
/// Проверка получаемой информации (ее типа на соответствие требуемому)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelBaseColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelDopColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)) && _boat is DrawingCatamaran)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
/// <summary>
/// Принимаем основной цвет
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
var color = (Color)e.Data.GetData(typeof(Color));
if (_boat is DrawingCatamaran)
{
_boat = ((DrawingCatamaran)_boat).Copy(bodyColor: color);
}
else if (_boat is DrawingBoat)
{
_boat = _boat.Copy(bodyColor: color);
}
2022-11-07 10:54:56 +04:00
DrawCatamaran();
2022-11-07 01:27:11 +04:00
// TODO Call method from object _boat and set color
}
/// <summary>
/// Принимаем дополнительный цвет
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
var color = (Color)e.Data.GetData(typeof(Color));
if (_boat is DrawingCatamaran)
{
_boat = ((DrawingCatamaran)_boat).Copy(dopColor: color);
}
2022-11-07 10:54:56 +04:00
DrawCatamaran();
2022-11-20 20:46:00 +04:00
// TODO Call method from object _boat if _boat is DrawingCatamaran and set dop color
2022-11-07 01:27:11 +04:00
}
/// <summary>
/// Добавление машины
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2022-11-07 10:54:56 +04:00
///
//public event System.Windows.Forms.Butt
2022-11-07 01:27:11 +04:00
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddBoat?.Invoke(_boat);
Close();
}
}
}