Added experimental OpenTK.Point/Size/Rectangle alternatives to System.Drawing, to make OpenTK usable without referencing System.Drawing (disabled by default, #define EXPERIMENTAL to test). Modified a number of using directives and namespace qualifiers to accommodate this change.

This commit is contained in:
the_fiddler 2009-11-01 12:44:38 +00:00
parent 019f54a851
commit 2340e87eda
12 changed files with 511 additions and 139 deletions

150
Source/OpenTK/Math/Point.cs Normal file
View file

@ -0,0 +1,150 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 the Open Toolkit library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenTK
{
#if EXPERIMENTAL
public struct Point : IEquatable<Point>
{
#region Fields
/// <summary>
/// The X coordinate of this instance.
/// </summary>
public int X;
/// <summary>
/// The Y coordinate of this instance.
/// </summary>
public int Y;
/// <summary>
/// Returns the Point (0, 0).
/// </summary>
public static readonly Point Zero = new Point();
/// <summary>
/// Returns the Point (0, 0).
/// </summary>
public static readonly Point Empty = new Point();
#endregion
#region Constructors
/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="x">The X coordinate of this instance.</param>
/// <param name="y">The Y coordinate of this instance.</param>
public Point(int x, int y)
{
X = x;
Y = y;
}
#endregion
#region Public Members
/// <summary>
/// Compares two instances for equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>True, if left is equal to right; false otherwise.</returns>
public static bool operator ==(Point left, Point right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances for inequality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>True, if left is not equal to right; false otherwise.</returns>
public static bool operator !=(Point left, Point right)
{
return !left.Equals(right);
}
/// <summary>
/// Indicates whether this instance is equal to the specified object.
/// </summary>
/// <param name="other">The object instance to compare to.</param>
/// <returns>True, if both instances are equal; false otherwise.</returns>
public override bool Equals(object obj)
{
if (obj is Point)
return Equals((Point)obj);
return false;
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A <see cref="System.Int32" that represents the hash code for this instance./></returns>
public override int GetHashCode()
{
return X.GetHashCode() ^ Y.GetHashCode();
}
/// <summary>
/// Returns a <see cref="System.String"/> that describes this instance.
/// </summary>
/// <returns>A <see cref="System.String"/> that describes this instance.</returns>
public override string ToString()
{
return String.Format("{{{0}, {1}}}", X, Y);
}
#endregion
#region IEquatable<Point> Members
/// <summary>
/// Indicates whether this instance is equal to the specified Point.
/// </summary>
/// <param name="other">The instance to compare to.</param>
/// <returns>True, if both instances are equal; false otherwise.</returns>
public bool Equals(Point other)
{
return X == other.X && Y == other.Y;
}
#endregion
}
#endif
}

View file

@ -0,0 +1,126 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 the Open Toolkit library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenTK
{
#if EXPERIMENTAL
public struct Rectangle : IEquatable<Rectangle>
{
#region Fields
public int X;
public int Y;
public int Width;
public int Height;
public static readonly Rectangle Empty = new Rectangle();
#endregion
#region Constructors
public Rectangle(Point location, Size size)
: this()
{
Location = location;
Size = size;
}
public Rectangle(int x, int y, int width, int height)
: this(new Point(x, y), new Size(width, height))
{ }
#endregion
#region Public Members
public Point Location
{
get { return new Point(X, Y); }
set { X = value.X; Y = value.Y; }
}
public Size Size
{
get { return new Size(Width, Height); }
set { Width = value.Width; Height = value.Height; }
}
public int Top { get { return Y; } }
public int Right { get { return X + Width; } }
public int Bottom { get { return Y + Height; } }
public int Left { get { return X; } }
public bool IsEmpty
{
get { return X == 0 && Y == 0 && Width == 0 && Height == 0; }
}
public static Rectangle FromLTRB(int left, int top, int right, int bottom)
{
return new Rectangle(new Point(left, top), new Size(right - left, bottom - top));
}
public bool Contains(Point point)
{
return point.X >= Left && point.X < Right &&
point.Y >= Top && point.Y < Bottom;
}
public static bool operator ==(Rectangle left, Rectangle right)
{
return left.Equals(right);
}
public static bool operator !=(Rectangle left, Rectangle right)
{
return !left.Equals(right);
}
#endregion
#region IEquatable<Rectangle> Members
public bool Equals(Rectangle other)
{
return Location.Equals(other.Location) &&
Size.Equals(other.Size);
}
#endregion
}
#endif
}

139
Source/OpenTK/Math/Size.cs Normal file
View file

@ -0,0 +1,139 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 the Open Toolkit library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenTK
{
#if EXPERIMENTAL
public struct Size : IEquatable<Size>
{
#region Fields
/// <summary>
/// The width of this instance.
/// </summary>
public int Width;
/// <summary>
/// The height of this instance.
/// </summary>
public int Height;
#endregion
#region Constructors
/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="width">The width of this instance.</param>
/// <param name="height">The height of this instance.</param>
public Size(int width, int height)
{
Width = width;
Height = height;
}
#endregion
#region Public Members
/// <summary>
/// Compares two instances for equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>True, if left is equal to right; false otherwise.</returns>
public static bool operator ==(Size left, Size right)
{
return left.Equals(right);
}
/// <summary>
/// Compares two instances for inequality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>True, if left is not equal to right; false otherwise.</returns>
public static bool operator !=(Size left, Size right)
{
return !left.Equals(right);
}
/// <summary>
/// Indicates whether this instance is equal to the specified object.
/// </summary>
/// <param name="other">The object instance to compare to.</param>
/// <returns>True, if both instances are equal; false otherwise.</returns>
public override bool Equals(object obj)
{
if (obj is Size)
return Equals((Size)obj);
return false;
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A <see cref="System.Int32" that represents the hash code for this instance./></returns>
public override int GetHashCode()
{
return Width.GetHashCode() ^ Height.GetHashCode();
}
/// <summary>
/// Returns a <see cref="System.String"/> that describes this instance.
/// </summary>
/// <returns>A <see cref="System.String"/> that describes this instance.</returns>
public override string ToString()
{
return String.Format("{{{0}, {1}}}", Width, Height);
}
#endregion
#region IEquatable<Size> Members
/// <summary>
/// Indicates whether this instance is equal to the specified Size.
/// </summary>
/// <param name="other">The instance to compare to.</param>
/// <returns>True, if both instances are equal; false otherwise.</returns>
public bool Equals(Size other)
{
return Width == other.Width && Height == other.Height;
}
#endregion
}
#endif
}

View file

@ -27,18 +27,12 @@ namespace OpenTK
#region --- Contructors --- #region --- Contructors ---
#region NativeWindow()
/// <summary>Constructs a new NativeWindow with default attributes without enabling events.</summary> /// <summary>Constructs a new NativeWindow with default attributes without enabling events.</summary>
public NativeWindow() public NativeWindow()
: this(640, 480, "OpenTK Native Window", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default) { } : this(640, 480, "OpenTK Native Window", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default) { }
#endregion
// TODO: Remaining constructors. // TODO: Remaining constructors.
#region NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
/// <summary>Constructs a new centered NativeWindow with the specified attributes.</summary> /// <summary>Constructs a new centered NativeWindow with the specified attributes.</summary>
/// <param name="width">The width of the NativeWindow in pixels.</param> /// <param name="width">The width of the NativeWindow in pixels.</param>
/// <param name="height">The height of the NativeWindow in pixels.</param> /// <param name="height">The height of the NativeWindow in pixels.</param>
@ -53,10 +47,6 @@ namespace OpenTK
device.Bounds.Top + (device.Bounds.Height - height) / 2, device.Bounds.Top + (device.Bounds.Height - height) / 2,
width, height, title, options, mode, device) { } width, height, title, options, mode, device) { }
#endregion
#region NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
/// <summary>Constructs a new NativeWindow with the specified attributes.</summary> /// <summary>Constructs a new NativeWindow with the specified attributes.</summary>
/// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param> /// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param>
/// <param name="y">Vertical screen space coordinate of the NativeWindow's origin.</param> /// <param name="y">Vertical screen space coordinate of the NativeWindow's origin.</param>
@ -94,8 +84,6 @@ namespace OpenTK
#endregion #endregion
#endregion
#region --- INativeWindow Members --- #region --- INativeWindow Members ---
#region Methods #region Methods
@ -124,7 +112,7 @@ namespace OpenTK
/// <returns> /// <returns>
/// The point transformed to client coordinates. /// The point transformed to client coordinates.
/// </returns> /// </returns>
public System.Drawing.Point PointToClient(System.Drawing.Point point) public Point PointToClient(Point point)
{ {
return implementation.PointToClient(point); return implementation.PointToClient(point);
} }
@ -142,11 +130,11 @@ namespace OpenTK
/// <returns> /// <returns>
/// The point transformed to screen coordinates. /// The point transformed to screen coordinates.
/// </returns> /// </returns>
public System.Drawing.Point PointToScreen(System.Drawing.Point point) public Point PointToScreen(Point point)
{ {
// Here we use the fact that PointToClient just translates the point, and PointToScreen // Here we use the fact that PointToClient just translates the point, and PointToScreen
// should perform the inverse operation. // should perform the inverse operation.
System.Drawing.Point trans = PointToClient(System.Drawing.Point.Empty); Point trans = PointToClient(Point.Empty);
point.X -= trans.X; point.X -= trans.X;
point.Y -= trans.Y; point.Y -= trans.Y;
return point; return point;

View file

@ -10,6 +10,7 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
namespace OpenTK.Platform.MacOS.Carbon namespace OpenTK.Platform.MacOS.Carbon
{ {
@ -17,12 +18,12 @@ namespace OpenTK.Platform.MacOS.Carbon
#region --- Types defined in MacTypes.h --- #region --- Types defined in MacTypes.h ---
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal struct Point internal struct CarbonPoint
{ {
internal short V; internal short V;
internal short H; internal short H;
public Point(int x, int y) public CarbonPoint(int x, int y)
{ {
V = (short)x; V = (short)x;
H = (short)y; H = (short)y;
@ -82,9 +83,9 @@ namespace OpenTK.Platform.MacOS.Carbon
"Rect: [{0}, {1}, {2}, {3}]", X, Y, Width, Height); "Rect: [{0}, {1}, {2}, {3}]", X, Y, Width, Height);
} }
public System.Drawing.Rectangle ToRectangle() public Rectangle ToRectangle()
{ {
return new System.Drawing.Rectangle(X, Y, Width, Height); return new Rectangle(X, Y, Width, Height);
} }
} }
@ -534,7 +535,7 @@ namespace OpenTK.Platform.MacOS.Carbon
public ushort what; public ushort what;
public uint message; public uint message;
public uint when; public uint when;
public Point where; public CarbonPoint where;
public uint modifiers; public uint modifiers;
} }
@ -875,16 +876,16 @@ namespace OpenTK.Platform.MacOS.Carbon
[DllImport(carbon, EntryPoint = "ZoomWindowIdeal")] [DllImport(carbon, EntryPoint = "ZoomWindowIdeal")]
unsafe static extern OSStatus _ZoomWindowIdeal(IntPtr windowRef, short inPartCode, IntPtr toIdealSize); unsafe static extern OSStatus _ZoomWindowIdeal(IntPtr windowRef, short inPartCode, IntPtr toIdealSize);
internal static void ZoomWindowIdeal(IntPtr windowRef, WindowPartCode inPartCode, ref Point toIdealSize) internal static void ZoomWindowIdeal(IntPtr windowRef, WindowPartCode inPartCode, ref CarbonPoint toIdealSize)
{ {
Point pt = toIdealSize; CarbonPoint pt = toIdealSize;
OSStatus error ; OSStatus error ;
IntPtr handle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Point))); IntPtr handle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CarbonPoint)));
Marshal.StructureToPtr(toIdealSize, handle, false); Marshal.StructureToPtr(toIdealSize, handle, false);
error = _ZoomWindowIdeal(windowRef, (short)inPartCode, handle); error = _ZoomWindowIdeal(windowRef, (short)inPartCode, handle);
toIdealSize = (Point)Marshal.PtrToStructure(handle,typeof(Point)); toIdealSize = (CarbonPoint)Marshal.PtrToStructure(handle,typeof(CarbonPoint));
Marshal.FreeHGlobal(handle); Marshal.FreeHGlobal(handle);

