private IntPtr GetQuartzDevice(CarbonWindowInfo carbonWindow) { IntPtr windowRef = carbonWindow.WindowRef; if (CarbonGLNative.WindowRefMap.ContainsKey(windowRef) == false) { return(IntPtr.Zero); } WeakReference nativeRef = CarbonGLNative.WindowRefMap[windowRef]; if (nativeRef.IsAlive == false) { return(IntPtr.Zero); } CarbonGLNative window = nativeRef.Target as CarbonGLNative; if (window == null) { return(IntPtr.Zero); } return(QuartzDisplayDeviceDriver.HandleTo(window.TargetDisplayDevice)); }
internal void SetFullScreen(CarbonWindowInfo info, out int width, out int height) { CarbonGLNative wind = GetCarbonWindow(info); Debug.Print("Switching to full screen {0}x{1} on context {2}", wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, Handle.Handle); CG.DisplayCapture(GetQuartzDevice(info)); Agl.aglSetFullScreen(Handle.Handle, wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, 0, 0); MakeCurrent(info); width = wind.TargetDisplayDevice.Width; height = wind.TargetDisplayDevice.Height; // This is a weird hack to workaround a bug where the first time a context // is made fullscreen, we just end up with a blank screen. So we undo it as fullscreen // and redo it as fullscreen. if (firstFullScreen == false) { firstFullScreen = true; UnsetFullScreen(info); SetFullScreen(info, out width, out height); } mIsFullscreen = true; }
public override void Update(IWindowInfo window) { CarbonWindowInfo carbonWindow1 = (CarbonWindowInfo)window; if (carbonWindow1.GoFullScreenHack) { carbonWindow1.GoFullScreenHack = false; CarbonGLNative carbonWindow2 = this.GetCarbonWindow(carbonWindow1); if (carbonWindow2 == null) { return; } carbonWindow2.SetFullscreen(this); } else { if (carbonWindow1.GoWindowedHack) { carbonWindow1.GoWindowedHack = false; CarbonGLNative carbonWindow2 = this.GetCarbonWindow(carbonWindow1); if (carbonWindow2 != null) { carbonWindow2.UnsetFullscreen(this); } } if (this.mIsFullscreen) { return; } this.SetDrawable(carbonWindow1); this.SetBufferRect(carbonWindow1); int num = (int)Agl.aglUpdateContext(this.Handle.Handle); } }
protected static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData) { // bail out if the window passed in is not actually our window. // I think this happens if using winforms with a GameWindow sometimes. if (!mWindows.ContainsKey(userData)) { return(OSStatus.EventNotHandled); } WeakReference reference = mWindows[userData]; // bail out if the CarbonGLNative window has been garbage collected. if (!reference.IsAlive) { mWindows.Remove(userData); return(OSStatus.EventNotHandled); } CarbonGLNative window = (CarbonGLNative)reference.Target; //Debug.Print("Processing {0} event for {1}.", evt, window.window); if (window == null) { Debug.Print("Window for event not found."); return(OSStatus.EventNotHandled); } EventInfo evt = new EventInfo(inEvent); return(window.DispatchEvent(inCaller, inEvent, evt, userData)); }
private IntPtr GetQuartzDevice(CarbonWindowInfo carbonWindow) { IntPtr windowRef = carbonWindow.WindowRef; if (!CarbonGLNative.WindowRefMap.ContainsKey(windowRef)) { return(IntPtr.Zero); } WeakReference weakReference = CarbonGLNative.WindowRefMap[windowRef]; if (!weakReference.IsAlive) { return(IntPtr.Zero); } CarbonGLNative carbonGlNative = weakReference.Target as CarbonGLNative; if (carbonGlNative == null) { return(IntPtr.Zero); } else { return(QuartzDisplayDeviceDriver.HandleTo(carbonGlNative.TargetDisplayDevice)); } }
public static void Run(CarbonGLNative window) { window.Closed += new EventHandler<EventArgs>(Application.MainWindowClosed); window.Visible = true; API.RunApplicationEventLoop(); window.Closed -= new EventHandler<EventArgs>(Application.MainWindowClosed); }
private OSStatus ProcessKeyboardEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) { MacOSKeyCode code = MacOSKeyCode.A; char charCode = char.MinValue; switch (evt.KeyboardEventKind) { case KeyboardEventKind.RawKeyDown: case KeyboardEventKind.RawKeyRepeat: case KeyboardEventKind.RawKeyUp: CarbonGLNative.GetCharCodes(inEvent, out code, out charCode); this.mKeyPressArgs.KeyChar = charCode; break; } switch (evt.KeyboardEventKind) { case KeyboardEventKind.RawKeyDown: Key index1; if (CarbonGLNative.Keymap.TryGetValue(code, out index1)) { this.InputDriver.Keyboard[0][index1] = true; this.OnKeyPress(this.mKeyPressArgs); } return(OSStatus.NoError); case KeyboardEventKind.RawKeyRepeat: if (!this.InputDriver.Keyboard[0].KeyRepeat) { break; } else { goto case KeyboardEventKind.RawKeyDown; } case KeyboardEventKind.RawKeyUp: Key index2; if (CarbonGLNative.Keymap.TryGetValue(code, out index2)) { this.InputDriver.Keyboard[0][index2] = false; } return(OSStatus.NoError); case KeyboardEventKind.RawKeyModifiersChanged: this.ProcessModifierKey(inEvent); return(OSStatus.NoError); } return(OSStatus.EventNotHandled); }
public override void Update(IWindowInfo window) { CarbonWindowInfo carbonWindow = (CarbonWindowInfo)window; if (carbonWindow.GoFullScreenHack) { carbonWindow.GoFullScreenHack = false; CarbonGLNative wind = GetCarbonWindow(carbonWindow); if (wind != null) { wind.SetFullscreen(this); } else { Debug.Print("Could not find window!"); } return; } else if (carbonWindow.GoWindowedHack) { carbonWindow.GoWindowedHack = false; CarbonGLNative wind = GetCarbonWindow(carbonWindow); if (wind != null) { wind.UnsetFullscreen(this); } else { Debug.Print("Could not find window!"); } } if (mIsFullscreen) { return; } SetDrawable(carbonWindow); SetBufferRect(carbonWindow); Agl.aglUpdateContext(Handle.Handle); }
internal void SetFullScreen(CarbonWindowInfo info, out int width, out int height) { CarbonGLNative carbonWindow = this.GetCarbonWindow(info); int num = (int)CG.DisplayCapture(this.GetQuartzDevice(info)); Agl.aglSetFullScreen(this.Handle.Handle, carbonWindow.TargetDisplayDevice.Width, carbonWindow.TargetDisplayDevice.Height, 0, 0); this.MakeCurrent((IWindowInfo)info); width = carbonWindow.TargetDisplayDevice.Width; height = carbonWindow.TargetDisplayDevice.Height; if (!this.firstFullScreen) { this.firstFullScreen = true; this.UnsetFullScreen(info); this.SetFullScreen(info, out width, out height); } this.mIsFullscreen = true; }
protected static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData) { // bail out if the window passed in is not actually our window. // I think this happens if using winforms with a GameWindow sometimes. if (mWindows.ContainsKey(userData) == false) { return(OSStatus.EventNotHandled); } WeakReference reference = mWindows[userData]; // bail out if the CarbonGLNative window has been garbage collected. if (reference.IsAlive == false) { mWindows.Remove(userData); return(OSStatus.EventNotHandled); } EventInfo evt = new EventInfo(inEvent); CarbonGLNative window = (CarbonGLNative)reference.Target; //Debug.Print("Processing {0} event for {1}.", evt, window.window); if (window == null) { Debug.WriteLine("Window for event not found."); return(OSStatus.EventNotHandled); } switch (evt.EventClass) { case EventClass.Window: return(window.ProcessWindowEvent(inCaller, inEvent, evt, userData)); case EventClass.Mouse: return(window.ProcessMouseEvent(inCaller, inEvent, evt, userData)); case EventClass.Keyboard: return(window.ProcessKeyboardEvent(inCaller, inEvent, evt, userData)); default: return(OSStatus.EventNotHandled); } }
protected static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData) { if (!CarbonGLNative.mWindows.ContainsKey(userData)) { return(OSStatus.EventNotHandled); } WeakReference weakReference = CarbonGLNative.mWindows[userData]; if (!weakReference.IsAlive) { CarbonGLNative.mWindows.Remove(userData); return(OSStatus.EventNotHandled); } else { CarbonGLNative carbonGlNative = (CarbonGLNative)weakReference.Target; if (carbonGlNative == null) { return(OSStatus.EventNotHandled); } EventInfo evt = new EventInfo(inEvent); return(carbonGlNative.DispatchEvent(inCaller, inEvent, evt, userData)); } }