Blender V4.3
GHOST_Rect.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#pragma once
11
12#include "GHOST_Types.h"
13
21 public:
29 GHOST_Rect(int32_t l = 0, int32_t t = 0, int32_t r = 0, int32_t b = 0)
30 : m_l(l), m_t(t), m_r(r), m_b(b)
31 {
32 }
33
37 virtual ~GHOST_Rect() {}
38
43 virtual inline int32_t getWidth() const;
44
49 virtual inline int32_t getHeight() const;
50
58 virtual inline void set(int32_t l, int32_t t, int32_t r, int32_t b);
59
65 virtual inline bool isEmpty() const;
66
73 virtual inline bool isValid() const;
74
80 virtual void inset(int32_t i);
81
87 virtual inline void unionRect(const GHOST_Rect &r);
88
94 virtual inline void unionPoint(int32_t x, int32_t y);
95
101 virtual inline void wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAxisFlag axis);
107 virtual inline void clampPoint(int32_t &x, int32_t &y);
108
116 virtual inline bool isInside(int32_t x, int32_t y) const;
117
124
131 virtual void setCenter(int32_t cx, int32_t cy);
132
142 virtual void setCenter(int32_t cx, int32_t cy, int32_t w, int32_t h);
143
151 virtual bool clip(GHOST_Rect &r) const;
152
161
162#ifdef WITH_CXX_GUARDEDALLOC
163 MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_Rect")
164#endif
165};
166
168{
169 return m_r - m_l;
170}
171
173{
174 return m_b - m_t;
175}
176
178{
179 m_l = l;
180 m_t = t;
181 m_r = r;
182 m_b = b;
183}
184
185inline bool GHOST_Rect::isEmpty() const
186{
187 return (getWidth() == 0) || (getHeight() == 0);
188}
189
190inline bool GHOST_Rect::isValid() const
191{
192 return (m_l <= m_r) && (m_t <= m_b);
193}
194
196{
197 if (r.m_l < m_l) {
198 m_l = r.m_l;
199 }
200 if (r.m_r > m_r) {
201 m_r = r.m_r;
202 }
203 if (r.m_t < m_t) {
204 m_t = r.m_t;
205 }
206 if (r.m_b > m_b) {
207 m_b = r.m_b;
208 }
209}
210
212{
213 if (x < m_l) {
214 m_l = x;
215 }
216 if (x > m_r) {
217 m_r = x;
218 }
219 if (y < m_t) {
220 m_t = y;
221 }
222 if (y > m_b) {
223 m_b = y;
224 }
225}
226
228{
229 int32_t w = getWidth();
230 int32_t h = getHeight();
231
232 /* highly unlikely but avoid eternal loop */
233 if (w - ofs * 2 <= 0 || h - ofs * 2 <= 0) {
234 return;
235 }
236
237 if (axis & GHOST_kAxisX) {
238 while (x - ofs < m_l) {
239 x += w - (ofs * 2);
240 }
241 while (x + ofs > m_r) {
242 x -= w - (ofs * 2);
243 }
244 }
245 if (axis & GHOST_kAxisY) {
246 while (y - ofs < m_t) {
247 y += h - (ofs * 2);
248 }
249 while (y + ofs > m_b) {
250 y -= h - (ofs * 2);
251 }
252 }
253}
254
256{
257 if (x < m_l) {
258 x = m_l;
259 }
260 else if (x > m_r) {
261 x = m_r;
262 }
263
264 if (y < m_t) {
265 y = m_t;
266 }
267 else if (y > m_b) {
268 y = m_b;
269 }
270}
271
272inline bool GHOST_Rect::isInside(int32_t x, int32_t y) const
273{
274 return (x >= m_l) && (x <= m_r) && (y >= m_t) && (y <= m_b);
275}
GHOST_TVisibility
GHOST_TAxisFlag
@ GHOST_kAxisX
@ GHOST_kAxisY
ATTR_WARN_UNUSED_RESULT const BMLoop * l
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
virtual bool isEmpty() const
virtual GHOST_TVisibility getVisibility(GHOST_Rect &r) const
Definition GHOST_Rect.cc:42
virtual void inset(int32_t i)
Definition GHOST_Rect.cc:11
virtual ~GHOST_Rect()
Definition GHOST_Rect.hh:37
virtual bool isInside(int32_t x, int32_t y) const
int32_t m_l
virtual bool clip(GHOST_Rect &r) const
Definition GHOST_Rect.cc:92
virtual void setCenter(int32_t cx, int32_t cy)
Definition GHOST_Rect.cc:70
int32_t m_r
int32_t m_b
virtual void wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAxisFlag axis)
virtual void clampPoint(int32_t &x, int32_t &y)
virtual int32_t getHeight() const
virtual bool isValid() const
virtual void unionRect(const GHOST_Rect &r)
int32_t m_t
virtual void set(int32_t l, int32_t t, int32_t r, int32_t b)
virtual int32_t getWidth() const
virtual void unionPoint(int32_t x, int32_t y)
GHOST_Rect(int32_t l=0, int32_t t=0, int32_t r=0, int32_t b=0)
Definition GHOST_Rect.hh:29
local_group_size(16, 16) .push_constant(Type b
signed int int32_t
Definition stdint.h:77