namespace TACO.Widgets { using System; using System.Drawing; public abstract class CanvasElement { public static Gdk.Drawable Drawable; private string mId; private Rectangle mBounds; private bool mSelected; private bool mVisible; public delegate void BoundsChangedEventHandler(object sender, BoundsChangedArgs args); public event System.EventHandler VisibilityChanged; public event System.EventHandler SelectionChanged; public event BoundsChangedEventHandler BoundsChanged; protected CanvasElement(string id) { mId = id; mBounds = new Rectangle(); mSelected = false; mVisible = false; } public string Id { get { return mId; } } public abstract string Name { get; } public virtual bool Visible { get { return mVisible; } set { if (mVisible != value) { mVisible = value; OnVisibilityChanged(new System.EventArgs()); } } } public Rectangle Bounds { get { return mBounds; } } public bool Selected { get { return mSelected; } set { if (mSelected != value) { mSelected = value; OnSelectionChanged(new System.EventArgs()); } } } public void SetBounds(int x, int y, int width, int height) { if (mBounds.X == x && mBounds.Y == y && mBounds.Width == width && mBounds.Height == height) { return; } Rectangle oldBounds = Bounds; mBounds.X = x; mBounds.Y = y; mBounds.Width = width; mBounds.Height = height; OnBoundsChanged(new BoundsChangedArgs(oldBounds)); } public void SetBounds(Rectangle bounds) { SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height); } public void MoveTo(int x, int y) { if (mBounds.X == x && mBounds.Y == y) return; SetBounds(x, y, Bounds.Width, Bounds.Height); } public void ResizeTo(int width, int height) { if (mBounds.Width == width && mBounds.Height == height) return; SetBounds(Bounds.X, Bounds.Y, width, height); } public virtual void Draw(System.Drawing.Graphics g) { } protected void OnVisibilityChanged(System.EventArgs e) { if (VisibilityChanged != null) VisibilityChanged(this, e); } protected void OnSelectionChanged(System.EventArgs e) { if (SelectionChanged != null) SelectionChanged(this, e); } protected void OnBoundsChanged(BoundsChangedArgs e) { if (BoundsChanged != null) BoundsChanged(this, e); } } }