5 using System.Collections.Generic;
8 using System.Threading.Tasks;
31 new VirtualKeyInfo[] {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0",
new VirtualKeyInfo(
"<=",
"", 1.0,
VirtualKeyType.Backspace)},
32 new VirtualKeyInfo[] {
"Q",
"W",
"E",
"R",
"T",
"Y",
"U",
"I",
"O",
"P",
"Å"},
33 new VirtualKeyInfo[] {
"A",
"S",
"D",
"F",
"G",
"H",
"J",
"K",
"L",
"Ö",
"Ä"},
34 new VirtualKeyInfo[] {
"Z",
"X",
"C",
"V",
"B",
"N",
"M",
".",
",",
"-",
"*"},
40 this.
game = jypeliGame;
43 public event EventHandler<VirtualKeyboardInputEventArgs>
InputEntered;
50 private List<VirtualKey>
keys;
65 keys =
new List<VirtualKey>();
73 int baseKeyWidth = (
Width -
KEY_PADDING * (1 + highestKeyCount)) / highestKeyCount;
77 for (
int y = 0; y <
keyLines.Length; y++)
82 for (
int x = 0; x <
keyLines[y].Length; x++)
87 xCoord, yCoord, (
int)(baseKeyWidth * keyInfo.
WidthMultiplier), keyHeight,
89 xCoord += virtualKey.Width;
102 int highestKeyCount =
int.MinValue;
106 if (highestKeyCount < line.Length)
107 highestKeyCount = line.Length;
110 return highestKeyCount;
154 public override void Update(GameTime gameTime)
156 bool checkForKeyPress;
167 checkForKeyPress = touchCollection.Count > 0 && touchCollection[0].State == TouchLocationState.Released;
169 Vector2 touchPos = touchCollection.Count > 0 ? touchCollection[0].Position : Vector2.Zero;
174 if (checkForKeyPress)
177 if (mouseState.Y >
Y + key.
Y && mouseState.Y <
Y + key.
Y + key.
Height &&
178 mouseState.X >
X + key.
X && mouseState.X <
X + key.
X + key.
Width)
181 checkForKeyPress =
false;
186 if (touchPos.Y >
Y + key.
Y && touchPos.Y <
Y + key.
Y + key.
Height &&
187 touchPos.X >
X + key.
X && touchPos.X <
X + key.
X + key.
Width)
190 checkForKeyPress =
false;
202 base.Update(gameTime);
205 public override void Draw(GameTime gameTime)
207 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied,
208 null,
null,
null,
null,
null);
239 int x,
int y,
int width,
int height,
Font font,
VirtualKeyType type) : this(game, text)
258 public string Value {
get;
private set; }
263 public string UIText {
get;
private set; }
265 public int X {
get;
set; }
266 public int Y {
get;
set; }
306 public void Draw(Texture2D whitePixelTexture, SpriteBatch sb,
int xOffset,
int yOffset)
323 sb.Draw(whitePixelTexture, rect, color);
328 Texture2D texture =
new Texture2D(gd, width, height,
false, SurfaceFormat.Color);
330 Color[] colorArray =
new Color[width * height];
332 for (
int i = 0; i < colorArray.Length; i++)
333 colorArray[i] = color;
335 texture.SetData(colorArray);
342 sb.DrawString(font, text,
new Vector2(location.X + 1f, location.Y + 1f),
XnaColor.Black);
343 sb.DrawString(font, text, location, color);
348 sb.Draw(whitePixelTexture,
new XnaRectangle(rect.X, rect.Y, rect.Width, thickness), color);
349 sb.Draw(whitePixelTexture,
new XnaRectangle(rect.X, rect.Y + thickness, thickness, rect.Height - thickness), color);
350 sb.Draw(whitePixelTexture,
new XnaRectangle(rect.X + rect.Width - thickness, rect.Y, thickness, rect.Height), color);
351 sb.Draw(whitePixelTexture,
new XnaRectangle(rect.X, rect.Y + rect.Height - thickness, rect.Width, thickness), color);
404 public string Value {
get;
private set; }
421 public string Text {
get;
private set; }