summaryrefslogtreecommitdiff
path: root/WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs
diff options
context:
space:
mode:
Diffstat (limited to 'WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs')
-rw-r--r--WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs35
1 files changed, 31 insertions, 4 deletions
diff --git a/WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs b/WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs
index e5af385..95e4a68 100644
--- a/WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs
+++ b/WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs
@@ -23,6 +23,8 @@ namespace KeyboardTest
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D keyboardImage;
+ List<string> output = new List<string>() {"Hello World"};
+ SpriteFont font;
public enum KeySymbol
{
@@ -43,7 +45,10 @@ namespace KeyboardTest
public Game1()
{
graphics = new GraphicsDeviceManager(this);
- graphics.SupportedOrientations = DisplayOrientation.Portrait;
+ graphics.PreferredBackBufferWidth = 480;
+ graphics.PreferredBackBufferHeight = 800;
+
+ //graphics.SupportedOrientations = DisplayOrientation.Portrait;
Content.RootDirectory = "Content";
@@ -77,6 +82,7 @@ namespace KeyboardTest
spriteBatch = new SpriteBatch(GraphicsDevice);
keyboardImage = Content.Load<Texture2D>("keyboard");
+ font = Content.Load<SpriteFont>("Courier New");
KeyboardDefinition def;
@@ -85,7 +91,9 @@ namespace KeyboardTest
def = KeyboardDefinition.Load(stream);
}
- keyboard = new KeyboardDriver<KeySymbol>(keyboardImage, Vector2.Zero, def);
+ keyboard = new KeyboardDriver<KeySymbol>(graphics.GraphicsDevice, keyboardImage, Vector2.Zero, def);
+
+ keyboard.KeyEvent += KeyPress;
}
/// <summary>
@@ -105,7 +113,7 @@ namespace KeyboardTest
protected override void Update(GameTime gameTime)
{
// TODO: Add your update logic here
-
+ keyboard.Update();
base.Update(gameTime);
}
@@ -115,10 +123,29 @@ namespace KeyboardTest
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
- graphics.GraphicsDevice.Clear(Color.PaleVioletRed);
+ graphics.GraphicsDevice.Clear(Color.MidnightBlue);
spriteBatch.Begin();
keyboard.Draw(spriteBatch);
+
+ Vector2 pos = new Vector2(0, 200);
+
+ foreach(string s in output)
+ {
+ spriteBatch.DrawString(font, s, pos, Color.White);
+ pos.Y += 30;
+ }
+
spriteBatch.End();
}
+
+ private void KeyPress(object sender, KeyboardDriver<KeySymbol>.KeyPress e)
+ {
+ if (output.Count > 15)
+ {
+ output.RemoveAt(0);
+ }
+
+ output.Add(String.Format("{0} - {1}", e.Key.ToString(), e.Pressed.ToString()));
+ }
}
}