Cleanups.

This commit is contained in:
Olle Håkansson 2014-04-21 19:41:45 +02:00 committed by thefiddler
parent 3798d268dc
commit ed87814a7f
2 changed files with 119 additions and 110 deletions

View file

@ -7,12 +7,12 @@ namespace OpenTK.Platform.MacOS
static class NSApplication static class NSApplication
{ {
internal static IntPtr Handle; internal static IntPtr Handle;
internal static IntPtr AutoreleasePool;
internal static void Initialize() internal static void Initialize()
{ {
// Create the NSAutoreleasePool // Create the NSAutoreleasePool
Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSAutoreleasePool"), Selector.Alloc), AutoreleasePool = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSAutoreleasePool"), Selector.Alloc), Selector.Init);
Selector.Init);
// Fetch the application handle // Fetch the application handle
Handle = Cocoa.SendIntPtr(Class.Get("NSApplication"), Selector.Get("sharedApplication")); Handle = Cocoa.SendIntPtr(Class.Get("NSApplication"), Selector.Get("sharedApplication"));
@ -20,7 +20,6 @@ namespace OpenTK.Platform.MacOS
// Setup the application // Setup the application
Cocoa.SendBool(Handle, Selector.Get("setActivationPolicy:"), (int)NSApplicationActivationPolicy.Regular); Cocoa.SendBool(Handle, Selector.Get("setActivationPolicy:"), (int)NSApplicationActivationPolicy.Regular);
Cocoa.SendVoid(Handle, Selector.Get("activateIgnoringOtherApps:"), true); Cocoa.SendVoid(Handle, Selector.Get("activateIgnoringOtherApps:"), true);
Cocoa.SendVoid(Handle, Selector.Get("finishLaunching"));
// Create the menu bar // Create the menu bar
var menubar = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSMenu"), Selector.Alloc), var menubar = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSMenu"), Selector.Alloc),
@ -32,6 +31,9 @@ namespace OpenTK.Platform.MacOS
// Add menu item to bar, and bar to application // Add menu item to bar, and bar to application
Cocoa.SendIntPtr(menubar, Selector.Get("addItem:"), menuItem); Cocoa.SendIntPtr(menubar, Selector.Get("addItem:"), menuItem);
Cocoa.SendIntPtr(Handle, Selector.Get("setMainMenu:"), menubar); Cocoa.SendIntPtr(Handle, Selector.Get("setMainMenu:"), menubar);
// Tell cocoa we're ready to run the application (usually called by [NSApp run]).
Cocoa.SendVoid(Handle, Selector.Get("finishLaunching"));
} }
} }
} }

View file

@ -266,6 +266,7 @@ namespace OpenTK.Platform.MacOS
if (trackingArea != IntPtr.Zero) if (trackingArea != IntPtr.Zero)
{ {
Cocoa.SendVoid(owner, selRemoveTrackingArea, trackingArea); Cocoa.SendVoid(owner, selRemoveTrackingArea, trackingArea);
Cocoa.SendVoid(trackingArea, Selector.Release);
} }
var ownerBounds = Cocoa.SendRect(owner, selBounds); var ownerBounds = Cocoa.SendRect(owner, selBounds);
@ -328,11 +329,13 @@ namespace OpenTK.Platform.MacOS
} }
public void ProcessEvents() public void ProcessEvents()
{
while (true)
{ {
var e = Cocoa.SendIntPtr(NSApplication.Handle, selNextEventMatchingMask, uint.MaxValue, IntPtr.Zero, NSDefaultRunLoopMode, true); var e = Cocoa.SendIntPtr(NSApplication.Handle, selNextEventMatchingMask, uint.MaxValue, IntPtr.Zero, NSDefaultRunLoopMode, true);
if (e == IntPtr.Zero) if (e == IntPtr.Zero)
return; break;
var type = (NSEventType)Cocoa.SendInt(e, selType); var type = (NSEventType)Cocoa.SendInt(e, selType);
switch (type) switch (type)
@ -417,10 +420,14 @@ namespace OpenTK.Platform.MacOS
var p = new Point((int)pf.X, (int)pf.Y); var p = new Point((int)pf.X, (int)pf.Y);
var s = ClientSize; var s = ClientSize;
if (p.X < 0) p.X = 0; if (p.X < 0)
if (p.Y < 0) p.Y = 0; p.X = 0;
if (p.X > s.Width) p.X = s.Width; if (p.Y < 0)
if (p.Y > s.Height) p.Y = s.Height; p.Y = 0;
if (p.X > s.Width)
p.X = s.Width;
if (p.Y > s.Height)
p.Y = s.Height;
p.Y = s.Height - p.Y; p.Y = s.Height - p.Y;
InputDriver.Mouse[0].Position = p; InputDriver.Mouse[0].Position = p;
@ -454,7 +461,7 @@ namespace OpenTK.Platform.MacOS
} }
Cocoa.SendVoid(NSApplication.Handle, selSendEvent, e); Cocoa.SendVoid(NSApplication.Handle, selSendEvent, e);
Cocoa.SendVoid(NSApplication.Handle, selUpdateWindows); }
} }
public System.Drawing.Point PointToClient(System.Drawing.Point point) public System.Drawing.Point PointToClient(System.Drawing.Point point)