home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gnu / aplusplus-1.01-src.lha / src / amiga / aplusplus-1.01 / include / aplusplus / graphics / RectObject.h < prev    next >
C/C++ Source or Header  |  1994-05-04  |  4KB  |  90 lines

  1. #ifndef APP_RectObject_H
  2. #define APP_RectObject_H
  3. /******************************************************************************
  4.  **
  5.  **    C++ Class Library for the Amiga© system software.
  6.  **
  7.  **    Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
  8.  **    All Rights Reserved.
  9.  **
  10.  **    $VER: apphome:APlusPlus/graphics/RectObject.h 1.04 (04.05.94) $
  11.  **    
  12.  ******************************************************************************/
  13.  
  14.  
  15. /******************************************************************************************
  16.       » RectObject class «
  17.  
  18.    Simply a storage for a rectangular object's dimensions.
  19.    The rectangle is specified through the upper left and lower right edge of the rect.
  20.    Usually the left and upper coordinate is nto bigger than the right and lower coordinate.
  21.    If you need to rely on that use width() and height() to span your rectangle since these
  22.    methods check for the edge order.
  23.    
  24.    RectObject class SHOULD ALWAYS BE INHERITED VIRTUALLY, so complex classes that indirectly
  25.    inherit several RectObjects work on the same dimensions.
  26.  ******************************************************************************************/
  27. typedef LONG XYVAL;  // for graphics x/y coordinates
  28. typedef LONG WHVAL;  // for graphics width/height values
  29.  
  30. class GBorder;
  31. class RectObject
  32. {
  33.     friend GBorder;
  34.     private:
  35.           XYVAL    MinX,MinY,MaxX,MaxY;
  36.         UBYTE     leftBorder,topBorder,rightBorder,bottomBorder;
  37.         
  38.    protected:
  39.  
  40.       void setRect(XYVAL minx,XYVAL miny,XYVAL maxx,XYVAL maxy)   // fill in graphic dimensions
  41.       { MinX = minx; MinY = miny; MaxX = maxx; MaxY = maxy; }
  42.       // use left upper edge and width
  43.       void setRectWH(XYVAL minx,XYVAL miny,XYVAL widthX,XYVAL heightY)
  44.       { MinX = minx; MinY = miny; MaxX = minx+widthX; MaxY = miny+heightY; }
  45.             
  46.       RectObject() { setRect(0,0,0,0); setBorders(0,0,0,0); }
  47.       RectObject(XYVAL minx,XYVAL miny,XYVAL maxx,XYVAL maxy)
  48.          { setRect(minx,miny,maxx,maxy); }
  49.       virtual ~RectObject() { };
  50.         
  51.         // set rectangle values
  52.         void minX(XYVAL x) { MinX = x; }
  53.         void minY(XYVAL y) { MinY = y; }
  54.         void maxX(XYVAL x) { MaxX = x; }
  55.         void maxY(XYVAL y) { MaxY = y; }
  56.         
  57.         // read border dimensions
  58.         XYVAL leftB() { return leftBorder; }
  59.         XYVAL topB() { return topBorder; }
  60.         XYVAL rightB() { return rightBorder; }
  61.         XYVAL bottomB() { return bottomBorder; }
  62.  
  63.    public:
  64.         // NOTE: new borders dimensions demand a new 'adjustChilds()' run for 'this' GraphicObject!
  65.         void setBorders(UBYTE lb,UBYTE tb,UBYTE rb,UBYTE bb)
  66.         { leftBorder = lb;topBorder = tb;rightBorder = rb;bottomBorder = bb; }
  67.  
  68.       // only read access to get the dimensions in pixel and left,upper edge relative to
  69.       // the window rastport.
  70.  
  71.       // width() and height() always return values greater or equal zero.
  72.         // outer dimensions (maximum for inner dimensions)
  73.       XYVAL left() { return MinX; }
  74.       XYVAL right() { return MaxX; }
  75.       XYVAL top() { return MinY; }
  76.       XYVAL bottom() { return MaxY; }
  77.         WHVAL width() { if (right()>left()) return right()-left()+1; else return 0;}
  78.       WHVAL height() { if (bottom()>top()) return bottom()-top()+1; else return 0;}
  79.  
  80.         // inner dimensions (diminished by borders)    
  81.         XYVAL iLeft() { return MinX+leftBorder; }
  82.         XYVAL iTop() { return MinY+topBorder; }
  83.         XYVAL iRight() { return MaxX-rightBorder; }
  84.         XYVAL iBottom() { return MaxY-bottomBorder; }
  85.         WHVAL iWidth()    { if (iRight()>iLeft()) return iRight()-iLeft()+1; else return 0;}
  86.       WHVAL iHeight() { if (iBottom()>iTop()) return iBottom()-iTop()+1; else return 0;}
  87.  
  88. };
  89. #endif   /* RectObject.h */
  90.