/*============================================================================= Project: SharpImage Module: siRendererForm.cs Language: C# Author: Dan Mueller Date: $Date: 2007-09-06 16:19:18 +1000 (Thu, 06 Sep 2007) $ Revision: $Revision: 24 $ 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.Diagnostics; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace SharpImage.Rendering { public abstract partial class siRendererForm : Form { protected Control RenderingControl = null; protected siRenderer Renderer = null; protected bool IsInitialised = false; /// /// Proctected constructor. /// NOTE: The rendering control MUST be set explicitly using SetRenderingControl(). /// protected siRendererForm() : base() { // Call the designer code InitializeComponent(); } /// /// Proctected constructor. /// /// The control responsible for rendering the scene. protected siRendererForm(Control control) : base() { // Call the designer code InitializeComponent(); this.SetRenderingControl(control); } protected void SetRenderingControl(Control control) { // Check control is not null if (control == null) throw new NullReferenceException("The control for rendering the scene can not be null."); // Set the control this.RenderingControl = control; this.RenderingControl.Dock = DockStyle.Fill; base.Controls.Add(control); // Watch the events on the control control.Paint += new PaintEventHandler(RenderingControl_Paint); control.MouseDown += new MouseEventHandler(RenderingControl_MouseDown); control.MouseUp += new MouseEventHandler(RenderingControl_MouseUp); control.MouseMove += new MouseEventHandler(RenderingControl_MouseMove); control.MouseEnter += new EventHandler(RenderingControl_MouseEnter); control.KeyDown += new KeyEventHandler(RenderingControl_KeyDown); control.KeyUp += new KeyEventHandler(RenderingControl_KeyUp); control.KeyPress += new KeyPressEventHandler(RenderingControl_KeyPress); control.GotFocus += new EventHandler(RenderingControl_GotFocus); // NOTE: We do NOT need to listen to the MouseWheel event on the control because for // some reason the Form MouseWheel event is fired. Listening to the control // aswell causes the event to be fired twice. //control.MouseWheel += new MouseEventHandler(RenderingControl_MouseWheel); } /// /// Get/set the size of the renderable area. /// public virtual Size ViewportSize { get { return this.RenderingControl.ClientSize; } set { this.ClientSize = value; } } /// /// Get the screen rectangle of the renderable area. /// public virtual Rectangle ViewportRectangle { get { return this.RenderingControl.ClientRectangle; } } /// /// Force the Form to repaint. /// public abstract void Repaint(); /// /// Initialise the Form. /// public virtual void Initialise(siRenderer renderer) { this.Renderer = renderer; this.IsInitialised = true; } /// /// Force the Form to resize. /// public virtual void ForceResize() { this.OnResize(new EventArgs()); } /// /// Focus the form and make the rendering control active. /// /// public new bool Focus() { this.ActiveControl = this.RenderingControl; return base.Focus(); } void RenderingControl_Paint(object sender, PaintEventArgs e) { this.Renderer.RaiseModified(); this.OnPaint(e); } void RenderingControl_MouseUp(object sender, MouseEventArgs e) { this.OnMouseUp(e); } void RenderingControl_MouseDown(object sender, MouseEventArgs e) { this.ActiveControl = this.RenderingControl; this.OnMouseDown(e); } void RenderingControl_MouseEnter(object sender, EventArgs e) { // Do nothing } void RenderingControl_MouseMove(object sender, MouseEventArgs e) { this.OnMouseMove(e); } void RenderingControl_MouseWheel(object sender, MouseEventArgs e) { this.OnMouseWheel(e); } void RenderingControl_KeyPress(object sender, KeyPressEventArgs e) { this.OnKeyPress(e); } void RenderingControl_KeyUp(object sender, KeyEventArgs e) { this.OnKeyUp(e); } void RenderingControl_KeyDown(object sender, KeyEventArgs e) { this.OnKeyDown(e); } void RenderingControl_GotFocus(object sender, EventArgs e) { this.OnGotFocus(e); } } }