Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

TRect.h

Go to the documentation of this file.
00001 /* 00002 File: TRect.h 00003 00004 Version: 1.0 00005 00006 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. 00007 ("Apple") in consideration of your agreement to the following terms, and your 00008 use, installation, modification or redistribution of this Apple software 00009 constitutes acceptance of these terms. If you do not agree with these terms, 00010 please do not use, install, modify or redistribute this Apple software. 00011 00012 In consideration of your agreement to abide by the following terms, and subject 00013 to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs 00014 copyrights in this original Apple software (the "Apple Software"), to use, 00015 reproduce, modify and redistribute the Apple Software, with or without 00016 modifications, in source and/or binary forms; provided that if you redistribute 00017 the Apple Software in its entirety and without modifications, you must retain 00018 this notice and the following text and disclaimers in all such redistributions of 00019 the Apple Software. Neither the name, trademarks, service marks or logos of 00020 Apple Computer, Inc. may be used to endorse or promote products derived from the 00021 Apple Software without specific prior written permission from Apple. Except as 00022 expressly stated in this notice, no other rights or licenses, express or implied, 00023 are granted by Apple herein, including but not limited to any patent rights that 00024 may be infringed by your derivative works or by other works in which the Apple 00025 Software may be incorporated. 00026 00027 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO 00028 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED 00029 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00030 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN 00031 COMBINATION WITH YOUR PRODUCTS. 00032 00033 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR 00034 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00035 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00036 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION 00037 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT 00038 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN 00039 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00040 00041 Copyright © 2002 Apple Computer, Inc., All Rights Reserved 00042 */ 00043 00044 #ifndef TRect_H_ 00045 #define TRect_H_ 00046 00047 #include <Carbon/Carbon.h> 00048 00049 class TRect 00050 : public HIRect 00051 { 00052 public: 00053 // Construction/Destruction 00054 TRect(); 00055 TRect( 00056 const HIRect* inRect ); 00057 TRect( 00058 const HIRect& inRect ); 00059 TRect( 00060 const HIPoint& inOrigin, 00061 const HISize& inSize ); 00062 TRect( 00063 float inX, 00064 float inY, 00065 float inWidth, 00066 float inHeight ); 00067 TRect( 00068 const Rect& inRect ); 00069 ~TRect(); 00070 00071 // Operators 00072 operator HIRect*() 00073 { return this; } 00074 operator Rect() const; 00075 00076 // Accessors 00077 float MinX() const 00078 { return CGRectGetMinX( *this ); } 00079 float MaxX() const 00080 { return CGRectGetMaxX( *this ); } 00081 float MinY() const 00082 { return CGRectGetMinY( *this ); } 00083 float MaxY() const 00084 { return CGRectGetMaxY( *this ); } 00085 00086 float Width() const 00087 { return CGRectGetWidth( *this ); } 00088 float Height() const 00089 { return CGRectGetHeight( *this ); } 00090 00091 const HIPoint& Origin() const 00092 { return origin; } 00093 const HISize& Size() const 00094 { return size; } 00095 00096 float CenterX() const 00097 { return CGRectGetMidX( *this ); } 00098 float CenterY() const 00099 { return CGRectGetMidY( *this ); } 00100 HIPoint Center() const; 00101 00102 // Modifiers 00103 const HIRect& Inset( 00104 float inX, 00105 float inY ); 00106 const HIRect& Outset( 00107 float inX, 00108 float inY ); 00109 const HIRect& MoveBy( 00110 float inDx, 00111 float inDy ); 00112 const HIRect& MoveTo( 00113 float inX, 00114 float inY ); 00115 00116 const HIRect& Set( 00117 const HIRect* inRect ); 00118 const HIRect& Set( 00119 const HIRect& inRect ); 00120 const HIRect& Set( 00121 float inX, 00122 float inY, 00123 float inWidth, 00124 float inHeight ); 00125 const HIRect& Set( 00126 const Rect* inRect ); 00127 00128 const HIRect& SetAroundCenter( 00129 float inCenterX, 00130 float inCenterY, 00131 float inWidth, 00132 float inHeight ); 00133 00134 const HIRect& SetWidth( 00135 float inWidth ); 00136 const HIRect& SetHeight( 00137 float inHeight ); 00138 00139 const HIRect& SetOrigin( 00140 const HIPoint& inOrigin ); 00141 const HIRect& SetOrigin( 00142 float inX, 00143 float inY ); 00144 const HIRect& SetSize( 00145 const HISize& inSize ); 00146 const HIRect& SetSize( 00147 float inWidth, 00148 float inHeight ); 00149 00150 // Tests 00151 bool Contains( 00152 const HIPoint& inPoint ); 00153 bool Contains( 00154 const HIRect& inRect ); 00155 bool Contains( 00156 const Point& inPoint ); 00157 bool Contains( 00158 const Rect& inRect ); 00159 }; 00160 00161 //----------------------------------------------------------------------------------- 00162 // TRect constructor 00163 //----------------------------------------------------------------------------------- 00164 // 00165 inline 00166 TRect::TRect() 00167 { 00168 } 00169 00170 //----------------------------------------------------------------------------------- 00171 // TRect constructor 00172 //----------------------------------------------------------------------------------- 00173 // 00174 inline 00175 TRect::TRect( 00176 const HIRect* inRect ) 00177 { 00178 *this = *inRect; 00179 } 00180 00181 //----------------------------------------------------------------------------------- 00182 // TRect constructor 00183 //----------------------------------------------------------------------------------- 00184 // 00185 inline 00186 TRect::TRect( 00187 const HIRect& inRect ) 00188 { 00189 origin = inRect.origin; 00190 size = inRect.size; 00191 } 00192 00193 //----------------------------------------------------------------------------------- 00194 // TRect constructor 00195 //----------------------------------------------------------------------------------- 00196 // 00197 inline 00198 TRect::TRect( 00199 const HIPoint& inOrigin, 00200 const HISize& inSize ) 00201 { 00202 origin = inOrigin; 00203 size = inSize; 00204 } 00205 00206 //----------------------------------------------------------------------------------- 00207 // TRect constructor 00208 //----------------------------------------------------------------------------------- 00209 // 00210 inline 00211 TRect::TRect( 00212 float inX, 00213 float inY, 00214 float inWidth, 00215 float inHeight ) 00216 { 00217 *this = CGRectMake( inX, inY, inWidth, inHeight ); 00218 } 00219 00220 //----------------------------------------------------------------------------------- 00221 // TRect destructor 00222 //----------------------------------------------------------------------------------- 00223 // 00224 inline 00225 TRect::~TRect() 00226 { 00227 } 00228 00229 //----------------------------------------------------------------------------------- 00230 // TRect constructor 00231 //----------------------------------------------------------------------------------- 00232 // 00233 inline 00234 TRect::TRect( 00235 const Rect& inRect ) 00236 { 00237 Set( &inRect ); 00238 } 00239 00240 //----------------------------------------------------------------------------------- 00241 // Rect operator 00242 //----------------------------------------------------------------------------------- 00243 // Converts the HIRect to a QD rect and returns it 00244 // 00245 inline 00246 TRect::operator Rect() const 00247 { 00248 Rect qdRect; 00249 00250 qdRect.top = (SInt16) MinY(); 00251 qdRect.left = (SInt16) MinX(); 00252 qdRect.bottom = (SInt16) MaxY(); 00253 qdRect.right = (SInt16) MaxX(); 00254 00255 return qdRect; 00256 } 00257 00258 //----------------------------------------------------------------------------------- 00259 // Center 00260 //----------------------------------------------------------------------------------- 00261 // 00262 inline HIPoint 00263 TRect::Center() const 00264 { 00265 return CGPointMake( CGRectGetMidX( *this ), CGRectGetMidY( *this ) ); 00266 } 00267 00268 //----------------------------------------------------------------------------------- 00269 // Inset 00270 //----------------------------------------------------------------------------------- 00271 // 00272 inline const HIRect& 00273 TRect::Inset( 00274 float inX, 00275 float inY ) 00276 { 00277 *this = CGRectInset( *this, inX, inY ); 00278 00279 return *this; 00280 } 00281 00282 //----------------------------------------------------------------------------------- 00283 // Outset 00284 //----------------------------------------------------------------------------------- 00285 // 00286 inline const HIRect& 00287 TRect::Outset( 00288 float inX, 00289 float inY ) 00290 { 00291 *this = CGRectInset( *this, -inX, -inY ); 00292 00293 return *this; 00294 } 00295 00296 //----------------------------------------------------------------------------------- 00297 // MoveBy 00298 //----------------------------------------------------------------------------------- 00299 // 00300 inline const HIRect& 00301 TRect::MoveBy( 00302 float inDx, 00303 float inDy ) 00304 { 00305 origin = CGPointMake( MinX() + inDx, MinY() + inDy ); 00306 00307 return *this; 00308 } 00309 00310 //----------------------------------------------------------------------------------- 00311 // MoveTo 00312 //----------------------------------------------------------------------------------- 00313 // 00314 inline const HIRect& 00315 TRect::MoveTo( 00316 float inX, 00317 float inY ) 00318 { 00319 origin = CGPointMake( inX, inY ); 00320 00321 return *this; 00322 } 00323 00324 //----------------------------------------------------------------------------------- 00325 // Set 00326 //----------------------------------------------------------------------------------- 00327 // 00328 inline const HIRect& 00329 TRect::Set( 00330 const HIRect* inRect ) 00331 { 00332 *this = *inRect; 00333 00334 return *this; 00335 } 00336 00337 //----------------------------------------------------------------------------------- 00338 // Set 00339 //----------------------------------------------------------------------------------- 00340 // 00341 inline const HIRect& 00342 TRect::Set( 00343 const HIRect& inRect ) 00344 { 00345 *this = inRect; 00346 00347 return *this; 00348 } 00349 00350 //----------------------------------------------------------------------------------- 00351 // Set 00352 //----------------------------------------------------------------------------------- 00353 // 00354 inline const HIRect& 00355 TRect::Set( 00356 float inX, 00357 float inY, 00358 float inWidth, 00359 float inHeight ) 00360 { 00361 *this = CGRectMake( inX, inY, inWidth, inHeight ); 00362 00363 return *this; 00364 } 00365 00366 //----------------------------------------------------------------------------------- 00367 // Set 00368 //----------------------------------------------------------------------------------- 00369 // 00370 inline const HIRect& 00371 TRect::Set( 00372 const Rect* inRect ) 00373 { 00374 origin.x = inRect->left; 00375 origin.y = inRect->top; 00376 size.width = inRect->right - inRect->left; 00377 size.height = inRect->bottom - inRect->top; 00378 00379 return *this; 00380 } 00381 00382 //----------------------------------------------------------------------------------- 00383 // SetAroundCenter 00384 //----------------------------------------------------------------------------------- 00385 // Sets the rectangle by specifying dimensions around a center point 00386 // 00387 inline const HIRect& 00388 TRect::SetAroundCenter( 00389 float inCenterX, 00390 float inCenterY, 00391 float inWidth, 00392 float inHeight ) 00393 { 00394 *this = CGRectMake( inCenterX - inWidth/2, inCenterY - inHeight/2, inWidth, inHeight ); 00395 00396 return *this; 00397 } 00398 00399 //----------------------------------------------------------------------------------- 00400 // SetWidth 00401 //----------------------------------------------------------------------------------- 00402 // 00403 inline const HIRect& 00404 TRect::SetWidth( 00405 float inWidth ) 00406 { 00407 size.width = inWidth; 00408 00409 return *this; 00410 } 00411 00412 //----------------------------------------------------------------------------------- 00413 // SetHeight 00414 //----------------------------------------------------------------------------------- 00415 // 00416 inline const HIRect& 00417 TRect::SetHeight( 00418 float inHeight ) 00419 { 00420 size.height = inHeight; 00421 00422 return *this; 00423 } 00424 00425 //----------------------------------------------------------------------------------- 00426 // SetOrigin 00427 //----------------------------------------------------------------------------------- 00428 // 00429 inline const HIRect& 00430 TRect::SetOrigin( 00431 const HIPoint& inOrigin ) 00432 { 00433 origin = inOrigin; 00434 00435 return *this; 00436 } 00437 00438 //----------------------------------------------------------------------------------- 00439 // SetOrigin 00440 //----------------------------------------------------------------------------------- 00441 // 00442 inline const HIRect& 00443 TRect::SetOrigin( 00444 float inX, 00445 float inY ) 00446 { 00447 origin = CGPointMake( inX, inY ); 00448 00449 return *this; 00450 } 00451 00452 //----------------------------------------------------------------------------------- 00453 // SetSize 00454 //----------------------------------------------------------------------------------- 00455 // 00456 inline const HIRect& 00457 TRect::SetSize( 00458 const HISize& inSize ) 00459 { 00460 size = inSize; 00461 00462 return *this; 00463 } 00464 00465 //----------------------------------------------------------------------------------- 00466 // SetSize 00467 //----------------------------------------------------------------------------------- 00468 // 00469 inline const HIRect& 00470 TRect::SetSize( 00471 float inWidth, 00472 float inHeight ) 00473 { 00474 size = CGSizeMake( inWidth, inHeight ); 00475 00476 return *this; 00477 } 00478 00479 //----------------------------------------------------------------------------------- 00480 // Contains 00481 //----------------------------------------------------------------------------------- 00482 // 00483 inline bool 00484 TRect::Contains( 00485 const HIPoint& inPoint ) 00486 { 00487 return CGRectContainsPoint( *this, inPoint ); 00488 } 00489 00490 //----------------------------------------------------------------------------------- 00491 // Contains 00492 //----------------------------------------------------------------------------------- 00493 // 00494 inline bool 00495 TRect::Contains( 00496 const HIRect& inRect ) 00497 { 00498 return CGRectContainsRect( *this, inRect ); 00499 } 00500 00501 //----------------------------------------------------------------------------------- 00502 // Contains 00503 //----------------------------------------------------------------------------------- 00504 // 00505 inline bool 00506 TRect::Contains( 00507 const Point& inPoint ) 00508 { 00509 return Contains( CGPointMake( inPoint.h, inPoint.v ) ); 00510 } 00511 00512 //----------------------------------------------------------------------------------- 00513 // Contains 00514 //----------------------------------------------------------------------------------- 00515 // 00516 inline bool 00517 TRect::Contains( 00518 const Rect& inRect ) 00519 { 00520 return Contains( CGRectMake( inRect.left, inRect.top, 00521 inRect.right - inRect.left, inRect.bottom - inRect.top ) ); 00522 } 00523 00524 #endif // TRect_H_





Generated on Sun May 23 09:05:17 2004 for AUGUI Framework by doxygen1.3.7

hosted on SourceForge.net Logo