Skip to content

Commit

Permalink
minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleyewdee committed Dec 5, 2018
1 parent 3c3c311 commit 74fed9a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/condo/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 74fed9a

Please sign in to comment.