home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qpoint.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  6KB  |  216 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qpoint.h   3.0.0   edited Jun 22 12:24 $
  3. **
  4. ** Definition of QPoint class
  5. **
  6. ** Created : 931028
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the kernel module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QPOINT_H
  39. #define QPOINT_H
  40.  
  41. #ifndef QT_H
  42. #include "qwindowdefs.h"
  43. #endif // QT_H
  44.  
  45.  
  46. class Q_EXPORT QPoint
  47. {
  48. public:
  49.     QPoint();
  50.     QPoint( int xpos, int ypos );
  51.  
  52.     bool   isNull()    const;
  53.  
  54.     int       x()        const;
  55.     int       y()        const;
  56.     void   setX( int x );
  57.     void   setY( int y );
  58.  
  59.     int manhattanLength() const;
  60.  
  61.     QCOORD &rx();
  62.     QCOORD &ry();
  63.  
  64.     QPoint &operator+=( const QPoint &p );
  65.     QPoint &operator-=( const QPoint &p );
  66.     QPoint &operator*=( int c );
  67.     QPoint &operator*=( double c );
  68.     QPoint &operator/=( int c );
  69.     QPoint &operator/=( double c );
  70.  
  71.     friend inline bool     operator==( const QPoint &, const QPoint & );
  72.     friend inline bool     operator!=( const QPoint &, const QPoint & );
  73.     friend inline const QPoint operator+( const QPoint &, const QPoint & );
  74.     friend inline const QPoint operator-( const QPoint &, const QPoint & );
  75.     friend inline const QPoint operator*( const QPoint &, int );
  76.     friend inline const QPoint operator*( int, const QPoint & );
  77.     friend inline const QPoint operator*( const QPoint &, double );
  78.     friend inline const QPoint operator*( double, const QPoint & );
  79.     friend inline const QPoint operator-( const QPoint & );
  80.     friend inline const QPoint operator/( const QPoint &, int );
  81.     friend inline const QPoint operator/( const QPoint &, double );
  82.  
  83. private:
  84.     static void warningDivByZero();
  85.  
  86. #if defined(Q_OS_MAC)
  87.     QCOORD yp;
  88.     QCOORD xp;
  89. #else
  90.     QCOORD xp;
  91.     QCOORD yp;
  92. #endif
  93. };
  94.  
  95.  
  96. /*****************************************************************************
  97.   QPoint stream functions
  98.  *****************************************************************************/
  99. #ifndef QT_NO_DATASTREAM
  100. Q_EXPORT QDataStream &operator<<( QDataStream &, const QPoint & );
  101. Q_EXPORT QDataStream &operator>>( QDataStream &, QPoint & );
  102. #endif
  103.  
  104. /*****************************************************************************
  105.   QPoint inline functions
  106.  *****************************************************************************/
  107.  
  108. inline QPoint::QPoint()
  109. { xp=0; yp=0; }
  110.  
  111. inline QPoint::QPoint( int xpos, int ypos )
  112. { xp=(QCOORD)xpos; yp=(QCOORD)ypos; }
  113.  
  114. inline bool QPoint::isNull() const
  115. { return xp == 0 && yp == 0; }
  116.  
  117. inline int QPoint::x() const
  118. { return xp; }
  119.  
  120. inline int QPoint::y() const
  121. { return yp; }
  122.  
  123. inline void QPoint::setX( int x )
  124. { xp = (QCOORD)x; }
  125.  
  126. inline void QPoint::setY( int y )
  127. { yp = (QCOORD)y; }
  128.  
  129. inline QCOORD &QPoint::rx()
  130. { return xp; }
  131.  
  132. inline QCOORD &QPoint::ry()
  133. { return yp; }
  134.  
  135. inline QPoint &QPoint::operator+=( const QPoint &p )
  136. { xp+=p.xp; yp+=p.yp; return *this; }
  137.  
  138. inline QPoint &QPoint::operator-=( const QPoint &p )
  139. { xp-=p.xp; yp-=p.yp; return *this; }
  140.  
  141. inline QPoint &QPoint::operator*=( int c )
  142. { xp*=(QCOORD)c; yp*=(QCOORD)c; return *this; }
  143.  
  144. inline QPoint &QPoint::operator*=( double c )
  145. { xp=(QCOORD)(xp*c); yp=(QCOORD)(yp*c); return *this; }
  146.  
  147. inline bool operator==( const QPoint &p1, const QPoint &p2 )
  148. { return p1.xp == p2.xp && p1.yp == p2.yp; }
  149.  
  150. inline bool operator!=( const QPoint &p1, const QPoint &p2 )
  151. { return p1.xp != p2.xp || p1.yp != p2.yp; }
  152.  
  153. inline const QPoint operator+( const QPoint &p1, const QPoint &p2 )
  154. { return QPoint(p1.xp+p2.xp, p1.yp+p2.yp); }
  155.  
  156. inline const QPoint operator-( const QPoint &p1, const QPoint &p2 )
  157. { return QPoint(p1.xp-p2.xp, p1.yp-p2.yp); }
  158.  
  159. inline const QPoint operator*( const QPoint &p, int c )
  160. { return QPoint(p.xp*c, p.yp*c); }
  161.  
  162. inline const QPoint operator*( int c, const QPoint &p )
  163. { return QPoint(p.xp*c, p.yp*c); }
  164.  
  165. inline const QPoint operator*( const QPoint &p, double c )
  166. { return QPoint((QCOORD)(p.xp*c), (QCOORD)(p.yp*c)); }
  167.  
  168. inline const QPoint operator*( double c, const QPoint &p )
  169. { return QPoint((QCOORD)(p.xp*c), (QCOORD)(p.yp*c)); }
  170.  
  171. inline const QPoint operator-( const QPoint &p )
  172. { return QPoint(-p.xp, -p.yp); }
  173.  
  174. inline QPoint &QPoint::operator/=( int c )
  175. {
  176. #if defined(QT_CHECK_MATH)
  177.     if ( c == 0 )
  178.     warningDivByZero();
  179. #endif
  180.     xp/=(QCOORD)c;
  181.     yp/=(QCOORD)c;
  182.     return *this;
  183. }
  184.  
  185. inline QPoint &QPoint::operator/=( double c )
  186. {
  187. #if defined(QT_CHECK_MATH)
  188.     if ( c == 0.0 )
  189.     warningDivByZero();
  190. #endif
  191.     xp=(QCOORD)(xp/c);
  192.     yp=(QCOORD)(yp/c);
  193.     return *this;
  194. }
  195.  
  196. inline const QPoint operator/( const QPoint &p, int c )
  197. {
  198. #if defined(QT_CHECK_MATH)
  199.     if ( c == 0 )
  200.     QPoint::warningDivByZero();
  201. #endif
  202.     return QPoint(p.xp/c, p.yp/c);
  203. }
  204.  
  205. inline const QPoint operator/( const QPoint &p, double c )
  206. {
  207. #if defined(QT_CHECK_MATH)
  208.     if ( c == 0.0 )
  209.     QPoint::warningDivByZero();
  210. #endif
  211.     return QPoint((QCOORD)(p.xp/c), (QCOORD)(p.yp/c));
  212. }
  213.  
  214.  
  215. #endif // QPOINT_H
  216.