|
using System;
using System .Collections .Generic;
using System .Drawing;
using System .Drawing .Drawing2D;
using System .IO;
using System .Windows .Forms;
using Microsoft .Win32;
using MoveGraphLibrary;
namespace UserDrivenApplications
{
public class BuildingsGroup : GraphicalObject
{
int version = 606;
List<Building> elements = new List<Building> ();
int [] sidespace = new int [4]; // Left, Top, Right, Bottom
Rectangle rcFrame; // only through calculation
SolidBrush brushBack;
bool bShowFrame;
Pen penFrame;
int minFrameSpace = 6;
// -------------------------------------------------
public BuildingsGroup (List<Building> elems, int [] framespaces, Pen pen)
{
elements = elems;
foreach (Building elem in elements)
{
elem .ParentID = id;
}
for (int i = 0; i < 4; i++)
{
sidespace [i] = Math .Max (minFrameSpace, framespaces [i]);
}
FrameArea ();
brushBack = new SolidBrush (Color .FromArgb (204, Color .Cyan)); // transparency = 0.2 A = 255 * (1 - coef)
bShowFrame = true;
penFrame = pen;
}
// -------------------------------------------------
public BuildingsGroup (List<Building> elems)
: this (elems, new int [] { 10, 10, 10, 10 }, new Pen (Color .Blue))
{
}
// ------------------------------------------------- FrameArea
private void FrameArea ()
{
RectangleF unionArea = elements [0] .RectAround ();
for (int i = 1; i < elements .Count; i++)
{
unionArea = RectangleF .Union (unionArea, elements [i] .RectAround ());
}
unionArea .X -= sidespace [0];
unionArea .Y -= sidespace [1];
unionArea .Width += sidespace [0] + sidespace [2];
unionArea .Height += sidespace [1] + sidespace [3];
rcFrame = Rectangle .Round (unionArea);
}
// ------------------------------------------------- RectAround
new public Rectangle RectAround
{
get
{
FrameArea ();
return (rcFrame);
}
}
// ------------------------------------------------- Frame
// when any building is moved outside the frame, the call to Frame prior to RectAround can give different results !!!
public Rectangle Frame
{
get { return (rcFrame); }
}
// ------------------------------------------------- Update
public void Update ()
{
FrameArea ();
DefineCover ();
}
// ------------------------------------------------- ID
new public long ID
{
get { return (id); }
set
{
id = value;
foreach (Building elem in elements)
{
elem .ParentID = id;
}
}
}
// ------------------------------------------------- Elements
public List<Building> Elements
{
get { return (elements); }
}
// ------------------------------------------------- SideSpaces
public int [] SideSpaces
{
get { return (sidespace); }
set
{
if (value != null && value .Length == 4)
{
for (int k = 0; k < 4; k++)
{
sidespace [k] = Math .Max (minFrameSpace, value [k]);
}
Update ();
}
}
}
// ------------------------------------------------- ShowFrame
public bool ShowFrame
{
get { return (bShowFrame); }
set { bShowFrame = value; }
}
// ------------------------------------------------- FrameColor
public Color FrameColor
{
get { return (penFrame .Color); }
set { penFrame .Color = value; }
}
// ------------------------------------------------- BackColor
public Color BackColor
{
get { return (brushBack .Color); }
//set { brushBack = new SolidBrush (value); }
}
// ------------------------------------------------- Pen
public Pen Pen
{
get { return (penFrame); }
set { penFrame = value; }
}
// ------------------------------------------------- Draw
public void Draw (Graphics grfx)
{
grfx .FillRectangle (brushBack, Rectangle .FromLTRB (rcFrame .Left - 3, rcFrame .Top - 3, rcFrame .Right + 3, rcFrame .Bottom + 3));
Auxi_Drawing .CurvedFrame (grfx, rcFrame, penFrame);
}
// ------------------------------------------------- DefineCover
public override void DefineCover ()
{
Rectangle rc = rcFrame;
rc .Inflate (3, 3);
cover = new Cover (rc, Resizing .None);
cover .SetCursor (Cursors .Hand);
}
// ------------------------------------------------- Move
public override void Move (int dx, int dy)
{
rcFrame .X += dx;
rcFrame .Y += dy;
foreach (Building elem in elements)
{
elem .Move (dx, dy);
}
}
// ------------------------------------------------- MoveNode
public override bool MoveNode (int i, int dx, int dy, Point ptM, MouseButtons mb)
{
bool bRet = false;
if (mb == MouseButtons .Left)
{
Move (dx, dy);
bRet = true;
}
return (bRet);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.