public void DrawHorizontalLine () { var buffer = new ConsoleBuffer(5); buffer.DrawHorizontalLine(0, 0, 5, Red); buffer.DrawHorizontalLine(1, 1, 3, Green); buffer.DrawHorizontalLine(-1, 3, 10, Blue, LineWidth.Wide); var c0 = new ConsoleChar(); var cr = new ConsoleChar { LineChar = LineChar.Horizontal, ForegroundColor = Red }; var cg = new ConsoleChar { LineChar = LineChar.Horizontal, ForegroundColor = Green }; var cb = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.HorizontalWide, ForegroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, cr, cr, cr, cr); buffer.GetLine(1).Should().Equal(c0, cg, cg, cg, c0); buffer.GetLine(2).Should().Equal(c0, c0, c0, c0, c0); buffer.GetLine(3).Should().Equal(cb, cb, cb, cb, cb); }
private static void SetColor (ref ConsoleChar c, BitmapPalette palette, int colorIndex) { ConsoleColor color; if (ConsolePaletteMap.TryGetValue(palette.Colors[colorIndex], out color)) c.BackgroundColor = color; }
public void DrawLine () { var buffer = new ConsoleBuffer(3); buffer.DrawLine(Line.Vertical(1, 0, 3), Red); buffer.DrawLine(Line.Horizontal(0, 1, 3), Green, LineWidth.Wide); var c0 = new ConsoleChar(); var cr = new ConsoleChar { LineChar = LineChar.Vertical, ForegroundColor = Red }; var cg = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.HorizontalWide, ForegroundColor = Green }; var cx = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.HorizontalWide | LineChar.Vertical, ForegroundColor = Green }; buffer.GetLine(0).Should().Equal(c0, cr, c0); buffer.GetLine(1).Should().Equal(cg, cx, cg); buffer.GetLine(2).Should().Equal(c0, cr, c0); }
public void FillBackgroundVerticalLine () { var buffer = new ConsoleBuffer(4); buffer.FillBackgroundVerticalLine(0, 0, 5, Red); buffer.FillBackgroundVerticalLine(1, 1, 3, Green); buffer.FillBackgroundVerticalLine(3, -1, 10, Blue); var c0 = new ConsoleChar(); var cr = new ConsoleChar { BackgroundColor = Red }; var cg = new ConsoleChar { BackgroundColor = Green }; var cb = new ConsoleChar { BackgroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, c0, c0, cb); buffer.GetLine(1).Should().Equal(cr, cg, c0, cb); buffer.GetLine(2).Should().Equal(cr, cg, c0, cb); buffer.GetLine(3).Should().Equal(cr, cg, c0, cb); buffer.GetLine(4).Should().Equal(cr, c0, c0, cb); }
public void FillBackgroundLine () { var buffer = new ConsoleBuffer(3); buffer.FillBackgroundLine(Line.Vertical(1, 0, 3), Red); buffer.FillBackgroundLine(Line.Horizontal(0, 1, 3), Green); var c0 = new ConsoleChar(); var cr = new ConsoleChar { BackgroundColor = Red }; var cg = new ConsoleChar { BackgroundColor = Green }; buffer.GetLine(0).Should().Equal(c0, cr, c0); buffer.GetLine(1).Should().Equal(cg, cg, cg); buffer.GetLine(2).Should().Equal(c0, cr, c0); }
public void FillForegroundVerticalLine () { var buffer = new ConsoleBuffer(4); buffer.FillForegroundVerticalLine(0, 0, 5, Red, '|'); buffer.FillForegroundVerticalLine(1, 1, 3, Green, ':'); buffer.FillForegroundVerticalLine(3, -1, 10, Blue, '*'); var c0 = new ConsoleChar(); var cr = new ConsoleChar { Char = '|', ForegroundColor = Red }; var cg = new ConsoleChar { Char = ':', ForegroundColor = Green }; var cb = new ConsoleChar { Char = '*', ForegroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, c0, c0, cb); buffer.GetLine(1).Should().Equal(cr, cg, c0, cb); buffer.GetLine(2).Should().Equal(cr, cg, c0, cb); buffer.GetLine(3).Should().Equal(cr, cg, c0, cb); buffer.GetLine(4).Should().Equal(cr, c0, c0, cb); }
public void FillForegroundHorizontalLine () { var buffer = new ConsoleBuffer(5); buffer.FillForegroundHorizontalLine(0, 0, 5, Red, '-'); buffer.FillForegroundHorizontalLine(1, 1, 3, Green, '='); buffer.FillForegroundHorizontalLine(-1, 3, 10, Blue, '_'); var c0 = new ConsoleChar(); var cr = new ConsoleChar { Char = '-', ForegroundColor = Red }; var cg = new ConsoleChar { Char = '=', ForegroundColor = Green }; var cb = new ConsoleChar { Char = '_', ForegroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, cr, cr, cr, cr); buffer.GetLine(1).Should().Equal(c0, cg, cg, cg, c0); buffer.GetLine(2).Should().Equal(c0, c0, c0, c0, c0); buffer.GetLine(3).Should().Equal(cb, cb, cb, cb, cb); }
public void DrawRectangleSimple () { var buffer = new ConsoleBuffer(3); buffer.DrawRectangle(new Rect(0, 0, 3, 3), Red, LineWidth.Single); var c0 = new ConsoleChar(); var cx = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.Vertical, ForegroundColor = Red }; var ch = new ConsoleChar { LineChar = LineChar.Horizontal, ForegroundColor = Red }; var cv = new ConsoleChar { LineChar = LineChar.Vertical, ForegroundColor = Red }; buffer.GetLine(0).Should().Equal(cx, ch, cx); buffer.GetLine(1).Should().Equal(cv, c0, cv); buffer.GetLine(2).Should().Equal(cx, ch, cx); }
public void UpdateScreen() { object bufferCS = TextConsole.BufferCS; lock (bufferCS) //acquire a lock, otherwise we get weird screens due to buffer contention { ScreenBuffer scrapBuffer = ScreenBuffer.GetScrapBuffer2(true); for (int i = 4; i < 24; i++) //4 is the first row any entry can appear on { if (scrapBuffer[3, i].Char == '$') //indicates a discrete location entry { char[] locationChars = new char[70]; for (int j = 9; j < 79; j++) { locationChars[j - 9] = scrapBuffer[j, i].Char; } string locationName = new string(locationChars).Trim().ToLower(); this.UpdateJournalNoteDictionary(); if (!this.CachedRelevantJournalNotesByName.ContainsKey(locationName)) { if (!this.ErroredJournalScreenStrings.Contains(locationName)) { Debug.Log("QudUX Mod: Error trying to parse location from journal screen. [locationName = " + locationName + "]\nKNOWN LOCATIONS:\n" + DebugGetKnownLocationsList()); this.ErroredJournalScreenStrings.Add(locationName); } continue; } JournalFacts jFacts = new JournalFacts(); bool bFactsIdentified = false; if (this.CachedRelevantJournalNotesByName[locationName].Count == 1) { //only one matching entry, no need to parse the directions jFacts = this.CachedRelevantJournalNotesByName[locationName][0]; bFactsIdentified = true; } else if (i < 23) //verify there's at least one line left for directoins to appear on screen { List <JournalFacts> jFactsArray = this.CachedRelevantJournalNotesByName[locationName]; char[] directionChars = new char[76]; for (int j = 3; j < 79; j++) { directionChars[j - 3] = scrapBuffer[j, i + 1].Char; } string directionString = new string(directionChars).Trim(); int count = 0; int index = -1; for (int j = 0; j < jFactsArray.Count; j++) { if (jFactsArray[j].directionsTo == directionString) { count++; index = j; } } if (count == 1) { jFacts = jFactsArray[index]; bFactsIdentified = true; } } if (bFactsIdentified) //draw the appropriate character to represent if this location was previously visited { string locationIndicator = jFacts.hasBeenVisited ? "&G" + this.ExploredLocationSymbol : "&K" + this.UnexploredLocationSymbol; this.AppliedSymbol = TextConsole.CurrentBuffer[4, i]; scrapBuffer.Goto(4, i); scrapBuffer.Write(locationIndicator); } } } Popup._TextConsole.DrawBuffer(scrapBuffer, null, false); } }
protected void RenderToFlowDocument([NotNull] IConsoleBufferSource buffer, [NotNull] FlowDocument document) { if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); } if (document == null) { throw new ArgumentNullException(nameof(document)); } var par = new Paragraph { Background = Background, FontFamily = FontFamily, FontSize = FontSize, FontStretch = FontStretch, FontStyle = FontStyle, FontWeight = FontWeight, TextAlignment = System.Windows.TextAlignment.Left, }; document.Blocks.Add(par); ConsoleColor currentForeColor = (ConsoleColor)int.MaxValue; ConsoleColor currentBackColor = (ConsoleColor)int.MaxValue; Run text = null; for (int iy = 0; iy < buffer.Height; iy++) { ConsoleChar[] charsLine = buffer.GetLine(iy); for (int ix = 0; ix < buffer.Width; ix++) { ConsoleChar chr = charsLine[ix]; ConsoleColor foreColor = chr.ForegroundColor; ConsoleColor backColor = chr.BackgroundColor; if (text == null || foreColor != currentForeColor || backColor != currentBackColor) { currentForeColor = foreColor; currentBackColor = backColor; AppendRunIfNeeded(); text = new Run { Foreground = ConsoleBrushes[foreColor], Background = ConsoleBrushes[backColor], }; } text.Text += chr.HasChar || chr.LineChar.IsEmpty ? chr.PrintableChar : buffer.GetLineChar(ix, iy); } AppendRunIfNeeded(); if (iy + 1 < buffer.Height) { par.Inlines.Add(new LineBreak()); } } AppendRunIfNeeded(); void AppendRunIfNeeded() { if (text == null) { return; } par.Inlines.Add(text); text = null; } }