From 74fed9ac1d5fbb53656573626bff7ad43cd8812a Mon Sep 17 00:00:00 2001 From: Chip Locke Date: Wed, 5 Dec 2018 00:53:07 -0800 Subject: [PATCH] minor optimizations --- src/condo/Screen.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/condo/Screen.cs b/src/condo/Screen.cs index eee722e..af1ca67 100644 --- a/src/condo/Screen.cs +++ b/src/condo/Screen.cs @@ -198,17 +198,20 @@ public void SetCellCharacter(int x, int y, bool invert = false) using (var dc = this.GetCell(x, y).RenderOpen()) { + var backgroundBrush = this.brushCache.GetBrush(ch.Background.R, ch.Background.G, ch.Background.B); + var foregroundBrush = this.brushCache.GetBrush(ch.Foreground.R, ch.Foreground.G, ch.Foreground.B); + dc.DrawRectangle(!invert ? backgroundBrush : foregroundBrush, null, new Rect(new Point(0, 0), new Point(this.cellWidth, this.cellHeight))); + + if (ch.Foreground == ch.Background) return; // no need to draw same color glyph. + GlyphRun gr; - if (!this.typeface.CharacterToGlyphMap.TryGetValue((char)ch.Glyph, out ushort glyphValue)) + if (!this.typeface.CharacterToGlyphMap.TryGetValue((char)ch.Glyph, out var glyphValue)) { glyphValue = 0; } gr = new GlyphRun(this.typeface, 0, false, this.fontSize, (float)this.dpiInfo.PixelsPerDip, new[] { glyphValue }, this.baselineOrigin, new[] { 0.0 }, new[] { new Point(0, 0) }, null, null, null, null, null); - var backgroundBrush = this.brushCache.GetBrush(ch.Background.R, ch.Background.G, ch.Background.B); - var foregroundBrush = this.brushCache.GetBrush(ch.Foreground.R, ch.Foreground.G, ch.Foreground.B); - dc.DrawRectangle(!invert ? backgroundBrush : foregroundBrush, null, new Rect(new Point(0, 0), new Point(this.cellWidth, this.cellHeight))); dc.DrawGlyphRun(!invert ? foregroundBrush : backgroundBrush, gr); } }