Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include "GHOST_Rect.h" 00034 00035 00036 00037 void GHOST_Rect::inset(GHOST_TInt32 i) 00038 { 00039 if (i > 0) { 00040 // Grow the rectangle 00041 m_l -= i; 00042 m_r += i; 00043 m_t -= i; 00044 m_b += i; 00045 } 00046 else if (i < 0) { 00047 // Shrink the rectangle, check for insets larger than half the size 00048 GHOST_TInt32 i2 = i * 2; 00049 if (getWidth() > i2) { 00050 m_l += i; 00051 m_r -= i; 00052 } 00053 else { 00054 m_l = m_l + ((m_r - m_l) / 2); 00055 m_r = m_l; 00056 } 00057 if (getHeight() > i2) { 00058 m_t += i; 00059 m_b -= i; 00060 } 00061 else { 00062 m_t = m_t + ((m_b - m_t) / 2); 00063 m_b = m_t; 00064 } 00065 } 00066 } 00067 00068 00069 GHOST_TVisibility GHOST_Rect::getVisibility(GHOST_Rect& r) const 00070 { 00071 bool lt = isInside(r.m_l, r.m_t); 00072 bool rt = isInside(r.m_r, r.m_t); 00073 bool lb = isInside(r.m_l, r.m_b); 00074 bool rb = isInside(r.m_r, r.m_b); 00075 GHOST_TVisibility v; 00076 if (lt && rt && lb && rb) { 00077 // All points inside, rectangle is inside this 00078 v = GHOST_kFullyVisible; 00079 } 00080 else if (!(lt || rt || lb || rb)) { 00081 // None of the points inside 00082 // Check to see whether the rectangle is larger than this one 00083 if ((r.m_l < m_l) && (r.m_t < m_t) && (r.m_r > m_r) && (r.m_b > m_b)) { 00084 v = GHOST_kPartiallyVisible; 00085 } 00086 else { 00087 v = GHOST_kNotVisible; 00088 } 00089 } 00090 else { 00091 // Some of the points inside, rectangle is partially inside 00092 v = GHOST_kPartiallyVisible; 00093 } 00094 return v; 00095 } 00096 00097 00098 void GHOST_Rect::setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy) 00099 { 00100 GHOST_TInt32 offset = cx - (m_l + (m_r - m_l)/2); 00101 m_l += offset; 00102 m_r += offset; 00103 offset = cy - (m_t + (m_b - m_t)/2); 00104 m_t += offset; 00105 m_b += offset; 00106 } 00107 00108 void GHOST_Rect::setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy, GHOST_TInt32 w, GHOST_TInt32 h) 00109 { 00110 long w_2, h_2; 00111 00112 w_2 = w >> 1; 00113 h_2 = h >> 1; 00114 m_l = cx - w_2; 00115 m_t = cy - h_2; 00116 m_r = m_l + w; 00117 m_b = m_t + h; 00118 } 00119 00120 bool GHOST_Rect::clip(GHOST_Rect& r) const 00121 { 00122 bool clipped = false; 00123 if (r.m_l < m_l) { 00124 r.m_l = m_l; 00125 clipped = true; 00126 } 00127 if (r.m_t < m_t) { 00128 r.m_t = m_t; 00129 clipped = true; 00130 } 00131 if (r.m_r > m_r) { 00132 r.m_r = m_r; 00133 clipped = true; 00134 } 00135 if (r.m_b > m_b) { 00136 r.m_b = m_b; 00137 clipped = true; 00138 } 00139 return clipped; 00140 } 00141