home *** CD-ROM | disk | FTP | other *** search
- #ifndef APP_RectObject_H
- #define APP_RectObject_H
- /******************************************************************************
- **
- ** C++ Class Library for the Amiga© system software.
- **
- ** Copyright (C) 1994 by Armin Vogt ** EMail: armin@uni-paderborn.de
- ** All Rights Reserved.
- **
- ** $VER: apphome:APlusPlus/graphics/RectObject.h 1.04 (04.05.94) $
- **
- ******************************************************************************/
-
-
- /******************************************************************************************
- » RectObject class «
-
- Simply a storage for a rectangular object's dimensions.
- The rectangle is specified through the upper left and lower right edge of the rect.
- Usually the left and upper coordinate is nto bigger than the right and lower coordinate.
- If you need to rely on that use width() and height() to span your rectangle since these
- methods check for the edge order.
-
- RectObject class SHOULD ALWAYS BE INHERITED VIRTUALLY, so complex classes that indirectly
- inherit several RectObjects work on the same dimensions.
- ******************************************************************************************/
- typedef LONG XYVAL; // for graphics x/y coordinates
- typedef LONG WHVAL; // for graphics width/height values
-
- class GBorder;
- class RectObject
- {
- friend GBorder;
- private:
- XYVAL MinX,MinY,MaxX,MaxY;
- UBYTE leftBorder,topBorder,rightBorder,bottomBorder;
-
- protected:
-
- void setRect(XYVAL minx,XYVAL miny,XYVAL maxx,XYVAL maxy) // fill in graphic dimensions
- { MinX = minx; MinY = miny; MaxX = maxx; MaxY = maxy; }
- // use left upper edge and width
- void setRectWH(XYVAL minx,XYVAL miny,XYVAL widthX,XYVAL heightY)
- { MinX = minx; MinY = miny; MaxX = minx+widthX; MaxY = miny+heightY; }
-
- RectObject() { setRect(0,0,0,0); setBorders(0,0,0,0); }
- RectObject(XYVAL minx,XYVAL miny,XYVAL maxx,XYVAL maxy)
- { setRect(minx,miny,maxx,maxy); }
- virtual ~RectObject() { };
-
- // set rectangle values
- void minX(XYVAL x) { MinX = x; }
- void minY(XYVAL y) { MinY = y; }
- void maxX(XYVAL x) { MaxX = x; }
- void maxY(XYVAL y) { MaxY = y; }
-
- // read border dimensions
- XYVAL leftB() { return leftBorder; }
- XYVAL topB() { return topBorder; }
- XYVAL rightB() { return rightBorder; }
- XYVAL bottomB() { return bottomBorder; }
-
- public:
- // NOTE: new borders dimensions demand a new 'adjustChilds()' run for 'this' GraphicObject!
- void setBorders(UBYTE lb,UBYTE tb,UBYTE rb,UBYTE bb)
- { leftBorder = lb;topBorder = tb;rightBorder = rb;bottomBorder = bb; }
-
- // only read access to get the dimensions in pixel and left,upper edge relative to
- // the window rastport.
-
- // width() and height() always return values greater or equal zero.
- // outer dimensions (maximum for inner dimensions)
- XYVAL left() { return MinX; }
- XYVAL right() { return MaxX; }
- XYVAL top() { return MinY; }
- XYVAL bottom() { return MaxY; }
- WHVAL width() { if (right()>left()) return right()-left()+1; else return 0;}
- WHVAL height() { if (bottom()>top()) return bottom()-top()+1; else return 0;}
-
- // inner dimensions (diminished by borders)
- XYVAL iLeft() { return MinX+leftBorder; }
- XYVAL iTop() { return MinY+topBorder; }
- XYVAL iRight() { return MaxX-rightBorder; }
- XYVAL iBottom() { return MaxY-bottomBorder; }
- WHVAL iWidth() { if (iRight()>iLeft()) return iRight()-iLeft()+1; else return 0;}
- WHVAL iHeight() { if (iBottom()>iTop()) return iBottom()-iTop()+1; else return 0;}
-
- };
- #endif /* RectObject.h */
-