diff options
-rw-r--r-- | WindowsPhone/KeyboardTest.suo | bin | 44544 -> 48128 bytes | |||
-rw-r--r-- | WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs | 19 | ||||
-rw-r--r-- | src/Noddybox.Emulation.Xna.Keyboard/KeyboardDriver.cs | 76 |
3 files changed, 71 insertions, 24 deletions
diff --git a/WindowsPhone/KeyboardTest.suo b/WindowsPhone/KeyboardTest.suo Binary files differindex 585204c..3e2bd4d 100644 --- a/WindowsPhone/KeyboardTest.suo +++ b/WindowsPhone/KeyboardTest.suo diff --git a/WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs b/WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs index 95e4a68..882ef72 100644 --- a/WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs +++ b/WindowsPhone/KeyboardTest/KeyboardTest/Game1.cs @@ -94,6 +94,7 @@ namespace KeyboardTest keyboard = new KeyboardDriver<KeySymbol>(graphics.GraphicsDevice, keyboardImage, Vector2.Zero, def);
keyboard.KeyEvent += KeyPress;
+ keyboard.TouchEvent += Touch;
}
/// <summary>
@@ -131,21 +132,31 @@ namespace KeyboardTest foreach(string s in output)
{
- spriteBatch.DrawString(font, s, pos, Color.White);
- pos.Y += 30;
+ spriteBatch.DrawString(font, s, pos, Color.White, 0f, Vector2.Zero, 0.5f, SpriteEffects.None, 1f);
+ pos.Y += 15;
}
spriteBatch.End();
}
- private void KeyPress(object sender, KeyboardDriver<KeySymbol>.KeyPress e)
+ private void KeyPress(object sender, KeyboardDriver<KeySymbol>.KeyPressEventArgs e)
{
- if (output.Count > 15)
+ if (output.Count > 35)
{
output.RemoveAt(0);
}
output.Add(String.Format("{0} - {1}", e.Key.ToString(), e.Pressed.ToString()));
}
+
+ private void Touch(object sender, KeyboardDriver<KeySymbol>.TouchLocationEventArgs e)
+ {
+ if (output.Count > 35)
+ {
+ output.RemoveAt(0);
+ }
+
+ output.Add(String.Format("{0} - {1} {2}", e.Location.Id, e.Location.Position, e.Location.State));
+ }
}
}
diff --git a/src/Noddybox.Emulation.Xna.Keyboard/KeyboardDriver.cs b/src/Noddybox.Emulation.Xna.Keyboard/KeyboardDriver.cs index b0671b8..1b6f61c 100644 --- a/src/Noddybox.Emulation.Xna.Keyboard/KeyboardDriver.cs +++ b/src/Noddybox.Emulation.Xna.Keyboard/KeyboardDriver.cs @@ -37,7 +37,7 @@ namespace Noddybox.Emulation.Xna.Keyboard /// <summary>
/// Event data when a key is pressed or released.
/// </summary>
- public class KeyPress : EventArgs
+ public class KeyPressEventArgs : EventArgs
{
/// <summary>
/// The key that was pressed.
@@ -50,6 +50,17 @@ namespace Noddybox.Emulation.Xna.Keyboard public bool Pressed {get; set;}
}
+ /// <summary>
+ /// Event data when the screen is touched away from a key.
+ /// </summary>
+ public class TouchLocationEventArgs : EventArgs
+ {
+ /// <summary>
+ /// The touch.
+ /// </summary>
+ public TouchLocation Location {get; set;}
+ }
+
#endregion
#region Private data
@@ -59,6 +70,7 @@ namespace Noddybox.Emulation.Xna.Keyboard public T Symbol {get;set;}
public bool IsPressed {get; set;}
public bool IsSticky {get; set;}
+ public int TouchId {get; set;}
}
private Rectangle[] keymapPos;
@@ -73,14 +85,6 @@ namespace Noddybox.Emulation.Xna.Keyboard #region Private members
- private void RaiseKeyChange(KeyState state)
- {
- if (KeyEvent != null)
- {
- KeyEvent(this, new KeyPress() {Key = state.Symbol, Pressed = state.IsPressed});
- }
- }
-
#endregion
#region Public members
@@ -97,18 +101,21 @@ namespace Noddybox.Emulation.Xna.Keyboard int f = 0;
KeyState key = null;
- for(f = 0; f < keymapSize && key == null; f++)
+
+ if (t.State == TouchLocationState.Pressed)
{
- if (keymapPos[f].Contains(x, y))
+ for(f = 0; f < keymapSize && key == null; f++)
{
- key = keymapState[f];
+ if (keymapPos[f].Contains(x, y))
+ {
+ key = keymapState[f];
+ }
}
- }
- if (key != null)
- {
- if (t.State == TouchLocationState.Pressed)
+ if (key != null)
{
+ key.TouchId = t.Id;
+
if (key.IsSticky)
{
key.IsPressed = !key.IsPressed;
@@ -118,17 +125,45 @@ namespace Noddybox.Emulation.Xna.Keyboard key.IsPressed = true;
}
- RaiseKeyChange(key);
+ if (KeyEvent != null)
+ {
+ KeyEvent(this, new KeyPressEventArgs() {Key = key.Symbol, Pressed = key.IsPressed});
+ }
+ }
+ }
+ else if (t.State == TouchLocationState.Released)
+ {
+ for(f = 0; f < keymapSize && key == null; f++)
+ {
+ if (keymapState[f].TouchId == t.Id)
+ {
+ key = keymapState[f];
+ }
}
- else if (t.State == TouchLocationState.Released)
+
+ if (key != null)
{
if (!key.IsSticky)
{
key.IsPressed = false;
- RaiseKeyChange(key);
+
+ if (KeyEvent != null)
+ {
+ KeyEvent(this, new KeyPressEventArgs() {Key = key.Symbol, Pressed = key.IsPressed});
+ }
}
}
}
+
+ // If no key handled, pass on the event
+ //
+ if (key == null && keymapState.Where(r => r.TouchId == t.Id).Count() == 0)
+ {
+ if (TouchEvent != null)
+ {
+ TouchEvent(this, new TouchLocationEventArgs() {Location = t});
+ }
+ }
}
}
@@ -153,7 +188,8 @@ namespace Noddybox.Emulation.Xna.Keyboard #region Events
- public EventHandler<KeyPress> KeyEvent;
+ public EventHandler<KeyPressEventArgs> KeyEvent;
+ public EventHandler<TouchLocationEventArgs> TouchEvent;
#endregion
|