private int draw_text(int y, string text, Font font, FontJustify justify, bool draw) { if (GetMaxValueInList(font.char_widths) * text.Length > this.width) { // We need to do some word wrapping string line = ""; int w = 0; foreach (char ch in text) { line += ch; w += font.size(ch.ToString()).First; if (w > this.width) { // Too much! We need to back-track for the last space. If possible... int idx = line.LastIndexOf(' '); if (idx == -1) { // No space, we'll have to break before this char and continue y = this.draw_line(y, line.Substring(0, line.Length - 1), font, justify, draw); line = ch.ToString(); } else { // We found a space! y = this.draw_line(y, line.Substring(0, idx), font, justify, draw); line = line.Substring(idx + 1, line.Length - idx - 1); } // Recalculate w w = font.size(line).First; } } if (line.Length > 0) // Left-over text we have to draw { y = this.draw_line(y, line, font, justify, draw); } return(y); } else { return(this.draw_line(y, text, font, justify, draw)); } }
/// <summary> /// Draw a line without concern for word wrapping /// </summary> private int draw_line(int y, string text, Font font, FontJustify justify, bool draw) { int w = 0; if (draw) { int x = 0; // TODO: x should be set based on justify if (justify != FontJustify.Left) { w = font.size(text).First; if (justify == FontJustify.Center) { x = (this.frame.width - w) / 2; } else { x = (this.frame.width - w); } } font.draw(this.frame, text, x, y); } y += font.char_size; return(y); }
/// <summary> /// Draw a line without concern for word wrapping /// </summary> private int draw_line(int y, string text, Font font, FontJustify justify, bool draw) { int w = 0; if (draw) { int x = 0; // TODO: x should be set based on justify if (justify != FontJustify.Left) { w = font.size(text).First; if (justify == FontJustify.Center) x = (this.frame.width - w) / 2; else x = (this.frame.width - w); } font.draw(this.frame, text, x, y); } y += font.char_size; return y; }
private int draw_text(int y, string text, Font font, FontJustify justify, bool draw) { if (GetMaxValueInList(font.char_widths) * text.Length > this.width) { // We need to do some word wrapping string line = ""; int w = 0; foreach (char ch in text) { line += ch; w += font.size(ch.ToString()).First; if (w > this.width) { // Too much! We need to back-track for the last space. If possible... int idx = line.LastIndexOf(' '); if (idx == -1) { // No space, we'll have to break before this char and continue y = this.draw_line(y, line.Substring(0, line.Length - 1), font, justify, draw); line = ch.ToString(); } else { // We found a space! y = this.draw_line(y, line.Substring(0, idx), font, justify, draw); line = line.Substring(idx + 1, line.Length - idx - 1); } // Recalculate w w = font.size(line).First; } } if (line.Length > 0) // Left-over text we have to draw y = this.draw_line(y, line, font, justify, draw); return y; } else return this.draw_line(y, text, font, justify, draw); }