public void Draw(SpriteBatch batch) { var currentPos = Pos; foreach (var item in _items) { currentPos = currentPos.Offset(item.Margin.Left, item.Margin.Top); batch.DrawBitmapFont(_font, currentPos, item.Text, GetItemColor(item)); currentPos = currentPos.Offset(0f, _font.Data.LineHeight + Padding + item.Margin.Bottom); } }
protected override void OnDraw(SpriteBatch batch) { GraphicsDevice.Clear(AppColors.WindowBackground); batch.Begin(); if (_highscore.Items.Length > 0) { var posY = 100; for (int i = 0; i < MathI.Min(_highscore.Items.Length, AppConstants.TopHighscorePlaces); i++) { var item = _highscore.Items[i]; var scoreText = item.Score.ToString("n0"); var scoreSize = AppContents.DefaultFont.MeasureString(scoreText); batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(100, posY), (1 + i).ToString(), AppColors.Descriptions); batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(160, posY), item.User, AppColors.Texts); batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(GraphicsDevice.Viewport.Width - scoreSize.X - 100, posY), scoreText, AppColors.Texts); posY += AppContents.DefaultFont.Data.LineHeight; } } else { batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(100, 100), "Empty", AppColors.Texts); } batch.End(); }
protected override void OnDraw(SpriteBatch batch) { GraphicsDevice.Clear(AppColors.WindowBackground); batch.Begin(); var size = AppContents.DefaultFont.MeasureString("Game Over"); var pos = new Vector2( GraphicsDevice.Viewport.Width / 2 - size.X / 2, GraphicsDevice.Viewport.Height / 2 - size.Y / 2); batch.DrawBitmapFont(AppContents.DefaultFont, pos, "Game Over"); batch.End(); }
protected override void OnDraw(SpriteBatch batch) { if (AutoSize) { batch.DrawBitmapFont(Manager.Skin.DefaultFont, Pos, _text, color: IsHovered ? ColorHovered : Color); } else { float x, y; switch (TextAlignment) { case TextAlignment.TopLeft: x = Pos.X; y = Pos.Y; break; case TextAlignment.TopCenter: x = Pos.X + Width / 2 - _textSize.X / 2; y = Pos.Y; break; case TextAlignment.TopRight: x = Pos.X + Width - _textSize.X; y = Pos.Y; break; case TextAlignment.Left: x = Pos.X; y = Pos.Y + Height / 2 - _textSize.Y / 2; break; case TextAlignment.Center: x = Pos.X + Width / 2 - _textSize.X / 2; y = Pos.Y + Height / 2 - _textSize.Y / 2; break; case TextAlignment.Right: x = Pos.X + Width - _textSize.X; y = Pos.Y + Height / 2 - _textSize.Y / 2; break; case TextAlignment.BottomLeft: x = Pos.X; y = Pos.Y + Height - _textSize.Y; break; case TextAlignment.BottomCenter: x = Pos.X + Width / 2 - _textSize.X / 2; y = Pos.Y + Height - _textSize.Y; break; case TextAlignment.BottomRight: x = Pos.X + Width - _textSize.X; y = Pos.Y + Height - _textSize.Y; break; default: throw new NotImplementedException(); } batch.DrawBitmapFont(Manager.Skin.DefaultFont, new Vector2(x, y), _text, color: IsHovered ? ColorHovered : Color); } }
protected override void OnDraw(SpriteBatch batch) { GraphicsDevice.Clear(AppColors.WindowBackground); batch.Begin(SpriteSortMode.FrontToBack); // grid GridRenderer.Draw(batch, new Vector2(AppConstants.GridX, AppConstants.GridY)); batch.End(); batch.Begin(); var y = AppConstants.GridY + 10; // time batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.GridRight, y), "Time:", AppColors.Descriptions); batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.WindowWidth - AppConstants.ScreenPadding - 140, y), TimeSpan.FromSeconds(Session.Time).ToString(@"hh\:mm\:ss"), AppColors.Texts); y += AppContents.DefaultFont.Data.LineHeight + 15; // score batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.GridRight, y), $"Score:", AppColors.Descriptions); batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.WindowWidth - AppConstants.ScreenPadding - 140, y), Session.Score.ToString("n0"), AppColors.Texts); y += AppContents.DefaultFont.Data.LineHeight + 15; batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.GridRight, y), $"Atoms:", AppColors.Descriptions); batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.WindowWidth - AppConstants.ScreenPadding - 140, y), Session.Atoms.ToString("n0"), AppColors.Texts); y += AppContents.DefaultFont.Data.LineHeight + 5; batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.GridRight, y), $"Molecules:", AppColors.Descriptions); batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.WindowWidth - AppConstants.ScreenPadding - 140, y), Session.Molecules.ToString("n0"), AppColors.Texts); y += AppContents.DefaultFont.Data.LineHeight + 5; // current/next atom y = AppConstants.WindowHeight - AppConstants.ScreenPadding - AppConstants.PreviewBoxHeight - AppContents.DefaultFont.Data.LineHeight - 8; batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.GridRight, y), "Current", AppColors.Descriptions); batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.GridRight + AppConstants.PreviewBoxWidth + AppConstants.PreviewBoxPadding, y), "Next", AppColors.Descriptions); y += AppContents.DefaultFont.Data.LineHeight + 8; batch.DrawRect(new Rectangle(AppConstants.GridRight, y, AppConstants.PreviewBoxWidth, AppConstants.PreviewBoxHeight), 1, AppColors.PreviewBorder); batch.DrawRect(new Rectangle(AppConstants.GridRight + AppConstants.PreviewBoxWidth + AppConstants.PreviewBoxPadding, y, AppConstants.PreviewBoxWidth, AppConstants.PreviewBoxHeight), 1, AppColors.PreviewBorder); if (Session.CurrentAtom != null) { Session.CurrentAtom.Draw(batch, pos: new Vector2( AppConstants.GridRight + AppConstants.PreviewBoxWidth / 2, y + AppConstants.PreviewBoxHeight / 2), layerDepth: LayerDepth.Default); } if (Session.NextAtom != null) { Session.NextAtom.Draw(batch, pos: new Vector2( AppConstants.GridRight + AppConstants.PreviewBoxWidth + AppConstants.PreviewBoxPadding + AppConstants.PreviewBoxWidth / 2, y + AppConstants.PreviewBoxHeight / 2), layerDepth: LayerDepth.Default); } // atom grid preview if (Session.CurrentAtom != null && IsMouseOverGrid() && IsOnTop) { var gridPos = GetMouseGridPos(); if (Grid.IsValidPos(gridPos.X, gridPos.Y) && !Grid.HasAtom(gridPos.X, gridPos.Y)) { if (Grid.CanSet(gridPos.X, gridPos.Y, Session.CurrentAtom)) { Session.CurrentAtom.Draw(batch, new Vector2( AppConstants.GridX + gridPos.X * Grid.TileSize + Grid.TileSize / 2, AppConstants.GridY + gridPos.Y * Grid.TileSize + Grid.TileSize / 2), LayerDepth.Default, AppColors.AtomValidPos); } else { Session.CurrentAtom.Draw(batch, new Vector2( AppConstants.GridX + gridPos.X * Grid.TileSize + Grid.TileSize / 2, AppConstants.GridY + gridPos.Y * Grid.TileSize + Grid.TileSize / 2), LayerDepth.Default, AppColors.AtomInvalidPos); } } } batch.End(); }