public ConsoleEntryAddedEventArgs(ConsoleEntry addedItem) { AddedItem = addedItem; }
public void Log(ConsoleEntry entry) { Entries.Add(entry); OnEntryAdded(new ConsoleEntryAddedEventArgs(entry)); }
public void Render(GameTime gameTime, SpriteBatch batch, Rectangle bounds) { if (bounds == Rectangle.Empty) { return; } batch.Begin(); int scrollBarWidth = _renderManager.Skin.ScrollBarWidth; Point scrollBarPadding = _renderManager.Skin.ScrollBarPadding; SpriteFont font = _renderManager.Font; //One output entry can be bigger than aviable width-space, so split it to a few lines ConsoleEntry[] dividedToLines = GetForBounds(font, new Rectangle(bounds.Location, new Point(bounds.Size.X - scrollBarWidth - scrollBarPadding.X - 5, bounds.Size.Y - scrollBarPadding.Y))); int linesToDraw = Math.Min(bounds.Height / font.LineSpacing, dividedToLines.Length); float linesScrolled = ScrollDelta / font.LineSpacing; int totalLines = dividedToLines.Length; int totalLinesSkipped = (int)linesScrolled + linesToDraw; if (totalLinesSkipped >= totalLines) { linesScrolled = totalLines - linesToDraw; ScrollDelta = font.LineSpacing * linesScrolled; } int lastTextIndex = dividedToLines.Length - 1 - (int)linesScrolled; int firstTextIndex = lastTextIndex - linesToDraw + 1; int drawAfterBounds = lastTextIndex == dividedToLines.Length - 1 ? 0 : 1; int drawBeforeBounds = firstTextIndex == 0 ? 0 : 1; float precentOfLineScrolled = linesScrolled - (int)linesScrolled; float scrolledPartInPixels = precentOfLineScrolled * font.LineSpacing; Vector2 offset = new Vector2(bounds.X, bounds.Y + scrolledPartInPixels - (drawBeforeBounds == 1 ? font.LineSpacing : 0)); Regex timePattern = new Regex(@"\[\d+:\d+:\d+\]"); for (int i = firstTextIndex - drawBeforeBounds; i <= lastTextIndex + drawAfterBounds; i++) { ConsoleEntry entry = dividedToLines[i]; string text = entry.Data; if (entry.TimeVisible) { Match match = timePattern.Match(text); Vector2 size = font.MeasureString(match.Value); batch.DrawString(font, match.Value, offset, _renderManager.Skin.HistoryTimeColor); batch.DrawString(font, text.Substring(match.Value.Length), new Vector2(offset.X + size.X, offset.Y), entry.TextColor ?? _renderManager.Skin.HistoryField.TextColor); } else { batch.DrawString(font, text, offset, entry.TextColor ?? _renderManager.Skin.HistoryField.TextColor); } offset.Y += font.LineSpacing; } if (ScrollBarVisible) { Rectangle scrollBarBounds = new Rectangle(bounds.Size.X - scrollBarWidth - scrollBarPadding.X, scrollBarPadding.Y, scrollBarWidth, bounds.Height - scrollBarPadding.Y * 2); batch.DrawRect(scrollBarBounds, _renderManager.Skin.ScrollBarColor); int stripHeight = (int)(linesToDraw / (float)totalLines * scrollBarBounds.Height); //not enought just compare equal, because possible loss of precision if (Math.Abs(stripHeight - scrollBarBounds.Height) > 0.01f) { int stripOffset = (int)(scrollBarBounds.Height / (float)totalLines * linesScrolled); Rectangle stripBounds = new Rectangle(scrollBarBounds.X, scrollBarBounds.Height - stripHeight - stripOffset + scrollBarPadding.Y, scrollBarBounds.Width, stripHeight); batch.DrawRect(stripBounds, _renderManager.Skin.ScrollBarStripColor); } } batch.End(); }
public void Log(ConsoleEntry entry) { InputManager.ConsoleHistory.Log(entry); }