2014-01-28 19:33:49 +00:00
using System.Windows.Forms ;
2020-02-18 16:31:49 +00:00
using BizHawk.Bizware.BizwareGL ;
namespace BizHawk.Client.EmuHawk
2014-01-27 00:02:21 +00:00
{
/// <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 )
{
2015-08-20 23:35:53 +00:00
IGL = owner ;
2014-01-28 19:33:49 +00:00
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 });
2020-02-28 18:32:45 +00:00
_igc = owner . Internal_CreateGraphicsControl ( ) ;
_managed = _igc as Control ;
_managed . Dock = DockStyle . Fill ;
Controls . Add ( _managed ) ;
2014-01-28 19:33:49 +00:00
2020-02-28 18:32:45 +00:00
// pass through these events to the form. I tried really hard to find a better way, but there is none.
// (don't use HTTRANSPARENT, it isn't portable, I would assume)
_managed . MouseDoubleClick + = ( sender , e ) = > OnMouseDoubleClick ( e ) ;
_managed . MouseClick + = ( sender , e ) = > OnMouseClick ( e ) ;
_managed . MouseEnter + = ( sender , e ) = > OnMouseEnter ( e ) ;
_managed . MouseLeave + = ( sender , e ) = > OnMouseLeave ( e ) ;
_managed . MouseMove + = ( sender , e ) = > OnMouseMove ( 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.
2020-02-28 18:32:45 +00:00
//So lets capture its paint event and use it for ourselves (it doesn't know how to do anything, anyway)
_managed . Paint + = GraphicsControl_Paint ;
2014-01-28 19:33:49 +00:00
}
2016-03-27 09:49:17 +00:00
/// <summary>
/// If this is the main window, things may be special
/// </summary>
public bool MainWindow ;
2014-01-28 19:33:49 +00:00
void GraphicsControl_Paint ( object sender , PaintEventArgs e )
{
OnPaint ( e ) ;
}
2015-08-20 23:35:53 +00:00
public readonly IGL IGL ;
2020-02-28 18:32:45 +00:00
private readonly IGraphicsControl _igc ;
readonly Control _managed ;
2014-01-28 19:33:49 +00:00
2020-02-28 18:32:45 +00:00
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
}
}