home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / ibmcli / ipoint.hp_ / IPOINT.HPP
Encoding:
C/C++ Source or Header  |  1992-10-26  |  10.6 KB  |  331 lines

  1. #if !defined(_IPoint_)
  2.   #define _IPoint_
  3.  
  4. /**************************************************************/
  5. /* CLASS NAME:      IPair, IPoint, ISize, IRange              */
  6. /*                                                            */
  7. /* DESCRIPTION  : This file defines a series of classes that  */
  8. /*         work on a pair of long integers.                   */
  9. /*         IPair, IPoint, ISize, and IRange.                  */
  10. /*                                                            */
  11. /* CHANGE ACTIVITY:                                           */
  12. /*   DATE:     INITIAL:        DESCRIPTION                    */
  13. /*                                                            */
  14. /*   101091    RDL             Move from ibasetyp.hxx         */
  15. /*   012292    RDL             Release 2.0 Changes            */
  16. /*   051692    RDL             Removed COORD&, added setX etc */
  17. /*   093092    RDL             max/min to maximum.minimum     */
  18. /**************************************************************/
  19. /* Copyright (c) IBM Corporation 1992                         */
  20. /**************************************************************/
  21.  
  22. #include <ibasetyp.hpp>
  23. #include <istring.hpp>
  24. class IPair;
  25. class ISize;
  26. class IPoint;
  27. class IRange;
  28. typedef long COORD;
  29. class IWindowHandle;
  30.  
  31.  
  32. /***********************************************************/
  33. /* IPair class                                             */
  34. /***********************************************************/
  35. class IPair 
  36. {
  37. public:
  38.                  IPair();
  39.                  IPair( long lInit);
  40.                  IPair(COORD coord1, COORD coord2);
  41.        virtual  ~IPair()  {}
  42.  
  43.           COORD  coord1()  const;
  44.           COORD  coord2()  const;
  45.           void   setCoord1(COORD coord1);
  46.           void   setCoord2(COORD coord2);
  47.           IPair  minimum(const IPair& pair) const;
  48.           IPair  maximum(const IPair& pair) const;
  49.  
  50.           /* Unary */
  51.           IPair  operator-() const;
  52.  
  53.           /*  Comparison Operators */
  54.        Boolean   operator==(const IPair& pair) const;
  55.        Boolean   operator!=(const IPair& pair) const;
  56.        Boolean   operator<(const IPair& pair) const;
  57.        Boolean   operator>(const IPair& pair) const;
  58.        Boolean   operator<=(const IPair& pair) const;
  59.        Boolean   operator>=(const IPair& pair) const;
  60.  
  61.  
  62.           /*  Manipulation Operators */
  63.    friend IPair  operator+(IPair pair1, IPair pair2);
  64.    friend IPair  operator*(IPair pair1, IPair pair2);
  65.    friend IPair  operator-(IPair pair1, IPair pair2);
  66.    friend IPair  operator/(IPair pair1, IPair pair2);
  67.    friend IPair  operator%(IPair pair1, IPair pair2);
  68.    friend IPair  operator*(IPair pair1, double dMultiplier);
  69.    friend IPair  operator/(IPair pair1, double dDivisor);
  70.  
  71.           IPair& operator+=(IPair pair);
  72.           IPair& operator*=(IPair pair);
  73.           IPair& operator*=(double d);
  74.           IPair& operator-=(IPair pair);
  75.           IPair& operator/=(IPair pair);
  76.           IPair& operator/=(double d);
  77.           IPair& operator%=(IPair pair);
  78.  
  79.  
  80.        virtual IString dump() const;
  81.  
  82. private:
  83.    COORD         coordCl1;
  84.    COORD         coordCl2;
  85. };
  86.  
  87.  
  88. /********************************************************/
  89. /* IPoint class                                         */
  90. /********************************************************/
  91. class IPoint : public    IPair   /* pt */
  92. {
  93. public:
  94.                  IPoint();
  95.                  IPoint(const IPair& pair);
  96.                  IPoint( COORD ptX, COORD ptY );
  97.                  IPoint( const ISize& siz);
  98. #if defined(OS2DEF_INCLUDED)
  99.                  IPoint( const POINTL& ptl);
  100.                  IPoint( const RECTL& rcl);
  101. #endif
  102.        virtual  ~IPoint() {}
  103.  
  104.    COORD         x() const;
  105.    COORD         y() const;
  106.    void          setX(COORD X);
  107.    void          setY(COORD Y);
  108.    COORD         pointX() const;
  109.    COORD         pointY() const;
  110.    IPoint        mapToWinPoint(IWindowHandle hwndFrom, IWindowHandle hwndTo) const;
  111. #if defined(OS2DEF_INCLUDED)
  112.    POINTL        pointl() const;
  113. #endif
  114.    double        distanceFrom(const IPoint& pt) const;
  115.  
  116.  virtual IString dump() const;
  117.  
  118. };
  119.  
  120. /********************************************************/
  121. /*  ISize class                                         */
  122. /********************************************************/
  123. class ISize  : public IPair 
  124. {
  125. public:
  126.                  ISize ();
  127.                  ISize (const IPair& pair);
  128.                  ISize (const IPoint& pt);
  129.                  ISize ( COORD coordWidth, COORD coordHeight );
  130. #if defined(GPI_INCLUDED)
  131.                  ISize( const SIZEL& sizl);
  132. #endif
  133. #if defined(OS2DEF_INCLUDED)
  134.                  ISize( const RECTL& rcl);
  135. #endif
  136.        virtual  ~ISize()  {}
  137.  
  138.    COORD        width()  const;
  139.    COORD        height() const;
  140.    void         setWidth(COORD cx);
  141.    void         setHeight(COORD cy);
  142.    COORD        sizeX()  const;
  143.    COORD        sizeY()  const;
  144. #if defined(GPI_INCLUDED)
  145.    SIZEL        sizel()  const;
  146. #endif
  147. virtual IString dump()   const;
  148. };
  149.  
  150. class IRange : public IPair 
  151. {
  152.   public:
  153.                  IRange ();
  154.                  IRange (const IPair& pair);
  155.                  IRange (COORD coordLower, COORD coordUpper);
  156.        virtual  ~IRange()  {}
  157.     COORD        lower() const;
  158.     COORD        upper() const;
  159.     void         setWidth(COORD lw);
  160.     void         setHeight(COORD up);
  161.  Boolean         isInRange(COORD coord) const;
  162.  virtual IString dump() const;
  163.   };
  164.  
  165.  
  166.  
  167.  
  168. /* IPair Inline Functions  */
  169.  
  170. inline IPair::IPair()  
  171.     { coordCl1 = coordCl2 = 0; }
  172.  
  173. inline IPair::IPair( long lInit)
  174.     { coordCl1 = coordCl2 = lInit; }
  175.  
  176. inline IPair::IPair(COORD coord1, COORD coord2)
  177.     { coordCl1 = coord1; coordCl2 = coord2; }
  178.  
  179. inline COORD  IPair::coord1()  const
  180.      { return ((IPair*)this)->coordCl1;}
  181.  
  182. inline COORD  IPair::coord2()  const 
  183.      { return ((IPair*)this)->coordCl2;}
  184.  
  185. inline void  IPair::setCoord1(COORD coord1) 
  186.      { coordCl1 = coord1;}
  187.  
  188. inline void  IPair::setCoord2(COORD coord2) 
  189.      { coordCl2 = coord2;}
  190.  
  191. inline IPair IPair::operator-() const
  192.      {return IPair(-coordCl1, -coordCl2);}
  193.  
  194. inline Boolean   IPair::operator==(const IPair& pair) const
  195.            {return (coordCl1==pair.coordCl1 &&
  196.                     coordCl2==pair.coordCl2); }
  197.  
  198. inline Boolean   IPair::operator!=(const IPair& pair) const
  199.            {return (coordCl1!=pair.coordCl1 ||
  200.                     coordCl2!=pair.coordCl2); }
  201.  
  202. inline Boolean   IPair::operator<(const IPair& pair) const
  203.            {return (coordCl1<pair.coordCl1 &&
  204.                     coordCl2<pair.coordCl2); }
  205.  
  206. inline Boolean   IPair::operator>(const IPair& pair) const
  207.            {return (coordCl1>pair.coordCl1 &&
  208.                     coordCl2>pair.coordCl2); }
  209.  
  210. inline Boolean   IPair::operator<=(const IPair& pair) const
  211.            {return (coordCl1<=pair.coordCl1 &&
  212.                     coordCl2<=pair.coordCl2); }
  213.  
  214. inline Boolean   IPair::operator>=(const IPair& pair) const
  215.            {return (coordCl1>=pair.coordCl1 &&
  216.                     coordCl2>=pair.coordCl2); }
  217.  
  218.  
  219.  
  220. inline IPair  operator+(IPair pair1, IPair pair2)
  221.     {return IPair(pair1.coord1()+pair2.coord1(),
  222.                  pair1.coord2()+pair2.coord2());}
  223.  
  224. inline IPair  operator*(IPair pair1, IPair pair2)
  225.     {return IPair(pair1.coord1()*pair2.coord1(),
  226.                  pair1.coord2()*pair2.coord2());}
  227.  
  228. inline IPair  operator*(IPair pair1, double d)
  229.     {return IPair((COORD)(d*pair1.coord1()),
  230.                   (COORD)(d*pair1.coord2()));}
  231.  
  232. inline IPair  operator-(IPair pair1, IPair pair2)
  233.     {return IPair(pair1.coord1()-pair2.coord1(),
  234.                  pair1.coord2()-pair2.coord2());}
  235.  
  236. inline IPair  operator/(IPair pair1, IPair pair2)
  237.     {return IPair(pair1.coord1()/pair2.coord1(),
  238.                  pair1.coord2()/pair2.coord2());}
  239.  
  240. inline IPair  operator/(IPair pair1, double d)
  241.     {return IPair((COORD)(pair1.coord1()/d),
  242.                   (COORD)(pair1.coord2()/d));}
  243.  
  244. inline IPair  operator%(IPair pair1, IPair pair2)
  245.     {return IPair(pair1.coord1()%pair2.coord1(),
  246.                  pair1.coord2()%pair2.coord2());}
  247.  
  248.  
  249. /* IPoint Inline Functions  */
  250.  
  251. inline IPoint::IPoint()  
  252.      {}
  253. inline IPoint::IPoint(const IPair& pair) 
  254.                       : IPair(pair)
  255.      {}
  256. inline IPoint::IPoint( COORD ptX, COORD ptY ) 
  257.                       : IPair( ptX, ptY )
  258.      {}
  259.  
  260. #if defined(OS2DEF_INCLUDED)
  261. inline IPoint::IPoint( const POINTL& ptl)     
  262.                       : IPair(ptl.x, ptl.y)
  263.      {}
  264. inline IPoint::IPoint( const RECTL& rcl)     
  265.                       : IPair(rcl.xLeft, rcl.yBottom) 
  266.     {}
  267. #endif
  268.  
  269. inline COORD IPoint::x() const  
  270.     {   return  coord1();  }
  271.  
  272. inline COORD IPoint::y() const  
  273.     {   return  coord2();  }
  274.  
  275. inline void  IPoint::setX(COORD X) 
  276.     {   setCoord1(X);    }
  277.  
  278. inline void  IPoint::setY(COORD Y) 
  279.     {   setCoord2(Y);    }
  280.  
  281. inline COORD IPoint::pointX() const 
  282.     {   return  coord1();  }
  283.  
  284. inline COORD IPoint::pointY() const 
  285.     {   return  coord2();  }
  286.  
  287. /* ISize inline functions */
  288. inline ISize::ISize ()  {}
  289.  
  290. inline ISize::ISize (const IPair& pair) :  IPair(pair) {}
  291.  
  292. inline ISize::ISize (const IPoint& pt)  : IPair(pt)   {}
  293. inline ISize::ISize ( COORD coordWidth, COORD coordHeight )
  294.                  :  IPair( coordWidth, coordHeight )  {}
  295. #if defined(GPI_INCLUDED)
  296. inline ISize::ISize( const SIZEL& sizl)  : IPair(sizl.cx, sizl.cy) {}
  297. #endif
  298. #if defined(OS2DEF_INCLUDED)
  299. inline ISize::ISize( const RECTL& rcl)
  300.              : IPair(rcl.xRight - rcl.xLeft, rcl.yTop - rcl.yBottom) {}
  301. #endif
  302.  
  303. inline   COORD ISize::width()  const     {   return  coord1();  }
  304. inline   COORD ISize::height() const     {   return  coord2();  }
  305. inline   void  ISize::setWidth(COORD cx) {   setCoord1(cx);     }
  306. inline   void  ISize::setHeight(COORD cy){   setCoord2(cy);     }
  307. inline   COORD ISize::sizeX()  const     {   return  coord1();  }
  308. inline   COORD ISize::sizeY()  const     {   return  coord2();  }
  309.  
  310.  
  311.  
  312. /* IRange Inline Functions  */
  313.  
  314. inline IRange::IRange () : IPair(0,0) {}
  315. inline IRange::IRange (const IPair& pair) : IPair(pair) {}
  316. inline IRange::IRange (COORD coordLower, COORD coordUpper)
  317.                    : IPair(coordLower, coordUpper) {}
  318. inline COORD IRange::lower() const   {return coord1(); }
  319. inline COORD IRange::upper() const   { return coord2(); }
  320. inline void  IRange::setWidth(COORD lw) {   setCoord1(lw); }
  321. inline void  IRange::setHeight(COORD up){   setCoord2(up); }
  322. inline  Boolean IRange :: isInRange(COORD coord) const
  323.     {return (coord>=lower() && coord<=upper());}
  324.  
  325. /* Conversion functions */
  326. inline IPoint::IPoint( const ISize& siz)
  327. : IPair(siz.width(), siz.height())   {}
  328.  
  329.  
  330. #endif
  331.