[Bf-blender-cvs] [5c814e75f2e] master: GHOST: add GHOST_Rect.clampPoint method

Campbell Barton noreply at git.blender.org
Sat Jun 18 07:07:54 CEST 2022


Commit: 5c814e75f2e866b31834e03f37a5918b021a1c1d
Author: Campbell Barton
Date:   Sat Jun 18 14:33:50 2022 +1000
Branches: master
https://developer.blender.org/rB5c814e75f2e866b31834e03f37a5918b021a1c1d

GHOST: add GHOST_Rect.clampPoint method

Method for clamping a point inside a rectangle.

===================================================================

M	intern/ghost/GHOST_Rect.h

===================================================================

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);



More information about the Bf-blender-cvs mailing list