- little bit more cleanup

- added fixme about Surface::move

svn-id: r29442
This commit is contained in:
Johannes Schickel 2007-11-06 23:03:19 +00:00
parent 3592690b78
commit 616c8357b4
2 changed files with 15 additions and 11 deletions

View file

@ -22,6 +22,7 @@
* $Id$ * $Id$
*/ */
#include "common/algorithm.h"
#include "common/util.h" #include "common/util.h"
#include "graphics/primitives.h" #include "graphics/primitives.h"
#include "graphics/surface.h" #include "graphics/surface.h"
@ -78,15 +79,15 @@ void Surface::hLine(int x, int y, int x2, uint32 color) {
if (x2 >= w) if (x2 >= w)
x2 = w - 1; x2 = w - 1;
if (x2 < x)
return;
if (bytesPerPixel == 1) { if (bytesPerPixel == 1) {
byte *ptr = (byte *)getBasePtr(x, y); byte *ptr = (byte *)getBasePtr(x, y);
if (x2 >= x)
memset(ptr, (byte)color, x2-x+1); memset(ptr, (byte)color, x2-x+1);
} else if (bytesPerPixel == 2) { } else if (bytesPerPixel == 2) {
uint16 *ptr = (uint16 *)getBasePtr(x, y); uint16 *ptr = (uint16 *)getBasePtr(x, y);
while (x++ <= x2) { Common::set_to(ptr, ptr + (x2-x+1), (uint16)color);
*ptr++ = (uint16)color;
}
} else { } else {
error("Surface::hLine: bytesPerPixel must be 1 or 2"); error("Surface::hLine: bytesPerPixel must be 1 or 2");
} }
@ -122,8 +123,7 @@ void Surface::vLine(int x, int y, int y2, uint32 color) {
} }
} }
void Surface::fillRect(const Common::Rect &rOld, uint32 color) { void Surface::fillRect(Common::Rect r, uint32 color) {
Common::Rect r(rOld);
r.clip(w, h); r.clip(w, h);
if (!r.isValidRect()) if (!r.isValidRect())
@ -142,9 +142,7 @@ void Surface::fillRect(const Common::Rect &rOld, uint32 color) {
} else if (bytesPerPixel == 2) { } else if (bytesPerPixel == 2) {
uint16 *ptr = (uint16 *)getBasePtr(r.left, r.top); uint16 *ptr = (uint16 *)getBasePtr(r.left, r.top);
while (height--) { while (height--) {
for (i = 0; i < width; i++) { Common::set_to(ptr, ptr + width, (uint16)color);
ptr[i] = (uint16)color;
}
ptr += pitch/2; ptr += pitch/2;
} }
} else { } else {
@ -159,6 +157,11 @@ void Surface::frameRect(const Common::Rect &r, uint32 color) {
vLine(r.right-1, r.top, r.bottom-1, color); vLine(r.right-1, r.top, r.bottom-1, color);
} }
// FIXME: LordHoto asks why is this in Surface, since this
// just supports 8bpp surfaces. Looks like someone wants
// to subclass Surface to add this or it should be extended
// to support 16bpp (or marked as just working for 8bpp
// surfaces).
void Surface::move(int dx, int dy, int height) { void Surface::move(int dx, int dy, int height) {
// Short circuit check - do we have to do anything anyway? // Short circuit check - do we have to do anything anyway?
if ((dx == 0 && dy == 0) || height <= 0) if ((dx == 0 && dy == 0) || height <= 0)

View file

@ -66,8 +66,9 @@ struct Surface {
void drawLine(int x0, int y0, int x1, int y1, uint32 color); void drawLine(int x0, int y0, int x1, int y1, uint32 color);
void hLine(int x, int y, int x2, uint32 color); void hLine(int x, int y, int x2, uint32 color);
void vLine(int x, int y, int y2, uint32 color); void vLine(int x, int y, int y2, uint32 color);
void fillRect(const Common::Rect &r, uint32 color); void fillRect(Common::Rect r, uint32 color);
void frameRect(const Common::Rect &r, uint32 color); void frameRect(const Common::Rect &r, uint32 color);
// See comment in graphics/surface.cpp about it
void move(int dx, int dy, int height); void move(int dx, int dy, int height);
}; };