Blender V5.0
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 : l_(l), t_(t), r_(r), 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 r_ - l_;
168}
169
171{
172 return b_ - t_;
173}
174
176{
177 l_ = l;
178 t_ = t;
179 r_ = r;
180 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 (l_ <= r_) && (t_ <= b_);
191}
192
194{
195 if (r.l_ < l_) {
196 l_ = r.l_;
197 }
198 if (r.r_ > r_) {
199 r_ = r.r_;
200 }
201 if (r.t_ < t_) {
202 t_ = r.t_;
203 }
204 if (r.b_ > b_) {
205 b_ = r.b_;
206 }
207}
208
210{
211 if (x < l_) {
212 l_ = x;
213 }
214 if (x > r_) {
215 r_ = x;
216 }
217 if (y < t_) {
218 t_ = y;
219 }
220 if (y > b_) {
221 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 < l_) {
237 x += w - (ofs * 2);
238 }
239 while (x + ofs > r_) {
240 x -= w - (ofs * 2);
241 }
242 }
243 if (axis & GHOST_kAxisY) {
244 while (y - ofs < t_) {
245 y += h - (ofs * 2);
246 }
247 while (y + ofs > b_) {
248 y -= h - (ofs * 2);
249 }
250 }
251}
252
254{
255 if (x < l_) {
256 x = l_;
257 }
258 else if (x > r_) {
259 x = r_;
260 }
261
262 if (y < t_) {
263 y = t_;
264 }
265 else if (y > b_) {
266 y = b_;
267 }
268}
269
271{
272 return (x >= l_) && (x <= r_) && (y >= t_) && (y <= 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
int32_t t_
virtual ~GHOST_Rect()=default
virtual bool isInside(int32_t x, int32_t y) const
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 r_
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
int32_t b_
virtual bool isValid() const
virtual void unionRect(const GHOST_Rect &r)
int32_t l_
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