139 lines
4.7 KiB
C#
139 lines
4.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
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
|
|
{
|
|
public partial class FormCatamaranConfig : Form
|
|
{
|
|
|
|
DrawningCatamaran? _catamaran = null;
|
|
|
|
private event Action<DrawningCatamaran>? EventAddCatamaran;
|
|
|
|
public void AddEvent(Action<DrawningCatamaran> ev)
|
|
{
|
|
if (EventAddCatamaran == null)
|
|
{
|
|
EventAddCatamaran = ev;
|
|
}
|
|
else
|
|
{
|
|
EventAddCatamaran += ev;
|
|
}
|
|
}
|
|
|
|
public FormCatamaranConfig()
|
|
{
|
|
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;
|
|
panelOrange.MouseDown += PanelColor_MouseDown;
|
|
panelBlue.MouseDown += PanelColor_MouseDown;
|
|
labelSimpleObject.MouseDown += LabelObject_MouseDown;
|
|
labelHardObject.MouseDown += LabelObject_MouseDown;
|
|
buttonRepeal.Click += (s, e) => Close();
|
|
}
|
|
|
|
private void DrawCatamaran()
|
|
{
|
|
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_catamaran?.SetPosition(5, 5);
|
|
_catamaran?.DrawTransport(gr);
|
|
pictureBoxObject.Image = bmp;
|
|
}
|
|
|
|
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
|
|
DragDropEffects.Move | DragDropEffects.Copy);
|
|
}
|
|
|
|
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
|
{
|
|
case "labelSimpleObject":
|
|
_catamaran = new DrawningCatamaran((int)numericUpDownSpeed.Value,
|
|
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
|
|
pictureBoxObject.Height);
|
|
break;
|
|
case "labelHardObject":
|
|
_catamaran = new DrawningCatamaranPro((int)numericUpDownSpeed.Value,
|
|
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxBodyKit.Checked,
|
|
checkBoxMotor.Checked, checkBoSail.Checked, pictureBoxObject.Width,
|
|
pictureBoxObject.Height);
|
|
break;
|
|
}
|
|
DrawCatamaran();
|
|
}
|
|
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 ButtonOk_Click(object sender, EventArgs e)
|
|
{
|
|
EventAddCatamaran?.Invoke(_catamaran);
|
|
Close();
|
|
}
|
|
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
|
|
DragDropEffects.Move | DragDropEffects.Copy);
|
|
|
|
}
|
|
private void ColorLabel_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
string senderName = ((Label)sender).Name;
|
|
if (_catamaran == null || e.Data.GetDataPresent(typeof(Color)) == false)
|
|
return;
|
|
|
|
Color droppedColor = (Color)e.Data.GetData(typeof(Color));
|
|
|
|
if (senderName == "labelColourMain")
|
|
{
|
|
labelColourMain.BackColor = droppedColor;
|
|
((DrawningCatamaran)_catamaran).ChangeColor(labelColourMain.BackColor);
|
|
}
|
|
else if (senderName == "labelAdditionalColor" && _catamaran is DrawningCatamaran)
|
|
{
|
|
labelAdditionalColor.BackColor = droppedColor;
|
|
((DrawningCatamaranPro)_catamaran).ChangeAddColor(labelAdditionalColor.BackColor);
|
|
}
|
|
|
|
DrawCatamaran();
|
|
}
|
|
private void ColorLabel_DragEnter(object sender, DragEventArgs e)
|
|
{
|
|
if (e.Data.GetDataPresent(typeof(Color)))
|
|
{
|
|
e.Effect = DragDropEffects.Copy;
|
|
}
|
|
else
|
|
{
|
|
e.Effect = DragDropEffects.None;
|
|
}
|
|
}
|
|
}
|
|
}
|