home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qpointarray.h.z / qpointarray.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  5.0 KB  |  171 lines

  1. /****************************************************************************
  2. ** $Id: qpointarray.h,v 2.8 1998/07/03 00:09:38 hanord Exp $
  3. **
  4. ** Definition of QPointArray class
  5. **
  6. ** Created : 940213
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QPOINTARRAY_H
  25. #define QPOINTARRAY_H
  26.  
  27. #ifndef QT_H
  28. #include "qarray.h"
  29. #include "qpoint.h"
  30. #endif // QT_H
  31.  
  32.  
  33. /*****************************************************************************
  34.   QPointData struct; platform dependent element i QPointArray
  35.  *****************************************************************************/
  36.  
  37. #if defined(_WS_WIN32_) || defined(_WS_PM_)
  38. typedef long Qpnta_t;
  39. #else
  40. typedef short Qpnta_t;
  41. #endif
  42.  
  43. struct QPointData {                // platform dependent point
  44.     QPointData() {}
  45.     QPointData( int xp, int yp )  { x=(Qpnta_t)xp; y=(Qpnta_t)yp; }
  46.     QPointData( const QPoint &p ) { x=(Qpnta_t)p.x(); y=(Qpnta_t)p.y(); }
  47. #if defined(_WS_MAC_)
  48.     Qpnta_t y;
  49.     Qpnta_t x;
  50. #else
  51.     Qpnta_t x;
  52.     Qpnta_t y;
  53. #endif
  54. };
  55.  
  56.  
  57. /*****************************************************************************
  58.   QPointVal class; a context class for QPointArray::operator[]
  59.  *****************************************************************************/
  60.  
  61. class QPointArray;
  62.  
  63. class QPointVal
  64. {
  65. public:
  66.     QPointVal( QPointData *ptr ) : p(ptr) {}
  67.     QPointVal &operator=( const QPoint &point );
  68.     QPointVal &operator+=( const QPoint &point );
  69.     QPointVal &operator-=( const QPoint &point );
  70.            operator QPoint() const    { return QPoint(p->x,p->y); }
  71.     int           x() const        { return (int)p->x; }
  72.     int           y() const        { return (int)p->y; }
  73. private:
  74.     QPointData *p;
  75. };
  76.  
  77.  
  78. /*****************************************************************************
  79.   QPointArray class
  80.  *****************************************************************************/
  81.  
  82. Q_DECLARE(QArrayM,QPointData);
  83.  
  84. class QPointArray : public QArrayM(QPointData)
  85. {
  86. public:
  87.     QPointArray() {}
  88.     QPointArray( int size ) : QArrayM(QPointData)( size ) {}
  89.     QPointArray( const QPointArray &a ) : QArrayM(QPointData)( a ) {}
  90.     QPointArray( const QRect &r, bool closed=FALSE );
  91.     QPointArray( int nPoints, const QCOORD *points );
  92.  
  93.     QPointArray     &operator=( const QPointArray &a )
  94.     { return (QPointArray&)assign( a ); }
  95.  
  96.     bool    fill( const QPoint &p, int size = -1 );
  97.  
  98.     QPointArray copy() const
  99.     { QPointArray tmp; return *((QPointArray*)&tmp.duplicate(*this)); }
  100.  
  101.     void    translate( int dx, int dy );
  102.  
  103.     void    point( uint i, int *x, int *y ) const;
  104.     QPoint  point( uint i ) const;
  105.     void    setPoint( uint i, int x, int y );
  106.     void    setPoint( uint i, const QPoint &p );
  107.     bool    setPoints( int nPoints, const QCOORD *points );
  108.     bool    setPoints( int nPoints, int firstx, int firsty, ... );
  109.     bool    putPoints( int index, int nPoints, const QCOORD *points );
  110.     bool    putPoints( int index, int nPoints, int firstx, int firsty, ... );
  111.  
  112.     QPoint  at( uint i ) const;
  113.     QPointVal operator[]( int i )
  114.         { return QPointVal( data()+i ); }
  115.     QPointVal operator[]( uint i )
  116.         { return QPointVal( data()+i ); }
  117.     QPoint operator[]( int i ) const
  118.         { return (QPoint)QPointVal( data()+i ); }
  119.     QPoint operator[]( uint i ) const
  120.         { return (QPoint)QPointVal( data()+i ); }
  121.  
  122.     QRect   boundingRect() const;
  123.  
  124.     void    makeArc( int x, int y, int w, int h, int a1, int a2 );
  125.     void    makeEllipse( int x, int y, int w, int h );
  126.  
  127.     QPointArray quadBezier() const;
  128. };
  129.  
  130.  
  131. /*****************************************************************************
  132.   QPointArray stream functions
  133.  *****************************************************************************/
  134.  
  135. QDataStream &operator<<( QDataStream &, const QPointArray & );
  136. QDataStream &operator>>( QDataStream &, QPointArray & );
  137.  
  138.  
  139. /*****************************************************************************
  140.   Misc. QPointArray functions
  141.  *****************************************************************************/
  142.  
  143. inline void QPointArray::setPoint( uint i, const QPoint &p )
  144. {
  145.     setPoint( i, p.x(), p.y() );
  146. }
  147.  
  148. inline QPointVal &QPointVal::operator=( const QPoint &point )
  149. {
  150.     p->x = (Qpnta_t)point.x();
  151.     p->y = (Qpnta_t)point.y();
  152.     return *this;
  153. }
  154.  
  155. inline QPointVal &QPointVal::operator+=( const QPoint &point )
  156. {
  157.     p->x += (Qpnta_t)point.x();
  158.     p->y += (Qpnta_t)point.y();
  159.     return *this;
  160. }
  161.  
  162. inline QPointVal &QPointVal::operator-=( const QPoint &point )
  163. {
  164.     p->x -= (Qpnta_t)point.x();
  165.     p->y -= (Qpnta_t)point.y();
  166.     return *this;
  167. }
  168.  
  169.  
  170. #endif // QPOINTARRAY_H
  171.