PIbd-21_Valitov_D.F_Sailboa.../Sailboat/FormBoatConfig.cs
2023-04-21 00:50:18 +04:00

119 lines
3.9 KiB
C#

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 Sailboat
{
public partial class FormBoatConfig : Form
{
DrawingBoat _boat = null;
private event BoatDelegate EventAddBoat;
public FormBoatConfig()
{
InitializeComponent();
panelBlack.MouseDown += panelColor_MouseDown;
panelWhite.MouseDown += panelColor_MouseDown;
panelGreen.MouseDown += panelColor_MouseDown;
panelYellow.MouseDown += panelColor_MouseDown;
panelRed.MouseDown += panelColor_MouseDown;
panelBlue.MouseDown += panelColor_MouseDown;
panelPurple.MouseDown += panelColor_MouseDown;
panelGray.MouseDown += panelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
}
public void AddEvent(BoatDelegate ev)
{
if (EventAddBoat == null)
{
EventAddBoat = new BoatDelegate(ev);
}
else
{
EventAddBoat += ev;
}
}
private void DrawBoat()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_boat?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
_boat?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
private void labelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
}
private void panelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void panelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data.GetData(DataFormats.Text).ToString())
{
case "labelBoat":
_boat = new DrawingBoat((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
break;
case "labelSailboat":
_boat = new DrawingSailboat((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
checkBoxSail.Checked, checkBoxExtendedBody.Checked);
break;
}
DrawBoat();
}
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
_boat?.Boat.ChangeBaseColor((Color)e.Data.GetData(typeof(Color)));
DrawBoat();
}
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
if (_boat?.Boat is Sailboat sailboat)
{
sailboat.ChangeDopColor((Color)e.Data.GetData(typeof(Color)));
DrawBoat();
}
}
private void buttonOK_Click(object sender, EventArgs e)
{
EventAddBoat?.Invoke(_boat);
Close();
}
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 panelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
}
}