Blender V4.5
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
9
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() = default;
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 MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_Rect")
163};
164
166{
167 return m_r - m_l;
168}
169
171{
172 return m_b - m_t;
173}
174
176{
177 m_l = l;
178 m_t = t;
179 m_r = r;
180 m_b = b;
181}
182
183inline bool GHOST_Rect::isEmpty() const
184{
185 return (getWidth() == 0) || (getHeight() == 0);
186}
187
188inline bool GHOST_Rect::isValid() const
189{
190 return (m_l <= m_r) && (m_t <= m_b);
191}
192
194{
195 if (r.m_l < m_l) {
196 m_l = r.m_l;
197 }
198 if (r.m_r > m_r) {
199 m_r = r.m_r;
200 }
201 if (r.m_t < m_t) {
202 m_t = r.m_t;
203 }
204 if (r.m_b > m_b) {
205 m_b = r.m_b;
206 }
207}
208
210{
211 if (x < m_l) {
212 m_l = x;
213 }
214 if (x > m_r) {
215 m_r = x;
216 }
217 if (y < m_t) {
218 m_t = y;
219 }
220 if (y > m_b) {
221 m_b = y;
222 }
223}
224
226{
227 int32_t w = getWidth();
228 int32_t h = getHeight();
229
230 /* highly unlikely but avoid eternal loop */
231 if (w - ofs * 2 <= 0 || h - ofs * 2 <= 0) {
232 return;
233 }
234
235 if (axis & GHOST_kAxisX) {
236 while (x - ofs < m_l) {
237 x += w - (ofs * 2);
238 }
239 while (x + ofs > m_r) {
240 x -= w - (ofs * 2);
241 }
242 }
243 if (axis & GHOST_kAxisY) {
244 while (y - ofs < m_t) {
245 y += h - (ofs * 2);
246 }
247 while (y + ofs > m_b) {
248 y -= h - (ofs * 2);
249 }
250 }
251}
252
254{
255 if (x < m_l) {
256 x = m_l;
257 }
258 else if (x > m_r) {
259 x = m_r;
260 }
261
262 if (y < m_t) {
263 y = m_t;
264 }
265 else if (y > m_b) {
266 y = m_b;
267 }
268}
269
271{
272 return (x >= m_l) && (x <= m_r) && (y >= m_t) && (y <= m_b);
273}
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()=default
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
i
Definition text_draw.cc:230