2014-01-27 00:02:21 +00:00
using System ;
2014-01-28 19:33:49 +00:00
using System.Windows.Forms ;
2014-01-27 00:02:21 +00:00
namespace BizHawk.Bizware.BizwareGL
{
/// <summary>
2014-01-28 19:33:49 +00:00
/// a base class for deriving/wrapping from a IGraphicsControl.
/// This is to work around the annoyance that we cant inherit from a control whose type is unknown (it would be delivered by the selected BizwareGL driver)
/// and so we have to resort to composition and c# sucks and events suck.
2014-01-27 00:02:21 +00:00
/// </summary>
2014-01-28 19:33:49 +00:00
public class GraphicsControl : UserControl
2014-01-27 00:02:21 +00:00
{
2014-01-28 19:33:49 +00:00
public GraphicsControl ( IGL owner )
{
SetStyle ( ControlStyles . Opaque , true ) ;
SetStyle ( ControlStyles . UserPaint , true ) ;
SetStyle ( ControlStyles . AllPaintingInWmPaint , true ) ;
SetStyle ( ControlStyles . UserMouse , true ) ;
//in case we need it
//GLControl.GetType().GetMethod("SetStyle", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(GLControl, new object[] { System.Windows.Forms.ControlStyles.UserMouse, true });
IGC = owner . Internal_CreateGraphicsControl ( ) ;
Managed = IGC as Control ;
Managed . Dock = DockStyle . Fill ;
Controls . Add ( Managed ) ;
//pass through these events to the form. I tried really hard to find a better way, but there is none.
//(dont use HTTRANSPARENT, it isnt portable, I would assume)
Managed . MouseDoubleClick + = ( object sender , MouseEventArgs e ) = > OnMouseDoubleClick ( e ) ;
Managed . MouseClick + = ( object sender , MouseEventArgs e ) = > OnMouseClick ( e ) ;
2014-06-23 01:21:12 +00:00
Managed . MouseEnter + = ( object sender , EventArgs e ) = > OnMouseEnter ( e ) ;
Managed . MouseLeave + = ( object sender , EventArgs e ) = > OnMouseLeave ( e ) ;
2014-01-28 19:33:49 +00:00
//the GraphicsControl is occupying all of our area. So we pretty much never get paint events ourselves.
//So lets capture its paint event and use it for ourselves (it doesnt know how to do anything, anyway)
Managed . Paint + = new PaintEventHandler ( GraphicsControl_Paint ) ;
}
void GraphicsControl_Paint ( object sender , PaintEventArgs e )
{
OnPaint ( e ) ;
}
IGraphicsControl IGC ;
Control Managed ;
//public virtual Control Control { get { return Managed; } } //do we need this anymore?
public virtual void SetVsync ( bool state ) { IGC . SetVsync ( state ) ; }
public virtual void SwapBuffers ( ) { IGC . SwapBuffers ( ) ; }
public virtual void Begin ( ) { IGC . Begin ( ) ; }
public virtual void End ( ) { IGC . End ( ) ; }
2014-01-27 00:02:21 +00:00
}
}