Blender V4.3
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
9#include "GHOST_Rect.hh"
10
12{
13 if (i > 0) {
14 /* Grow the rectangle. */
15 m_l -= i;
16 m_r += i;
17 m_t -= i;
18 m_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 m_l += i;
25 m_r -= i;
26 }
27 else {
28 m_l = m_l + ((m_r - m_l) / 2);
29 m_r = m_l;
30 }
31 if (getHeight() > i2) {
32 m_t += i;
33 m_b -= i;
34 }
35 else {
36 m_t = m_t + ((m_b - m_t) / 2);
37 m_b = m_t;
38 }
39 }
40}
41
43{
44 bool lt = isInside(r.m_l, r.m_t);
45 bool rt = isInside(r.m_r, r.m_t);
46 bool lb = isInside(r.m_l, r.m_b);
47 bool rb = isInside(r.m_r, r.m_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.m_l < m_l) && (r.m_t < m_t) && (r.m_r > m_r) && (r.m_b > m_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 - (m_l + (m_r - m_l) / 2);
73 m_l += offset;
74 m_r += offset;
75 offset = cy - (m_t + (m_b - m_t) / 2);
76 m_t += offset;
77 m_b += offset;
78}
79
81{
82 long w_2, h_2;
83
84 w_2 = w >> 1;
85 h_2 = h >> 1;
86 m_l = cx - w_2;
87 m_t = cy - h_2;
88 m_r = m_l + w;
89 m_b = m_t + h;
90}
91
93{
94 bool clipped = false;
95 if (r.m_l < m_l) {
96 r.m_l = m_l;
97 clipped = true;
98 }
99 if (r.m_t < m_t) {
100 r.m_t = m_t;
101 clipped = true;
102 }
103 if (r.m_r > m_r) {
104 r.m_r = m_r;
105 clipped = true;
106 }
107 if (r.m_b > m_b) {
108 r.m_b = m_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
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 int32_t getHeight() const
int32_t m_t
virtual int32_t getWidth() const
signed int int32_t
Definition stdint.h:77