/*=============================================================================
Project: SharpImage
Module: siRendererForm.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.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.
///
/// The control responsible for rendering
/// the scene.
protected siRendererForm(Control renderingControl) : base()
{
// Call the designer code
InitializeComponent();
// Check control is not null
if (renderingControl == null)
throw new NullReferenceException("The Control for rendering the scene can not be null.");
// Set the control
this.RenderingControl = renderingControl;
this.RenderingControl.Dock = DockStyle.Fill;
base.Controls.Add(this.RenderingControl);
// Watch the events on the control
this.RenderingControl.Paint += new PaintEventHandler(RenderingControl_Paint);
this.RenderingControl.MouseDown += new MouseEventHandler(RenderingControl_MouseDown);
this.RenderingControl.MouseUp += new MouseEventHandler(RenderingControl_MouseUp);
this.RenderingControl.MouseMove += new MouseEventHandler(RenderingControl_MouseMove);
this.RenderingControl.MouseEnter += new EventHandler(RenderingControl_MouseEnter);
this.RenderingControl.KeyDown += new KeyEventHandler(RenderingControl_KeyDown);
this.RenderingControl.KeyUp += new KeyEventHandler(RenderingControl_KeyUp);
this.RenderingControl.KeyPress += new KeyPressEventHandler(RenderingControl_KeyPress);
this.RenderingControl.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.
//this.RenderingControl.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);
}
}
}