using System.Drawing; namespace Netron.Diagramming.Core { // ---------------------------------------------------------------------- /// /// A simple rectangular shape. /// // ---------------------------------------------------------------------- [Shape( "Rectangle", "SimpleRectangle", "Standard", "A simple rectangular shape.")] public partial class SimpleRectangle : SimpleShapeBase { #region Fields // ------------------------------------------------------------------ /// /// Implementation of IVersion - the current version of /// SimpleRectangle. /// // ------------------------------------------------------------------ protected const double simpleRectangleVersion = 1.0; // ------------------------------------------------------------------ /// /// The bottom connector. /// // ------------------------------------------------------------------ //Connector cBottom; // ------------------------------------------------------------------ /// /// The left connector. /// // ------------------------------------------------------------------ //Connector cLeft; // ------------------------------------------------------------------ /// /// The right connector. /// // ------------------------------------------------------------------ //Connector cRight; // ------------------------------------------------------------------ /// /// The top connector. /// // ------------------------------------------------------------------ //Connector cTop; #endregion #region Properties // ------------------------------------------------------------------ /// /// Gets the current version. /// // ------------------------------------------------------------------ public override double Version { get { return simpleRectangleVersion; } } // ------------------------------------------------------------------ /// /// Gets the friendly name of the entity to be displayed in the UI /// /// string // ------------------------------------------------------------------ public override string EntityName { get { return "Simple Rectangle"; } } public override Rectangle Rectangle { get { return base.Rectangle; } } #endregion #region Constructor // ------------------------------------------------------------------ /// /// Default constructor. /// /// // ------------------------------------------------------------------ public SimpleRectangle(IModel s) : base(s) { } // ------------------------------------------------------------------ /// /// Initializes a new instance of the /// class. /// // ------------------------------------------------------------------ public SimpleRectangle() : base() { } #endregion #region Methods // ----------------------------------------------------------------- /// /// Initializes this instance. /// // ----------------------------------------------------------------- protected override void Initialize() { base.Initialize(); //the initial size Transform(0, 0, 200, 50); this.mTextArea = Rectangle; // I'm changing the "simple" shapes to have no connectors. #region Connectors //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); #endregion } // ------------------------------------------------------------------ /// /// Paints the bundle on the canvas /// /// Graphics: The GDI+ graphics surface. // ------------------------------------------------------------------ public override void Paint(Graphics g) { // Draw the shadow. if (ArtPalette.EnableShadows) { g.FillRectangle( ArtPalette.ShadowBrush, mRectangle.X + 5, mRectangle.Y + 5, mRectangle.Width, mRectangle.Height); } // Fill the shape. g.FillRectangle(Brush, mRectangle); // Draw the edge of the bundle. if (Hovered) { g.DrawRectangle(ArtPalette.HighlightPen, mRectangle); } else { g.DrawRectangle(Pen, mRectangle); } // Finally, the connectors. if (this.ShowConnectors) { for (int k = 0; k < Connectors.Count; k++) { Connectors[k].Paint(g); } } //here we keep it really simple: if (!string.IsNullOrEmpty(Text)) { //StringFormat format = new StringFormat(); //format.Alignment = this.VerticalAlignment; //format.LineAlignment = this.HorizontalAlignment; //SolidBrush textBrush = new SolidBrush(mForeColor); //g.DrawString( // Text, // mFont, // textBrush, // TextArea, // format); g.DrawString( mTextStyle.GetFormattedText(Text), mTextStyle.Font, mTextStyle.GetBrush(), TextArea, mTextStyle.StringFormat); } } #endregion } }