diff options
author | Paul Gilbert | 2012-06-18 19:50:29 +1000 |
---|---|---|
committer | Paul Gilbert | 2012-06-18 19:50:29 +1000 |
commit | 565bf7383a0000cf8564ac63da08a61778194254 (patch) | |
tree | bf4ae3ef20836881f58288c8a156b72802203b27 /engines | |
parent | f2e6b4615356d17205a1d4e04100f6de8676a194 (diff) | |
download | scummvm-rg350-565bf7383a0000cf8564ac63da08a61778194254.tar.gz scummvm-rg350-565bf7383a0000cf8564ac63da08a61778194254.tar.bz2 scummvm-rg350-565bf7383a0000cf8564ac63da08a61778194254.zip |
TONY: Refactored the RMRect topLeft/bottomRight properties into a cleaner implementation
Diffstat (limited to 'engines')
-rw-r--r-- | engines/tony/utils.cpp | 32 | ||||
-rw-r--r-- | engines/tony/utils.h | 17 |
2 files changed, 33 insertions, 16 deletions
diff --git a/engines/tony/utils.cpp b/engines/tony/utils.cpp index 7661c600da..647ef0ed82 100644 --- a/engines/tony/utils.cpp +++ b/engines/tony/utils.cpp @@ -843,10 +843,24 @@ RMDataStream &operator>>(RMDataStream &ds, RMPoint &p) { } /****************************************************************************\ +* RMPointReference methods +\****************************************************************************/ + +RMPointReference &RMPointReference::operator=(const RMPoint &p) { + _x = p._x; _y = p._y; + return *this; +} + +RMPointReference &RMPointReference::operator-=(const RMPoint &p) { + _x -= p._x; _y -= p._y; + return *this; +} + +/****************************************************************************\ * RMRect methods \****************************************************************************/ -RMRect::RMRect() { +RMRect::RMRect(): _topLeft(_x1, _y1), _bottomRight(_x2, _y2) { setEmpty(); } @@ -854,15 +868,15 @@ void RMRect::setEmpty() { _x1 = _y1 = _x2 = _y2 = 0; } -RMRect::RMRect(const RMPoint &p1, const RMPoint &p2) { +RMRect::RMRect(const RMPoint &p1, const RMPoint &p2): _topLeft(_x1, _y1), _bottomRight(_x2, _y2) { setRect(p1, p2); } -RMRect::RMRect(int X1, int Y1, int X2, int Y2) { +RMRect::RMRect(int X1, int Y1, int X2, int Y2): _topLeft(_x1, _y1), _bottomRight(_x2, _y2) { setRect(X1, Y1, X2, Y2); } -RMRect::RMRect(const RMRect &rc) { +RMRect::RMRect(const RMRect &rc): _topLeft(_x1, _y1), _bottomRight(_x2, _y2) { copyRect(rc); } @@ -891,16 +905,6 @@ void RMRect::copyRect(const RMRect &rc) { _y2 = rc._y2; } -RMPoint &RMRect::topLeft() { - // FIXME: This seems very bad - return *((RMPoint *)this); -} - -RMPoint &RMRect::bottomRight() { - // FIXME: This seems very bad - return *((RMPoint *)this + 1); -} - RMPoint RMRect::center() { return RMPoint((_x2 - _x1) / 2, (_y2 - _y1) / 2); } diff --git a/engines/tony/utils.h b/engines/tony/utils.h index c4f7386739..e7f943b231 100644 --- a/engines/tony/utils.h +++ b/engines/tony/utils.h @@ -247,10 +247,23 @@ public: friend RMDataStream &operator>>(RMDataStream &ds, RMPoint &p); }; +class RMPointReference { +public: + int &_x; + int &_y; + + RMPointReference(int &x, int &y): _x(x), _y(y) {} + RMPointReference &operator=(const RMPoint &p); + RMPointReference &operator-=(const RMPoint &p); + operator RMPoint() const { return RMPoint(_x, _y); } +}; + class RMRect { public: int _x1, _y1; int _x2, _y2; + RMPointReference _topLeft; + RMPointReference _bottomRight; public: RMRect(); @@ -259,8 +272,8 @@ public: RMRect(const RMRect &rc); // Attributes - RMPoint &topLeft(); - RMPoint &bottomRight(); + RMPointReference &topLeft() { return _topLeft; } + RMPointReference &bottomRight() { return _bottomRight; } RMPoint center(); int width() const; int height() const; |