Added initial support for GameWindow.PointToClient.

This commit is contained in:
the_fiddler 2009-05-07 19:48:22 +00:00
parent bc236a7c0b
commit 2f54b29ed8
6 changed files with 103 additions and 64 deletions

View file

@ -1347,24 +1347,27 @@ namespace OpenTK
}
*/
#endregion
#if false // TODO: 0.9.2 (Linux support missing)
#region PointToClient
/// <summary>
/// Converts the screen coordinates of a specified point on the screen to client-area coordinates.
/// </summary>
/// <param name="p">A System.Drawing.Point structure that specifies the screen coordinates to be converted</param>
/// <param name="point">A System.Drawing.Point structure that specifies the screen coordinates to be converted</param>
/// <returns>The client-area coordinates of the point. The new coordinates are relative to the upper-left corner of the GameWindow's client area.</returns>
public System.Drawing.Point PointToClient(System.Drawing.Point p)
public System.Drawing.Point PointToClient(System.Drawing.Point point)
{
glWindow.PointToClient(ref p);
return p;
point = glWindow.PointToClient(point);
point.X = Width - point.X;
point.Y = Height - point.Y;
return point;
}
#endregion
#region PointToScreen
#if false // Todo: Linux / Mac OS X support missing.
/// <summary>
/// Converts the client-area coordinates of a specified point to screen coordinates.
/// </summary>
@ -1372,12 +1375,11 @@ namespace OpenTK
/// <returns>The screen coordinates of the point, relative to the upper-left corner of the screen. Note, a screen-coordinate point that is above the window's client area has a negative y-coordinate. Similarly, a screen coordinate to the left of a client area has a negative x-coordinate.</returns>
public System.Drawing.Point PointToScreen(System.Drawing.Point p)
{
glWindow.PointToScreen(ref p);
return p;
return glWindow.PointToScreen(p);
}
#endregion
#endif
#endregion
#region --- IDisposable Members ---
/// <summary>

View file

@ -12,6 +12,7 @@ using System.Text;
using OpenTK.Input;
using OpenTK.Graphics;
using System.Drawing;
namespace OpenTK.Platform
{
@ -20,8 +21,8 @@ namespace OpenTK.Platform
void CreateWindow(int width, int height, GraphicsMode mode, int major, int minor, GraphicsContextFlags flags, out IGraphicsContext context);
void DestroyWindow();
void ProcessEvents();
void PointToClient(ref System.Drawing.Point p);
void PointToScreen(ref System.Drawing.Point p);
Point PointToClient(Point point);
Point PointToScreen(Point point);
bool Exists { get; }
IWindowInfo WindowInfo { get; }

View file

@ -883,13 +883,33 @@ namespace OpenTK.Platform.MacOS.Carbon
internal unsafe static extern OSStatus DMGetGDeviceByDisplayID(
IntPtr displayID, out IntPtr displayDevice, Boolean failToMain);
[DllImport(carbon, EntryPoint = "HIViewConvertPoint")]
extern static OSStatus _HIViewConvertPoint(ref HIPoint point, IntPtr pView, IntPtr cView);
internal static HIPoint HIViewConvertPoint(IntPtr handle, HIPoint point)
{
Carbon.Rect window_bounds = new Carbon.Rect();
Carbon.API.GetWindowBounds(handle, WindowRegionCode.StructureRegion /*32*/, out window_bounds);
point.X -= window_bounds.X;
point.Y -= window_bounds.Y;
OSStatus error = _HIViewConvertPoint(ref point, IntPtr.Zero, handle);
if (error != OSStatus.NoError)
{
throw new MacOSException(error);
}
return point;
}
const string gestaltlib = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
[DllImport(gestaltlib)]
internal static extern OSStatus Gestalt(GestaltSelector selector, out int response);
}
#endregion

View file

@ -596,13 +596,23 @@ namespace OpenTK.Platform.MacOS
Application.ProcessEvents();
}
public void PointToClient(ref System.Drawing.Point p)
public System.Drawing.Point PointToClient(System.Drawing.Point point)
{
throw new Exception("The method or operation is not implemented.");
IntPtr handle = window.WindowRef;
HIPoint native_point = new HIPoint();
native_point.X = (float)point.X;
native_point.Y = (float)point.Y;
native_point = Carbon.API.HIViewConvertPoint(handle, native_point);
point.X = (int)native_point.X;
point.Y = (int)native_point.Y;
return point;
}
public void PointToScreen(ref System.Drawing.Point p)
public System.Drawing.Point PointToScreen(System.Drawing.Point point)
{
throw new Exception("The method or operation is not implemented.");
throw new NotImplementedException();
}
public bool Exists

View file

