aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2003-05-15 21:40:36 +0000
committerMax Horn2003-05-15 21:40:36 +0000
commit128f793be03e389891a0fe92373269bfb8b39114 (patch)
treec7e6978c8c0047bcae5744472a928bd47ee1b5e8 /common
parentc0e8eb0cb77807236897a764f4414cb5e33e7ba9 (diff)
downloadscummvm-rg350-128f793be03e389891a0fe92373269bfb8b39114.tar.gz
scummvm-rg350-128f793be03e389891a0fe92373269bfb8b39114.tar.bz2
scummvm-rg350-128f793be03e389891a0fe92373269bfb8b39114.zip
make SWAP a template function, so that it works for swapping non-int stuff, too; 'int16' should be sufficient for points/rects
svn-id: r7540
Diffstat (limited to 'common')
-rw-r--r--common/rect.h20
-rw-r--r--common/util.h4
2 files changed, 13 insertions, 11 deletions
diff --git a/common/rect.h b/common/rect.h
index 420be79ddd..8f983abe66 100644
--- a/common/rect.h
+++ b/common/rect.h
@@ -31,12 +31,12 @@ namespace ScummVM {
This small class is an helper for position and size values.
*/
struct Point {
- int x; //!< The horizontal part of the point
- int y; //!< The vertical part of the point
+ int16 x; //!< The horizontal part of the point
+ int16 y; //!< The vertical part of the point
Point() : x(0), y(0) {};
Point(const Point & p) : x(p.x), y(p.y) {};
- explicit Point(int x1, int y1) : x(x1), y(y1) {};
+ explicit Point(int16 x1, int16 y1) : x(x1), y(y1) {};
Point & operator=(const Point & p) { x = p.x; y = p.y; return *this; };
bool operator==(const Point & p) const { return x == p.x && y == p.y; };
};
@@ -47,14 +47,14 @@ struct Point {
It is mostly used by the blitter class.
*/
struct Rect {
- int top, left; //!< The point at the top left of the rectangle (part of the rect).
- int bottom, right; //!< The point at the bottom right of the rectangle (not part of the rect).
+ int16 top, left; //!< The point at the top left of the rectangle (part of the rect).
+ int16 bottom, right; //!< The point at the bottom right of the rectangle (not part of the rect).
Rect() : top(0), left(0), bottom(0), right(0) {}
- Rect(int x, int y) : top(0), left(0), bottom(x), right(y) {}
- Rect(int x1, int y1, int x2, int y2) : top(x1), left(y1), bottom(x2), right(y2) {}
- int width() const { return right - left; }
- int height() const { return top - bottom; }
+ Rect(int16 x, int16 y) : top(0), left(0), bottom(x), right(y) {}
+ Rect(int16 x1, int16 y1, int16 x2, int16 y2) : top(x1), left(y1), bottom(x2), right(y2) {}
+ int16 width() const { return right - left; }
+ int16 height() const { return top - bottom; }
/*! @brief check if given position is inside the rectangle
@@ -63,7 +63,7 @@ struct Rect {
@return true if the given position is inside the rectangle, false otherwise
*/
- bool isInside(int x, int y) const {
+ bool isInside(int16 x, int16 y) const {
return (left <= x) && (x < right) && (top <= y) && (y < bottom);
}
/*! @brief check if given point is inside the rectangle
diff --git a/common/util.h b/common/util.h
index 7123a8e4a1..330d9d369b 100644
--- a/common/util.h
+++ b/common/util.h
@@ -35,7 +35,9 @@
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
-static inline void SWAP(int &a, int &b) { int tmp = a; a = b; b = tmp; }
+template<class T>
+static inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
+
#define ARRAYSIZE(x) (sizeof(x) / sizeof(x[0]))
int RGBMatch(byte *palette, int r, int g, int b);