From 2a2ab00ca99c58ce9beddb05c1598a4283813218 Mon Sep 17 00:00:00 2001 From: lethosor Date: Tue, 22 Dec 2015 11:42:51 -0500 Subject: [PATCH] Add "map" parameter to a lot of drawing functions Ref #746 --- library/include/modules/Gui.h | 1 + library/include/modules/Screen.h | 38 ++++++++++----------- library/modules/Screen.cpp | 16 ++++----- plugins/devel/color-dfhack-text.cpp | 15 +++++++-- plugins/mousequery.cpp | 2 +- plugins/uicommon.h | 52 +++++++++++++++++------------ 6 files changed, 71 insertions(+), 53 deletions(-) diff --git a/library/include/modules/Gui.h b/library/include/modules/Gui.h index effa7347e..ae53e7603 100644 --- a/library/include/modules/Gui.h +++ b/library/include/modules/Gui.h @@ -131,6 +131,7 @@ namespace DFHack struct DwarfmodeDims { int map_x1, map_x2, menu_x1, menu_x2, area_x1, area_x2; int y1, y2; + int map_y1, map_y2; bool menu_on, area_on, menu_forced; rect2d map() { return mkrect_xy(map_x1, y1, map_x2, y2); } diff --git a/library/include/modules/Screen.h b/library/include/modules/Screen.h index 389becbfe..37dc9808c 100644 --- a/library/include/modules/Screen.h +++ b/library/include/modules/Screen.h @@ -184,16 +184,16 @@ namespace DFHack DFHACK_EXPORT bool inGraphicsMode(); /// Paint one screen tile with the given pen - DFHACK_EXPORT bool paintTile(const Pen &pen, int x, int y); + DFHACK_EXPORT bool paintTile(const Pen &pen, int x, int y, bool map = false); /// Retrieves one screen tile from the buffer DFHACK_EXPORT Pen readTile(int x, int y); /// Paint a string onto the screen. Ignores ch and tile of pen. - DFHACK_EXPORT bool paintString(const Pen &pen, int x, int y, const std::string &text); + DFHACK_EXPORT bool paintString(const Pen &pen, int x, int y, const std::string &text, bool map = false); /// Fills a rectangle with one pen. Possibly more efficient than a loop over paintTile. - DFHACK_EXPORT bool fillRect(const Pen &pen, int x1, int y1, int x2, int y2); + DFHACK_EXPORT bool fillRect(const Pen &pen, int x1, int y1, int x2, int y2, bool map = false); /// Draws a standard dark gray window border with a title string DFHACK_EXPORT bool drawBorder(const std::string &title); @@ -261,34 +261,34 @@ namespace DFHack return *this; } - Painter &fill(const rect2d &area, const Pen &pen) { + Painter &fill(const rect2d &area, const Pen &pen, bool map = false) { rect2d irect = intersect(area, clip); - fillRect(pen, irect.first.x, irect.first.y, irect.second.x, irect.second.y); + fillRect(pen, irect.first.x, irect.first.y, irect.second.x, irect.second.y, map); return *this; } - Painter &fill(const rect2d &area) { return fill(area, cur_pen); } + Painter &fill(const rect2d &area, bool map = false) { return fill(area, cur_pen, map); } - Painter &tile(const Pen &pen) { - if (isValidPos()) paintTile(pen, gcursor.x, gcursor.y); + Painter &tile(const Pen &pen, bool map = false) { + if (isValidPos()) paintTile(pen, gcursor.x, gcursor.y, map); return advance(1); } - Painter &tile() { return tile(cur_pen); } - Painter &tile(char ch) { return tile(cur_pen.chtile(ch)); } - Painter &tile(char ch, int tileid) { return tile(cur_pen.chtile(ch, tileid)); } + Painter &tile(bool map = false) { return tile(cur_pen, map); } + Painter &tile(char ch, bool map = false) { return tile(cur_pen.chtile(ch), map); } + Painter &tile(char ch, int tileid, bool map = false) { return tile(cur_pen.chtile(ch, tileid), map); } - Painter &string(const std::string &str, const Pen &pen) { - do_paint_string(str, pen); return advance(str.size()); + Painter &string(const std::string &str, const Pen &pen, bool map = false) { + do_paint_string(str, pen, map); return advance(str.size()); } - Painter &string(const std::string &str) { return string(str, cur_pen); } - Painter &string(const std::string &str, int8_t fg) { return string(str, cur_pen.color(fg)); } + Painter &string(const std::string &str, bool map = false) { return string(str, cur_pen, map); } + Painter &string(const std::string &str, int8_t fg, bool map = false) { return string(str, cur_pen.color(fg), map); } - Painter &key(df::interface_key kc, const Pen &pen) { - return string(getKeyDisplay(kc), pen); + Painter &key(df::interface_key kc, const Pen &pen, bool map = false) { + return string(getKeyDisplay(kc), pen, map); } - Painter &key(df::interface_key kc) { return key(kc, cur_key_pen); } + Painter &key(df::interface_key kc, bool map = false) { return key(kc, cur_key_pen, map); } private: - void do_paint_string(const std::string &str, const Pen &pen); + void do_paint_string(const std::string &str, const Pen &pen, bool map = false); }; namespace Hooks { diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index c0ced42a2..0f79e1a46 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -115,14 +115,14 @@ static void doSetTile(const Pen &pen, int x, int y, bool map) GUI_HOOK_TOP(Screen::Hooks::set_tile)(pen, x, y, map); } -bool Screen::paintTile(const Pen &pen, int x, int y) +bool Screen::paintTile(const Pen &pen, int x, int y, bool map) { if (!gps || !pen.valid()) return false; auto dim = getWindowSize(); if (x < 0 || x >= dim.x || y < 0 || y >= dim.y) return false; - doSetTile(pen, x, y, false); + doSetTile(pen, x, y, map); return true; } @@ -161,7 +161,7 @@ Pen Screen::readTile(int x, int y) return pen; } -bool Screen::paintString(const Pen &pen, int x, int y, const std::string &text) +bool Screen::paintString(const Pen &pen, int x, int y, const std::string &text, bool map) { auto dim = getWindowSize(); if (!gps || y < 0 || y >= dim.y) return false; @@ -176,14 +176,14 @@ bool Screen::paintString(const Pen &pen, int x, int y, const std::string &text) tmp.ch = text[i]; tmp.tile = (pen.tile ? pen.tile + uint8_t(text[i]) : 0); - paintTile(tmp, x+i, y); + paintTile(tmp, x+i, y, map); ok = true; } return ok; } -bool Screen::fillRect(const Pen &pen, int x1, int y1, int x2, int y2) +bool Screen::fillRect(const Pen &pen, int x1, int y1, int x2, int y2, bool map) { auto dim = getWindowSize(); if (!gps || !pen.valid()) return false; @@ -197,7 +197,7 @@ bool Screen::fillRect(const Pen &pen, int x1, int y1, int x2, int y2) for (int x = x1; x <= x2; x++) { for (int y = y1; y <= y2; y++) - doSetTile(pen, x, y, false); + doSetTile(pen, x, y, map); } return true; @@ -247,7 +247,7 @@ bool Screen::invalidate() const Pen Screen::Painter::default_pen(0,COLOR_GREY,0); const Pen Screen::Painter::default_key_pen(0,COLOR_LIGHTGREEN,0); -void Screen::Painter::do_paint_string(const std::string &str, const Pen &pen) +void Screen::Painter::do_paint_string(const std::string &str, const Pen &pen, bool map) { if (gcursor.y < clip.first.y || gcursor.y > clip.second.y) return; @@ -256,7 +256,7 @@ void Screen::Painter::do_paint_string(const std::string &str, const Pen &pen) int len = std::min((int)str.size(), int(clip.second.x - gcursor.x + 1)); if (len > dx) - paintString(pen, gcursor.x + dx, gcursor.y, str.substr(dx, len-dx)); + paintString(pen, gcursor.x + dx, gcursor.y, str.substr(dx, len-dx), map); } bool Screen::findGraphicsTile(const std::string &pagename, int x, int y, int *ptile, int *pgs) diff --git a/plugins/devel/color-dfhack-text.cpp b/plugins/devel/color-dfhack-text.cpp index 761782303..eb5e9c659 100644 --- a/plugins/devel/color-dfhack-text.cpp +++ b/plugins/devel/color-dfhack-text.cpp @@ -25,9 +25,18 @@ void color_text_tile(const Screen::Pen &pen, int x, int y, bool map) { Screen::Pen pen2 = pen; uint8_t color = config.flicker ? config.tick % 8 : config.color; - pen2.fg = color; - pen2.bg = color; - pen2.bold = true; + if (map) + { + pen2.fg = color % 8; + pen2.bg = (color % 8) + 8; + pen2.bold = false; + } + else + { + pen2.fg = color; + pen2.bg = color; + pen2.bold = true; + } return color_text_hook.next()(pen2, x, y, map); } diff --git a/plugins/mousequery.cpp b/plugins/mousequery.cpp index 389d443cf..3731d96c0 100644 --- a/plugins/mousequery.cpp +++ b/plugins/mousequery.cpp @@ -674,7 +674,7 @@ struct mousequery_hook : public df::viewscreen_dwarfmodest } } - OutputString(color, mx, my, "X"); + OutputString(color, mx, my, "X", false, 0, 0, true); return; } diff --git a/plugins/uicommon.h b/plugins/uicommon.h index 7182ee2f2..156552504 100644 --- a/plugins/uicommon.h +++ b/plugins/uicommon.h @@ -91,9 +91,9 @@ static void transform_(vector &src, vector &dst, Fn func) typedef int8_t UIColor; static void OutputString(UIColor color, int &x, int &y, const std::string &text, - bool newline = false, int left_margin = 0, const UIColor bg_color = 0) + bool newline = false, int left_margin = 0, const UIColor bg_color = 0, bool map = false) { - Screen::paintString(Screen::Pen(' ', color, bg_color), x, y, text); + Screen::paintString(Screen::Pen(' ', color, bg_color), x, y, text, map); if (newline) { ++y; @@ -104,54 +104,62 @@ static void OutputString(UIColor color, int &x, int &y, const std::string &text, } static void OutputHotkeyString(int &x, int &y, const char *text, const char *hotkey, bool newline = false, - int left_margin = 0, int8_t text_color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN) + int left_margin = 0, int8_t text_color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN, bool map = false) { - OutputString(hotkey_color, x, y, hotkey); + OutputString(hotkey_color, x, y, hotkey, false, 0, 0, map); string display(": "); display.append(text); - OutputString(text_color, x, y, display, newline, left_margin); + OutputString(text_color, x, y, display, newline, left_margin, 0, map); } static void OutputHotkeyString(int &x, int &y, const char *text, df::interface_key hotkey, - bool newline = false, int left_margin = 0, int8_t text_color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN) + bool newline = false, int left_margin = 0, int8_t text_color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN, + bool map = false) { - OutputHotkeyString(x, y, text, DFHack::Screen::getKeyDisplay(hotkey).c_str(), newline, left_margin, text_color, hotkey_color); + OutputHotkeyString(x, y, text, DFHack::Screen::getKeyDisplay(hotkey).c_str(), newline, left_margin, text_color, hotkey_color, map); } static void OutputLabelString(int &x, int &y, const char *text, const char *hotkey, const string &label, bool newline = false, - int left_margin = 0, int8_t text_color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN) + int left_margin = 0, int8_t text_color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN, bool map = false) { - OutputString(hotkey_color, x, y, hotkey); + OutputString(hotkey_color, x, y, hotkey, false, 0, 0, map); string display(": "); display.append(text); display.append(": "); - OutputString(text_color, x, y, display); - OutputString(hotkey_color, x, y, label, newline, left_margin); + OutputString(text_color, x, y, display, false, 0, 0, map); + OutputString(hotkey_color, x, y, label, newline, left_margin, 0, map); +} + +static void OutputLabelString(int &x, int &y, const char *text, df::interface_key hotkey, const string &label, bool newline = false, + int left_margin = 0, int8_t text_color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN, bool map = false) +{ + OutputLabelString(x, y, text, DFHack::Screen::getKeyDisplay(hotkey).c_str(), label, newline, + left_margin, text_color, hotkey_color, map); } static void OutputFilterString(int &x, int &y, const char *text, const char *hotkey, bool state, bool newline = false, - int left_margin = 0, int8_t hotkey_color = COLOR_LIGHTGREEN) + int left_margin = 0, int8_t hotkey_color = COLOR_LIGHTGREEN, bool map = false) { - OutputString(hotkey_color, x, y, hotkey); - OutputString(COLOR_WHITE, x, y, ": "); - OutputString((state) ? COLOR_WHITE : COLOR_GREY, x, y, text, newline, left_margin); + OutputString(hotkey_color, x, y, hotkey, false, 0, 0, map); + OutputString(COLOR_WHITE, x, y, ": ", false, 0, 0, map); + OutputString((state) ? COLOR_WHITE : COLOR_GREY, x, y, text, newline, left_margin, 0, map); } static void OutputToggleString(int &x, int &y, const char *text, const char *hotkey, bool state, bool newline = true, - int left_margin = 0, int8_t color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN) + int left_margin = 0, int8_t color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN, bool map = false) { - OutputHotkeyString(x, y, text, hotkey, false, 0, color, hotkey_color); - OutputString(color, x, y, ": "); + OutputHotkeyString(x, y, text, hotkey, false, 0, color, hotkey_color, map); + OutputString(color, x, y, ": ", false, 0, 0, map); if (state) - OutputString(COLOR_GREEN, x, y, "On", newline, left_margin); + OutputString(COLOR_GREEN, x, y, "On", newline, left_margin, 0, map); else - OutputString(COLOR_GREY, x, y, "Off", newline, left_margin); + OutputString(COLOR_GREY, x, y, "Off", newline, left_margin, 0, map); } static void OutputToggleString(int &x, int &y, const char *text, df::interface_key hotkey, bool state, bool newline = true, - int left_margin = 0, int8_t color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN) + int left_margin = 0, int8_t color = COLOR_WHITE, int8_t hotkey_color = COLOR_LIGHTGREEN, bool map = false) { - OutputToggleString(x, y, text, DFHack::Screen::getKeyDisplay(hotkey).c_str(), state, newline, left_margin, color, hotkey_color); + OutputToggleString(x, y, text, DFHack::Screen::getKeyDisplay(hotkey).c_str(), state, newline, left_margin, color, hotkey_color, map); } inline string int_to_string(const int n)