diff options
Diffstat (limited to 'intern/ghost/GHOST_Rect.h')
-rw-r--r-- | intern/ghost/GHOST_Rect.h | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/intern/ghost/GHOST_Rect.h b/intern/ghost/GHOST_Rect.h index 0a5561b7d68..1cbc75fe60b 100644 --- a/intern/ghost/GHOST_Rect.h +++ b/intern/ghost/GHOST_Rect.h @@ -101,6 +101,12 @@ class GHOST_Rect { * \param y: The y-coordinate of the point. */ virtual inline void wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAxisFlag axis); + /** + * Confine x & y within the rectangle (inclusive). + * \param x: The x-coordinate of the point. + * \param y: The y-coordinate of the point. + */ + virtual inline void clampPoint(int32_t &x, int32_t &y); /** * Returns whether the point is inside this rectangle. @@ -190,26 +196,34 @@ inline bool GHOST_Rect::isValid() const inline void GHOST_Rect::unionRect(const GHOST_Rect &r) { - if (r.m_l < m_l) + if (r.m_l < m_l) { m_l = r.m_l; - if (r.m_r > m_r) + } + if (r.m_r > m_r) { m_r = r.m_r; - if (r.m_t < m_t) + } + if (r.m_t < m_t) { m_t = r.m_t; - if (r.m_b > m_b) + } + if (r.m_b > m_b) { m_b = r.m_b; + } } inline void GHOST_Rect::unionPoint(int32_t x, int32_t y) { - if (x < m_l) + if (x < m_l) { m_l = x; - if (x > m_r) + } + if (x > m_r) { m_r = x; - if (y < m_t) + } + if (y < m_t) { m_t = y; - if (y > m_b) + } + if (y > m_b) { m_b = y; + } } inline void GHOST_Rect::wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAxisFlag axis) @@ -223,16 +237,37 @@ inline void GHOST_Rect::wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAx } if (axis & GHOST_kAxisX) { - while (x - ofs < m_l) + while (x - ofs < m_l) { x += w - (ofs * 2); - while (x + ofs > m_r) + } + while (x + ofs > m_r) { x -= w - (ofs * 2); + } } if (axis & GHOST_kGrabAxisY) { - while (y - ofs < m_t) + while (y - ofs < m_t) { y += h - (ofs * 2); - while (y + ofs > m_b) + } + while (y + ofs > m_b) { y -= h - (ofs * 2); + } + } +} + +inline void GHOST_Rect::clampPoint(int32_t &x, int32_t &y) +{ + if (x < m_l) { + x = m_l; + } + else if (x > m_r) { + x = m_r; + } + + if (y < m_t) { + y = m_t; + } + else if (y > m_b) { + y = m_b; } } |