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_PlusRight : Form
{
public event EventHandler Changed;
Mover mover;
RuralPlusRight house;
Sample_RuralPlusRight sample;
Point ptMouseClick;
// -------------------------------------------------
public Form_Colors_PlusRight (RuralPlusRight srcHouse, Point ptScreenMouseClick)
{
InitializeComponent ();
mover = new Mover (this);
house = srcHouse;
ptMouseClick = ptScreenMouseClick;
// drawing coordinates
Rectangle rcHouse = new Rectangle (ClientSize .Width / 10, ClientSize .Height * 2 / 5,
ClientSize .Width * 2 / 5, ClientSize .Height / 2);
int room_W = rcHouse .Width / 2;
int room_H = rcHouse .Height / 2;
int dx = room_W * 3 / 5;
rcHouse .Width += dx;
Point ptPien = new Point ((rcHouse .Left + rcHouse .Right) / 2, ClientSize .Height / 10);
Size sizeSlope = new Size (rcHouse .Width / 3, (rcHouse .Top - ptPien .Y) / 3);
int window_W = room_W * 2 / 3;
int window_H = room_H / 2;
int [] cxWindow = new int [2];
int [] cyWindow = new int [2];
cxWindow [0] = rcHouse .Left + (room_W - window_W) / 2;
cxWindow [1] = cxWindow [0] + room_W;
cyWindow [0] = rcHouse .Top + (room_H - window_H) / 2;
cyWindow [1] = cyWindow [0] + room_H;
Rectangle [] rcWins = new Rectangle [4] {new Rectangle (cxWindow [0], cyWindow [0], window_W, window_H),
new Rectangle (cxWindow [0], cyWindow [1], window_W, window_H),
new Rectangle (cxWindow [1], cyWindow [0], window_W, window_H),
new Rectangle (cxWindow [1], cyWindow [1], window_W, window_H) };
int garageW = (ClientSize .Width - rcHouse .Right) * 2 / 3;
int cy = (rcHouse .Top + rcHouse .Bottom) / 2;
Rectangle rcGarage = new Rectangle (rcHouse .Right, cy, garageW, rcHouse .Bottom - cy);
Rectangle rcDoor = new Rectangle (rcGarage .Left + 6, rcGarage .Top + 10, rcGarage .Width - 12, rcGarage .Height - 10);
Point ptGarageSlopeTop = new Point (rcHouse .Right, rcGarage .Top - 24);
buttonRoof .Location = new Point (ptPien .X - buttonRoof .Width * 3 / 4, ptPien .Y + buttonRoof .Height);
buttonHouse .Location = new Point (rcHouse .Right - (buttonHouse .Width + 10),
(rcHouse .Top + rcHouse .Bottom) / 2 - buttonHouse .Height / 2);
buttonWindow .Location = new Point (cxWindow [0] + 6, cyWindow [0] + window_H - buttonWindow .Height + 6);
buttonDoor .Location = new Point (rcDoor .Right - (buttonDoor .Width + 6),
rcDoor .Bottom - (buttonDoor .Height + 6));
buttonEdge .Location = new Point (ptPien .X + sizeSlope .Width, ptPien .Y + sizeSlope .Height - buttonEdge .Height);
List<Control> ctrls = new List<Control> ();
ctrls .Add (buttonRoof);
ctrls .Add (buttonHouse);
ctrls .Add (buttonWindow);
ctrls .Add (buttonDoor);
ctrls .Add (buttonEdge);
sample = new Sample_RuralPlusRight (rcHouse, ptPien, sizeSlope, rcWins, rcGarage, ptGarageSlopeTop, 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_btnRoof
private void Click_btnRoof (object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog ();
dlg .Color = house .RoofColor;
if (dlg .ShowDialog () == DialogResult .OK)
{
house .RoofColor = dlg .Color;
sample .RoofColor = dlg .Color;
Invalidate ();
if (Changed != null) Changed (this, new EventArgs ());
}
}
// ------------------------------------------------- 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 ());
}
}
// ------------------------------------------------- Click_btnWindow
private void Click_btnWindow (object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog ();
dlg .Color = house .WindowColor;
if (dlg .ShowDialog () == DialogResult .OK)
{
house .WindowColor = dlg .Color;
sample .WindowColor = dlg .Color;
Invalidate ();
if (Changed != null) Changed (this, new EventArgs ());
}
}
// ------------------------------------------------- Click_btnEdge
private void Click_btnEdge (object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog ();
dlg .Color = house .EdgeColor;
if (dlg .ShowDialog () == DialogResult .OK)
{
house .EdgeColor = dlg .Color;
sample .EdgeColor = dlg .Color;
Invalidate ();
if (Changed != null) Changed (this, new EventArgs ());
}
}
}
// ******************************************
public class Sample_RuralPlusRight : GraphicalObject
{
Rectangle rcHouse;
Point ptPien;
Size sizeSlopes;
Rectangle [] rcWindows;
Rectangle rcGarage;
Point ptGarageRoof;
Rectangle rcDoor;
List<Control> controls = new List<Control> ();
SolidBrush brushHouse, brushRoof, brushWindow, brushDoor;
Pen penEdge;
// -------------------------------------------------
public Sample_RuralPlusRight (Rectangle rcMain, Point ptTop, Size sizeShift, Rectangle [] rcwins,
Rectangle rcAdd, Point ptTop2, Rectangle rcEntrance, List<Control> ctrls, Color [] clrs)
{
rcHouse = rcMain;
ptPien = ptTop;
sizeSlopes = sizeShift;
rcWindows = rcwins;
rcGarage = rcAdd;
ptGarageRoof = ptTop2;
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)
{
grfx .FillRectangle (brushHouse, rcHouse);
grfx .DrawRectangle (penEdge, rcHouse);
Point [] ptsRoof = {rcHouse .Location, new Point (ptPien .X - sizeSlopes .Width, ptPien .Y + sizeSlopes .Height), ptPien,
new Point (ptPien .X + sizeSlopes .Width, ptPien .Y + sizeSlopes .Height),
new Point (rcHouse .Right, rcHouse .Top) };
grfx .FillPolygon (brushRoof, ptsRoof);
grfx .DrawPolygon (penEdge, ptsRoof);
for (int i = 0; i < rcWindows .Length; i++)
{
grfx .FillRectangle (brushWindow, rcWindows [i]);
grfx .DrawRectangle (penEdge, rcWindows [i]);
}
grfx .FillRectangle (brushHouse, rcGarage);
grfx .DrawRectangle (penEdge, rcGarage);
ptsRoof = new Point [] {new Point (rcGarage .Left, rcGarage .Top), ptGarageRoof,
new Point (rcGarage .Right, rcGarage .Top) };
grfx .FillPolygon (brushRoof, ptsRoof);
grfx .DrawPolygon (penEdge, ptsRoof);
grfx .FillRectangle (brushDoor, rcDoor);
grfx .DrawRectangle (penEdge, rcDoor);
}
// ------------------------------------------------- DefineCover
public override void DefineCover ()
{
CoverNode [] nodes = new CoverNode [2];
nodes [0] = new CoverNode (0, new Point [] {rcHouse .Location,
new Point (ptPien .X - sizeSlopes .Width, ptPien .Y + sizeSlopes .Height),
ptPien,
new Point (ptPien .X + sizeSlopes .Width, ptPien .Y + sizeSlopes .Height),
new Point (rcHouse .Right, rcHouse .Top),
new Point (rcHouse .Right, rcHouse .Bottom),
new Point (rcHouse .Left, rcHouse .Bottom) });
nodes [1] = new CoverNode (1, new Point [] {new Point (rcGarage .Left, rcHouse .Bottom),
ptGarageRoof,
new Point (rcGarage .Right, rcHouse .Top),
new Point (rcGarage .Right, rcHouse .Bottom) });
cover = new Cover (nodes);
}
// ------------------------------------------------- Move
public override void Move (int dx, int dy)
{
Size size = new Size (dx, dy);
rcHouse .X += dx;
rcHouse .Y += dy;
ptPien += size;
for (int i = 0; i < rcWindows .Length; i++)
{
rcWindows [i] .X += dx;
rcWindows [i] .Y += dy;
}
rcGarage .X += dx;
rcGarage .Y += dy;
ptGarageRoof += size;
rcDoor .X += dx;
rcDoor .Y += dy;
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);
}
}
}