1using Microsoft.Xna.Framework;
2using Microsoft.Xna.Framework.Graphics;
3using Microsoft.Xna.Framework.Input;
5using System.Collections.Generic;
8using System.Threading.Tasks;
9using XnaGame = Microsoft.Xna.Framework.Game;
12using XnaMouse = Microsoft.Xna.Framework.Input.Mouse;
15using Microsoft.Xna.Framework.Input.Touch;
32 new VirtualKeyInfo[] {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0",
new VirtualKeyInfo(
"<=",
"", 1.0,
VirtualKeyType.Backspace)},
33 new VirtualKeyInfo[] {
"Q",
"W",
"E",
"R",
"T",
"Y",
"U",
"I",
"O",
"P",
"Å"},
34 new VirtualKeyInfo[] {
"A",
"S",
"D",
"F",
"G",
"H",
"J",
"K",
"L",
"Ö",
"Ä"},
35 new VirtualKeyInfo[] {
"Z",
"X",
"C",
"V",
"B",
"N",
"M",
".",
",",
"-",
"*"},
41 this.
game = jypeliGame;
44 public event EventHandler<VirtualKeyboardInputEventArgs>
InputEntered;
51 private List<VirtualKey>
keys;
66 keys =
new List<VirtualKey>();
74 int baseKeyWidth = (
Width -
KEY_PADDING * (1 + highestKeyCount)) / highestKeyCount;
78 for (
int y = 0; y <
keyLines.Length; y++)
83 for (
int x = 0; x <
keyLines[y].Length; x++)
88 xCoord, yCoord, (
int)(baseKeyWidth * keyInfo.
WidthMultiplier), keyHeight,
90 xCoord += virtualKey.Width;
103 int highestKeyCount =
int.MinValue;
107 if (highestKeyCount < line.Length)
108 highestKeyCount = line.Length;
111 return highestKeyCount;
155 public override void Update(GameTime gameTime)
157 bool checkForKeyPress;
168 checkForKeyPress = touchCollection.Count > 0 && touchCollection[0].State == TouchLocationState.Released;
170 Vector2 touchPos = touchCollection.Count > 0 ? touchCollection[0].Position :
Vector2.Zero;
175 if (checkForKeyPress)
178 if (mouseState.Y >
Y + key.
Y && mouseState.Y <
Y + key.
Y + key.
Height &&
179 mouseState.X >
X + key.
X && mouseState.X <
X + key.
X + key.
Width)
182 checkForKeyPress =
false;
187 if (touchPos.Y >
Y + key.
Y && touchPos.Y <
Y + key.
Y + key.
Height &&
188 touchPos.X >
X + key.
X && touchPos.X <
X + key.
X + key.
Width)
191 checkForKeyPress =
false;
203 base.Update(gameTime);
206 public override void Draw(GameTime gameTime)
208 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied,
209 null,
null,
null,
null,
null);
240 int x,
int y,
int width,
int height,
Font font,
VirtualKeyType type) : this(game, text)
259 public string Value {
get;
private set; }
264 public string UIText {
get;
private set; }
266 public int X {
get;
set; }
267 public int Y {
get;
set; }
307 public void Draw(Texture2D whitePixelTexture, SpriteBatch sb,
int xOffset,
int yOffset)
324 sb.Draw(whitePixelTexture, rect, color);
329 Texture2D texture =
new Texture2D(gd, width, height,
false, SurfaceFormat.Color);
331 Color[] colorArray =
new Color[width * height];
333 for (
int i = 0; i < colorArray.Length; i++)
334 colorArray[i] = color;
336 texture.SetData(colorArray);
344 font.DrawText(
Graphics.
FontRenderer, text, location.ToSystemNumerics(), color.ToSystemDrawing());
349 sb.Draw(whitePixelTexture,
new XnaRectangle(rect.X, rect.Y, rect.Width, thickness), color);
350 sb.Draw(whitePixelTexture,
new XnaRectangle(rect.X, rect.Y + thickness, thickness, rect.Height - thickness), color);
351 sb.Draw(whitePixelTexture,
new XnaRectangle(rect.X + rect.Width - thickness, rect.Y, thickness, rect.Height), color);
352 sb.Draw(whitePixelTexture,
new XnaRectangle(rect.X, rect.Y + rect.Height - thickness, rect.Width, thickness), color);
405 public string Value {
get;
private set; }
422 public string Text {
get;
private set; }
System.Numerics.Vector2 Vector2
Microsoft.Xna.Framework.Game XnaGame
Microsoft.Xna.Framework.Rectangle XnaRectangle
Microsoft.Xna.Framework.Color XnaColor
Microsoft.Xna.Framework.Input.Mouse XnaMouse
Microsoft.Xna.Framework.Input.ButtonState XnaButtonState
Microsoft.Xna.Framework.Input.Touch.TouchPanel XnaTouchPanel
Yksittäinen näppäin virtuaalisessa näppäimistössä.
static XnaColor backgroundColorIdle
const float HIGHLIGHT_TIME_ON_PRESS
string Value
Teksti, joka syötetään näppäintä painettaessa.
VirtualKeyType Type
Näppäimen tyyppi.
void Update(GameTime gameTime)
Päivittää näppäimen tilaa.
VirtualKey(XnaGame game, string text)
string UIText
Käyttöliittymässä näppäimen kohdalla näytetty teksti.
static XnaColor textColorIdle
VirtualKey(XnaGame game, string text, string value, int x, int y, int width, int height, Font font, VirtualKeyType type)
static XnaColor backgroundColorPressed
void Draw(Texture2D whitePixelTexture, SpriteBatch sb, int xOffset, int yOffset)
Piirtää näppäimen.
void Pressed()
Kutsutaan, kun näppäintä on painettu.
static XnaColor textColorPressed
Virtuaalinen näppäimistö. Tarkoitettu ensisijaisesti mobiilialustoille, joiden oman virtuaalinäppäimi...
static readonly VirtualKeyInfo[][] keyLines
MouseState prevMouseState
EventHandler< VirtualKeyboardInputEventArgs > InputEntered
override void Draw(GameTime gameTime)
override void Update(GameTime gameTime)
void Show()
Avaa virtuaalisen näppäimistön.
void Hide()
Piilottaa virtuaalisen näppäimistön.
Texture2D whitePixelTexture
override void Initialize()
VirtualKeyboard(Game jypeliGame)
EventHandler BackspacePressed
void HandleKeyPress(VirtualKey key)
Käsittelee näppäimen painalluksen.
EventHandler EnterPressed
int GetKeyCountOnSingleLine()
Sisältää näppäimistön piitämiseen käytettyjä metodeja.
static Texture2D CreateTexture(GraphicsDevice gd, Color color, int width, int height)
static void FillRectangle(Texture2D whitePixelTexture, SpriteBatch sb, XnaRectangle rect, XnaColor color)
static void DrawRectangle(Texture2D whitePixelTexture, SpriteBatch sb, XnaRectangle rect, int thickness, XnaColor color)
static void DrawStringWithShadow(SpriteBatch sb, string text, DynamicSpriteFont font, Vector2 location, XnaColor color)
DynamicSpriteFont XnaFont
static new GraphicsDevice GraphicsDevice
XNA:n grafiikkakortti.
Contains graphics resources.
static FontStashSharp.Renderer FontRenderer
VirtualKeyType
Näppäimen tyyppi.
@ Normal
Näppäin syöttää tekstiä kuin "tavallinen" näppäin.
@ Backspace
Näppäin toimii Backspace-painikkeena.
Microsoft.Xna.Framework.Input.Touch.TouchPanel XnaTouchPanel
Microsoft.Xna.Framework.Input.MouseState MouseState
@ Enter
Siirtymässä olion päälle.
Microsoft.Xna.Framework.Input.ButtonState XnaButtonState
Microsoft.Xna.Framework.Input.Mouse XnaMouse
static readonly Color White
Valkoinen.
Tietue, joka sisältää olennaiset tiedot näppäimestä sen luontia varten.
VirtualKeyInfo(string displayString, string value, double widthMultiplier=1.0, VirtualKeyType keyType=VirtualKeyType.Normal)