View file

@ -29,6 +29,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.Text; using System.Text;
namespace OpenTK.Platform.MacOS namespace OpenTK.Platform.MacOS
@ -49,7 +50,7 @@ namespace OpenTK.Platform.MacOS
IntPtr uppHandler; IntPtr uppHandler;
string title = "OpenTK Window"; string title = "OpenTK Window";
System.Drawing.Rectangle bounds, windowedBounds, clientRectangle; Rectangle bounds, windowedBounds, clientRectangle;
bool mIsDisposed = false; bool mIsDisposed = false;
WindowAttributes mWindowAttrib; WindowAttributes mWindowAttrib;
@ -415,10 +416,7 @@ namespace OpenTK.Platform.MacOS
if (this.windowState == WindowState.Fullscreen) if (this.windowState == WindowState.Fullscreen)
{ {
InputDriver.Mouse[0].Position = InputDriver.Mouse[0].Position = new Point((int)pt.X, (int)pt.Y);
new System.Drawing.Point(
(int)pt.X,
(int)pt.Y);
} }
else else
{ {
@ -427,9 +425,7 @@ namespace OpenTK.Platform.MacOS
return OSStatus.EventNotHandled; return OSStatus.EventNotHandled;
InputDriver.Mouse[0].Position = InputDriver.Mouse[0].Position =
new System.Drawing.Point( new Point((int)pt.X, (int)(pt.Y - mTitlebarHeight));
(int)pt.X,
(int)(pt.Y - mTitlebarHeight));
} }
switch (evt.MouseEventKind) switch (evt.MouseEventKind)
@ -627,16 +623,16 @@ namespace OpenTK.Platform.MacOS
Application.ProcessEvents(); Application.ProcessEvents();
} }
public System.Drawing.Point PointToClient(System.Drawing.Point point) public Point PointToClient(Point point)
{ {
IntPtr handle = window.WindowRef; IntPtr handle = window.WindowRef;
Rect r = Carbon.API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion); Rect r = Carbon.API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion);
Console.WriteLine("Rect: {0}", r); Console.WriteLine("Rect: {0}", r);
return new System.Drawing.Point(point.X - r.X, point.Y - r.Y); return new Point(point.X - r.X, point.Y - r.Y);
} }
public System.Drawing.Point PointToScreen(System.Drawing.Point point) public Point PointToScreen(Point point)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -716,7 +712,7 @@ namespace OpenTK.Platform.MacOS
get { throw new NotImplementedException(); } get { throw new NotImplementedException(); }
} }
public System.Drawing.Rectangle Bounds public Rectangle Bounds
{ {
get get
{ {
@ -729,7 +725,7 @@ namespace OpenTK.Platform.MacOS
} }
} }
public System.Drawing.Point Location public Point Location
{ {
get get
{ {
@ -741,7 +737,7 @@ namespace OpenTK.Platform.MacOS
} }
} }
public System.Drawing.Size Size public Size Size
{ {
get get
{ {
@ -756,13 +752,13 @@ namespace OpenTK.Platform.MacOS
public int Width public int Width
{ {
get { return Bounds.Width; } get { return Bounds.Width; }
set { Size = new System.Drawing.Size(value, Height); } set { Size = new Size(value, Height); }
} }
public int Height public int Height
{ {
get { return Bounds.Height; } get { return Bounds.Height; }
set { Size = new System.Drawing.Size(Width, value); } set { Size = new Size(Width, value); }
} }
public int X public int X
@ -773,7 +769,7 @@ namespace OpenTK.Platform.MacOS
} }
set set
{ {
Location = new System.Drawing.Point(value, Y); Location = new Point(value, Y);
} }
} }
@ -785,11 +781,11 @@ namespace OpenTK.Platform.MacOS
} }
set set
{ {
Location = new System.Drawing.Point(X, value); Location = new Point(X, value);
} }
} }
public System.Drawing.Rectangle ClientRectangle public Rectangle ClientRectangle
{ {
get get
{ {
@ -801,7 +797,7 @@ namespace OpenTK.Platform.MacOS
} }
} }
public System.Drawing.Size ClientSize public Size ClientSize
{ {
get get
{ {
@ -851,7 +847,7 @@ namespace OpenTK.Platform.MacOS
{ {
API.CollapseWindow(window.WindowRef, false); API.CollapseWindow(window.WindowRef, false);
} }
Point idealSize; CarbonPoint idealSize;
switch (value) switch (value)
{ {
@ -864,14 +860,14 @@ namespace OpenTK.Platform.MacOS
// hack because mac os has no concept of maximized. Instead windows are "zoomed" // hack because mac os has no concept of maximized. Instead windows are "zoomed"
// meaning they are maximized up to their reported ideal size. So we report a // meaning they are maximized up to their reported ideal size. So we report a
// large ideal size. // large ideal size.
idealSize = new Point(9000, 9000); idealSize = new CarbonPoint(9000, 9000);
API.ZoomWindowIdeal(window.WindowRef, WindowPartCode.inZoomOut, ref idealSize); API.ZoomWindowIdeal(window.WindowRef, WindowPartCode.inZoomOut, ref idealSize);
break; break;
case WindowState.Normal: case WindowState.Normal:
if (WindowState == WindowState.Maximized) if (WindowState == WindowState.Maximized)
{ {
idealSize = new Point(); idealSize = new CarbonPoint();
API.ZoomWindowIdeal(window.WindowRef, WindowPartCode.inZoomIn, ref idealSize); API.ZoomWindowIdeal(window.WindowRef, WindowPartCode.inZoomIn, ref idealSize);
} }
break; break;

View file

@ -8,6 +8,7 @@
#region --- Using Directives --- #region --- Using Directives ---
using System; using System;
using System.Drawing;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Security; using System.Security;
@ -55,7 +56,7 @@ namespace OpenTK.Platform.Windows
using ATOM = System.Int32; using ATOM = System.Int32;
using COLORREF = System.Int32; using COLORREF = System.Int32;
using RECT = OpenTK.Platform.Windows.Rectangle; using RECT = OpenTK.Platform.Windows.Win32Rectangle;
using WNDPROC = System.IntPtr; using WNDPROC = System.IntPtr;
using LPDEVMODE = DeviceMode; using LPDEVMODE = DeviceMode;
@ -139,10 +140,10 @@ namespace OpenTK.Platform.Windows
/// Found Winuser.h, user32.dll /// Found Winuser.h, user32.dll
/// </remarks> /// </remarks>
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern BOOL AdjustWindowRect([In, Out] ref Rectangle lpRect, WindowStyle dwStyle, BOOL bMenu); internal static extern BOOL AdjustWindowRect([In, Out] ref Win32Rectangle lpRect, WindowStyle dwStyle, BOOL bMenu);
[DllImport("user32.dll", EntryPoint = "AdjustWindowRectEx", CallingConvention = CallingConvention.StdCall, SetLastError = true), SuppressUnmanagedCodeSecurity] [DllImport("user32.dll", EntryPoint = "AdjustWindowRectEx", CallingConvention = CallingConvention.StdCall, SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern bool AdjustWindowRectEx(ref Rectangle lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle); internal static extern bool AdjustWindowRectEx(ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle);
#endregion #endregion
@ -738,7 +739,7 @@ namespace OpenTK.Platform.Windows
/// </remarks> /// </remarks>
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
//internal static extern BOOL ScreenToClient(HWND hWnd, ref POINT point); //internal static extern BOOL ScreenToClient(HWND hWnd, ref POINT point);
internal static extern BOOL ScreenToClient(HWND hWnd, ref System.Drawing.Point point); internal static extern BOOL ScreenToClient(HWND hWnd, ref Point point);
#endregion #endregion
@ -755,7 +756,7 @@ namespace OpenTK.Platform.Windows
/// <para>All coordinates are device coordinates.</para> /// <para>All coordinates are device coordinates.</para>
/// </remarks> /// </remarks>
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern BOOL ClientToScreen(HWND hWnd, ref System.Drawing.Point point); internal static extern BOOL ClientToScreen(HWND hWnd, ref Point point);
#endregion #endregion
@ -772,7 +773,7 @@ namespace OpenTK.Platform.Windows
/// </returns> /// </returns>
/// <remarks>In conformance with conventions for the RECT structure, the bottom-right coordinates of the returned rectangle are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle.</remarks> /// <remarks>In conformance with conventions for the RECT structure, the bottom-right coordinates of the returned rectangle are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle.</remarks>
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal extern static BOOL GetClientRect(HWND windowHandle, out Rectangle clientRectangle); internal extern static BOOL GetClientRect(HWND windowHandle, out Win32Rectangle clientRectangle);
#endregion #endregion
@ -789,7 +790,7 @@ namespace OpenTK.Platform.Windows
/// </returns> /// </returns>
/// <remarks>In conformance with conventions for the RECT structure, the bottom-right coordinates of the returned rectangle are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle.</remarks> /// <remarks>In conformance with conventions for the RECT structure, the bottom-right coordinates of the returned rectangle are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle.</remarks>
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal extern static BOOL GetWindowRect(HWND windowHandle, out Rectangle windowRectangle); internal extern static BOOL GetWindowRect(HWND windowHandle, out Win32Rectangle windowRectangle);
#endregion #endregion
@ -955,7 +956,7 @@ namespace OpenTK.Platform.Windows
/// <para>The input desktop must be the current desktop when you call GetCursorPos. Call OpenInputDesktop to determine whether the current desktop is the input desktop. If it is not, call SetThreadDesktop with the HDESK returned by OpenInputDesktop to switch to that desktop.</para> /// <para>The input desktop must be the current desktop when you call GetCursorPos. Call OpenInputDesktop to determine whether the current desktop is the input desktop. If it is not, call SetThreadDesktop with the HDESK returned by OpenInputDesktop to switch to that desktop.</para>
/// </remarks> /// </remarks>
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern BOOL GetCursorPos(ref System.Drawing.Point point); internal static extern BOOL GetCursorPos(ref Point point);
#endregion #endregion
@ -1994,11 +1995,11 @@ namespace OpenTK.Platform.Windows
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal struct MINMAXINFO internal struct MINMAXINFO
{ {
System.Drawing.Point Reserved; Point Reserved;
public System.Drawing.Size MaxSize; public Size MaxSize;
public System.Drawing.Point MaxPosition; public Point MaxPosition;
public System.Drawing.Size MinTrackSize; public Size MinTrackSize;
public System.Drawing.Size MaxTrackSize; public Size MaxTrackSize;
} }
#endregion #endregion
@ -2610,9 +2611,9 @@ namespace OpenTK.Platform.Windows
/// By convention, the right and bottom edges of the rectangle are normally considered exclusive. In other words, the pixel whose coordinates are (right, bottom) lies immediately outside of the the rectangle. For example, when RECT is passed to the FillRect function, the rectangle is filled up to, but not including, the right column and bottom row of pixels. This structure is identical to the RECTL structure. /// By convention, the right and bottom edges of the rectangle are normally considered exclusive. In other words, the pixel whose coordinates are (right, bottom) lies immediately outside of the the rectangle. For example, when RECT is passed to the FillRect function, the rectangle is filled up to, but not including, the right column and bottom row of pixels. This structure is identical to the RECTL structure.
/// </remarks> /// </remarks>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal struct Rectangle internal struct Win32Rectangle
{ {
internal Rectangle(int width, int height) internal Win32Rectangle(int width, int height)
{ {
left = top = 0; left = top = 0;
right = width; right = width;
@ -2644,14 +2645,14 @@ namespace OpenTK.Platform.Windows
return String.Format("({0},{1})-({2},{3})", left, top, right, bottom); return String.Format("({0},{1})-({2},{3})", left, top, right, bottom);
} }
internal System.Drawing.Rectangle ToRectangle() internal Rectangle ToRectangle()
{ {
return System.Drawing.Rectangle.FromLTRB(left, top, right, bottom); return Rectangle.FromLTRB(left, top, right, bottom);
} }
internal static Rectangle From(System.Drawing.Rectangle value) internal static Win32Rectangle From(Rectangle value)
{ {
Rectangle rect = new Rectangle(); Win32Rectangle rect = new Win32Rectangle();
rect.left = value.Left; rect.left = value.Left;
rect.right = value.Right; rect.right = value.Right;
rect.top = value.Top; rect.top = value.Top;
@ -2659,9 +2660,9 @@ namespace OpenTK.Platform.Windows
return rect; return rect;
} }
internal static Rectangle From(System.Drawing.Size value) internal static Win32Rectangle From(Size value)
{ {
Rectangle rect = new Rectangle(); Win32Rectangle rect = new Win32Rectangle();
rect.left = 0; rect.left = 0;
rect.right = value.Width; rect.right = value.Width;
rect.top = 0; rect.top = 0;
@ -2743,9 +2744,9 @@ namespace OpenTK.Platform.Windows
[StructLayout(LayoutKind.Sequential, Pack=1)] [StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct NcCalculateSize internal struct NcCalculateSize
{ {
public Rectangle NewBounds; public Win32Rectangle NewBounds;
public Rectangle OldBounds; public Win32Rectangle OldBounds;
public Rectangle OldClientRectangle; public Win32Rectangle OldClientRectangle;
unsafe public WindowPosition* Position; unsafe public WindowPosition* Position;
} }
@ -4144,9 +4145,9 @@ namespace OpenTK.Platform.Windows
this.Y = y; this.Y = y;
} }
internal System.Drawing.Point ToPoint() internal Point ToPoint()
{ {
return new System.Drawing.Point(X, Y); return new Point(X, Y);
} }
public override string ToString() public override string ToString()

View file

@ -11,6 +11,7 @@ using System.Windows.Forms;
using OpenTK.Input; using OpenTK.Input;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
namespace OpenTK.Platform.Windows namespace OpenTK.Platform.Windows
{ {
@ -80,7 +81,7 @@ namespace OpenTK.Platform.Windows
break; break;
case WindowMessage.MOUSEMOVE: case WindowMessage.MOUSEMOVE:
mouse.Position = new System.Drawing.Point( mouse.Position = new Point(
(int)(lparam.ToUInt32() & 0x0000FFFF), (int)(lparam.ToUInt32() & 0x0000FFFF),
(int)(lparam.ToUInt32() & 0xFFFF0000) >> 16); (int)(lparam.ToUInt32() & 0xFFFF0000) >> 16);
if (mouse_about_to_enter) if (mouse_about_to_enter)

View file

@ -27,13 +27,13 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK.Input; using OpenTK.Input;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Drawing;
namespace OpenTK.Platform.Windows namespace OpenTK.Platform.Windows
{ {
@ -67,11 +67,11 @@ namespace OpenTK.Platform.Windows
bool borderless_maximized_window_state = false; // Hack to get maximized mode with hidden border (not normally possible). bool borderless_maximized_window_state = false; // Hack to get maximized mode with hidden border (not normally possible).
bool focused; bool focused;
System.Drawing.Rectangle Rectangle
bounds = new System.Drawing.Rectangle(), bounds = new Rectangle(),
client_rectangle = new System.Drawing.Rectangle(), client_rectangle = new Rectangle(),
previous_bounds = new System.Drawing.Rectangle(); // Used to restore previous size when leaving fullscreen mode. previous_bounds = new Rectangle(); // Used to restore previous size when leaving fullscreen mode.
Icon icon; System.Drawing.Icon icon;
static readonly ClassStyle ClassStyle = static readonly ClassStyle ClassStyle =
ClassStyle.OwnDC | ClassStyle.VRedraw | ClassStyle.HRedraw | ClassStyle.Ime; ClassStyle.OwnDC | ClassStyle.VRedraw | ClassStyle.HRedraw | ClassStyle.Ime;
@ -223,7 +223,7 @@ namespace OpenTK.Platform.Windows
bounds.Width = pos->cx; bounds.Width = pos->cx;
bounds.Height = pos->cy; bounds.Height = pos->cy;
Rectangle rect; Win32Rectangle rect;
Functions.GetClientRect(handle, out rect); Functions.GetClientRect(handle, out rect);
client_rectangle = rect.ToRectangle(); client_rectangle = rect.ToRectangle();
@ -292,12 +292,12 @@ namespace OpenTK.Platform.Windows
break; break;
case WindowMessage.MOUSEMOVE: case WindowMessage.MOUSEMOVE:
System.Drawing.Point point = new System.Drawing.Point( Point point = new Point(
(int)(lParam.ToInt32() & 0x0000FFFF), (int)(lParam.ToInt32() & 0x0000FFFF),
(int)(lParam.ToInt32() & 0xFFFF0000) >> 16); (int)(lParam.ToInt32() & 0xFFFF0000) >> 16);
mouse.Position = point; mouse.Position = point;
{ {
Rectangle rect; Win32Rectangle rect;
Functions.GetClientRect(window.WindowHandle, out rect); Functions.GetClientRect(window.WindowHandle, out rect);
if (!rect.ToRectangle().Contains(point)) if (!rect.ToRectangle().Contains(point))
{ {
@ -452,7 +452,7 @@ namespace OpenTK.Platform.Windows
bounds.Width = cs.cx; bounds.Width = cs.cx;
bounds.Height = cs.cy; bounds.Height = cs.cy;
Rectangle rect; Win32Rectangle rect;
Functions.GetClientRect(handle, out rect); Functions.GetClientRect(handle, out rect);
client_rectangle = rect.ToRectangle(); client_rectangle = rect.ToRectangle();
} }
@ -532,7 +532,7 @@ namespace OpenTK.Platform.Windows
} }
// Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc). // Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc).
Rectangle rect = new Rectangle(); Win32Rectangle rect = new Win32Rectangle();
rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height; rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
Functions.AdjustWindowRectEx(ref rect, style, false, ex_style); Functions.AdjustWindowRectEx(ref rect, style, false, ex_style);
@ -588,38 +588,6 @@ namespace OpenTK.Platform.Windows
#endregion #endregion
#region GetApplicationIcon
// Gets the shell application icon for the executing process or the default icon, if not available.
Icon GetApplicationIcon()
{
//return Icon.FromHandle(Functions.LoadIcon(Process.GetCurrentProcess().Handle, ""));
try { return Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetEntryAssembly().CodeBase); }
catch { return null; }
//IntPtr retval = IntPtr.Zero;
//try
//{
// SHFILEINFO info = new SHFILEINFO();
// info.szDisplayName = "";
// info.szTypeName = "";
// int cbFileInfo = Marshal.SizeOf(info);
// ShGetFileIconFlags flags = ShGetFileIconFlags.Icon | ShGetFileIconFlags.SmallIcon | ShGetFileIconFlags.UseFileAttributes;
// string path = System.Reflection.Assembly.GetEntryAssembly().CodeBase;
// retval = Functions.SHGetFileInfo(path, 256, ref info, (uint)cbFileInfo, flags);
// return Icon.FromHandle(info.hIcon);
//}
//catch
//{
// // Shallow exceptions and fall-back to default icon.
// Debug.Print("SHGetFileInfo failed, return value: {0}", retval);
// return null;
//}
}
#endregion
void EnableMouseLeaveNotifications() void EnableMouseLeaveNotifications()
{ {
TrackMouseEventStructure tme = new TrackMouseEventStructure(); TrackMouseEventStructure tme = new TrackMouseEventStructure();
@ -638,7 +606,7 @@ namespace OpenTK.Platform.Windows
#region Bounds #region Bounds
public System.Drawing.Rectangle Bounds public Rectangle Bounds
{ {
get { return bounds; } get { return bounds; }
set set
@ -680,7 +648,7 @@ namespace OpenTK.Platform.Windows
#region ClientRectangle #region ClientRectangle
public System.Drawing.Rectangle ClientRectangle public Rectangle ClientRectangle
{ {
get get
{ {
@ -709,7 +677,7 @@ namespace OpenTK.Platform.Windows
set set
{ {
WindowStyle style = (WindowStyle)Functions.GetWindowLong(window.WindowHandle, GetWindowLongOffsets.STYLE); WindowStyle style = (WindowStyle)Functions.GetWindowLong(window.WindowHandle, GetWindowLongOffsets.STYLE);
Rectangle rect = Rectangle.From(value); Win32Rectangle rect = Win32Rectangle.From(value);
Functions.AdjustWindowRect(ref rect, style, false); Functions.AdjustWindowRect(ref rect, style, false);
Size = new Size(rect.Width, rect.Height); Size = new Size(rect.Width, rect.Height);
} }
@ -722,7 +690,7 @@ namespace OpenTK.Platform.Windows
public int Width public int Width
{ {
get { return ClientRectangle.Width; } get { return ClientRectangle.Width; }
set { ClientRectangle = new System.Drawing.Rectangle(Location, new Size(value, Height)); } set { ClientRectangle = new Rectangle(Location, new Size(value, Height)); }
} }
#endregion #endregion
@ -732,7 +700,7 @@ namespace OpenTK.Platform.Windows
public int Height public int Height
{ {
get { return ClientRectangle.Height; } get { return ClientRectangle.Height; }
set { ClientRectangle = new System.Drawing.Rectangle(Location, new Size(Width, value)); } set { ClientRectangle = new Rectangle(Location, new Size(Width, value)); }
} }
#endregion #endregion
@ -742,7 +710,7 @@ namespace OpenTK.Platform.Windows
public int X public int X
{ {
get { return ClientRectangle.X; } get { return ClientRectangle.X; }
set { ClientRectangle = new System.Drawing.Rectangle(new Point(value, Y), Size); } set { ClientRectangle = new Rectangle(new Point(value, Y), Size); }
} }
#endregion #endregion
@ -752,14 +720,14 @@ namespace OpenTK.Platform.Windows
public int Y public int Y
{ {
get { return ClientRectangle.Y; } get { return ClientRectangle.Y; }
set { ClientRectangle = new System.Drawing.Rectangle(new Point(X, value), Size); } set { ClientRectangle = new Rectangle(new Point(X, value), Size); }
} }
#endregion #endregion
#region Icon #region Icon
public Icon Icon public System.Drawing.Icon Icon
{ {
get get
{ {
@ -919,10 +887,10 @@ namespace OpenTK.Platform.Windows
Functions.ShowWindow(window.WindowHandle, command); Functions.ShowWindow(window.WindowHandle, command);
// Restore previous window size/location if necessary // Restore previous window size/location if necessary
if (command == ShowWindowCommand.RESTORE && previous_bounds != System.Drawing.Rectangle.Empty) if (command == ShowWindowCommand.RESTORE && previous_bounds != Rectangle.Empty)
{ {
Bounds = previous_bounds; Bounds = previous_bounds;
previous_bounds = System.Drawing.Rectangle.Empty; previous_bounds = Rectangle.Empty;
} }
// Restore previous window border or apply pending border change when leaving fullscreen mode. // Restore previous window border or apply pending border change when leaving fullscreen mode.
@ -985,7 +953,7 @@ namespace OpenTK.Platform.Windows
// Make sure client size doesn't change when changing the border style. // Make sure client size doesn't change when changing the border style.
Size client_size = ClientSize; Size client_size = ClientSize;
Rectangle rect = Rectangle.From(client_size); Win32Rectangle rect = Win32Rectangle.From(client_size);
Functions.AdjustWindowRectEx(ref rect, style, false, ParentStyleEx); Functions.AdjustWindowRectEx(ref rect, style, false, ParentStyleEx);
// This avoids leaving garbage on the background window. // This avoids leaving garbage on the background window.

View file

@ -11,6 +11,7 @@ using OpenTK.Input;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.Win32; using Microsoft.Win32;
using System.Drawing;
namespace OpenTK.Platform.Windows namespace OpenTK.Platform.Windows
{ {
@ -153,7 +154,7 @@ namespace OpenTK.Platform.Windows
else else
{ {
Debug.Print("Registered mouse {0}", mouse.ToString()); Debug.Print("Registered mouse {0}", mouse.ToString());
System.Drawing.Point p = new System.Drawing.Point(); Point p = new Point();
if (Functions.GetCursorPos(ref p)) if (Functions.GetCursorPos(ref p))
mouse.Position = p; mouse.Position = p;
} }
@ -197,11 +198,11 @@ namespace OpenTK.Platform.Windows
if ((rin.Data.Mouse.Flags & RawMouseFlags.MOUSE_MOVE_ABSOLUTE) != 0) if ((rin.Data.Mouse.Flags & RawMouseFlags.MOUSE_MOVE_ABSOLUTE) != 0)
{ {
mouse.Position = new System.Drawing.Point(rin.Data.Mouse.LastX, rin.Data.Mouse.LastY); mouse.Position = new Point(rin.Data.Mouse.LastX, rin.Data.Mouse.LastY);
} }
else else
{ // Seems like MOUSE_MOVE_RELATIVE is the default, unless otherwise noted. { // Seems like MOUSE_MOVE_RELATIVE is the default, unless otherwise noted.
mouse.Position = new System.Drawing.Point(mouse.X + rin.Data.Mouse.LastX, mouse.Position = new Point(mouse.X + rin.Data.Mouse.LastX,
mouse.Y + rin.Data.Mouse.LastY); mouse.Y + rin.Data.Mouse.LastY);
} }

View file

@ -29,12 +29,12 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK.Input; using OpenTK.Input;
using System.Drawing;
namespace OpenTK.Platform.X11 namespace OpenTK.Platform.X11
{ {
@ -92,7 +92,7 @@ namespace OpenTK.Platform.X11
Rectangle bounds, client_rectangle; Rectangle bounds, client_rectangle;
int border_width; int border_width;
Icon icon; System.Drawing.Icon icon;
bool has_focus; bool has_focus;
bool visible; bool visible;
@ -701,7 +701,7 @@ namespace OpenTK.Platform.X11
#region Bounds #region Bounds
public System.Drawing.Rectangle Bounds public Rectangle Bounds
{ {
get { return bounds; } get { return bounds; }
set set
@ -746,7 +746,7 @@ namespace OpenTK.Platform.X11
#region ClientRectangle #region ClientRectangle
public System.Drawing.Rectangle ClientRectangle public Rectangle ClientRectangle
{ {
get get
{ {
@ -823,7 +823,7 @@ namespace OpenTK.Platform.X11
#region Icon #region Icon
public Icon Icon public System.Drawing.Icon Icon
{ {
get get
{ {
@ -844,7 +844,7 @@ namespace OpenTK.Platform.X11
else else
{ {
// Set _NET_WM_ICON // Set _NET_WM_ICON
Bitmap bitmap = value.ToBitmap(); System.Drawing.Bitmap bitmap = value.ToBitmap();
int size = bitmap.Width * bitmap.Height + 2; int size = bitmap.Width * bitmap.Height + 2;
IntPtr[] data = new IntPtr[size]; IntPtr[] data = new IntPtr[size];
int index = 0; int index = 0;

View file

@ -11,6 +11,7 @@ using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using OpenTK.Input; using OpenTK.Input;
using System.Drawing;
namespace OpenTK.Platform.X11 namespace OpenTK.Platform.X11
{ {
@ -198,7 +199,7 @@ namespace OpenTK.Platform.X11
break; break;
case XEventName.MotionNotify: case XEventName.MotionNotify:
mouse.Position = new System.Drawing.Point(e.MotionEvent.x, e.MotionEvent.y); mouse.Position = new Point(e.MotionEvent.x, e.MotionEvent.y);
break; break;
} }
} }