MacOS: Correct resizing behavior and correctly implement Bounds, ClientRectangle, and ClientSize getters and setters.

This commit is contained in:
kanato 2009-11-15 19:31:23 +00:00
parent d695bb599c
commit 69c05cdb20

View file

@ -43,6 +43,8 @@ namespace OpenTK.Platform.MacOS
CarbonWindowInfo window; CarbonWindowInfo window;
CarbonInput mInputDriver; CarbonInput mInputDriver;
[Obsolete]
GraphicsContext context; GraphicsContext context;
static MacOSKeyMap Keymap = new MacOSKeyMap(); static MacOSKeyMap Keymap = new MacOSKeyMap();
@ -50,7 +52,8 @@ namespace OpenTK.Platform.MacOS
IntPtr uppHandler; IntPtr uppHandler;
string title = "OpenTK Window"; string title = "OpenTK Window";
Rectangle bounds, windowedBounds, clientRectangle; Rectangle bounds, clientRectangle;
Rectangle windowedBounds;
bool mIsDisposed = false; bool mIsDisposed = false;
bool mExists = true; bool mExists = true;
DisplayDevice mDisplayDevice; DisplayDevice mDisplayDevice;
@ -257,6 +260,7 @@ namespace OpenTK.Platform.MacOS
Debug.Print("Prev Size: {0}, {1}", Width, Height); Debug.Print("Prev Size: {0}, {1}", Width, Height);
// TODO: if we go full screen we need to make this use the device specified.
bounds = DisplayDevice.Default.Bounds; bounds = DisplayDevice.Default.Bounds;
Debug.Print("New Size: {0}, {1}", Width, Height); Debug.Print("New Size: {0}, {1}", Width, Height);
@ -631,34 +635,19 @@ namespace OpenTK.Platform.MacOS
if (WindowState == WindowState.Fullscreen) if (WindowState == WindowState.Fullscreen)
return; return;
// Todo: why call SizeWindow twice? // The bounds of the window should be the size specified, but
// API.SizeWindow sets the content region size. So
// we reduce the size to get the correct bounds.
width -= (short)(bounds.Width - clientRectangle.Width);
height -= (short)(bounds.Height - clientRectangle.Height);
API.SizeWindow(window.WindowRef, width, height, true); API.SizeWindow(window.WindowRef, width, height, true);
bounds.Width = (short)width;
bounds.Height = (short)height;
Rect contentBounds = API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion);
Rect newSize = new Rect(0, 0,
(short)(2 * width - contentBounds.Width),
(short)(2 * height - contentBounds.Height));
Debug.Print("Content region was: {0}", contentBounds);
Debug.Print("Resizing window to: {0}", newSize);
API.SizeWindow(window.WindowRef, newSize.Width, newSize.Height, true);
contentBounds = API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion);
Debug.Print("New content region size: {0}", contentBounds);
clientRectangle = contentBounds.ToRectangle();
} }
protected void OnResize() protected void OnResize()
{ {
LoadSize(); LoadSize();
if (context != null && this.windowState != WindowState.Fullscreen)
context.Update(window);
if (Resize != null) if (Resize != null)
{ {
Resize(this, EventArgs.Empty); Resize(this, EventArgs.Empty);
@ -670,7 +659,11 @@ namespace OpenTK.Platform.MacOS
if (WindowState == WindowState.Fullscreen) if (WindowState == WindowState.Fullscreen)
return; return;
bounds = GetRegion().ToRectangle(); Rect r = API.GetWindowBounds(window.WindowRef, WindowRegionCode.StructureRegion);
bounds = new Rectangle(r.X, r.Y, r.Width, r.Height);
r = API.GetWindowBounds(window.WindowRef, WindowRegionCode.GlobalPortRegion);
clientRectangle = new Rectangle(0, 0, r.Width, r.Height);
} }
#endregion #endregion
@ -762,8 +755,8 @@ namespace OpenTK.Platform.MacOS
private void SetIcon(Icon icon) private void SetIcon(Icon icon)
{ {
// The code for this function was adapted from Mono's XplatUICarbon implementation, // The code for this function was adapted from Mono's
// written by Geoff Norton // XplatUICarbon implementation, written by Geoff Norton
// http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUICarbon.cs?view=markup&pathrev=136932 // http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUICarbon.cs?view=markup&pathrev=136932
if (icon == null) if (icon == null)
{ {
@ -845,7 +838,8 @@ namespace OpenTK.Platform.MacOS
{ {
get get
{ {
return bounds;
return bounds;
} }
set set
{ {
@ -858,7 +852,7 @@ namespace OpenTK.Platform.MacOS
{ {
get get
{ {
return bounds.Location; return Bounds.Location;
} }
set set
{ {
@ -875,7 +869,6 @@ namespace OpenTK.Platform.MacOS
set set
{ {
SetSize((short)value.Width, (short)value.Height); SetSize((short)value.Width, (short)value.Height);
context.Update(WindowInfo);
} }
} }
@ -919,11 +912,13 @@ namespace OpenTK.Platform.MacOS
{ {
get get
{ {
return clientRectangle; return clientRectangle;
} }
set set
{ {
throw new NotImplementedException(); // just set the size, and ignore the location value.
// this is the behavior of the Windows WinGLNative.
ClientSize = value.Size;
} }
} }
@ -935,7 +930,8 @@ namespace OpenTK.Platform.MacOS
} }
set set
{ {
throw new NotImplementedException(); API.SizeWindow(window.WindowRef, (short)value.Width, (short)value.Height, true);
OnResize();
} }
} }