aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--graphics/surface.cpp23
-rw-r--r--graphics/surface.h3
2 files changed, 15 insertions, 11 deletions
diff --git a/graphics/surface.cpp b/graphics/surface.cpp
index ccf5523be0..84b833adfd 100644
--- a/graphics/surface.cpp
+++ b/graphics/surface.cpp
@@ -22,6 +22,7 @@
* $Id$
*/
+#include "common/algorithm.h"
#include "common/util.h"
#include "graphics/primitives.h"
#include "graphics/surface.h"
@@ -78,15 +79,15 @@ void Surface::hLine(int x, int y, int x2, uint32 color) {
if (x2 >= w)
x2 = w - 1;
+ if (x2 < x)
+ return;
+
if (bytesPerPixel == 1) {
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) {
uint16 *ptr = (uint16 *)getBasePtr(x, y);
- while (x++ <= x2) {
- *ptr++ = (uint16)color;
- }
+ Common::set_to(ptr, ptr + (x2-x+1), (uint16)color);
} else {
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) {
- Common::Rect r(rOld);
+void Surface::fillRect(Common::Rect r, uint32 color) {
r.clip(w, h);
if (!r.isValidRect())
@@ -142,9 +142,7 @@ void Surface::fillRect(const Common::Rect &rOld, uint32 color) {
} else if (bytesPerPixel == 2) {
uint16 *ptr = (uint16 *)getBasePtr(r.left, r.top);
while (height--) {
- for (i = 0; i < width; i++) {
- ptr[i] = (uint16)color;
- }
+ Common::set_to(ptr, ptr + width, (uint16)color);
ptr += pitch/2;
}
} else {
@@ -159,6 +157,11 @@ void Surface::frameRect(const Common::Rect &r, uint32 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) {
// Short circuit check - do we have to do anything anyway?
if ((dx == 0 && dy == 0) || height <= 0)
diff --git a/graphics/surface.h b/graphics/surface.h
index f583e4a81f..3e42b69c69 100644
--- a/graphics/surface.h
+++ b/graphics/surface.h
@@ -66,8 +66,9 @@ struct Surface {
void drawLine(int x0, int y0, int x1, int y1, uint32 color);
void hLine(int x, int y, int x2, 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);
+ // See comment in graphics/surface.cpp about it
void move(int dx, int dy, int height);
};