diff --git a/Source/OpenTK/GameWindow.cs b/Source/OpenTK/GameWindow.cs index 01b3cbf8..f9dbcde7 100644 --- a/Source/OpenTK/GameWindow.cs +++ b/Source/OpenTK/GameWindow.cs @@ -1347,24 +1347,27 @@ namespace OpenTK } */ #endregion -#if false // TODO: 0.9.2 (Linux support missing) + #region PointToClient /// /// Converts the screen coordinates of a specified point on the screen to client-area coordinates. /// - /// A System.Drawing.Point structure that specifies the screen coordinates to be converted + /// A System.Drawing.Point structure that specifies the screen coordinates to be converted /// The client-area coordinates of the point. The new coordinates are relative to the upper-left corner of the GameWindow's client area. - 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. /// /// Converts the client-area coordinates of a specified point to screen coordinates. /// @@ -1372,12 +1375,11 @@ namespace OpenTK /// 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. 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 --- /// diff --git a/Source/OpenTK/Platform/INativeGLWindow.cs b/Source/OpenTK/Platform/INativeGLWindow.cs index 5cdc561e..fee7bff4 100644 --- a/Source/OpenTK/Platform/INativeGLWindow.cs +++ b/Source/OpenTK/Platform/INativeGLWindow.cs @@ -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; } diff --git a/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs b/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs index 849eba68..e2b44af2 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs @@ -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 diff --git a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs index 1fcc3ec9..2123a19a 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs @@ -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 diff --git a/Source/OpenTK/Platform/Windows/WinGLNative.cs b/Source/OpenTK/Platform/Windows/WinGLNative.cs index 3312d08a..9af50437 100644 --- a/Source/OpenTK/Platform/Windows/WinGLNative.cs +++ b/Source/OpenTK/Platform/Windows/WinGLNative.cs @@ -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(); } diff --git a/Source/OpenTK/Platform/X11/X11GLNative.cs b/Source/OpenTK/Platform/X11/X11GLNative.cs index 82232b1c..237e8059 100644 --- a/Source/OpenTK/Platform/X11/X11GLNative.cs +++ b/Source/OpenTK/Platform/X11/X11GLNative.cs @@ -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(); } @@ -792,41 +796,6 @@ namespace OpenTK.Platform.X11 #endregion #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 --- @@ -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