using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Netron.Diagramming.Core
{
///
/// A complex rectangular shape
///
public partial class ComplexRectangle : ComplexShapeBase, IAdditionCallback
{
#region Fields
// ------------------------------------------------------------------
///
/// Implementation of IVersion - the current version of
/// ComplexRectangle.
///
// ------------------------------------------------------------------
protected const double complexRectangleVersion = 1.0;
///
/// holds the bottom connector
///
Connector cBottom, cLeft, cRight, cTop;
#endregion
#region Properties
// ------------------------------------------------------------------
///
/// Gets the current version.
///
// ------------------------------------------------------------------
public override double Version
{
get
{
return complexRectangleVersion;
}
}
///
/// Gets the friendly name of the entity to be displayed in the UI
///
///
public override string EntityName
{
get { return "Complex Rectangle"; }
}
#endregion
#region Constructor
///
/// Default ctor
///
///
public ComplexRectangle(IModel s) : base(s)
{
}
///
/// Initializes a new instance of the class.
///
public ComplexRectangle()
: base()
{
}
// -----------------------------------------------------------------
///
/// Initializes this instance.
///
// -----------------------------------------------------------------
protected override void Initialize()
{
base.Initialize();
cTop = new Connector(new Point((int)(Rectangle.Left + Rectangle.Width / 2), Rectangle.Top), Model);
cTop.Name = "Top connector";
cTop.Parent = this;
Connectors.Add(cTop);
cRight = new Connector(new Point(Rectangle.Right, (int)(Rectangle.Top + Rectangle.Height / 2)), Model);
cRight.Name = "Right connector";
cRight.Parent = this;
Connectors.Add(cRight);
cBottom = new Connector(new Point((int)(Rectangle.Left + Rectangle.Width / 2), Rectangle.Bottom), Model);
cBottom.Name = "Bottom connector";
cBottom.Parent = this;
Connectors.Add(cBottom);
cLeft = new Connector(new Point(Rectangle.Left, (int)(Rectangle.Top + Rectangle.Height / 2)), Model);
cLeft.Name = "Left connector";
cLeft.Parent = this;
Connectors.Add(cLeft);
#region Some examples of materials; feel free to add/remove what you wish
/*
ClickableIconMaterial cicon = new ClickableIconMaterial("Resources.Schema.ico");
cicon.Resizable = false;
cicon.Gliding = false;
cicon.Transform(new Rectangle(Rectangle.X + 10, Rectangle.Y + 10, 16, 16));
Children.Add(cicon);
*/
/*
SwitchIconMaterial xicon = new SwitchIconMaterial(SwitchIconType.PlusMinus);
xicon.Gliding = false;
xicon.Resizable = false;
xicon.Transform(new Rectangle(Rectangle.X + 10, Rectangle.Y + 10, 16, 16));
Children.Add(xicon);
*/
/*
IconLabelMaterial ilab = new IconLabelMaterial("Resources.PublicMethod.ico", "ISerializable.GetObjectData");
ilab.Gliding = false;
ilab.Resizable = false;
ilab.Transform(new Rectangle(Rectangle.X + 10, Rectangle.Y + 10, Rectangle.Width - 20, Rectangle.Height - 30));
Children.Add(ilab);
*/
/*
IconMaterial icon = new IconMaterial("Resources.Web.png");
icon.Resizable = false;
icon.Gliding = false;
if(icon.Icon!=null)
icon.Transform(new Rectangle(Rectangle.X + 10, Rectangle.Y + 10, icon.Icon.Width , icon.Icon.Height));
Children.Add(icon);
*/
/*
LabelMaterial label = new LabelMaterial();
label.Text = "Complex rectangle example";
label.Transform( new Rectangle(Rectangle.X + 10, Rectangle.Y + 10, Rectangle.Width - 20, Rectangle.Height-30));
this.Children.Add(label);
*/
string[] stuff = new string[] {
"Wagner",
"van Beethoven",
"Sibelius",
"Lutovski",
"Haydn",
"Prokofiev",
"Karduso" };
FolderMaterial folder = new FolderMaterial("Expand me!", stuff);
folder.Transform(
new Rectangle(
Rectangle.X + 10,
Rectangle.Y + 10,
Rectangle.Width - 20,
Rectangle.Height - 30));
folder.OnFolderChanged +=
new EventHandler(folder_OnFolderChanged);
this.Children.Add(folder);
#endregion
Resizable = true;
Services[typeof(IAdditionCallback)] = this;
}
void folder_OnFolderChanged(object sender, RectangleEventArgs e)
{
Rectangle rec = e.Rectangle;
Transform(
new Rectangle(
Rectangle.Location,
new Size(Rectangle.Width, rec.Height + 20)));
}
#endregion
#region Methods
///
/// Paints the bundle on the canvas
///
///
public override void Paint(System.Drawing.Graphics g)
{
/*
Matrix or = g.Transform;
Matrix m = new Matrix();
m.RotateAt(20, Rectangle.Location);
g.MultiplyTransform(m, MatrixOrder.Append);
*/
g.SmoothingMode = SmoothingMode.HighQuality;
//the shadow
if (ArtPalette.EnableShadows)
{
g.FillRectangle(
ArtPalette.ShadowBrush,
Rectangle.X + 5,
Rectangle.Y + 5,
Rectangle.Width,
Rectangle.Height);
}
//the actual bundle
g.FillRectangle(Brush,Rectangle);
//the edge of the bundle
if(Hovered)
g.DrawRectangle(ArtPalette.HighlightPen,Rectangle);
else
g.DrawRectangle(ArtPalette.BlackPen, Rectangle);
//the connectors
if (this.ShowConnectors)
{
for (int k = 0; k < Connectors.Count; k++)
{
Connectors[k].Paint(g);
}
}
foreach (IPaintable material in Children)
{
material.Paint(g);
}
}
///
/// Called when the shape is added to the canvas.
///
public void OnAddition()
{
Transform(new Rectangle(Rectangle.Location, new Size(150, FolderMaterial.HeaderHeight + 20)));
//use a light color rather than the random low saturation color to show off the connection lines
PaintStyle = ArtPalette.GetDefaultSolidPaintStyle();
(PaintStyle as SolidPaintStyle).SolidColor= Color.WhiteSmoke;
}
#endregion
}
}