GOB: Add Surface::drawRect()

This commit is contained in:
Sven Hesse 2012-06-21 23:59:59 +02:00
parent b1e50b4e30
commit 62cf663957
2 changed files with 29 additions and 0 deletions

View File

@ -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

View File

@ -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;