public MarkupGenerator(int width = 128, int min_height = 32) { this.width = width; this.min_height = min_height; this.frame = null; this.font_plain = FontManager.instance.font_named("Font07x5.dmd"); this.font_bold = FontManager.instance.font_named("Font09Bx7.dmd"); }
public TextLayer(int x, int y, Font font, FontJustify justify, bool opaque = false) : base(opaque) { this.set_target_position(x, y); this.font = font; this.started_at = -1; this.seconds = -1; this.frame = null; this.frame_old = null; this.justify = justify; this.blink_frames = -1; this.blink_frames_counter = 0; }
public DisplayController(GameController game, int width = 128, int height = 32, Font message_font = null) { this.game = game; this.width = width; this.height = height; if (message_font != null) this.message_layer = new TextLayer(1, 1, message_font, FontJustify.Center); // Do two updates to get the "pump primed" ? -- Yeah. for (int i = 0; i < 2; i++) this.update(); this.frame_handlers = new List<DMDFrameHandler>(); this.frame_handlers.Add(new DMDFrameHandler(game.PROC.dmd_draw)); }
public ScoreDisplay(GameController game, int priority, FontJustify left_players_justify = FontJustify.Right) : base(game, priority) { this.layer = new ScoreLayer(128, 32, this); this.font_common = FontManager.instance.font_named("Font07x5.dmd"); this.font_18x12 = FontManager.instance.font_named("Font18x12.dmd"); this.font_18x11 = FontManager.instance.font_named("Font18x11.dmd"); this.font_18x10 = FontManager.instance.font_named("Font18x10.dmd"); this.font_14x10 = FontManager.instance.font_named("Font14x10.dmd"); this.font_14x9 = FontManager.instance.font_named("Font14x9.dmd"); this.font_14x8 = FontManager.instance.font_named("Font14x8.dmd"); this.font_09x5 = FontManager.instance.font_named("Font09x5.dmd"); this.font_09x6 = FontManager.instance.font_named("Font09x6.dmd"); this.font_09x7 = FontManager.instance.font_named("Font09x7.dmd"); this.score_posns = new Dictionary<bool, List<Pair<int, int>>>(); this.set_left_players_justify(left_players_justify); }
/// <summary> /// Searches the font path for a font file of the given name and returns an instance of the /// Font class for the given font if it exists. /// </summary> public Font font_named(string name) { if (_font_cache.ContainsKey(name)) return _font_cache[name]; foreach (string _font_path in font_paths) { if (File.Exists(_font_path + name)) { Font font = new Font(_font_path + name); _font_cache.Add(name, font); return font; } else if (File.Exists(_font_path + name + ".dmd")) { Font font = new Font(_font_path + name + ".dmd"); _font_cache.Add(name, font); return font; } } throw new Exception("Font named " + name + " not found. Paths = " + get_font_paths()); }
/// <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); }