From 78adb7aa6ccd4bfe8924d08ac655b325f32d7562 Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 1 May 2012 22:30:05 +0000 Subject: Working version of the XNA keyboard. --- Native/EmuKeyboardDesigner/EmuKeyboardDesigner.suo | Bin 50176 -> 50176 bytes WindowsPhone/KeyboardTest.suo | Bin 46592 -> 44544 bytes WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs | 35 +++- .../KeyboardTest/KeyboardTest/Spectrum.keyboard | Bin 235 -> 235 bytes .../KeyboardTestContent/Courier New.spritefont | 52 ++++++ .../KeyboardTestContent.contentproj | 7 + .../KeyboardDriver.cs | 200 +++++++++++++++++++++ 7 files changed, 290 insertions(+), 4 deletions(-) create mode 100644 WindowsPhone/KeyboardTest/KeyboardTestContent/Courier New.spritefont create mode 100644 src/Noddybox.Emulation.Xna.Keyboard/KeyboardDriver.cs diff --git a/Native/EmuKeyboardDesigner/EmuKeyboardDesigner.suo b/Native/EmuKeyboardDesigner/EmuKeyboardDesigner.suo index db01de5..6a93ec2 100644 Binary files a/Native/EmuKeyboardDesigner/EmuKeyboardDesigner.suo and b/Native/EmuKeyboardDesigner/EmuKeyboardDesigner.suo differ diff --git a/WindowsPhone/KeyboardTest.suo b/WindowsPhone/KeyboardTest.suo index 9205510..585204c 100644 Binary files a/WindowsPhone/KeyboardTest.suo and b/WindowsPhone/KeyboardTest.suo differ 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 output = new List() {"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("keyboard"); + font = Content.Load("Courier New"); KeyboardDefinition def; @@ -85,7 +91,9 @@ namespace KeyboardTest def = KeyboardDefinition.Load(stream); } - keyboard = new KeyboardDriver(keyboardImage, Vector2.Zero, def); + keyboard = new KeyboardDriver(graphics.GraphicsDevice, keyboardImage, Vector2.Zero, def); + + keyboard.KeyEvent += KeyPress; } /// @@ -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 /// Provides a snapshot of timing values. 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.KeyPress e) + { + if (output.Count > 15) + { + output.RemoveAt(0); + } + + output.Add(String.Format("{0} - {1}", e.Key.ToString(), e.Pressed.ToString())); + } } } diff --git a/WindowsPhone/KeyboardTest/KeyboardTest/Spectrum.keyboard b/WindowsPhone/KeyboardTest/KeyboardTest/Spectrum.keyboard index 2607d6c..c0574cf 100644 Binary files a/WindowsPhone/KeyboardTest/KeyboardTest/Spectrum.keyboard and b/WindowsPhone/KeyboardTest/KeyboardTest/Spectrum.keyboard differ diff --git a/WindowsPhone/KeyboardTest/KeyboardTestContent/Courier New.spritefont b/WindowsPhone/KeyboardTest/KeyboardTestContent/Courier New.spritefont new file mode 100644 index 0000000..ebefa68 --- /dev/null +++ b/WindowsPhone/KeyboardTest/KeyboardTestContent/Courier New.spritefont @@ -0,0 +1,52 @@ + + + + + + + Courier New + + + 28 + + + 2 + + + + + + + + + ~ + + + + \ No newline at end of file diff --git a/WindowsPhone/KeyboardTest/KeyboardTestContent/KeyboardTestContent.contentproj b/WindowsPhone/KeyboardTest/KeyboardTestContent/KeyboardTestContent.contentproj index 3ed205e..390995e 100644 --- a/WindowsPhone/KeyboardTest/KeyboardTestContent/KeyboardTestContent.contentproj +++ b/WindowsPhone/KeyboardTest/KeyboardTestContent/KeyboardTestContent.contentproj @@ -36,6 +36,13 @@ TextureProcessor + + + Courier New + FontDescriptionImporter + FontDescriptionProcessor + +