Blender V5.0
GHOST_Rect.cc
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
8
9#include "GHOST_Rect.hh"
10
12{
13 if (i > 0) {
14 /* Grow the rectangle. */
15 l_ -= i;
16 r_ += i;
17 t_ -= i;
18 b_ += i;
19 }
20 else if (i < 0) {
21 /* Shrink the rectangle, check for insets larger than half the size. */
22 int32_t i2 = i * 2;
23 if (getWidth() > i2) {
24 l_ += i;
25 r_ -= i;
26 }
27 else {
28 l_ = l_ + ((r_ - l_) / 2);
29 r_ = l_;
30 }
31 if (getHeight() > i2) {
32 t_ += i;
33 b_ -= i;
34 }
35 else {
36 t_ = t_ + ((b_ - t_) / 2);
37 b_ = t_;
38 }
39 }
40}
41
43{
44 bool lt = isInside(r.l_, r.t_);
45 bool rt = isInside(r.r_, r.t_);
46 bool lb = isInside(r.l_, r.b_);
47 bool rb = isInside(r.r_, r.b_);
49 if (lt && rt && lb && rb) {
50 /* All points inside, rectangle is inside this. */
52 }
53 else if (!(lt || rt || lb || rb)) {
54 /* None of the points inside.
55 * Check to see whether the rectangle is larger than this one. */
56 if ((r.l_ < l_) && (r.t_ < t_) && (r.r_ > r_) && (r.b_ > b_)) {
58 }
59 else {
61 }
62 }
63 else {
64 /* Some of the points inside, rectangle is partially inside. */
66 }
67 return v;
68}
69
71{
72 int32_t offset = cx - (l_ + (r_ - l_) / 2);
73 l_ += offset;
74 r_ += offset;
75 offset = cy - (t_ + (b_ - t_) / 2);
76 t_ += offset;
77 b_ += offset;
78}
79
81{
82 long w_2, h_2;
83
84 w_2 = w >> 1;
85 h_2 = h >> 1;
86 l_ = cx - w_2;
87 t_ = cy - h_2;
88 r_ = l_ + w;
89 b_ = t_ + h;
90}
91
93{
94 bool clipped = false;
95 if (r.l_ < l_) {
96 r.l_ = l_;
97 clipped = true;
98 }
99 if (r.t_ < t_) {
100 r.t_ = t_;
101 clipped = true;
102 }
103 if (r.r_ > r_) {
104 r.r_ = r_;
105 clipped = true;
106 }
107 if (r.b_ > b_) {
108 r.b_ = b_;
109 clipped = true;
110 }
111 return clipped;
112}
GHOST_TVisibility
@ GHOST_kFullyVisible
@ GHOST_kPartiallyVisible
@ GHOST_kNotVisible
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
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 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 int32_t getHeight() const
int32_t b_
int32_t l_
virtual int32_t getWidth() const
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