Skip to content

Commit

Permalink
GOB: Add Surface::drawRect()
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Jun 22, 2012
1 parent b1e50b4 commit 62cf663
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions engines/gob/surface.cpp
Expand Up @@ -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<int32>(right - left + 1, 0, _width - left);
const uint16 height = CLIP<int32>(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
Expand Down
1 change: 1 addition & 0 deletions engines/gob/surface.h
Expand Up @@ -158,6 +158,7 @@ class Surface {

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;
Expand Down

0 comments on commit 62cf663

Please sign in to comment.