From 51ba2523446596f4cdf0f179702ecc3b1eefa965 Mon Sep 17 00:00:00 2001 From: Quietust Date: Tue, 21 Aug 2012 15:28:11 -0500 Subject: [PATCH] Add Screen::drawBorder(string), duplicates DF's interfacest::drawborder() --- library/include/modules/Screen.h | 3 +++ library/modules/Screen.cpp | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/library/include/modules/Screen.h b/library/include/modules/Screen.h index 334b466ff..e29233170 100644 --- a/library/include/modules/Screen.h +++ b/library/include/modules/Screen.h @@ -98,6 +98,9 @@ namespace DFHack /// 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); + /// Draws a standard dark gray window border with a title string + DFHACK_EXPORT bool drawBorder(const std::string &title); + /// Wipes the screen to full black DFHACK_EXPORT bool clear(); diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index 57b014aca..561ae2c5e 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -151,6 +151,27 @@ bool Screen::fillRect(const Pen &pen, int x1, int y1, int x2, int y2) return true; } +bool Screen::drawBorder(const std::string &title) +{ + if (!gps) return false; + + int dimx = gps->dimx, dimy = gps->dimy; + Pen border(0xDB, 8); + Pen text(0, 0, 7); + + for (int x = 0; x < dimx; x++) + { + doSetTile(border, x * dimy + 0); + doSetTile(border, x * dimy + dimy - 1); + } + for (int y = 0; y < dimy; y++) + { + doSetTile(border, 0 * dimy + y); + doSetTile(border, (dimx - 1) * dimy + y); + } + return paintString(text, (dimx - title.length()) / 2, 0, title); +} + bool Screen::clear() { if (!gps) return false;