home *** CD-ROM | disk | FTP | other *** search
- #if !defined( _IRectangle_)
- #define _IRectangle_
-
- /**************************************************************/
- /* CLASS NAME: IRectangle */
- /* */
- /* DESCRIPTION : This file defines a class that represents */
- /* a rectangular area defined by two points that form */
- /* opposite corners of the rectangle. The rectangle is */
- /* represented via the lower left ('origin') and upper */
- /* right ('corner') corners. */
- /* */
- /* 'Mathematically,' a rectangle is considered to include */
- /* all the points on the lines that form its lower and */
- /* left edges. It does *not* include the points that lie */
- /* on either its upper or right edges. */
- /* */
- /* Such Rectangles are used by the various graphics and */
- /* windowing classes and their member functions. */
- /* */
- /* Hungarian notation is "rect". */
- /* */
- /* NOTES: This class is based closely on the Rectangle */
- /* class provided by Bill Law in Cary. Thanks Bill. */
- /* */
- /* CHANGE ACTIVITY: */
- /* DATE: INITIAL: DESCRIPTION */
- /* */
- /* 101091 RDL New Component */
- /* 012292 RDL Release 2.0 Changes */
- /* */
- /**************************************************************/
- /* Copyright (c) IBM Corporation 1992 */
- /**************************************************************/
-
- class IRectangle;
-
- #include <ibasetyp.hpp>
- #include <ipoint.hpp>
-
-
- class IRectangle /* rect */
- {
- public:
-
- /*****************************************************************/
- /* Instance Creation */
- /* */
- /* There are five basic categories of constructors: */
- /* */
- /* 1. Construct a null rectangle (0,0)x(0,0). */
- /* */
- /* 2. Construct a rectangle with two given points at opposite */
- /* corners. */
- /* */
- /* 3. Construct a rectangle given 4 (long) integers representing*/
- /* the coordinates for two points at opposite corners of the */
- /* rectangle. */
- /* */
- /* 4. Construct a rectangle with opposite corners at (0,0) and */
- /* (width, height); the width and height and be given either */
- /* as two (long) integers, an ISize, or an IPoint. */
- /* */
- /* 5. Construct a copy of a given IRectangle. */
- /* */
- /* Note: Rectangles are constucted by giving two points that */
- /* are taken as opposite corners, *not* as origin/corner */
- /* (or lower-left/upper-right corners); this ensures that */
- /* internally the origin/corner points always are such */
- /* that origin < corner. */
- /* */
- /*****************************************************************/
- IRectangle ( );
-
- IRectangle ( const IPoint& pt1,
- const IPoint& pt2 );
-
- IRectangle ( const IPoint& pt,
- const ISize& siz );
-
- IRectangle ( COORD coordXLeft,
- COORD coordYBottom,
- COORD coordXRight,
- COORD coordYTop );
- #if defined(OS2DEF_INCLUDED)
- IRectangle ( const RECTL& rectl);
- #endif
-
- IRectangle ( COORD coordWidth,
- COORD coordHeight );
- IRectangle ( const IPoint& pt );
- IRectangle ( const ISize& siz );
-
- IRectangle ( const IRectangle& rect );
-
- virtual ~IRectangle() {}
- /*****************************************************************/
- /* Displaying */
- /* */
- /* This function can be used to display a Rectangle on an output */
- /* stream, using the traditional left-shift operator (<<). The */
- /* rectangle will be displayed as "Rectangle(l,b,r,t)". */
- /* */
- /*****************************************************************/
- friend class ostream&
- operator<< ( class ostream& aStream,
- const IRectangle& rect );
- IString dump() const;
-
- /********************************************************************/
- /* Accessing */
- /* */
- /* These functions provide access to various tidbits of information */
- /* about the receiver. */
- /* */
- /* One can query any of eight points on the rectangle perimeter or */
- /* its center via functions with names like: */
- /* */
- /* < top | bottom >< Left | Center | Right > */
- /* or */
- /* < left | right >< Center > */
- /* or */
- /* center */
- /* */
- /* Other characteristics of the rectangle can be queried via: */
- /* */
- /* area - returns the area of the receiver */
- /* bottom - returns the y-coordinate of the horizontal line */
- /* forming the bottom of the receiver rectangle */
- /* extent - returns the ISize( width, height ) */
- /* height - returns the height of the receiver */
- /* left - returns the x-coordinate of the vertical line */
- /* forming the left side of the receiver rectangle */
- /* right - returns the x-coordinate of the vertical line */
- /* forming the right side of the receiver rectangle */
- /* top - returns the y-coordinate of the horizontal line */
- /* forming the top of the receiver rectangle */
- /* width - returns the width of the receiver */
- /********************************************************************/
-
- IPoint bottomLeft ( ) const;
- IPoint bottomCenter ( ) const;
- IPoint bottomRight ( ) const;
- IPoint center ( ) const;
- IPoint leftCenter ( ) const;
- IPoint rightCenter ( ) const;
- IPoint topLeft ( ) const;
- IPoint topCenter ( ) const;
- IPoint topRight ( ) const;
-
- ISize extent ( ) const;
-
- COORD area ( ) const;
- COORD bottom ( ) const;
- COORD height ( ) const;
- COORD left ( ) const;
- COORD right ( ) const;
- COORD top ( ) const;
- COORD width ( ) const;
- #if defined(OS2DEF_INCLUDED)
- RECTL rectl ( ) const;
- POINTL pointl ( ) const;
- #endif
- #if defined(GPI_INCLUDED)
- SIZEL sizel ( ) const;
- #endif
-
- /**********************************************************************/
- /* Comparison */
- /* */
- /* Two rectangles can be compared for equality or inequality. The */
- /* other comparison operators don't have reasonable interpretations*/
- /* so are not defined. */
- /**********************************************************************/
-
- Boolean operator == ( const IRectangle& rect ) const;
- Boolean operator != ( const IRectangle& rect ) const;
-
- /**********************************************************************/
- /* Manipulation */
- /* */
- /* These functions modify the receiving rectangle, changing its */
- /* size, proportions, and/or location. */
- /* */
- /* centerOn - move the receiver so that its center is at */
- /* the argument point */
- /* expandBy - move the corners of the receiver outward from */
- /* the center by the given amount; the argument can */
- /* be either a scalar (long int) or a point */
- /* moveBy - move the receiver by the amount specified by the */
- /* argument point */
- /* moveTo - move the receiver so that its bottom left corner */
- /* is at the argument point */
- /* operator = - assign the argument rectangle to the receiver; */
- /* this function is implemented as the default */
- /* assignment operator *should* be, but there */
- /* seems to be a Zortech bug so we must do it */
- /* ourselves */
- /* operator &= - reset the receiver to its intersection with the */
- /* argument rectangle */
- /* operator |= - reset the receiver to the smallest rectangle that */
- /* encompasses both it and the argument rectangle */
- /* scaleBy - scale the rectangle by the argument amount; it can */
- /* be either a scalar (long int or double) or a point */
- /* (which scales by different amounts in the x- and */
- /* y- directions) */
- /* shrinkBy - move the corners of the receiver inward toward */
- /* the center by the given amount (again, either a */
- /* scalar or point); shrinkBy( lAmount ) is always */
- /* equivalent to expandBy( - lAmount ), and vice */
- /* versa */
- /* */
- /* There are corresponding versions of each of these that return the */
- /* same result rectangle, but leave the receiver unmodified: */
- /* */
- /* centeredOn */
- /* expandedBy */
- /* movedBy */
- /* movedTo */
- /* operator & */
- /* operator | */
- /* scaledBy */
- /* shrunkBy */
- /* */
- /**********************************************************************/
-
- IRectangle& centerOn ( const IPoint& pt );
- IRectangle& expandBy ( const ISize& siz );
- IRectangle& expandBy ( COORD coord );
- IRectangle& moveBy ( const ISize& siz );
- IRectangle& moveTo ( const IPoint& pt );
- IRectangle& sizeTo ( const ISize& siz );
-
- IRectangle& operator = ( const IRectangle& rect );
- IRectangle& operator &= ( const IRectangle& rect );
- IRectangle& operator |= ( const IRectangle& rect );
-
- IRectangle& scaleBy ( const ISize& siz );
- IRectangle& scaleBy ( COORD coord );
- IRectangle& scaleBy ( double dAmount );
-
- IRectangle& shrinkBy ( const ISize& siz );
- IRectangle& shrinkBy ( COORD coord );
- IRectangle centeredOn ( const IPoint& pt ) const;
- IRectangle expandedBy ( const ISize& pt ) const;
- IRectangle expandedBy ( COORD coord ) const;
-
- IRectangle movedBy ( const ISize& siz ) const;
- IRectangle movedTo ( const IPoint& pt ) const;
- IRectangle sizedTo ( const ISize& siz ) const;
-
- IRectangle operator & ( const IRectangle& rect ) const;
- IRectangle operator | ( const IRectangle& rect ) const;
-
- IRectangle scaledBy ( const ISize& siz ) const;
- IRectangle scaledBy ( COORD coord ) const;
- IRectangle scaledBy ( double dAmount ) const;
- IRectangle shrunkBy ( const ISize& siz ) const;
- IRectangle shrunkBy ( COORD coord ) const;
-
- /************************************************************************/
- /* Testing */
- /* */
- /* These functions test various attributes of a rectangle: */
- /* */
- /* contains - returns true iff the receiver contains the argument*/
- /* point or rectangle */
- /* intersects - returns true iff the receiver and the argument */
- /* rectangle overlap */
- /* */
- /************************************************************************/
- Boolean contains ( const IPoint& pt ) const;
- Boolean contains ( const IRectangle& rect ) const;
-
- Boolean intersects ( const IRectangle& rect ) const;
-
- protected://------------------Protected--------------------------------------
-
- /************************************************************************/
- /* Data Members */
- /* */
- /* The rectangle object is maintained internally by its bottomLeft */
- /* and topRight corners, named 'origin' and 'corner', respectively. */
- /* */
- /************************************************************************/
-
- IPoint origin;
- IPoint corner;
-
- /* Function to 'correct' invalid rectangle after expansion or
- intersection.
- */
- IRectangle& validate ( );
- };
- #endif