/// <summary> /// Piirtää näppäimen. /// </summary> public void Draw(Texture2D whitePixelTexture, SpriteBatch sb, int xOffset, int yOffset) { var drawRectangle = new XnaRectangle(xOffset + X, yOffset + Y, Width, Height); XnaRenderer.FillRectangle(whitePixelTexture, sb, drawRectangle, backgroundColor); XnaRenderer.DrawRectangle(whitePixelTexture, sb, drawRectangle, 2, new XnaColor(196, 196, 196, 255)); XnaRenderer.DrawStringWithShadow(sb, UIText, Font.XnaFont, new Vector2(xOffset + X + VirtualKeyboard.KEY_PADDING, yOffset + Y + VirtualKeyboard.KEY_PADDING), textColor); }
public override void Draw(GameTime gameTime) { spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, null); XnaRenderer.FillRectangle(whitePixelTexture, spriteBatch, new XnaRectangle(X, Y, Width, Height), XnaColor.White); foreach (VirtualKey key in keys) { key.Draw(whitePixelTexture, spriteBatch, X, Y); } spriteBatch.End(); base.Draw(gameTime); }
public override void Initialize() { base.Initialize(); keys = new List <VirtualKey>(); Width = Game.GraphicsDevice.Viewport.Width; Height = Game.GraphicsDevice.Viewport.Height / 2; Y = Game.GraphicsDevice.Viewport.Height - Height; int highestKeyCount = GetKeyCountOnSingleLine(); int baseKeyWidth = (Width - KEY_PADDING * (1 + highestKeyCount)) / highestKeyCount; int keyHeight = ((Height - KEY_PADDING) / keyLines.Length) - KEY_PADDING; // Create keys for (int y = 0; y < keyLines.Length; y++) { int yCoord = KEY_PADDING + y * (keyHeight + KEY_PADDING); int xCoord = KEY_PADDING; for (int x = 0; x < keyLines[y].Length; x++) { VirtualKeyInfo keyInfo = keyLines[y][x]; var virtualKey = new VirtualKey(game, keyInfo.DisplayString, keyInfo.Value, xCoord, yCoord, (int)(baseKeyWidth * keyInfo.WidthMultiplier), keyHeight, new Font(60), keyInfo.KeyType); xCoord += virtualKey.Width; xCoord += KEY_PADDING; keys.Add(virtualKey); } } spriteBatch = new SpriteBatch(GraphicsDevice); whitePixelTexture = XnaRenderer.CreateTexture(GraphicsDevice, Color.White, 1, 1); }