mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-11 00:25:29 +00:00
Enhanced WindowInfo API. A WindowInfo struct can now be initialized from any Control, Form, NativeWindow or GameWindow.
This commit is contained in:
parent
af35f805ba
commit
f2b92be34f
|
@ -15,10 +15,6 @@ namespace OpenTK.Platform
|
|||
/// </summary>
|
||||
public interface IMutableWindowInfo : IWindowInfo
|
||||
{
|
||||
IWindowInfo GetInfoFrom(System.Windows.Forms.Control control);
|
||||
IWindowInfo GetInfoFrom(System.Windows.Forms.NativeWindow window);
|
||||
IWindowInfo GetInfoFrom(OpenTK.GameWindow window);
|
||||
IWindowInfo GetInfoFrom(IWindowInfo info);
|
||||
void CopyInfoFrom(IWindowInfo info);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,5 +18,9 @@ namespace OpenTK.Platform
|
|||
{
|
||||
IntPtr Handle { get; }
|
||||
IWindowInfo Parent { get; }
|
||||
IWindowInfo GetInfoFrom(System.Windows.Forms.Control control);
|
||||
IWindowInfo GetInfoFrom(System.Windows.Forms.NativeWindow window);
|
||||
IWindowInfo GetInfoFrom(OpenTK.GameWindow window);
|
||||
IWindowInfo GetInfoFrom(IWindowInfo info);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace OpenTK.Platform
|
|||
/// <param name="window">The System.Windows.Forms.NativeWindow to get info from.</param>
|
||||
public WindowInfo(NativeWindow window) : this()
|
||||
{
|
||||
implementation.GetInfoFrom(window);
|
||||
implementation.CopyInfoFrom(implementation.GetInfoFrom(window));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -69,7 +69,7 @@ namespace OpenTK.Platform
|
|||
/// <param name="window">The OpenTK.GameWindow to get info from.</param>
|
||||
public WindowInfo(GameWindow window) : this()
|
||||
{
|
||||
implementation.GetInfoFrom(window);
|
||||
implementation.CopyInfoFrom(implementation.GetInfoFrom(window));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -92,10 +92,6 @@ namespace OpenTK.Platform
|
|||
get { return implementation.Parent; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IMutableWindowInfo Members ---
|
||||
|
||||
/// <summary>
|
||||
/// Updates the WindowInfo to describe the specified Control.
|
||||
/// </summary>
|
||||
|
@ -132,11 +128,25 @@ namespace OpenTK.Platform
|
|||
return implementation.GetInfoFrom(info);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IMutableWindowInfo Members ---
|
||||
|
||||
public void CopyInfoFrom(IWindowInfo info)
|
||||
{
|
||||
implementation.CopyInfoFrom(info);
|
||||
}
|
||||
|
||||
public static implicit operator Windows.WindowInfo (WindowInfo info)
|
||||
{
|
||||
return (Windows.WindowInfo)info.implementation;
|
||||
}
|
||||
|
||||
public static implicit operator X11.WindowInfo (WindowInfo info)
|
||||
{
|
||||
return (X11.WindowInfo)info.implementation;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace OpenTK.Platform.Windows
|
|||
/// Describes a Windows.Form.Control, Windows.Forms.NativeWindow or OpenTK.GameWindow on the Windows platform.
|
||||
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
/// </summary>
|
||||
internal sealed class WindowInfo : IMutableWindowInfo
|
||||
public sealed class WindowInfo : IMutableWindowInfo
|
||||
{
|
||||
private IntPtr handle;
|
||||
private WindowInfo parent;
|
||||
|
@ -24,19 +24,16 @@ namespace OpenTK.Platform.Windows
|
|||
{
|
||||
}
|
||||
|
||||
public WindowInfo(IntPtr handle, IWindowInfo parent)
|
||||
{
|
||||
this.Handle = handle;
|
||||
this.Parent = parent;
|
||||
}
|
||||
|
||||
public WindowInfo(IWindowInfo info)
|
||||
{
|
||||
/*
|
||||
if (info == null)
|
||||
throw new ArgumentException("WindowInfo cannot be null.");
|
||||
|
||||
this.Handle = info.Handle;
|
||||
this.Parent = info.Parent;
|
||||
*/
|
||||
this.CopyInfoFrom(info);
|
||||
}
|
||||
|
||||
public WindowInfo(Control control)
|
||||
|
@ -61,9 +58,11 @@ namespace OpenTK.Platform.Windows
|
|||
{
|
||||
if (window == null)
|
||||
throw new ArgumentException("GameWindow cannot be null.");
|
||||
|
||||
/*
|
||||
this.Handle = window.WindowInfo.Handle;
|
||||
this.Parent = window.WindowInfo.Parent;
|
||||
*/
|
||||
this.CopyInfoFrom(window.WindowInfo);
|
||||
}
|
||||
|
||||
#region --- IWindowInfo Members ---
|
||||
|
@ -88,12 +87,7 @@ namespace OpenTK.Platform.Windows
|
|||
if (control == null)
|
||||
throw new ArgumentException("Control cannot be null.");
|
||||
|
||||
if (control.Parent == null)
|
||||
{
|
||||
return new WindowInfo(control.Handle, null);
|
||||
}
|
||||
|
||||
return new WindowInfo(control.Handle, GetInfoFrom(control.Parent));
|
||||
return new WindowInfo(control);
|
||||
}
|
||||
|
||||
public IWindowInfo GetInfoFrom(NativeWindow window)
|
||||
|
@ -101,7 +95,7 @@ namespace OpenTK.Platform.Windows
|
|||
if (window == null)
|
||||
throw new ArgumentException("NativeWindow cannot be null.");
|
||||
|
||||
return new WindowInfo(window.Handle, null);
|
||||
return new WindowInfo(window);
|
||||
}
|
||||
|
||||
public IWindowInfo GetInfoFrom(GameWindow window)
|
||||
|
@ -120,10 +114,14 @@ namespace OpenTK.Platform.Windows
|
|||
return info;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IMutableWindowInfo Members ---
|
||||
|
||||
public void CopyInfoFrom(IWindowInfo info)
|
||||
{
|
||||
this.Handle = info.Handle;
|
||||
this.Parent = info.Parent;
|
||||
this.Parent = info.Parent;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -15,36 +15,53 @@ namespace OpenTK.Platform.X11
|
|||
/// Describes a Windows.Form.Control, Windows.Forms.NativeWindow or OpenTK.GameWindow on the X11 platform.
|
||||
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
||||
/// </summary>
|
||||
internal sealed class WindowInfo : IMutableWindowInfo
|
||||
public sealed class WindowInfo : IMutableWindowInfo
|
||||
{
|
||||
private IntPtr rootWindow, handle, topLevelWindow, display;
|
||||
private IntPtr handle, topLevelWindow;
|
||||
private IntPtr rootWindow, display;
|
||||
private int screen;
|
||||
private WindowInfo parent;
|
||||
private XVisualInfo visinfo;
|
||||
private static Type xplatui;
|
||||
|
||||
public WindowInfo()
|
||||
{
|
||||
visinfo = new XVisualInfo();
|
||||
//visinfo = new XVisualInfo();
|
||||
}
|
||||
|
||||
public WindowInfo(IWindowInfo info)
|
||||
{
|
||||
this.CopyInfoFrom(info);
|
||||
}
|
||||
|
||||
public WindowInfo(Control control)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (control == null)
|
||||
throw new ArgumentException("Control cannot be null.");
|
||||
|
||||
this.CopyInfoFromXPlatUI();
|
||||
this.Handle = control.Handle;
|
||||
this.Parent = control.Parent != null ? new WindowInfo(control.Parent) : this.Parent;
|
||||
this.TopLevelWindow = control.TopLevelControl != null ? control.TopLevelControl.Handle : IntPtr.Zero;
|
||||
}
|
||||
|
||||
public WindowInfo(NativeWindow window)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (window == null)
|
||||
throw new ArgumentException("NativeWindow cannot be null.");
|
||||
|
||||
this.CopyInfoFromXPlatUI();
|
||||
this.Handle = window.Handle;
|
||||
this.Parent = null;
|
||||
this.TopLevelWindow = IntPtr.Zero;
|
||||
}
|
||||
|
||||
public WindowInfo(GameWindow window)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
if (window == null)
|
||||
throw new ArgumentException("GameWindow cannot be null.");
|
||||
|
||||
public WindowInfo(WindowInfo info)
|
||||
{
|
||||
this.GetInfoFrom(info);
|
||||
this.CopyInfoFrom(window.WindowInfo);
|
||||
}
|
||||
|
||||
#region --- IWindowInfo Members ---
|
||||
|
@ -52,24 +69,20 @@ namespace OpenTK.Platform.X11
|
|||
public IntPtr Handle { get { return handle; } internal set { handle = value; } }
|
||||
public IWindowInfo Parent { get { return parent; } internal set { parent = value as WindowInfo; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IMutableWindowInfo Members ---
|
||||
|
||||
public IWindowInfo GetInfoFrom(Control control)
|
||||
{
|
||||
if (control == null)
|
||||
throw new ArgumentException("GameWindow cannot be null.");
|
||||
|
||||
throw new NotImplementedException();
|
||||
throw new ArgumentException("Control cannot be null.");
|
||||
|
||||
return new WindowInfo(control);
|
||||
}
|
||||
|
||||
public IWindowInfo GetInfoFrom(NativeWindow window)
|
||||
{
|
||||
if (window == null)
|
||||
throw new ArgumentException("GameWindow cannot be null.");
|
||||
throw new ArgumentException("NativeWindow cannot be null.");
|
||||
|
||||
throw new NotImplementedException();
|
||||
return new WindowInfo(window);
|
||||
}
|
||||
|
||||
public IWindowInfo GetInfoFrom(GameWindow window)
|
||||
|
@ -88,6 +101,10 @@ namespace OpenTK.Platform.X11
|
|||
return info;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IMutableWindowInfo Members ---
|
||||
|
||||
public void CopyInfoFrom(IWindowInfo info)
|
||||
{
|
||||
this.Handle = info.Handle;
|
||||
|
@ -115,5 +132,19 @@ namespace OpenTK.Platform.X11
|
|||
return String.Format("X11.WindowInfo: Display {0}, Screen {1}, Handle {2}, Parent: ({3})",
|
||||
this.Display, this.Screen, this.Handle, this.Parent != null ? this.Parent.ToString() : "null");
|
||||
}
|
||||
|
||||
private void CopyInfoFromXPlatUI()
|
||||
{
|
||||
xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
||||
if (xplatui == null)
|
||||
throw new ApplicationException("Could not get System.Windows.Forms.XplatUIX11 through reflection. Unsupported platform or Mono runtime version, aborting.");
|
||||
|
||||
this.Display = (IntPtr)xplatui.GetField("DisplayHandle",
|
||||
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null);
|
||||
this.RootWindow = (IntPtr)xplatui.GetField("RootWindow",
|
||||
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null);
|
||||
this.Screen = (int)xplatui.GetField("ScreenNo",
|
||||
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue