From 2db6f74ec14385388569364b5e5d3b34d4216fa8 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Mon, 1 Nov 2010 07:57:21 +0000 Subject: [PATCH] * OpenTK/Test/GameWindowStates.cs: Print information on pressed keyboard keys and mouse buttons. --- .../Examples/OpenTK/Test/GameWindowStates.cs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Source/Examples/OpenTK/Test/GameWindowStates.cs b/Source/Examples/OpenTK/Test/GameWindowStates.cs index 144940de..33c42000 100644 --- a/Source/Examples/OpenTK/Test/GameWindowStates.cs +++ b/Source/Examples/OpenTK/Test/GameWindowStates.cs @@ -104,6 +104,47 @@ namespace Examples.Tests gfx.DrawString(str, TextFont, Brushes.White, new PointF(0, line * TextFont.Height)); } + static void DrawString(Graphics gfx, string str, int line, float offset) + { + gfx.DrawString(str, TextFont, Brushes.White, new PointF(offset, line * TextFont.Height)); + } + + static void DrawKeyboard(Graphics gfx, KeyboardState keyboard, int line) + { + const string str = "Keys pressed:"; + float space = gfx.MeasureString(" ", TextFont).Width; + float offset = gfx.MeasureString(str, TextFont).Width + space; + DrawString(gfx, str, line); + for (int i = 0; i < (int)Key.LastKey; i++) + { + Key k = (Key)i; + if (keyboard[k]) + { + string key = k.ToString(); + DrawString(gfx, key, line, offset); + offset += gfx.MeasureString(key, TextFont).Width + space; + } + } + } + + static void DrawMouse(Graphics gfx, MouseState mouse, int line) + { + const string str = "Buttons pressed:"; + float space = gfx.MeasureString(" ", TextFont).Width; + float offset = gfx.MeasureString(str, TextFont).Width + space; + DrawString(gfx, str, line); + for (int i = 0; i < (int)MouseButton.LastButton; i++) + { + MouseButton b = (MouseButton)i; + if (mouse[b]) + { + string button = b.ToString(); + DrawString(gfx, button, line, offset); + offset += gfx.MeasureString(button, TextFont).Width + space; + } + } + } + protected override void OnUpdateFrame(FrameEventArgs e) { mouse = OpenTK.Input.Mouse.GetState(); @@ -137,6 +178,8 @@ 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++); + DrawKeyboard(gfx, keyboard, line++); + DrawMouse(gfx, mouse, line++); } }