internal void LoadStream(System.IO.Stream stream) { StreamReader reader = new StreamReader(stream); CellRows.Clear(); CellRows = new List <List <CellInfo> >(); //int col = 0; int row = 0; while (reader.Peek() >= 0) { int bc = 100; int fc = 100; CellRows.Add(new List <CellInfo>()); string strline = reader.ReadLine(); char[] str = strline.ToCharArray(); bool bold = false; bool underlined = false; for (int i = 0; i < str.Length; i++) { if (IsControlCode(str[i])) { if (str[i] == BoldControl) { bold = (bold ? false : true); continue; } else if (str[i] == UnderlineControl) { underlined = (underlined ? false : true); continue; } else if (str[i] == ReverseControl) { continue; } else if (str[i] == PlainControl) { bold = false; underlined = false; continue; } else if (str[i] == ColorControl) { //bc = 100; fc = 100; if (i + 1 == str.Length) { break; } i++; if (Char.IsDigit(str[i])) { // forecolor += str[i]; fc = ParseChar(str[i]); if (i + 1 == str.Length) { break; } i++; if (Char.IsDigit(str[i])) { fc = ((fc * 10)) + ParseChar(str[i]); if (i + 1 == str.Length) { break; } i++; } } if (fc > 15 && fc != 100) { fc = 0; } if (str[i] == ',') { if (++i == str.Length) { break; } if (Char.IsDigit(str[i])) { bc = ParseChar(str[i]); if (++i == str.Length) { break; } if (Char.IsDigit(str[i])) { bc = (bc * 10) + ParseChar(str[i]); if (++i == str.Length) { break; } } } } if (bc > 15 && bc != 100) { bc = 1; } /*for (; i < str.Length && IsControlCode(str[i]); i++) * { * } */ } } CellInfo ci = new CellInfo(); ci.Character = str[i]; if (fc != 100) { ci.ForeColor = (byte)fc; } if (bc != 100) { ci.BackColor = (byte)bc; } ci.Bold = bold; ci.Underlined = underlined; CellRows[row].Add(ci); } row++; } // find longest row. int longest = 0; foreach (List <CellInfo> cellrow in CellRows) { if (cellrow.Count > longest) { longest = cellrow.Count; } } this.m_Columns = longest; this.m_Rows = CellRows.Count; ResizeCellRows(); ResizeByCellSize(); PaintIntoBackground(); }
public string GetIRCString(bool watermark) { StringBuilder sb = new StringBuilder(); CellInfo lastcell; int rowcount = 0; foreach (List <CellInfo> row in AsciiPaintCanvas.CellRows) { rowcount++; if (rowcount > AsciiPaintCanvas.Rows) { break; } // something that will not be used normally so that color is always printed at beginning of line lastcell = new CellInfo('z', 100, 100); int cellcount = 0; foreach (CellInfo cell in row) { // FIXME: check for digits and use two digit color code. cellcount++; if (cellcount > AsciiPaintCanvas.Columns) { break; } if (lastcell.Bold != cell.Bold) { sb.Append(BoldControl); } if (lastcell.Underlined != cell.Underlined) { sb.Append(UnderlineControl); } if (cell.Character == ' ' && watermark) { cell.ForeColor = cell.BackColor; char character = WatermarkCharAtPos(cellcount - 1); if (lastcell.BackColor != cell.BackColor || lastcell.ForeColor != cell.BackColor) { if (cell.BackColor < 10 && char.IsDigit(character)) { sb.AppendFormat(ColorControl + "{0},0{1}{2}", cell.ForeColor, cell.BackColor, character); } else { sb.AppendFormat(ColorControl + "{0},{1}{2}", cell.ForeColor, cell.BackColor, character); } } else { sb.Append(character); } } else if (lastcell.BackColor != cell.BackColor) { if (char.IsDigit(cell.Character) || cell.Character == ',') { if (cell.BackColor < 10 && char.IsDigit(cell.Character)) { sb.AppendFormat(ColorControl + "{0},0{1}{2}", cell.ForeColor, cell.BackColor, cell.Character); } else { sb.AppendFormat(ColorControl + "{0},{1}{2}", cell.ForeColor, cell.BackColor, cell.Character); } } else { sb.AppendFormat(ColorControl + "{0},{1}{2}", cell.ForeColor, cell.BackColor, cell.Character); } } else if (lastcell.ForeColor != cell.ForeColor) { if (char.IsDigit(cell.Character)) { if (cell.ForeColor < 10 && char.IsDigit(cell.Character)) { sb.AppendFormat(ColorControl + "0{0}{1}", cell.ForeColor, cell.Character); } else { sb.AppendFormat(ColorControl + "{0}{1}", cell.ForeColor, cell.Character); } } else if (cell.Character == ',') { if (cell.BackColor < 10 && char.IsDigit(cell.Character)) { sb.AppendFormat(ColorControl + "{0},0{1}{2}", cell.ForeColor, cell.BackColor, cell.Character); } else { sb.AppendFormat(ColorControl + "{0},{1}{2}", cell.ForeColor, cell.BackColor, cell.Character); } } else { sb.AppendFormat(ColorControl + "{0}{1}", cell.ForeColor, cell.Character); } } else { sb.Append(cell.Character); } lastcell = cell; } sb.Append("\r\n"); } return(sb.ToString()); }
private void RepaintSingleCell(Point cellpos) { if (m_DontRepaint) { return; } if (cellpos.X < 0 || cellpos.Y < 0 || cellpos.Y >= CellRows.Count || cellpos.X >= CellRows[0].Count) { return; } /* int max_x = cellpos.X + 1; * int max_y = cellpos.Y + 1; * for (cellpos.X--; cellpos.X < max_x; cellpos.X++) * { * for (cellpos.Y--; cellpos.Y < max_y; cellpos.Y++) * { * if (cellpos.Y < 0 || cellpos.X < 0) * continue; */ CellInfo ci = CellRows[cellpos.Y][cellpos.X]; //m_PaintBuffer.FillRectangle(new SolidBrush(this.BackColor), cellpos.X * m_CellWidth, cellpos.Y * m_CellHeight, m_CellWidth, m_CellHeight); m_PaintBuffer.FillRectangle(this.Colors.SolidBrushes[ci.BackColor], cellpos.X * m_CellWidth, cellpos.Y * m_CellHeight, m_CellWidth, m_CellHeight); if (CellRows[cellpos.Y][cellpos.X].Character != ' ') { FontStyle styles = new FontStyle(); if (ci.Bold) { styles |= FontStyle.Bold; } if (ci.Underlined) { styles |= FontStyle.Underline; } Font font = new Font(this.Font, styles); m_PaintBuffer.DrawString(ci.Character.ToString(), font, this.Colors.SolidBrushes[ci.ForeColor], cellpos.X * m_CellWidth, cellpos.Y * m_CellHeight); } m_PaintBuffer.DrawLine(m_SeperatorPen, cellpos.X * m_CellWidth, (1 + cellpos.Y) * m_CellHeight, (1 + cellpos.X) * m_CellWidth, (1 + cellpos.Y) * m_CellHeight); m_PaintBuffer.DrawLine(m_SeperatorPen, (1 + cellpos.X) * m_CellWidth, (cellpos.Y) * m_CellHeight, (1 + cellpos.X) * m_CellWidth, (1 + cellpos.Y) * m_CellHeight); m_PaintBuffer.DrawLine(m_SeperatorPen, (cellpos.X) * m_CellWidth, (cellpos.Y) * m_CellHeight, (1 + cellpos.X) * m_CellWidth, (cellpos.Y) * m_CellHeight); m_PaintBuffer.DrawLine(m_SeperatorPen, (cellpos.X) * m_CellWidth, (cellpos.Y) * m_CellHeight, (cellpos.X) * m_CellWidth, (1 + cellpos.Y) * m_CellHeight); if (m_SelectedCellPosition.X == cellpos.X && m_SelectedCellPosition.Y == cellpos.Y) { m_PaintBuffer.DrawRectangle(m_HighlightPen, 1 + (m_SelectedCellPosition.X * (m_CellWidth + (m_SeperatorWidth / 2))), 1 + (m_SelectedCellPosition.Y * (m_CellHeight + (m_SeperatorWidth / 2))), m_CellWidth - 2, m_CellHeight - 2); } // } //} int xpos = (cellpos.X * m_CellWidth) - 5; int ypos = (cellpos.Y * m_CellHeight) - 5; if (xpos < 0) { xpos = 0; } if (ypos < 0) { ypos = 0; } this.Invalidate(new Rectangle(new Point(xpos, ypos), new Size(m_CellWidth + 5, m_CellHeight + 5))); }