public void Write(string text, SpriteFont font, Rect bounds, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Color color, float scale) { // get text coords Vector2 size = font.MeasureString(text); var pos = new Vector2(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2); var origin = size * 0.5f; //origin.Y -= origin.Y/4; if (horizontalAlignment == HorizontalAlignment.Left) origin.X += bounds.Width / 2 - size.X / 2; else if (horizontalAlignment == HorizontalAlignment.Right) origin.X -= bounds.Width / 2 - size.X / 2; if (verticalAlignment == VerticalAlignment.Top) origin.Y += bounds.Height / 2 - size.Y / 2; else if (verticalAlignment == VerticalAlignment.Bottom) origin.Y -= bounds.Height / 2 - size.Y / 2; // draw StartSpriteBatch(); if (DrawMode == DrawMode.Screen) { _spriteBatch.DrawString(font, text, pos, color, 0, origin, scale, SpriteEffects.None, 0); } else { _spriteBatch.DrawString(font, text, Render.Camera.ConvertWorldToScreen(pos), color, 0, origin, scale * Render.Camera.Zoom, SpriteEffects.None, 0); } }
public void Write(string text, SpriteFont font, Rect bounds, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Color color) { Write(text, font, bounds, horizontalAlignment, verticalAlignment, color, 1); }
public void DrawRectangle(Rect rectangle, bool solid, Color color) { DrawRectangle(new Vector2(rectangle.X, rectangle.Y), rectangle.Width, rectangle.Height, solid, color); }
public static bool IsStriclyInside(this Vector2 point, Rect rectangle) { return !(point.X <= rectangle.X + 1 || point.Y <= rectangle.Y + 1 || point.X >= rectangle.Right - 1 || point.Y >= rectangle.Bottom - 1); }
public static bool IsInside(this Vector2 point, Rect rectangle) { return !(point.X < rectangle.X || point.Y < rectangle.Y || point.X > rectangle.Right || point.Y > rectangle.Bottom); }
private void Draw(Graphic g) { // draw cards for (int i = 0; i < GridSize; i++) { for (int j = 0; j < GridSize; j++) { var cardValue = _cards[i][j]; if(cardValue == 0) continue; Color cardColor; if(!CardColors.TryGetValue(cardValue, out cardColor)) { cardColor = Color.White; } var cardPosition = new Vector2(i * CardWidth + (i + 1) * Spacing, j * CardHeight + (j + 1) * Spacing) + _offset[i][j]; g.DrawRectangle(GridOrigin + cardPosition, CardWidth, CardHeight, true, cardColor); // draw digit var cardRect = new Rect(GridOrigin.X + cardPosition.X, GridOrigin.Y + cardPosition.Y, CardWidth, CardHeight); var digitColor = cardValue > 2 ? Color.Black : Color.White; g.Write(cardValue.ToString(), _font, cardRect, HorizontalAlignment.Center, VerticalAlignment.Center, digitColor, 3); } } }