Blender  V2.93
GHOST_Rect.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include "GHOST_Rect.h"
25 
27 {
28  if (i > 0) {
29  // Grow the rectangle
30  m_l -= i;
31  m_r += i;
32  m_t -= i;
33  m_b += i;
34  }
35  else if (i < 0) {
36  // Shrink the rectangle, check for insets larger than half the size
37  GHOST_TInt32 i2 = i * 2;
38  if (getWidth() > i2) {
39  m_l += i;
40  m_r -= i;
41  }
42  else {
43  m_l = m_l + ((m_r - m_l) / 2);
44  m_r = m_l;
45  }
46  if (getHeight() > i2) {
47  m_t += i;
48  m_b -= i;
49  }
50  else {
51  m_t = m_t + ((m_b - m_t) / 2);
52  m_b = m_t;
53  }
54  }
55 }
56 
58 {
59  bool lt = isInside(r.m_l, r.m_t);
60  bool rt = isInside(r.m_r, r.m_t);
61  bool lb = isInside(r.m_l, r.m_b);
62  bool rb = isInside(r.m_r, r.m_b);
64  if (lt && rt && lb && rb) {
65  // All points inside, rectangle is inside this
67  }
68  else if (!(lt || rt || lb || rb)) {
69  // None of the points inside
70  // Check to see whether the rectangle is larger than this one
71  if ((r.m_l < m_l) && (r.m_t < m_t) && (r.m_r > m_r) && (r.m_b > m_b)) {
73  }
74  else {
76  }
77  }
78  else {
79  // Some of the points inside, rectangle is partially inside
81  }
82  return v;
83 }
84 
86 {
87  GHOST_TInt32 offset = cx - (m_l + (m_r - m_l) / 2);
88  m_l += offset;
89  m_r += offset;
90  offset = cy - (m_t + (m_b - m_t) / 2);
91  m_t += offset;
92  m_b += offset;
93 }
94 
96 {
97  long w_2, h_2;
98 
99  w_2 = w >> 1;
100  h_2 = h >> 1;
101  m_l = cx - w_2;
102  m_t = cy - h_2;
103  m_r = m_l + w;
104  m_b = m_t + h;
105 }
106 
108 {
109  bool clipped = false;
110  if (r.m_l < m_l) {
111  r.m_l = m_l;
112  clipped = true;
113  }
114  if (r.m_t < m_t) {
115  r.m_t = m_t;
116  clipped = true;
117  }
118  if (r.m_r > m_r) {
119  r.m_r = m_r;
120  clipped = true;
121  }
122  if (r.m_b > m_b) {
123  r.m_b = m_b;
124  clipped = true;
125  }
126  return clipped;
127 }
int GHOST_TInt32
Definition: GHOST_Types.h:63
GHOST_TVisibility
Definition: GHOST_Types.h:125
@ GHOST_kFullyVisible
Definition: GHOST_Types.h:128
@ GHOST_kPartiallyVisible
Definition: GHOST_Types.h:127
@ GHOST_kNotVisible
Definition: GHOST_Types.h:126
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
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.cpp:57
virtual GHOST_TInt32 getWidth() const
Definition: GHOST_Rect.h:182
virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy)
Definition: GHOST_Rect.cpp:85
virtual void inset(GHOST_TInt32 i)
Definition: GHOST_Rect.cpp:26
virtual bool clip(GHOST_Rect &r) const
Definition: GHOST_Rect.cpp:107
GHOST_TInt32 m_l
Definition: GHOST_Rect.h:169
GHOST_TInt32 m_t
Definition: GHOST_Rect.h:171
GHOST_TInt32 m_r
Definition: GHOST_Rect.h:173
GHOST_TInt32 m_b
Definition: GHOST_Rect.h:175
virtual bool isInside(GHOST_TInt32 x, GHOST_TInt32 y) const
Definition: GHOST_Rect.h:261
virtual GHOST_TInt32 getHeight() const
Definition: GHOST_Rect.h:187