home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IRECT.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
19KB
|
335 lines
#ifndef _IRECT_
#define _IRECT_
/*******************************************************************************
* FILE NAME: irect.hpp *
* *
* DESCRIPTION: *
* Declaration of the class(es): *
* IRectangle - rectangle class *
* *
* COPYRIGHT: *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#ifndef _IBASE_
#include <ibase.hpp>
#endif
#ifndef _IPOINT_
#include <ipoint.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
struct _RECTL;
class IRectangle : public IBase {
typedef IBase
Inherited;
/*******************************************************************************
* Objects of the IRectangle class represent a rectangular area defined by two *
* points that form opposite corners of the rectangle. The rectangle is *
* represented by 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. *
* *
* IRectangles are used by the various graphics and windowing classes and *
* their member functions. *
*******************************************************************************/
public:
/*------------------------------ Related Types ---------------------------------
| The following related type is defined for this class: |
| Coord - Type of the coordinate values; this must match the type of the |
| coordinates supported by the IPair class. |
------------------------------------------------------------------------------*/
typedef IPair::Coord Coord;
/*------------------------------- Constructors ---------------------------------
| You can construct instances of this class in the following ways: |
| |
| - Construct a null rectangle (0,0)x(0,0); this is the default. |
| - Construct a rectangle with two given points at opposite corners. |
| - Construct a rectangle at a given point (presumed to be the lower left |
| corner) and a given size. |
| - Construct a rectangle given four values that represent the coordinates |
| for two points at opposite corners. |
| - Construct a rectangle from a Presentation Manager Toolkit RECTL |
| structure. |
| - Construct a rectangle with opposite corners at (0,0) and (width, |
| height); the width and height can be given either as two (long) |
| integers or an IPair (ordered pair of coordinates). |
| |
| NOTE: Rectangles are constucted by giving two points that are taken as |
| opposite corners, not as origin and corner (or lower-left and |
| upper-right corners); this ensures that internally the origin and |
| corner points always are such that origin <= corner. |
------------------------------------------------------------------------------*/
IRectangle ( );
IRectangle ( const IPoint &pt1,
const IPoint &pt2 );
IRectangle ( const IPoint &pt,
const ISize &size );
IRectangle ( Coord left,
Coord bottom,
Coord right,
Coord top );
IRectangle ( const struct _RECTL &rectl);
IRectangle ( Coord width,
Coord height );
IRectangle ( const IPair &aPair );
/*-------------------------------- Accessors -----------------------------------
| Use the following functions to access information about the receiver. You |
| can query any of nine points on the rectangle perimeter or its center by |
| using these functions: |
| |
| topLeft - Returns the X- and Y-coordinates of the top left corner of |
| the rectangle. |
| topCenter - Returns the X- and Y-coordinates of the top center point |
| of the rectangle. |
| topRight - Returns the X- and Y-coordinates of the top right corner |
| of the rectangle. |
| leftCenter - Returns the X- and Y-coordinates of the left center point |
| of the rectangle. |
| center - Returns the X- and Y-coordinates of the center point of |
| the rectangle. |
| rightCenter - Returns the X- and Y-coordinates of the right center point |
| of the rectangle. |
| bottomLeft - Returns the X- and Y-coordinates of the bottom left corner |
| of the rectangle. |
| bottomCenter - Returns the X- and Y-coordinates of the bottom center |
| point of the rectangle. |
| bottomRight - Returns the X- and Y-coordinates of the bottom right |
| corner of the rectangle. |
| |
| Other characteristics of the rectangle can be queried using: |
| |
| area - Returns the area of the rectangle. |
| bottom - Returns the Y-coordinate of the horizontal line that forms the |
| bottom of the rectangle. |
| height - Returns the height of the rectangle. |
| left - Returns the X-coordinate of the vertical line that forms the |
| left side of the rectangle. |
| right - Returns the X-coordinate of the vertical line that forms the |
| right side of the rectangle. |
| size - Returns the ISize(width, height). |
| top - Returns the Y-coordinate of the horizontal line that forms the |
| top of the rectangle. |
| width - Returns the width of the rectangle. |
------------------------------------------------------------------------------*/
IPoint
bottomLeft ( ) const,
bottomCenter ( ) const,
bottomRight ( ) const,
center ( ) const,
leftCenter ( ) const,
rightCenter ( ) const,
topLeft ( ) const,
topCenter ( ) const,
topRight ( ) const;
ISize
size ( ) const;
Coord
area ( ) const,
bottom ( ) const,
height ( ) const,
left ( ) const,
right ( ) const,
top ( ) const,
width ( ) const;
/*-------------------------------- Conversion ----------------------------------
| Use the following functions to convert a rectangle into various formats: |
| asRECTL - Renders the rectangle as a Presentation Manager Toolkit |
| RECTL structure. |
| asString - Renders the rectangle as an |
| 'IString( "IRectangle(x1,y1,x2,y2)" )'. |
| asDebugInfo - Renders the rectangle as a diagnostic representation. |
------------------------------------------------------------------------------*/
struct _RECTL
asRECTL ( ) const;
IString
asString ( ) const,
asDebugInfo ( ) const;
/*--------------------------- Comparison Operators -----------------------------
| Two rectangles can be compared for equality or inequality using the |
| following operators: |
| operator == - Returns true if the two rectangles are identical. |
| operator != - Returns true if the rectangles differ. |
------------------------------------------------------------------------------*/
Boolean
operator == ( const IRectangle &aRect ) const,
operator != ( const IRectangle &aRect ) const;
/*-------------------------- Manipulation Operators ----------------------------
| Use the following operators to calculate a rectangle's union and |
| intersection with another rectangle: |
| |
| operator & - Returns a rectangle that represents the intersection of the |
| argument rectangles. |
| operator &= - Resets the rectangle to its intersection with the argument. |
| operator | - Returns the rectangle that represents the union of the |
| argument rectangles. This is the smallest rectangle that |
| encompasses both arguments. |
| operator |= - Resets the rectangle to its union with the argument. |
------------------------------------------------------------------------------*/
IRectangle
operator & ( const IRectangle &aRect ) const,
&operator &= ( const IRectangle &aRect ),
operator | ( const IRectangle &aRect ) const,
&operator |= ( const IRectangle &aRect );
/*------------------------------- Manipulation ---------------------------------
| These functions modify the receiving rectangle, changing its size, |
| proportions, or location. |
| centerAt - Moves the rectangle so that its center is at the argument |
| point. |
| centeredAt - Same as centerAt, but returns a new rectangle, leaving the |
| original unmodifed. |
| expandBy - Moves the corners of the rectangle outward from the center |
| by the given amount; the argument can be either a scalar |
| (long int) or a point. |
| expandedBy - Same as expandBy, but returns a new rectangle, leaving the |
| original unmodified. |
| moveBy - Moves the rectangle by the amount specified by the argument |
| point. |
| movedBy - Same as moveBy, but returns a new rectangle, leaving the |
| original unmodified. |
| moveTo - Moves the rectangle so that its bottom left corner is at the |
| argument point. |
| movedTo - Same as moveTo, but returns a new rectangle, leaving the |
| original unmodified. |
| scaleBy - Scales the rectangle by the argument amount. It can be |
| one of the following: |
| - A scalar, either a long integer or double |
| - A point that scales by different amounts in the X- and |
| Y-axis directions |
| - A pair of doubles. The first is used to scale in the |
| X-axis direction, the second in the Y-axis direction. |
| scaledBy - Same as scaleBy, but returns a new rectangle, leaving the |
| original unmodified. |
| shrinkBy - Moves the corners of the rectangle inward toward the center |
| by the given amount, either a scalar or a point. The |
| shrinkBy(anAmount) function is always equivalent to the |
| expandBy(- anAmount) function, and vice versa. |
| shrunkBy - Same as shrinkBy, but returns a new rectangle, leaving the |
| original unmodified. |
| sizeTo - Sizes the rectangle to the argument size. |
| sizedTo - Same as sizeTo, but returns a new rectangle, leaving the |
| original unmodified. |
| sizeBy - Scales the rectangle by the argument value, leaving the |
| rectangle at the same location because the bottomLeft point |
| remains fixed. The scaling factor is one of the following: |
| - An integer scalar, to scale by the same factor in both |
| the X-axis and Y-axis directions |
| - A pair of integer scalars, to scale by different factors |
| in the X-axis and Y-axis directions. |
| - One or two floating point values, the two values used to |
| scale by different amounts in each direction. |
| sizedBy - Same as sizeBy, but returns a new rectangle, leaving the |
| original unmodified. |
------------------------------------------------------------------------------*/
IRectangle
¢erAt ( const IPoint &aPoint ),
centeredAt ( const IPoint &aPoint ) const,
&expandBy ( const IPair &aPair ),
&expandBy ( Coord coord ),
expandedBy ( const IPair &aPair ) const,
expandedBy ( Coord coord ) const,
&moveBy ( const IPair &aPair ),
movedBy ( const IPair &aPair ) const,
&moveTo ( const IPoint &aPoint ),
movedTo ( const IPoint &aPoint ) const,
&scaleBy ( const IPair &aPair ),
&scaleBy ( Coord coord ),
&scaleBy ( double factor ),
&scaleBy ( double xfact,
double yfact ),
scaledBy ( const IPair &aPair ) const,
scaledBy ( Coord coord ) const,
scaledBy ( double factor ) const,
scaledBy ( double xfact,
double yfact ) const,
&shrinkBy ( const IPair &aPair ),
&shrinkBy ( Coord coord ),
shrunkBy ( const IPair &aPair ) const,
shrunkBy ( Coord coord ) const,
&sizeTo ( const IPair &aPair ),
sizedTo ( const IPair &aPair ) const,
&sizeBy ( const IPair &aPair ),
&sizeBy ( Coord factor ),
&sizeBy ( double factor ),
&sizeBy ( double xfact,
double yfact ),
sizedBy ( const IPair &aPair ) const,
sizedBy ( Coord factor ) const,
sizedBy ( double factor ) const,
sizedBy ( double xfact,
double yfact ) const;
/*--------------------------------- Testing ------------------------------------
| Use these functions to test various attributes of a rectangle: |
| contains - Returns true if the rectangle contains the argument point or |
| rectangle. |
| intersects - Returns true if the rectangle and argument rectangles |
| overlap. |
------------------------------------------------------------------------------*/
Boolean
contains ( const IPoint &aPoint ) const,
contains ( const IRectangle &aRect ) const,
intersects ( const IRectangle &aRect ) const;
/*-------------------------------- Displaying ----------------------------------
| Use the following operator to display rectangles: |
| operator << - This operator lets you write rectangles to ostreams in the |
| conventional manner. |
------------------------------------------------------------------------------*/
friend ostream
&operator << ( ostream &aStream,
const IRectangle &aRectangle );
protected:
/*------------------------------ Implementation --------------------------------
| The following function provides utilities used to implement this class: |
| validate - Corrects an invalid rectangle after creation, expansion, or |
| intersection. |
------------------------------------------------------------------------------*/
IRectangle
&validate ( );
private: /*------------------------ PRIVATE ----------------------------------*/
IPoint
origin,
corner;
}; // class IRectangle
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
/*--------------------------------- INLINES ----------------------------------*/
#ifndef I_NO_INLINES
#include <irect.inl>
#endif
#endif /* _IRECT_ */