From 62cf66395736e1cc368b31588472fe9d74221c87 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Thu, 21 Jun 2012 23:59:59 +0200 Subject: GOB: Add Surface::drawRect() --- engines/gob/surface.cpp | 28 ++++++++++++++++++++++++++++ engines/gob/surface.h | 1 + 2 files changed, 29 insertions(+) diff --git a/engines/gob/surface.cpp b/engines/gob/surface.cpp index 3af19f891d..3eaf741be2 100644 --- a/engines/gob/surface.cpp +++ b/engines/gob/surface.cpp @@ -695,6 +695,34 @@ void Surface::drawLine(uint16 x0, uint16 y0, uint16 x1, uint16 y1, uint32 color) Graphics::drawLine(x0, y0, x1, y1, color, &plotPixel, this); } +void Surface::drawRect(uint16 left, uint16 top, uint16 right, uint16 bottom, uint32 color) { + // Just in case those are swapped + if (left > right) + SWAP(left, right); + if (top > bottom) + SWAP(top, bottom); + + if ((left >= _width) || (top >= _height)) + // Nothing to do + return; + + // Area to actually draw + const uint16 width = CLIP(right - left + 1, 0, _width - left); + const uint16 height = CLIP(bottom - top + 1, 0, _height - top); + + if ((width == 0) || (height == 0)) + // Nothing to do + return; + + right = left + width - 1; + bottom = top + height - 1; + + drawLine(left , top , left , bottom, color); + drawLine(right, top , right, bottom, color); + drawLine(left , top , right, top , color); + drawLine(left , bottom, right, bottom, color); +} + /* * The original's version of the Bresenham Algorithm was a bit "unclean" * and produced strange edges at 45, 135, 225 and 315 degrees, so using the diff --git a/engines/gob/surface.h b/engines/gob/surface.h index 5376603801..09be8d1a49 100644 --- a/engines/gob/surface.h +++ b/engines/gob/surface.h @@ -158,6 +158,7 @@ public: void putPixel(uint16 x, uint16 y, uint32 color); void drawLine(uint16 x0, uint16 y0, uint16 x1, uint16 y1, uint32 color); + void drawRect(uint16 left, uint16 top, uint16 right, uint16 bottom, uint32 color); void drawCircle(uint16 x0, uint16 y0, uint16 radius, uint32 color, int16 pattern = 0); void blitToScreen(uint16 left, uint16 top, uint16 right, uint16 bottom, uint16 x, uint16 y) const; -- cgit v1.2.3