public override void DrawString(string text, Point point, Brush brush, int size, FontStyle style, Rectangle bounds, bool ignoreFormatting = false) { SetClipArea(bounds); var pos = new Vector2((int) Math.Round(point.X), (int) Math.Round(point.Y)); var closest = GetClosestFontSize(size); var colorBrush = brush as ColorBrush; var gradientBrush = brush as GradientBrush; var defaultColor = Color.Black; if (colorBrush != null) defaultColor = colorBrush.Color; if (gradientBrush != null) { UseMaskStencil(bounds); } if (!ignoreFormatting) // If formatting is enabled, parse it and render each part. { var parts = ParseFormattedText(text, defaultColor, style); foreach (var part in parts) { var font = GetFont(Path.Combine(part.Style.ToString(), closest.ToString())); var measure = MeasureTextNoTrim(part.Text, size, part.Style); var col = new ColorXNA(part.Color.R, part.Color.G, part.Color.B, defaultColor.A); manager.SpriteBatch.DrawString(font, part.Text, pos, col * (defaultColor.A / 255f), 0, Vector2.Zero, size / (float) closest, SpriteEffects.None, 0); pos = new Vector2(pos.X + (float) measure.Width, pos.Y); } } else // Draw plain string { var font = GetFont(Path.Combine(style.ToString(), closest.ToString())); var col = new ColorXNA(defaultColor.R, defaultColor.G, defaultColor.B, defaultColor.A); manager.SpriteBatch.DrawString(font, text, pos, col * (defaultColor.A / 255f), 0, Vector2.Zero, size / (float) closest, SpriteEffects.None, 0); } // If using a gradient brush, draw a gradient over the mask. if (gradientBrush != null) { UseRenderStencil(); DrawGradient(bounds, gradientBrush); EndStencil(); } ResetClipArea(); }
/// <summary> /// Draws a string at the specified point. /// </summary> public abstract void DrawString(string text, Point point, Brush brush, int size, FontStyle style, Rectangle bounds,bool ignoreFormatting = false);
/// <summary> /// Draws a string at the specified point. /// </summary> public void DrawString(string text, Point point, Brush brush, int size, Rectangle bounds, bool ignoreFormatting = false) => DrawString(text, point, brush, size, FontStyle.Regular, bounds, ignoreFormatting);
/// <summary> /// Draws a string at the specified point. /// </summary> public void DrawString(string text, Point point, int size, Rectangle bounds,bool ignoreFormatting = false) => DrawString(text, point, Color.Black, size, bounds, ignoreFormatting);
/// <summary> /// Draws a string at the specified point. /// </summary> public void DrawString(string text, Point point, ColorBrush color, Rectangle bounds, bool ignoreFormatting = false) => DrawString(text, point, color, defaultSize, bounds, ignoreFormatting);
public override void Update(float elapsed, float total) { lastks = ks; lastms = ms; ms = Mouse.GetState(); ks = Keyboard.GetState(); var keys = ks.GetPressedKeys(); // Mouse move if (lastms.Position != ms.Position) OnMouseMove(ms.Position.ToOriginal()); // Mouse down if (ms.LeftButton == ButtonState.Pressed && lastms.LeftButton == ButtonState.Released) OnMouseDown(MouseButton.Left); if (ms.RightButton == ButtonState.Pressed && lastms.RightButton == ButtonState.Released) OnMouseDown(MouseButton.Right); if (ms.MiddleButton == ButtonState.Pressed && lastms.MiddleButton == ButtonState.Released) OnMouseDown(MouseButton.Middle); // Mouse up if (ms.LeftButton == ButtonState.Released && lastms.LeftButton == ButtonState.Pressed) OnMouseUp(MouseButton.Left); if (ms.RightButton == ButtonState.Released && lastms.RightButton == ButtonState.Pressed) OnMouseUp(MouseButton.Right); if (ms.MiddleButton == ButtonState.Released && lastms.MiddleButton == ButtonState.Pressed) OnMouseUp(MouseButton.Middle); if (lastKeys != null) { // Key down foreach (var key in keys.Where(key => !lastKeys.Contains(key))) { OnKeyDown((Key) key); firstPress = total; lastKey = key; } // If a key is being held down, after .7 seconds, make it repeat. if (total > firstPress + .7f && IsKeyDown((Key) lastKey)) { OnKeyPress((Key) lastKey); firstPress = total - .665f; // The next repeat time will be much shorter. } // Key up foreach (var key in lastKeys.Where(key => !keys.Contains(key))) { OnKeyUp((Key) key); } } MousePosition = new Point(ms.Position.X, ms.Position.Y); lastKeys = keys; }