From d3001f8a267462ced50c216709d0e8d5c2c20c10 Mon Sep 17 00:00:00 2001 From: kanato Date: Tue, 9 Dec 2008 20:10:24 +0000 Subject: [PATCH] Correct position of buffer rect to be within the GLControl. --- .../WinForms/W01_First_Window.Designer.cs | 2 +- Source/OpenTK/Platform/MacOS/AglContext.cs | 47 ++++++++++------- .../MacOS/CarbonBindings/CarbonAPI.cs | 50 +++++++++++++++---- .../OpenTK/Platform/MacOS/CarbonGLNative.cs | 4 +- 4 files changed, 71 insertions(+), 32 deletions(-) diff --git a/Source/Examples/WinForms/W01_First_Window.Designer.cs b/Source/Examples/WinForms/W01_First_Window.Designer.cs index 8057f7a2..b546aafe 100644 --- a/Source/Examples/WinForms/W01_First_Window.Designer.cs +++ b/Source/Examples/WinForms/W01_First_Window.Designer.cs @@ -73,7 +73,7 @@ namespace Examples.WinForms | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.glControl1.BackColor = System.Drawing.SystemColors.ControlDarkDark; - this.glControl1.Location = new System.Drawing.Point(10, 10); + this.glControl1.Location = new System.Drawing.Point(10, 30); this.glControl1.Name = "glControl1"; this.glControl1.Size = new System.Drawing.Size(629, 225); this.glControl1.TabIndex = 0; diff --git a/Source/OpenTK/Platform/MacOS/AglContext.cs b/Source/OpenTK/Platform/MacOS/AglContext.cs index 5fb930ca..8d6b239d 100644 --- a/Source/OpenTK/Platform/MacOS/AglContext.cs +++ b/Source/OpenTK/Platform/MacOS/AglContext.cs @@ -10,6 +10,7 @@ using System; using System.Diagnostics; using System.Runtime.InteropServices; +using Control = System.Windows.Forms.Control; namespace OpenTK.Platform.MacOS { @@ -101,28 +102,38 @@ namespace OpenTK.Platform.MacOS } void SetBufferRect(CarbonWindowInfo carbonWindow) { - if (carbonWindow.IsControl) - { - Rect rect = API.GetControlBounds(carbonWindow.WindowRef); - HIRect hirect = API.HIViewGetFrame(carbonWindow.WindowRef); + if (carbonWindow.IsControl == false) + return; + + System.Windows.Forms.Control ctrl = Control.FromHandle(carbonWindow.WindowRef); + + if (ctrl.TopLevelControl == null) + return; + + Rect rect = API.GetControlBounds(carbonWindow.WindowRef); - Debug.Print("Setting buffer_rect for control."); - Debug.Print("Rect: {0}", rect); - Debug.Print("HIRect: {0}", hirect); - - int[] glrect = new int[4]; + rect.X = (short)ctrl.Left; + rect.Y = (short)ctrl.Top; + + Debug.Print("Setting buffer_rect for control."); + Debug.Print("MacOS Coordinate Rect: {0}", rect); + + rect.Y = (short)(ctrl.TopLevelControl.ClientSize.Height - rect.Y - rect.Height); + Debug.Print(" AGL Coordinate Rect: {0}", rect); + + int[] glrect = new int[4]; - glrect[0] = rect.Left; - glrect[1] = rect.Top; - glrect[2] = rect.Width; - glrect[3] = rect.Height; + glrect[0] = rect.X; + glrect[1] = rect.Y; + glrect[2] = rect.Width; + glrect[3] = rect.Height; - Agl.aglSetInteger(contextRef, Agl.ParameterNames.AGL_BUFFER_RECT, glrect); - MyAGLReportError(); + Agl.aglSetInteger(contextRef, Agl.ParameterNames.AGL_BUFFER_RECT, glrect); + MyAGLReportError(); - Agl.aglEnable(contextRef, Agl.ParameterNames.AGL_BUFFER_RECT); - MyAGLReportError(); - } + Agl.aglEnable(contextRef, Agl.ParameterNames.AGL_BUFFER_RECT); + MyAGLReportError(); + } void SetDrawable(CarbonWindowInfo carbonWindow) { diff --git a/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs b/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs index 14d5eeee..bfd22492 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs @@ -26,26 +26,54 @@ namespace OpenTK.Platform.MacOS.Carbon [StructLayout(LayoutKind.Sequential)] internal struct Rect { - internal short Top; - internal short Left; - internal short Bottom; - internal short Right; + short top; + short left; + short bottom; + short right; internal Rect(short _left, short _top, short _width, short _height) { - Top = _top; - Left = _left; - Bottom = (short)(_top + _height); - Right = (short)(_left + _width); + top = _top; + left = _left; + bottom = (short)(_top + _height); + right = (short)(_left + _width); } - internal short Width { get { return (short)(Right - Left); } } - internal short Height { get { return (short)(Bottom - Top); } } + internal short X + { + get { return left; } + set + { + short width = Width; + left = value; + right = (short)(left + width); + } + } + internal short Y + { + get { return top; } + set + { + short height = Height; + top = value; + bottom = (short)(top + height); + } + } + internal short Width + { + get { return (short)(right - left); } + set { right = (short)(left + value); } + } + internal short Height + { + get { return (short)(bottom - top); } + set { bottom = (short)(top + value); } + } public override string ToString() { return string.Format( - "Rect: [{0}, {1}, {2}, {3}]", Top, Left, Width, Height); + "Rect: [{0}, {1}, {2}, {3}]", X, Y, Width, Height); } } diff --git a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs index 56edc872..dccb9a9f 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs @@ -482,8 +482,8 @@ namespace OpenTK.Platform.MacOS { Rect region = GetRegion(); - mWidth = (short)(region.Right - region.Left); - mHeight = (short)(region.Bottom - region.Top); + mWidth = (short)(region.Width); + mHeight = (short)(region.Height); } protected virtual void OnQueryWindowClose(CancelEventArgs e)