diff options
author | Ian C <ianc@noddybox.co.uk> | 2012-05-01 22:30:05 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2012-05-01 22:30:05 +0000 |
commit | 78adb7aa6ccd4bfe8924d08ac655b325f32d7562 (patch) | |
tree | 09e0fc9e31e94085f963a2b48476805879f330e3 /WindowsPhone | |
parent | e0df170a198f6b875fbbe37a7fa8a3c5fdf3aa5c (diff) |
Working version of the XNA keyboard.
Diffstat (limited to 'WindowsPhone')
-rw-r--r-- | WindowsPhone/KeyboardTest.suo | bin | 46592 -> 44544 bytes | |||
-rw-r--r-- | WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs | 35 | ||||
-rw-r--r-- | WindowsPhone/KeyboardTest/KeyboardTest/Spectrum.keyboard | bin | 235 -> 235 bytes | |||
-rw-r--r-- | WindowsPhone/KeyboardTest/KeyboardTestContent/Courier New.spritefont | 52 | ||||
-rw-r--r-- | WindowsPhone/KeyboardTest/KeyboardTestContent/KeyboardTestContent.contentproj | 7 |
5 files changed, 90 insertions, 4 deletions
diff --git a/WindowsPhone/KeyboardTest.suo b/WindowsPhone/KeyboardTest.suo Binary files differindex 9205510..585204c 100644 --- a/WindowsPhone/KeyboardTest.suo +++ b/WindowsPhone/KeyboardTest.suo 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()));
+ }
}
}
diff --git a/WindowsPhone/KeyboardTest/KeyboardTest/Spectrum.keyboard b/WindowsPhone/KeyboardTest/KeyboardTest/Spectrum.keyboard Binary files differindex 2607d6c..c0574cf 100644 --- a/WindowsPhone/KeyboardTest/KeyboardTest/Spectrum.keyboard +++ b/WindowsPhone/KeyboardTest/KeyboardTest/Spectrum.keyboard 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 @@ +<?xml version="1.0" encoding="utf-8"?>
+<!--
+This file contains an xml description of a font, and will be read by the XNA
+Framework Content Pipeline. Follow the comments to customize the appearance
+of the font in your game, and to change the characters which are available to draw
+with.
+-->
+<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
+ <Asset Type="Graphics:FontDescription">
+
+ <!--
+ Modify this string to change the font that will be imported.
+ -->
+ <FontName>Courier New</FontName>
+
+ <!--
+ Size is a float value, measured in points. Modify this value to change
+ the size of the font.
+ -->
+ <Size>28</Size>
+
+ <!--
+ Spacing is a float value, measured in pixels. Modify this value to change
+ the amount of spacing in between characters.
+ -->
+ <Spacing>2</Spacing>
+
+ <!--
+ Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
+ and "Bold, Italic", and are case sensitive.
+ -->
+ <Style>Regular</Style>
+
+ <!--
+ CharacterRegions control what letters are available in the font. Every
+ character from Start to End will be built and made available for drawing. The
+ default range is from 32 to 127, which is the basic Latin character set. The
+ characters are ordered according to the Unicode standard.
+ Change these regions to make more or fewer letters available. To save
+ graphics memory and decrease build time, try to use as few letters as possible.
+ You can specify additional regions by adding more <CharacterRegion> tags.
+ Alternatively, you can use a custom processor to add specific characters. See
+ the documentation for more information.
+ -->
+ <CharacterRegions>
+ <CharacterRegion>
+ <Start> </Start>
+ <End>~</End>
+ </CharacterRegion>
+ </CharacterRegions>
+ </Asset>
+</XnaContent>
\ 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 @@ <Processor>TextureProcessor</Processor>
</Compile>
</ItemGroup>
+ <ItemGroup>
+ <Compile Include="Courier New.spritefont">
+ <Name>Courier New</Name>
+ <Importer>FontDescriptionImporter</Importer>
+ <Processor>FontDescriptionProcessor</Processor>
+ </Compile>
+ </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
|