diff options
| author | Alexander Gavrilov | 2012-09-07 11:36:45 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-09-07 11:36:45 +0400 |
| commit | e925d8f4d999817d3ccf7f3180e7abee382e03b4 (patch) | |
| tree | 5a48c08b6c8a45aa3cf85e7d4b05e79cc2d4e028 /library/modules | |
| parent | c971a819def1c5cc29dc926f62456c336a1dfa17 (diff) | |
| download | dfhack-e925d8f4d999817d3ccf7f3180e7abee382e03b4.tar.gz dfhack-e925d8f4d999817d3ccf7f3180e7abee382e03b4.tar.bz2 dfhack-e925d8f4d999817d3ccf7f3180e7abee382e03b4.tar.xz | |
Add an API function for reading tiles from the screen buffers.
Diffstat (limited to 'library/modules')
| -rw-r--r-- | library/modules/Screen.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index c2377f2c..9f258fe0 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -100,7 +100,7 @@ static void doSetTile(const Pen &pen, int index) bool Screen::paintTile(const Pen &pen, int x, int y) { - if (!gps) return false; + if (!gps || !pen.valid()) return false; int dimx = gps->dimx, dimy = gps->dimy; if (x < 0 || x >= dimx || y < 0 || y >= dimy) return false; @@ -109,6 +109,41 @@ bool Screen::paintTile(const Pen &pen, int x, int y) return true; } +Pen Screen::readTile(int x, int y) +{ + if (!gps) return Pen(0,0,0,-1); + + int dimx = gps->dimx, dimy = gps->dimy; + if (x < 0 || x >= dimx || y < 0 || y >= dimy) + return Pen(0,0,0,-1); + + int index = x*dimy + y; + auto screen = gps->screen + index*4; + if (screen[3] & 0x80) + return Pen(0,0,0,-1); + + Pen pen( + screen[0], screen[1], screen[2], screen[3]?true:false, + gps->screentexpos[index] + ); + + if (pen.tile) + { + if (gps->screentexpos_grayscale[index]) + { + pen.tile_mode = Screen::Pen::TileColor; + pen.tile_fg = gps->screentexpos_cf[index]; + pen.tile_bg = gps->screentexpos_cbr[index]; + } + else if (gps->screentexpos_addcolor[index]) + { + pen.tile_mode = Screen::Pen::CharColor; + } + } + + return pen; +} + bool Screen::paintString(const Pen &pen, int x, int y, const std::string &text) { if (!gps || y < 0 || y >= gps->dimy) return false; @@ -132,7 +167,7 @@ bool Screen::paintString(const Pen &pen, int x, int y, const std::string &text) bool Screen::fillRect(const Pen &pen, int x1, int y1, int x2, int y2) { - if (!gps) return false; + if (!gps || !pen.valid()) return false; if (x1 < 0) x1 = 0; if (y1 < 0) y1 = 0; |
