using System; using OpenTK.Graphics; using System.Drawing; namespace OpenTK.Platform.MacOS { class CocoaNativeWindow : INativeWindow { public event System.EventHandler Move; public event System.EventHandler Resize; public event System.EventHandler Closing; public event System.EventHandler Closed; public event System.EventHandler Disposed; public event System.EventHandler IconChanged; public event System.EventHandler TitleChanged; public event System.EventHandler VisibleChanged; public event System.EventHandler FocusedChanged; public event System.EventHandler WindowBorderChanged; public event System.EventHandler WindowStateChanged; public event System.EventHandler KeyDown; public event System.EventHandler KeyPress; public event System.EventHandler KeyUp; public event System.EventHandler MouseLeave; public event System.EventHandler MouseEnter; static readonly IntPtr nextEventMatchingMask = Selector.Get("nextEventMatchingMask:untilDate:inMode:dequeue:"); static readonly IntPtr sendEvent = Selector.Get("sendEvent:"); static readonly IntPtr updateWindows = Selector.Get("updateWindows"); static readonly IntPtr contentView = Selector.Get("contentView"); static readonly IntPtr NSDefaultRunLoopMode; static CocoaNativeWindow() { Cocoa.Initialize(); NSDefaultRunLoopMode = Cocoa.GetStringConstant(Cocoa.FoundationLibrary, "NSDefaultRunLoopMode"); } private CocoaWindowInfo windowInfo; private IntPtr windowClass; public CocoaNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) { // Create the window class windowClass = Class.AllocateClass("OpenTKWindow", "NSWindow"); Class.RegisterMethod(windowClass, new WindowDidResizeDelegate(WindowDidResize), "windowDidResize:", "v@:@"); Class.RegisterClass(windowClass); // Create window instance var contentRect = new System.Drawing.RectangleF(x, y, width, height); var style = NSWindowStyle.Titled | NSWindowStyle.Resizable; var bufferingType = NSBackingStore.Buffered; IntPtr windowPtr; windowPtr = Cocoa.SendIntPtr(windowClass, Selector.Alloc); windowPtr = Cocoa.SendIntPtr(windowPtr, Selector.Get("initWithContentRect:styleMask:backing:defer:"), contentRect, (int)style, (int)bufferingType, false); windowPtr = Cocoa.SendIntPtr(windowPtr, Selector.Autorelease); // Set up behavior Cocoa.SendIntPtr(windowPtr, Selector.Get("setDelegate:"), windowPtr); // The window class acts as its own delegate Cocoa.SendVoid(windowPtr, Selector.Get("cascadeTopLeftFromPoint:"), new System.Drawing.PointF(20, 20)); Cocoa.SendVoid(windowPtr, Selector.Get("setTitle:"), Cocoa.ToNative(title)); Cocoa.SendVoid(windowPtr, Selector.Get("makeKeyAndOrderFront:"), IntPtr.Zero); windowInfo = new CocoaWindowInfo(windowPtr); } delegate void WindowDidResizeDelegate(IntPtr self, IntPtr cmd, IntPtr notification); void WindowDidResize(IntPtr self, IntPtr cmd, IntPtr notification) { GraphicsContext.CurrentContext.Update(windowInfo); } public static IntPtr GetView(IntPtr windowHandle) { return Cocoa.SendIntPtr(windowHandle, contentView); } public void Close() { throw new System.NotImplementedException(); } public void ProcessEvents() { var e = Cocoa.SendIntPtr(NSApplication.Handle, nextEventMatchingMask, uint.MaxValue, IntPtr.Zero, NSDefaultRunLoopMode, true); if (e == IntPtr.Zero) return; Cocoa.SendVoid(NSApplication.Handle, sendEvent, e); Cocoa.SendVoid(NSApplication.Handle, updateWindows); } public System.Drawing.Point PointToClient(System.Drawing.Point point) { throw new System.NotImplementedException(); } public System.Drawing.Point PointToScreen(System.Drawing.Point point) { throw new System.NotImplementedException(); } public System.Drawing.Icon Icon { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public string Title { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public bool Focused { get { throw new System.NotImplementedException(); } } public bool Visible { get { //throw new System.NotImplementedException(); return true; } set { //throw new System.NotImplementedException(); } } public bool Exists { get { return true; } } public IWindowInfo WindowInfo { get { return windowInfo; } } public WindowState WindowState { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public WindowBorder WindowBorder { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public System.Drawing.Rectangle Bounds { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public System.Drawing.Point Location { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public System.Drawing.Size Size { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public int X { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public int Y { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public int Width { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public int Height { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public System.Drawing.Rectangle ClientRectangle { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public System.Drawing.Size ClientSize { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public OpenTK.Input.IInputDriver InputDriver { get { throw new System.NotImplementedException(); } } public bool CursorVisible { get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } public void Dispose() { } } }