From 32a5e0fc50b6cc10674b60f4c7102d8a1d18311e Mon Sep 17 00:00:00 2001 From: "Stefanos A." Date: Fri, 22 Nov 2013 18:25:30 +0100 Subject: [PATCH] Add test for new text input events --- Source/Examples/OpenTK/Test/GameWindowStates.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Source/Examples/OpenTK/Test/GameWindowStates.cs b/Source/Examples/OpenTK/Test/GameWindowStates.cs index 6977de2a..73d81002 100644 --- a/Source/Examples/OpenTK/Test/GameWindowStates.cs +++ b/Source/Examples/OpenTK/Test/GameWindowStates.cs @@ -21,6 +21,7 @@ namespace Examples.Tests { static readonly Font TextFont = new Font(FontFamily.GenericSansSerif, 11); Bitmap TextBitmap = new Bitmap(1024, 1024); + StringBuilder TypedText = new StringBuilder(); int texture; bool mouse_in_window = false; bool viewport_changed = true; @@ -33,7 +34,8 @@ namespace Examples.Tests { VSync = VSyncMode.On; Keyboard.KeyRepeat = true; - Keyboard.KeyDown += KeyDownHandler; + KeyDown += KeyDownHandler; + KeyPress += KeyPressHandler; MouseEnter += delegate { mouse_in_window = true; }; MouseLeave += delegate { mouse_in_window = false; }; @@ -54,6 +56,14 @@ namespace Examples.Tests } } + private void KeyPressHandler(object sender, KeyPressEventArgs e) + { + if (TypedText.Length > 32) + TypedText.Remove(0, 1); + + TypedText.Append(e.KeyChar); + } + void KeyDownHandler(object sender, KeyboardKeyEventArgs e) { switch (e.Key) @@ -222,10 +232,10 @@ namespace Examples.Tests DrawString(gfx, String.Format("Window.Location: {0}, Size: {1}", Location, Size), line++); DrawString(gfx, String.Format("Window: {{X={0},Y={1},Width={2},Height={3}}}", X, Y, Width, Height), line++); DrawString(gfx, String.Format("Window.ClientRectangle: {0}", ClientRectangle), line++); + DrawString(gfx, TypedText.ToString(), line++); DrawKeyboard(gfx, keyboard, line++); DrawMouse(gfx, mouse, line++); DrawJoysticks(gfx, Joysticks, line++); - } }