Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-06-18 07:33:50 +0300
committerCampbell Barton <campbell@blender.org>2022-06-18 07:33:50 +0300
commit5c814e75f2e866b31834e03f37a5918b021a1c1d (patch)
tree68475acb835398c13ee652ef05ea117dc8943793
parent600c391a6559ae3113ecbf505490ace8ef1da828 (diff)
GHOST: add GHOST_Rect.clampPoint method
Method for clamping a point inside a rectangle.
-rw-r--r--intern/ghost/GHOST_Rect.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/intern/ghost/GHOST_Rect.h b/intern/ghost/GHOST_Rect.h
index a8082bf015a..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.
@@ -248,6 +254,23 @@ inline void GHOST_Rect::wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAx
}
}
+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;
+ }
+}
+
inline bool GHOST_Rect::isInside(int32_t x, int32_t y) const
{
return (x >= m_l) && (x <= m_r) && (y >= m_t) && (y <= m_b);