rss resume / curriculum vitae linkedin linkedin gitlab github twitter mastodon instagram
MonoCanvas, closer.
Apr 16, 2006

The updating to the Gtk# based version is closest ever, I'm missing Copy&Paste, DnD and MonoCanvas.Line, no doubt Line's implementation will take some time due to behavioral details when line is "glued" to other elements, after finishing it first release will hit the streets. While implementing this API I've been testing performance against its older brother, and yes, works better and faster, I was worried about this last solution wouldn't choose any other if this fails! :-P. I feel exaggerating is good to test your application in the worst case scenario, some kind of extremist but doing it that way feels better.

Subclassing Shapes in MonoCanvas is easy, you need to implement the InnerElement, usually the drawn element, and subclass from ShapeGroup. The following is a sample that would be Actor class, spplited in ActorElement.cs:

using System;
using Drawing = System.Drawing;
using MonoCanvas;

namespace MonoCanvasGtkSharp
{

public class ActorElement : Element
{

public ActorElement () : base ()
{ }

public override void Draw (Drawing.Graphics graphics)

{
Drawing.Rectangle r = base.Rectangle;
int headWidth = r.Width / 3;
int headHeight = r.Height / 4;

Drawing.Rectangle head = new Drawing.Rectangle (
headWidth, 0,
headWidth, headHeight);
graphics.FillEllipse (base.Brush, head);

graphics.DrawEllipse (base.Pen, head);

int half = r.Width / 2;
graphics.DrawLine (base.Pen, half,
headHeight, half / 2, headHeight * 2);
graphics.DrawLine (base.Pen, half,
headHeight, r.Width - half / 2, headHeight * 2);

graphics.DrawLine (base.Pen, half,
headHeight, half, headHeight * 3);

graphics.DrawLine (base.Pen, half,
headHeight * 3, half / 2, r.Height);
graphics.DrawLine (base.Pen, half,
headHeight * 3, r.Width - half / 2, r.Height);

}
}

}

And ActorShape.cs:

using Gtk;
using Gdk;
using System;
using MonoCanvas;

namespace MonoCanvasGtkSharp
{

public class ActorShape : ShapeGroup
{

public ActorShape () : base ()
{
base.InnerElement = new ActorElement ();
base.AddShape (new TextShape ("Actor name",
base.X, base.Y + base.Height,
100, 20), true);
}
}

}

Notice the following, ActorElement class only draws the Actor but might be doing other things, the second parameter of ShapeGroup.AddShape, determines Shape's independece, meaning that the Shape is allowed to act as an Independent Shape (Moved and Resizing be dragging). This is a quick sample for subclassing MonoCanvas, the idea is to be easy and rapid to implement to create UMLCanvas.

MonoCanvas' actor  MonoCanvas' actor


Back to posts