aboutsummaryrefslogtreecommitdiff
path: root/common/rect.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/rect.h')
-rw-r--r--common/rect.h53
1 files changed, 11 insertions, 42 deletions
diff --git a/common/rect.h b/common/rect.h
index f71124434a..0cd10a2147 100644
--- a/common/rect.h
+++ b/common/rect.h
@@ -26,45 +26,10 @@
#ifndef COMMON_RECT_H
#define COMMON_RECT_H
-#include "common/scummsys.h"
-#include "common/util.h"
+#include "common/shape.h"
namespace Common {
-/*! @brief simple class for handling both 2D position and size
-
- This small class is an helper for position and size values.
-*/
-struct 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(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; };
- bool operator!=(const Point & p) const { return x != p.x || y != p.y; };
-
- /**
- * Return the square of the distance between this point and the point p.
- *
- * @param p the other point
- * @return the distance between this and p
- */
- uint sqrDist(const Point & p) const {
- int diffx = ABS(p.x - x);
- if (diffx >= 0x1000)
- return 0xFFFFFF;
-
- int diffy = ABS(p.y - y);
- if (diffy >= 0x1000)
- return 0xFFFFFF;
-
- return uint(diffx*diffx + diffy*diffy);
- }
-};
-
/*! @brief simple class for handling a rectangular zone.
This small class is an helper for rectangles.
@@ -83,7 +48,7 @@ struct Point {
When writing code using our Rect class, always keep this principle in mind!
*/
-struct Rect {
+struct Rect : public Shape {
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).
@@ -110,7 +75,7 @@ struct Rect {
@return true if the given position is inside this rectangle, false otherwise
*/
- bool contains(int16 x, int16 y) const {
+ virtual bool contains(int16 x, int16 y) const {
return (left <= x) && (x < right) && (top <= y) && (y < bottom);
}
@@ -120,7 +85,7 @@ struct Rect {
@return true if the given point is inside this rectangle, false otherwise
*/
- bool contains(const Point &p) const {
+ virtual bool contains(const Point &p) const {
return contains(p.x, p.y);
}
@@ -181,19 +146,19 @@ struct Rect {
return (left <= right && top <= bottom);
}
- void moveTo(int16 x, int16 y) {
+ virtual void moveTo(int16 x, int16 y) {
bottom += y - top;
right += x - left;
top = y;
left = x;
}
- void translate(int16 dx, int16 dy) {
+ virtual void translate(int16 dx, int16 dy) {
left += dx; right += dx;
top += dy; bottom += dy;
}
- void moveTo(const Point &p) {
+ virtual void moveTo(const Point &p) {
moveTo(p.x, p.y);
}
@@ -207,6 +172,10 @@ struct Rect {
h /= 2;
return Rect(cx - w, cy - h, cx + w, cy + h);
}
+
+ virtual Rect getBoundingRect() const {
+ return *this;
+ }
};
} // End of namespace Common