using System;
using System .Collections .Generic;
using System .ComponentModel;
using System .Drawing;
using System .Windows .Forms;
using MoveGraphLibrary;
namespace UserDrivenApplications
{
public partial class Form_Colors_Hangar : Form
{
public event EventHandler Changed;
Mover mover;
Hangar house;
Sample_Hangar sample;
Point ptMouseClick;
// -------------------------------------------------
public Form_Colors_Hangar (Hangar srcHouse, Point ptScreenMouseClick)
{
InitializeComponent ();
mover = new Mover (this);
house = srcHouse;
ptMouseClick = ptScreenMouseClick;
// drawing coordinates
int nRadius = ClientSize .Height * 2 / 3;
Point ptCenter = new Point (ClientSize .Width / 2, (ClientSize .Height - nRadius) / 2 + nRadius);
int hDoor = 60;
int wDoor = 100;
Rectangle rcDoor = new Rectangle (ptCenter .X - wDoor / 2, ptCenter .Y - hDoor, wDoor, hDoor);
buttonHouse .Location = new Point (ptCenter .X + buttonHouse .Width / 2, ptCenter .Y - nRadius + buttonHouse .Height * 2 / 3);
buttonDoor .Location = new Point (rcDoor .Left + 6, rcDoor .Bottom - (buttonDoor .Height + 6));
List<Control> ctrls = new List<Control> ();
ctrls .Add (buttonHouse);
ctrls .Add (buttonDoor);
sample = new Sample_Hangar (ptCenter, nRadius, rcDoor, ctrls, house .GetColors ());
mover .Add (sample);
}
// ------------------------------------------------- OnLoad
private void OnLoad (object sender, EventArgs e)
{
Location = ptMouseClick;
}
// ------------------------------------------------- OnPaint
private void OnPaint (object sender, PaintEventArgs e)
{
sample .Draw (e .Graphics);
}
// ------------------------------------------------- OnMouseDown
private void OnMouseDown (object sender, MouseEventArgs e)
{
mover .Catch (e .Location, e .Button);
}
// ------------------------------------------------- OnMouseUp
private void OnMouseUp (object sender, MouseEventArgs e)
{
mover .Release ();
}
// ------------------------------------------------- OnMouseMove
private void OnMouseMove (object sender, MouseEventArgs e)
{
if (mover .Move (e .Location))
{
Invalidate ();
}
}
// ------------------------------------------------- Click_btnHouse
private void Click_btnHouse (object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog ();
dlg .Color = house .HouseColor;
if (dlg .ShowDialog () == DialogResult .OK)
{
house .HouseColor = dlg .Color;
sample .HouseColor = dlg .Color;
Invalidate ();
if (Changed != null) Changed (this, new EventArgs ());
}
}
// ------------------------------------------------- Click_btnDoor
private void Click_btnDoor (object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog ();
dlg .Color = house .DoorColor;
if (dlg .ShowDialog () == DialogResult .OK)
{
house .DoorColor = dlg .Color;
sample .DoorColor = dlg .Color;
Invalidate ();
if (Changed != null) Changed (this, new EventArgs ());
}
}
}
// ******************************************
public class Sample_Hangar : GraphicalObject
{
Point ptCenter;
int radius;
Rectangle rcDoor;
List<Control> controls = new List<Control> ();
SolidBrush brushHouse, brushRoof, brushWindow, brushDoor;
Pen penEdge;
// -------------------------------------------------
public Sample_Hangar (Point ptC, int nRad, Rectangle rcEntrance, List<Control> ctrls, Color [] clrs)
{
ptCenter = ptC;
radius = nRad;
rcDoor = rcEntrance;
controls = ctrls;
SetColors (clrs);
}
// ------------------------------------------------- SetColors
public void SetColors (Color [] clrs)
{
brushHouse = new SolidBrush (clrs [0]);
brushRoof = new SolidBrush (clrs [1]);
brushWindow = new SolidBrush (clrs [2]);
brushDoor = new SolidBrush (clrs [3]);
penEdge = new Pen (clrs [4]);
}
// ------------------------------------------------- HouseColor
public Color HouseColor
{
set { brushHouse = new SolidBrush (value); }
}
// ------------------------------------------------- RoofColor
public Color RoofColor
{
set { brushRoof = new SolidBrush (value); }
}
// ------------------------------------------------- WindowColor
public Color WindowColor
{
set { brushWindow = new SolidBrush (value); }
}
// ------------------------------------------------- DoorColor
public Color DoorColor
{
set { brushDoor = new SolidBrush (value); }
}
// ------------------------------------------------- EdgeColor
public Color EdgeColor
{
set { penEdge = new Pen (value); }
}
// ------------------------------------------------- Draw
public void Draw (Graphics grfx)
{
Rectangle rc = new Rectangle (ptCenter .X - radius, ptCenter .Y - radius, 2 * radius, 2 * radius);
grfx .FillPie (brushHouse, rc, 0, -180);
grfx .DrawPie (penEdge, rc, 0, -180);
grfx .FillRectangle (brushDoor, rcDoor);
grfx .DrawRectangle (penEdge, rcDoor);
int cx = ptCenter .X;
grfx .DrawLine (penEdge, cx, rcDoor .Top, cx, rcDoor .Bottom);
}
// ------------------------------------------------- DefineCover
public override void DefineCover ()
{
CoverNode [] nodes = new CoverNode [2];
nodes [0] = new CoverNode (0, new Rectangle (ptCenter .X - radius, ptCenter .Y, 2 * radius, radius),
MovementFreedom .Transparent, Cursors .Default);
nodes [1] = new CoverNode (1, ptCenter, radius, Cursors .SizeAll);
cover = new Cover (nodes);
}
// ------------------------------------------------- Move
public override void Move (int dx, int dy)
{
Size size = new Size (dx, dy);
ptCenter += size;
for (int i = 0; i < controls .Count; i++)
{
controls [i] .Location += size;
}
}
// ------------------------------------------------- MoveNode
public override bool MoveNode (int i, int dx, int dy, Point ptM, MouseButtons catcher)
{
bool bRet = false;
if (catcher == MouseButtons .Left)
{
Move (dx, dy);
bRet = true;
}
return (bRet);
}
}
}