From 67bdd39d0811d60aad55d3c0eeb8afd8a1fb0a9f Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 19 Jul 2009 17:49:51 +0000 Subject: [PATCH] Added INativeWindow.CreateKeyboardDriver() Added INativeWindow.KeyPress event (KeyPressEventArgs). Removed INativeWindow.Icon property. --- Source/OpenTK/GameWindow.cs | 35 ++--------- Source/OpenTK/INativeWindow.cs | 17 ++---- Source/OpenTK/KeyPressEventArgs.cs | 58 +++++++++++++++++++ Source/OpenTK/Platform/Factory.cs | 29 +++++++--- Source/OpenTK/Platform/IPlatformFactory.cs | 2 + .../OpenTK/Platform/MacOS/CarbonGLNative.cs | 2 + Source/OpenTK/Platform/MacOS/MacOSFactory.cs | 5 ++ Source/OpenTK/Platform/Windows/WinFactory.cs | 5 ++ Source/OpenTK/Platform/Windows/WinGLNative.cs | 2 + Source/OpenTK/Platform/X11/X11Factory.cs | 5 ++ Source/OpenTK/Platform/X11/X11GLNative.cs | 12 +++- 11 files changed, 123 insertions(+), 49 deletions(-) create mode 100644 Source/OpenTK/KeyPressEventArgs.cs diff --git a/Source/OpenTK/GameWindow.cs b/Source/OpenTK/GameWindow.cs index 8e28b245..9ec7fcba 100644 --- a/Source/OpenTK/GameWindow.cs +++ b/Source/OpenTK/GameWindow.cs @@ -1052,31 +1052,6 @@ namespace OpenTK #region --- INativeWindow Members --- - #region Icon - - /// - /// Gets or sets the System.Drawing.Icon for this GameWindow. - /// - public Icon Icon - { - get - { - if (disposed) - throw new ObjectDisposedException(this.GetType().Name); - - return glWindow.Icon; - } - set - { - if (disposed) - throw new ObjectDisposedException(this.GetType().Name); - - glWindow.Icon = value; - } - } - - #endregion - #region Focused /// @@ -1456,11 +1431,6 @@ namespace OpenTK /// public event EventHandler Disposed = delegate { }; - /// - /// Occurs when the property of the window changes. - /// - public event EventHandler IconChanged = delegate { }; - /// /// Occurs when the property of the window changes. /// @@ -1476,6 +1446,11 @@ namespace OpenTK /// public event EventHandler FocusedChanged = delegate { }; + /// + /// Occurs whenever a character is typed. + /// + public event EventHandler KeyPress = delegate { }; + #endregion #endregion diff --git a/Source/OpenTK/INativeWindow.cs b/Source/OpenTK/INativeWindow.cs index 0b254a9f..7513f6d0 100644 --- a/Source/OpenTK/INativeWindow.cs +++ b/Source/OpenTK/INativeWindow.cs @@ -39,11 +39,6 @@ namespace OpenTK /// public interface INativeWindow : IDisposable { - /// - /// Gets or sets the of the window. - /// - Icon Icon { get; set; } - /// /// Gets or sets the title of the window. /// @@ -186,11 +181,6 @@ namespace OpenTK /// event EventHandler Disposed; - /// - /// Occurs when the property of the window changes. - /// - event EventHandler IconChanged; - /// /// Occurs when the property of the window changes. /// @@ -206,6 +196,11 @@ namespace OpenTK /// event EventHandler FocusedChanged; + /// + /// Occurs whenever a character is typed. + /// + event EventHandler KeyPress; + //event EventHandler MouseEnter; //event EventHandler MouseMove; //event EventHandler MouseWheel; @@ -216,7 +211,7 @@ namespace OpenTK //event EventHandler KeyDown; //event EventHandler KeyUp; - //event EventHandler KeyPress; + //event EventHandler DragDrop; //event EventHandler DragEnter; diff --git a/Source/OpenTK/KeyPressEventArgs.cs b/Source/OpenTK/KeyPressEventArgs.cs new file mode 100644 index 00000000..6df2143f --- /dev/null +++ b/Source/OpenTK/KeyPressEventArgs.cs @@ -0,0 +1,58 @@ +// #region License +// // +// // The Open Toolkit Library License +// // +// // Copyright (c) 2006 - 2009 the Open Toolkit library. +// // +// // Permission is hereby granted, free of charge, to any person obtaining a copy +// // of this software and associated documentation files (the "Software"), to deal +// // in the Software without restriction, including without limitation the rights to +// // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +// // the Software, and to permit persons to whom the Software is furnished to do +// // so, subject to the following conditions: +// // +// // The above copyright notice and this permission notice shall be included in all +// // copies or substantial portions of the Software. +// // +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// // OTHER DEALINGS IN THE SOFTWARE. +// // +// #endregion + +using System; + +namespace OpenTK +{ + /// + /// Defines the event arguments for KeyPress events. Instances of this class are cached: + /// KeyPressEventArgs should only be used inside the relevant event, unless manually cloned. + /// + public class KeyPressEventArgs : EventArgs + { + char key_char; + + /// + /// Constructs a new instance. + /// + /// The ASCII character that was typed. + public KeyPressEventArgs(char keyChar) + { + KeyChar = keyChar; + } + + /// + /// Gets a that defines the ASCII character that was typed. + /// + public char KeyChar + { + get { return key_char; } + private set { key_char = value; } + } + } +} diff --git a/Source/OpenTK/Platform/Factory.cs b/Source/OpenTK/Platform/Factory.cs index 4a7c12f5..c7dbaed7 100644 --- a/Source/OpenTK/Platform/Factory.cs +++ b/Source/OpenTK/Platform/Factory.cs @@ -94,42 +94,57 @@ namespace OpenTK.Platform { return implementation.CreateGraphicsMode(); } + + public OpenTK.Input.IKeyboardDriver CreateKeyboardDriver() + { + return implementation.CreateKeyboardDriver(); + } class UnsupportedPlatform : IPlatformFactory { + #region Fields + + static readonly string error_string = "Please, refer to http://www.opentk.com for more information."; + + #endregion + #region IPlatformFactory Members public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) { - throw new PlatformNotSupportedException("Please, refer to http://www.opentk.com for more information."); + throw new PlatformNotSupportedException(error_string); } public IGLControl CreateGLControl(GraphicsMode mode, GLControl owner) { - throw new PlatformNotSupportedException("Please, refer to http://www.opentk.com for more information."); + throw new PlatformNotSupportedException(error_string); } public IDisplayDeviceDriver CreateDisplayDeviceDriver() { - throw new PlatformNotSupportedException("Please, refer to http://www.opentk.com for more information."); + throw new PlatformNotSupportedException(error_string); } public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool DirectRendering, int major, int minor, GraphicsContextFlags flags) { - throw new PlatformNotSupportedException("Please, refer to http://www.opentk.com for more information."); + throw new PlatformNotSupportedException(error_string); } public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext() { - throw new PlatformNotSupportedException("Please, refer to http://www.opentk.com for more information."); + throw new PlatformNotSupportedException(error_string); } - public IGraphicsMode CreateGraphicsMode() { - throw new PlatformNotSupportedException("Please, refer to http://www.opentk.com for more information."); + throw new PlatformNotSupportedException(error_string); } + public OpenTK.Input.IKeyboardDriver CreateKeyboardDriver() + { + throw new PlatformNotSupportedException(error_string); + } + #endregion } diff --git a/Source/OpenTK/Platform/IPlatformFactory.cs b/Source/OpenTK/Platform/IPlatformFactory.cs index f1918219..65209e34 100644 --- a/Source/OpenTK/Platform/IPlatformFactory.cs +++ b/Source/OpenTK/Platform/IPlatformFactory.cs @@ -46,5 +46,7 @@ namespace OpenTK.Platform OpenTK.Graphics.GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext(); OpenTK.Graphics.IGraphicsMode CreateGraphicsMode(); + + OpenTK.Input.IKeyboardDriver CreateKeyboardDriver(); } } diff --git a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs index 80006bc7..b895871e 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs @@ -949,6 +949,8 @@ namespace OpenTK.Platform.MacOS public event EventHandler FocusedChanged; + public event EventHandler KeyPress; + #endregion } } diff --git a/Source/OpenTK/Platform/MacOS/MacOSFactory.cs b/Source/OpenTK/Platform/MacOS/MacOSFactory.cs index 15c76f15..a3789a83 100644 --- a/Source/OpenTK/Platform/MacOS/MacOSFactory.cs +++ b/Source/OpenTK/Platform/MacOS/MacOSFactory.cs @@ -70,6 +70,11 @@ namespace OpenTK.Platform.MacOS return new MacOSGraphicsMode(); } + public OpenTK.Input.IKeyboardDriver CreateKeyboardDriver() + { + throw new NotImplementedException(); + } + #endregion } } diff --git a/Source/OpenTK/Platform/Windows/WinFactory.cs b/Source/OpenTK/Platform/Windows/WinFactory.cs index a5efcbf2..12c4a4d9 100644 --- a/Source/OpenTK/Platform/Windows/WinFactory.cs +++ b/Source/OpenTK/Platform/Windows/WinFactory.cs @@ -71,6 +71,11 @@ using OpenTK.Input; return new WinGraphicsMode(); } + public OpenTK.Input.IKeyboardDriver CreateKeyboardDriver() + { + throw new NotImplementedException(); + } + #endregion } } diff --git a/Source/OpenTK/Platform/Windows/WinGLNative.cs b/Source/OpenTK/Platform/Windows/WinGLNative.cs index f91c9ee8..6a6fc8e8 100644 --- a/Source/OpenTK/Platform/Windows/WinGLNative.cs +++ b/Source/OpenTK/Platform/Windows/WinGLNative.cs @@ -907,6 +907,8 @@ namespace OpenTK.Platform.Windows public event EventHandler FocusedChanged; + public event EventHandler KeyPress; + #endregion #endregion diff --git a/Source/OpenTK/Platform/X11/X11Factory.cs b/Source/OpenTK/Platform/X11/X11Factory.cs index 0cd1b52b..63f55fba 100644 --- a/Source/OpenTK/Platform/X11/X11Factory.cs +++ b/Source/OpenTK/Platform/X11/X11Factory.cs @@ -42,6 +42,11 @@ namespace OpenTK.Platform.X11 { return new X11GraphicsMode(); } + + public OpenTK.Input.IKeyboardDriver CreateKeyboardDriver() + { + throw new NotImplementedException(); + } #endregion } diff --git a/Source/OpenTK/Platform/X11/X11GLNative.cs b/Source/OpenTK/Platform/X11/X11GLNative.cs index a716eafe..265e4e61 100644 --- a/Source/OpenTK/Platform/X11/X11GLNative.cs +++ b/Source/OpenTK/Platform/X11/X11GLNative.cs @@ -609,11 +609,19 @@ namespace OpenTK.Platform.X11 break; case XEventName.KeyPress: + driver.ProcessEvent(ref e); + break; + case XEventName.KeyRelease: + // Todo: raise KeyPress event. Use code from + // http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/X11Keyboard.cs?view=markup + + driver.ProcessEvent(ref e); + break; + case XEventName.MotionNotify: case XEventName.ButtonPress: case XEventName.ButtonRelease: - //Functions.XPutBackEvent(window.Display, ref e); driver.ProcessEvent(ref e); break; @@ -852,6 +860,8 @@ namespace OpenTK.Platform.X11 public event EventHandler FocusedChanged; + public event EventHandler KeyPress; + #endregion #endregion