@ -437,19 +437,21 @@ namespace OpenTK.Platform.Windows
#region PointToClient
public void PointToClient(ref System.Drawing.Point p)
public Point PointToClient(Point point)
{
if (!Functions.ScreenToClient(this.Handle, ref p))
if (!Functions.ScreenToClient(this.Handle, ref point))
throw new InvalidOperationException(String.Format(
"Could not convert point {0} from client to screen coordinates. Windows error: {1}",
p.ToString(), Marshal.GetLastWin32Error()));
point.ToString(), Marshal.GetLastWin32Error()));
return point;
}
#endregion
#region PointToScreen
public void PointToScreen(ref System.Drawing.Point p)
public Point PointToScreen(Point p)
{
throw new NotImplementedException();
}

View file

@ -16,6 +16,7 @@ using OpenTK.Graphics.OpenGL;
using OpenTK.Input;
using OpenTK.Platform.Windows;
using OpenTK.Graphics;
using System.Drawing;
//using OpenTK.Graphics.OpenGL;
@ -601,21 +602,24 @@ namespace OpenTK.Platform.X11
#region PointToClient
public void PointToClient(ref System.Drawing.Point p)
public Point PointToClient(Point point)
{
/*
if (!Functions.ScreenToClient(this.Handle, p))
throw new InvalidOperationException(String.Format(
"Could not convert point {0} from client to screen coordinates. Windows error: {1}",
p.ToString(), Marshal.GetLastWin32Error()));
*/
int ox, oy;
IntPtr child;
Functions.XTranslateCoordinates(window.Display, window.RootWindow, window.WindowHandle, point.X, point.Y, out ox, out oy, out child);
point.X = ox;
point.Y = oy;
return point;
}
#endregion
#region PointToScreen
public void PointToScreen(ref System.Drawing.Point p)
public Point PointToScreen(Point p)
{
throw new NotImplementedException();
}
@ -793,41 +797,6 @@ namespace OpenTK.Platform.X11
#endregion
void SetWindowMinMax(short min_width, short min_height, short max_width, short max_height)
{
IntPtr dummy;
XSizeHints hints = new XSizeHints();
Functions.XGetWMNormalHints(window.Display, window.WindowHandle, ref hints, out dummy);
if (min_width > 0 || min_height > 0)
{
hints.flags = (IntPtr)((int)hints.flags | (int)XSizeHintsFlags.PMinSize);
hints.min_width = min_width;
hints.min_height = min_height;
}
else
hints.flags = (IntPtr)((int)hints.flags & ~(int)XSizeHintsFlags.PMinSize);
if (max_width > 0 || max_height > 0)
{
hints.flags = (IntPtr)((int)hints.flags | (int)XSizeHintsFlags.PMaxSize);
hints.max_width = max_width;
hints.max_height = max_height;
}
else
hints.flags = (IntPtr)((int)hints.flags & ~(int)XSizeHintsFlags.PMaxSize);
if (hints.flags != IntPtr.Zero)
{
// The Metacity team has decided that they won't care about this when clicking the maximize
// icon, will maximize the window to fill the screen/parent no matter what.
// http://bugzilla.ximian.com/show_bug.cgi?id=80021
Functions.XSetWMNormalHints(window.Display, window.WindowHandle, ref hints);
}
}
#region --- IResizable Members ---
#region public int Width
@ -973,6 +942,41 @@ namespace OpenTK.Platform.X11
#region --- Private Methods ---
void SetWindowMinMax(short min_width, short min_height, short max_width, short max_height)
{
IntPtr dummy;
XSizeHints hints = new XSizeHints();
Functions.XGetWMNormalHints(window.Display, window.WindowHandle, ref hints, out dummy);
if (min_width > 0 || min_height > 0)
{
hints.flags = (IntPtr)((int)hints.flags | (int)XSizeHintsFlags.PMinSize);
hints.min_width = min_width;
hints.min_height = min_height;
}
else
hints.flags = (IntPtr)((int)hints.flags & ~(int)XSizeHintsFlags.PMinSize);
if (max_width > 0 || max_height > 0)
{
hints.flags = (IntPtr)((int)hints.flags | (int)XSizeHintsFlags.PMaxSize);
hints.max_width = max_width;
hints.max_height = max_height;
}
else
hints.flags = (IntPtr)((int)hints.flags & ~(int)XSizeHintsFlags.PMaxSize);
if (hints.flags != IntPtr.Zero)
{
// The Metacity team has decided that they won't care about this when clicking the maximize
// icon, will maximize the window to fill the screen/parent no matter what.
// http://bugzilla.ximian.com/show_bug.cgi?id=80021
Functions.XSetWMNormalHints(window.Display, window.WindowHandle, ref hints);
}
}
bool IsWindowBorderResizable
{
get