Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add test for new text input events

  • Loading branch information...
commit 32a5e0fc50b6cc10674b60f4c7102d8a1d18311e 1 parent 6ee04b2
@thefiddler thefiddler authored
Showing with 12 additions and 2 deletions.
  1. +12 −2 Source/Examples/OpenTK/Test/GameWindowStates.cs
View
14 Source/Examples/OpenTK/Test/GameWindowStates.cs
@@ -21,6 +21,7 @@ public class GameWindowStates : GameWindow
{
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 @@ public GameWindowStates()
{
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 @@ public GameWindowStates()
}
}
+ 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 @@ protected override void OnUpdateFrame(FrameEventArgs e)
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++);
-
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.