/*============================================================================= Project: SharpImage Module: siActor.cs Language: C# Author: Dan Mueller Date: $Date: 2007-07-06 10:57:00 +1000 (Fri, 06 Jul 2007) $ Revision: $Revision: 2 $ Copyright (c) Queensland University of Technology (QUT) 2007. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =============================================================================*/ using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Windows.Forms; using System.Diagnostics; using SharpImage.Main; using SharpImage.Properties; namespace SharpImage.Rendering { public class siActor where TParent: class { #region Instance Variables //===================================================================== //========================================================================= #endregion #region Construction and Disposal //===================================================================== /// /// Protected parameterless constructor for serialization. /// protected siActor() { } //===================================================================== #endregion #region Properties //===================================================================== #region Visible //===================================================================== private bool m_Visible = true; /// /// Gets/sets if the actor is visible in the Renderer. /// [System.ComponentModel.Browsable(true)] [System.ComponentModel.Category("General")] public bool Visible { get { return this.m_Visible; } set { this.m_Visible = value; this.RaiseModified(); } } //===================================================================== #endregion #region Metadata //===================================================================== private Dictionary m_Metadata = new Dictionary(); /// /// Gets the Metadata variable list. /// [System.ComponentModel.Browsable(false)] [System.Xml.Serialization.XmlIgnore] public Dictionary Metadata { get { return this.m_Metadata; } } //===================================================================== #endregion //===================================================================== #endregion #region Events //===================================================================== public delegate void siActorHandler(siActor sender); public delegate void siActorModifiedHandler(siActor sender, bool partial); private siActorModifiedHandler m_EventStorage_Modified; private MouseEventHandler m_EventStorage_MouseDown; /// /// An event raised when the actor is modified. /// public event siActorModifiedHandler Modified { add { this.m_EventStorage_Modified += value; } remove { this.m_EventStorage_Modified -= value; } } /// /// Raises the Modified event. Actor subclasses should call this /// when a change occurs in the actor that requires the parent /// Renderer to be repainted. This signals a full modification /// (ie. partial = false). /// public void RaiseModified() { if (this.m_EventStorage_Modified != null) this.m_EventStorage_Modified(this, false); } /// /// Raises the Modified event. Actor subclasses should call this /// when a change occurs in the actor that requires the parent /// Renderer to be repainted. /// /// True and only a partial modification occured, otherwise /// False and a full modification occurred. public void RaiseModified(bool partial) { if (this.m_EventStorage_Modified != null) this.m_EventStorage_Modified(this, partial); } /// /// An event raised when the mouse is clicked. /// public event MouseEventHandler MouseDownEvent { add { this.m_EventStorage_MouseDown += value; } remove { this.m_EventStorage_MouseDown -= value; } } /// /// Raises the MouseDown event. /// protected void RaiseMouseDownEvent(MouseEventArgs e) { if (this.m_EventStorage_MouseDown != null) this.m_EventStorage_MouseDown(this, e); } //===================================================================== #endregion #region Public Methods //===================================================================== //===================================================================== #endregion #region Event Methods //===================================================================== /// /// Renders the actor. /// /// /// public void Paint(TParent parent, PaintEventArgs e) { this.OnPaint(parent, e); } /// /// Allows the actor to render itself. /// /// /// protected virtual void OnPaint(TParent parent, PaintEventArgs e) { return; } /// /// Gives the actor a chance to consume a MouseDown event. /// Returns true if the actor has consumed the event. /// /// /// true AND the event was consumed OR /// false AND the event was ignores/not relevant. public bool MouseDown(TParent parent, MouseEventArgs e) { return this.OnMouseDown(parent, e); } /// /// Allows the actor to consume the MouseDown event. /// /// /// protected virtual bool OnMouseDown(TParent parent, MouseEventArgs e) { this.RaiseMouseDownEvent(e); return false; } /// /// Gives the actor a chance to consume a MouseUp event. /// Returns true if the actor has consumed the event. /// /// /// true AND the event was consumed OR /// false AND the event was ignores/not relevant. public bool MouseUp(TParent parent, MouseEventArgs e) { return this.OnMouseUp(parent, e); } /// /// Allows the actor to consume the MouseDown event. /// /// /// protected virtual bool OnMouseUp(TParent parent, MouseEventArgs e) { return false; } /// /// Gives the actor a chance to consume a MouseMove event. /// Returns true if the actor has consumed the event. /// /// /// true AND the event was consumed OR /// false AND the event was ignores/not relevant. public bool MouseMove(TParent parent, MouseEventArgs e) { return this.OnMouseMove(parent, e); } /// /// Allows the actor to consume the MouseMove event. /// /// /// protected virtual bool OnMouseMove(TParent parent, MouseEventArgs e) { return false; } //===================================================================== #endregion } }