| 1 | /********************************************************************** | 
|---|
| 2 | ** $Id: qcanvas.h 71 2006-03-22 15:15:38Z dmik $ | 
|---|
| 3 | ** | 
|---|
| 4 | ** Definition of QCanvas classes | 
|---|
| 5 | ** | 
|---|
| 6 | ** Created : 991211 | 
|---|
| 7 | ** | 
|---|
| 8 | ** Copyright (C) 1999-2002 Trolltech AS.  All rights reserved. | 
|---|
| 9 | ** | 
|---|
| 10 | ** This file is part of the canvas 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 licenses may use this | 
|---|
| 22 | ** file in accordance with the Qt Commercial License Agreement provided | 
|---|
| 23 | ** 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 QCANVAS_H | 
|---|
| 39 | #define QCANVAS_H | 
|---|
| 40 |  | 
|---|
| 41 | #ifndef QT_H | 
|---|
| 42 | #include "qscrollview.h" | 
|---|
| 43 | #include "qpixmap.h" | 
|---|
| 44 | #include "qptrlist.h" | 
|---|
| 45 | #include "qbrush.h" | 
|---|
| 46 | #include "qpen.h" | 
|---|
| 47 | #include "qvaluelist.h" | 
|---|
| 48 | #include "qpointarray.h" | 
|---|
| 49 | #endif // QT_H | 
|---|
| 50 |  | 
|---|
| 51 | #if !defined( QT_MODULE_CANVAS ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_CANVAS ) | 
|---|
| 52 | #define QM_EXPORT_CANVAS | 
|---|
| 53 | #define QM_TEMPLATE_EXTERN_CANVAS | 
|---|
| 54 | #else | 
|---|
| 55 | #define QM_EXPORT_CANVAS Q_EXPORT | 
|---|
| 56 | #define QM_TEMPLATE_EXTERN_CANVAS Q_TEMPLATE_EXTERN | 
|---|
| 57 | #endif | 
|---|
| 58 |  | 
|---|
| 59 | #ifndef QT_NO_CANVAS | 
|---|
| 60 |  | 
|---|
| 61 |  | 
|---|
| 62 | class QCanvasSprite; | 
|---|
| 63 | class QCanvasPolygonalItem; | 
|---|
| 64 | class QCanvasRectangle; | 
|---|
| 65 | class QCanvasPolygon; | 
|---|
| 66 | class QCanvasEllipse; | 
|---|
| 67 | class QCanvasText; | 
|---|
| 68 | class QCanvasLine; | 
|---|
| 69 | class QCanvasChunk; | 
|---|
| 70 | class QCanvas; | 
|---|
| 71 | class QCanvasItem; | 
|---|
| 72 | class QCanvasView; | 
|---|
| 73 | class QCanvasPixmap; | 
|---|
| 74 |  | 
|---|
| 75 | #if defined(Q_TEMPLATEDLL) && ( !defined(Q_CC_BOR) || !defined(QT_MAKEDLL) || defined(Q_EXPORT_TEMPLATES) ) | 
|---|
| 76 | // MOC_SKIP_BEGIN | 
|---|
| 77 | QM_TEMPLATE_EXTERN_CANVAS template class QM_EXPORT_CANVAS QValueListIterator< QCanvasItem* >; | 
|---|
| 78 | QM_TEMPLATE_EXTERN_CANVAS template class QM_EXPORT_CANVAS QValueList< QCanvasItem* >; | 
|---|
| 79 | // MOC_SKIP_END | 
|---|
| 80 | #endif | 
|---|
| 81 |  | 
|---|
| 82 | class QM_EXPORT_CANVAS QCanvasItemList : public QValueList<QCanvasItem*> { | 
|---|
| 83 | public: | 
|---|
| 84 | void sort(); | 
|---|
| 85 | void drawUnique( QPainter& painter ); | 
|---|
| 86 | QCanvasItemList operator+(const QCanvasItemList &l) const; | 
|---|
| 87 | }; | 
|---|
| 88 |  | 
|---|
| 89 |  | 
|---|
| 90 | class QCanvasItemExtra; | 
|---|
| 91 |  | 
|---|
| 92 | class QM_EXPORT_CANVAS QCanvasItem : public Qt | 
|---|
| 93 | { | 
|---|
| 94 | public: | 
|---|
| 95 | QCanvasItem(QCanvas* canvas); | 
|---|
| 96 | virtual ~QCanvasItem(); | 
|---|
| 97 |  | 
|---|
| 98 | double x() const | 
|---|
| 99 | { return myx; } | 
|---|
| 100 | double y() const | 
|---|
| 101 | { return myy; } | 
|---|
| 102 | double z() const | 
|---|
| 103 | { return myz; } // (depth) | 
|---|
| 104 |  | 
|---|
| 105 | virtual void moveBy(double dx, double dy); | 
|---|
| 106 | void move(double x, double y); | 
|---|
| 107 | void setX(double a) { move(a,y()); } | 
|---|
| 108 | void setY(double a) { move(x(),a); } | 
|---|
| 109 | void setZ(double a) { myz=a; changeChunks(); } | 
|---|
| 110 |  | 
|---|
| 111 | bool animated() const; | 
|---|
| 112 | virtual void setAnimated(bool y); | 
|---|
| 113 | virtual void setVelocity( double vx, double vy); | 
|---|
| 114 | void setXVelocity( double vx ) { setVelocity(vx,yVelocity()); } | 
|---|
| 115 | void setYVelocity( double vy ) { setVelocity(xVelocity(),vy); } | 
|---|
| 116 | double xVelocity() const; | 
|---|
| 117 | double yVelocity() const; | 
|---|
| 118 | virtual void advance(int stage); | 
|---|
| 119 |  | 
|---|
| 120 | virtual bool collidesWith( const QCanvasItem* ) const=0; | 
|---|
| 121 |  | 
|---|
| 122 | QCanvasItemList collisions(bool exact /* NO DEFAULT */ ) const; | 
|---|
| 123 |  | 
|---|
| 124 | virtual void setCanvas(QCanvas*); | 
|---|
| 125 |  | 
|---|
| 126 | virtual void draw(QPainter&)=0; | 
|---|
| 127 |  | 
|---|
| 128 | void show(); | 
|---|
| 129 | void hide(); | 
|---|
| 130 |  | 
|---|
| 131 | virtual void setVisible(bool yes); | 
|---|
| 132 | bool isVisible() const | 
|---|
| 133 | { return (bool)vis; } | 
|---|
| 134 | virtual void setSelected(bool yes); | 
|---|
| 135 | bool isSelected() const | 
|---|
| 136 | { return (bool)sel; } | 
|---|
| 137 | virtual void setEnabled(bool yes); | 
|---|
| 138 | bool isEnabled() const | 
|---|
| 139 | { return (bool)ena; } | 
|---|
| 140 | virtual void setActive(bool yes); | 
|---|
| 141 | bool isActive() const | 
|---|
| 142 | { return (bool)act; } | 
|---|
| 143 | #ifndef QT_NO_COMPAT | 
|---|
| 144 | bool visible() const | 
|---|
| 145 | { return (bool)vis; } | 
|---|
| 146 | bool selected() const | 
|---|
| 147 | { return (bool)sel; } | 
|---|
| 148 | bool enabled() const | 
|---|
| 149 | { return (bool)ena; } | 
|---|
| 150 | bool active() const | 
|---|
| 151 | { return (bool)act; } | 
|---|
| 152 | #endif | 
|---|
| 153 |  | 
|---|
| 154 | enum RttiValues { | 
|---|
| 155 | Rtti_Item = 0, | 
|---|
| 156 | Rtti_Sprite = 1, | 
|---|
| 157 | Rtti_PolygonalItem = 2, | 
|---|
| 158 | Rtti_Text = 3, | 
|---|
| 159 | Rtti_Polygon = 4, | 
|---|
| 160 | Rtti_Rectangle = 5, | 
|---|
| 161 | Rtti_Ellipse = 6, | 
|---|
| 162 | Rtti_Line = 7, | 
|---|
| 163 | Rtti_Spline = 8 | 
|---|
| 164 | }; | 
|---|
| 165 |  | 
|---|
| 166 | virtual int rtti() const; | 
|---|
| 167 | static int RTTI; | 
|---|
| 168 |  | 
|---|
| 169 | virtual QRect boundingRect() const=0; | 
|---|
| 170 | virtual QRect boundingRectAdvanced() const; | 
|---|
| 171 |  | 
|---|
| 172 | QCanvas* canvas() const | 
|---|
| 173 | { return cnv; } | 
|---|
| 174 |  | 
|---|
| 175 | protected: | 
|---|
| 176 | void update() { changeChunks(); } | 
|---|
| 177 |  | 
|---|
| 178 | private: | 
|---|
| 179 | // For friendly subclasses... | 
|---|
| 180 |  | 
|---|
| 181 | friend class QCanvasPolygonalItem; | 
|---|
| 182 | friend class QCanvasSprite; | 
|---|
| 183 | friend class QCanvasRectangle; | 
|---|
| 184 | friend class QCanvasPolygon; | 
|---|
| 185 | friend class QCanvasEllipse; | 
|---|
| 186 | friend class QCanvasText; | 
|---|
| 187 | friend class QCanvasLine; | 
|---|
| 188 |  | 
|---|
| 189 | virtual QPointArray chunks() const; | 
|---|
| 190 | virtual void addToChunks(); | 
|---|
| 191 | virtual void removeFromChunks(); | 
|---|
| 192 | virtual void changeChunks(); | 
|---|
| 193 | virtual bool collidesWith( const QCanvasSprite*, | 
|---|
| 194 | const QCanvasPolygonalItem*, | 
|---|
| 195 | const QCanvasRectangle*, | 
|---|
| 196 | const QCanvasEllipse*, | 
|---|
| 197 | const QCanvasText* ) const = 0; | 
|---|
| 198 | // End of friend stuff | 
|---|
| 199 |  | 
|---|
| 200 | QCanvas* cnv; | 
|---|
| 201 | static QCanvas* current_canvas; | 
|---|
| 202 | double myx,myy,myz; | 
|---|
| 203 | QCanvasItemExtra *ext; | 
|---|
| 204 | QCanvasItemExtra& extra(); | 
|---|
| 205 | uint ani:1; | 
|---|
| 206 | uint vis:1; | 
|---|
| 207 | uint val:1; | 
|---|
| 208 | uint sel:1; | 
|---|
| 209 | uint ena:1; | 
|---|
| 210 | uint act:1; | 
|---|
| 211 | }; | 
|---|
| 212 |  | 
|---|
| 213 |  | 
|---|
| 214 | class QCanvasData; | 
|---|
| 215 |  | 
|---|
| 216 | class QM_EXPORT_CANVAS QCanvas : public QObject | 
|---|
| 217 | { | 
|---|
| 218 | Q_OBJECT | 
|---|
| 219 | public: | 
|---|
| 220 | QCanvas( QObject* parent = 0, const char* name = 0 ); | 
|---|
| 221 | QCanvas(int w, int h); | 
|---|
| 222 | QCanvas( QPixmap p, int h, int v, int tilewidth, int tileheight ); | 
|---|
| 223 |  | 
|---|
| 224 | virtual ~QCanvas(); | 
|---|
| 225 |  | 
|---|
| 226 | virtual void setTiles( QPixmap tiles, int h, int v, | 
|---|
| 227 | int tilewidth, int tileheight ); | 
|---|
| 228 | virtual void setBackgroundPixmap( const QPixmap& p ); | 
|---|
| 229 | QPixmap backgroundPixmap() const; | 
|---|
| 230 |  | 
|---|
| 231 | virtual void setBackgroundColor( const QColor& c ); | 
|---|
| 232 | QColor backgroundColor() const; | 
|---|
| 233 |  | 
|---|
| 234 | virtual void setTile( int x, int y, int tilenum ); | 
|---|
| 235 | int tile( int x, int y ) const | 
|---|
| 236 | { return grid[x+y*htiles]; } | 
|---|
| 237 |  | 
|---|
| 238 | int tilesHorizontally() const | 
|---|
| 239 | { return htiles; } | 
|---|
| 240 | int tilesVertically() const | 
|---|
| 241 | { return vtiles; } | 
|---|
| 242 |  | 
|---|
| 243 | int tileWidth() const | 
|---|
| 244 | { return tilew; } | 
|---|
| 245 | int tileHeight() const | 
|---|
| 246 | { return tileh; } | 
|---|
| 247 |  | 
|---|
| 248 | virtual void resize(int width, int height); | 
|---|
| 249 | int width() const | 
|---|
| 250 | { return awidth; } | 
|---|
| 251 | int height() const | 
|---|
| 252 | { return aheight; } | 
|---|
| 253 | QSize size() const | 
|---|
| 254 | { return QSize(awidth,aheight); } | 
|---|
| 255 | QRect rect() const | 
|---|
| 256 | { return QRect( 0, 0, awidth, aheight ); } | 
|---|
| 257 | bool onCanvas( int x, int y ) const | 
|---|
| 258 | { return x>=0 && y>=0 && x<awidth && y<aheight; } | 
|---|
| 259 | bool onCanvas( const QPoint& p ) const | 
|---|
| 260 | { return onCanvas(p.x(),p.y()); } | 
|---|
| 261 | bool validChunk( int x, int y ) const | 
|---|
| 262 | { return x>=0 && y>=0 && x<chwidth && y<chheight; } | 
|---|
| 263 | bool validChunk( const QPoint& p ) const | 
|---|
| 264 | { return validChunk(p.x(),p.y()); } | 
|---|
| 265 |  | 
|---|
| 266 | int chunkSize() const | 
|---|
| 267 | { return chunksize; } | 
|---|
| 268 | virtual void retune(int chunksize, int maxclusters=100); | 
|---|
| 269 |  | 
|---|
| 270 | bool sameChunk(int x1, int y1, int x2, int y2) const | 
|---|
| 271 | { return x1/chunksize==x2/chunksize && y1/chunksize==y2/chunksize; } | 
|---|
| 272 | virtual void setChangedChunk(int i, int j); | 
|---|
| 273 | virtual void setChangedChunkContaining(int x, int y); | 
|---|
| 274 | virtual void setAllChanged(); | 
|---|
| 275 | virtual void setChanged(const QRect& area); | 
|---|
| 276 | virtual void setUnchanged(const QRect& area); | 
|---|
| 277 |  | 
|---|
| 278 | // These call setChangedChunk. | 
|---|
| 279 | void addItemToChunk(QCanvasItem*, int i, int j); | 
|---|
| 280 | void removeItemFromChunk(QCanvasItem*, int i, int j); | 
|---|
| 281 | void addItemToChunkContaining(QCanvasItem*, int x, int y); | 
|---|
| 282 | void removeItemFromChunkContaining(QCanvasItem*, int x, int y); | 
|---|
| 283 |  | 
|---|
| 284 | QCanvasItemList allItems(); | 
|---|
| 285 | QCanvasItemList collisions( const QPoint&) const; | 
|---|
| 286 | QCanvasItemList collisions( const QRect&) const; | 
|---|
| 287 | QCanvasItemList collisions( const QPointArray& pa, const QCanvasItem* item, | 
|---|
| 288 | bool exact) const; | 
|---|
| 289 |  | 
|---|
| 290 | void drawArea(const QRect&, QPainter* p, bool double_buffer=FALSE); | 
|---|
| 291 |  | 
|---|
| 292 | // These are for QCanvasView to call | 
|---|
| 293 | virtual void addView(QCanvasView*); | 
|---|
| 294 | virtual void removeView(QCanvasView*); | 
|---|
| 295 | void drawCanvasArea(const QRect&, QPainter* p=0, bool double_buffer=TRUE); | 
|---|
| 296 | void drawViewArea( QCanvasView* view, QPainter* p, const QRect& r, bool dbuf ); | 
|---|
| 297 |  | 
|---|
| 298 | // These are for QCanvasItem to call | 
|---|
| 299 | virtual void addItem(QCanvasItem*); | 
|---|
| 300 | virtual void addAnimation(QCanvasItem*); | 
|---|
| 301 | virtual void removeItem(QCanvasItem*); | 
|---|
| 302 | virtual void removeAnimation(QCanvasItem*); | 
|---|
| 303 |  | 
|---|
| 304 | virtual void setAdvancePeriod(int ms); | 
|---|
| 305 | virtual void setUpdatePeriod(int ms); | 
|---|
| 306 |  | 
|---|
| 307 | virtual void setDoubleBuffering(bool y); | 
|---|
| 308 |  | 
|---|
| 309 | signals: | 
|---|
| 310 | void resized(); | 
|---|
| 311 |  | 
|---|
| 312 | public slots: | 
|---|
| 313 | virtual void advance(); | 
|---|
| 314 | virtual void update(); | 
|---|
| 315 |  | 
|---|
| 316 | protected: | 
|---|
| 317 | virtual void drawBackground(QPainter&, const QRect& area); | 
|---|
| 318 | virtual void drawForeground(QPainter&, const QRect& area); | 
|---|
| 319 |  | 
|---|
| 320 | private: | 
|---|
| 321 | void init(int w, int h, int chunksze=16, int maxclust=100); | 
|---|
| 322 |  | 
|---|
| 323 | QCanvasChunk& chunk(int i, int j) const; | 
|---|
| 324 | QCanvasChunk& chunkContaining(int x, int y) const; | 
|---|
| 325 |  | 
|---|
| 326 | QRect changeBounds(const QRect& inarea); | 
|---|
| 327 | void drawChanges(const QRect& inarea); | 
|---|
| 328 |  | 
|---|
| 329 | void ensureOffScrSize( int osw, int osh ); | 
|---|
| 330 | QPixmap offscr; | 
|---|
| 331 | int awidth,aheight; | 
|---|
| 332 | int chunksize; | 
|---|
| 333 | int maxclusters; | 
|---|
| 334 | int chwidth,chheight; | 
|---|
| 335 | QCanvasChunk* chunks; | 
|---|
| 336 |  | 
|---|
| 337 | QCanvasData* d; | 
|---|
| 338 |  | 
|---|
| 339 | void initTiles(QPixmap p, int h, int v, int tilewidth, int tileheight); | 
|---|
| 340 | ushort *grid; | 
|---|
| 341 | ushort htiles; | 
|---|
| 342 | ushort vtiles; | 
|---|
| 343 | ushort tilew; | 
|---|
| 344 | ushort tileh; | 
|---|
| 345 | bool oneone; | 
|---|
| 346 | QPixmap pm; | 
|---|
| 347 | QTimer* update_timer; | 
|---|
| 348 | QColor bgcolor; | 
|---|
| 349 | bool debug_redraw_areas; | 
|---|
| 350 | bool dblbuf; | 
|---|
| 351 |  | 
|---|
| 352 | friend void qt_unview(QCanvas* c); | 
|---|
| 353 |  | 
|---|
| 354 | #if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator= | 
|---|
| 355 | QCanvas( const QCanvas & ); | 
|---|
| 356 | QCanvas &operator=( const QCanvas & ); | 
|---|
| 357 | #endif | 
|---|
| 358 | }; | 
|---|
| 359 |  | 
|---|
| 360 | class QCanvasViewData; | 
|---|
| 361 |  | 
|---|
| 362 | class QM_EXPORT_CANVAS QCanvasView : public QScrollView | 
|---|
| 363 | { | 
|---|
| 364 | Q_OBJECT | 
|---|
| 365 | public: | 
|---|
| 366 |  | 
|---|
| 367 | QCanvasView(QWidget* parent=0, const char* name=0, WFlags f=0); | 
|---|
| 368 | QCanvasView(QCanvas* viewing, QWidget* parent=0, const char* name=0, WFlags f=0); | 
|---|
| 369 | ~QCanvasView(); | 
|---|
| 370 |  | 
|---|
| 371 | QCanvas* canvas() const | 
|---|
| 372 | { return viewing; } | 
|---|
| 373 | void setCanvas(QCanvas* v); | 
|---|
| 374 |  | 
|---|
| 375 | const QWMatrix &worldMatrix() const; | 
|---|
| 376 | const QWMatrix &inverseWorldMatrix() const; | 
|---|
| 377 | bool setWorldMatrix( const QWMatrix & ); | 
|---|
| 378 |  | 
|---|
| 379 | protected: | 
|---|
| 380 | void drawContents( QPainter*, int cx, int cy, int cw, int ch ); | 
|---|
| 381 | QSize sizeHint() const; | 
|---|
| 382 |  | 
|---|
| 383 | private: | 
|---|
| 384 | void drawContents( QPainter* ); | 
|---|
| 385 | QCanvas* viewing; | 
|---|
| 386 | QCanvasViewData* d; | 
|---|
| 387 | friend void qt_unview(QCanvas* c); | 
|---|
| 388 |  | 
|---|
| 389 | private slots: | 
|---|
| 390 | void cMoving(int,int); | 
|---|
| 391 | void updateContentsSize(); | 
|---|
| 392 |  | 
|---|
| 393 | private: | 
|---|
| 394 | #if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator= | 
|---|
| 395 | QCanvasView( const QCanvasView & ); | 
|---|
| 396 | QCanvasView &operator=( const QCanvasView & ); | 
|---|
| 397 | #endif | 
|---|
| 398 | }; | 
|---|
| 399 |  | 
|---|
| 400 |  | 
|---|
| 401 | class QM_EXPORT_CANVAS QCanvasPixmap : public QPixmap | 
|---|
| 402 | { | 
|---|
| 403 | public: | 
|---|
| 404 | #ifndef QT_NO_IMAGEIO | 
|---|
| 405 | QCanvasPixmap(const QString& datafilename); | 
|---|
| 406 | #endif | 
|---|
| 407 | QCanvasPixmap(const QImage& image); | 
|---|
| 408 | QCanvasPixmap(const QPixmap&, const QPoint& hotspot); | 
|---|
| 409 | ~QCanvasPixmap(); | 
|---|
| 410 |  | 
|---|
| 411 | int offsetX() const | 
|---|
| 412 | { return hotx; } | 
|---|
| 413 | int offsetY() const | 
|---|
| 414 | { return hoty; } | 
|---|
| 415 | void setOffset(int x, int y) { hotx = x; hoty = y; } | 
|---|
| 416 |  | 
|---|
| 417 | private: | 
|---|
| 418 | #if defined(Q_DISABLE_COPY) | 
|---|
| 419 | QCanvasPixmap( const QCanvasPixmap & ); | 
|---|
| 420 | QCanvasPixmap &operator=( const QCanvasPixmap & ); | 
|---|
| 421 | #endif | 
|---|
| 422 | void init(const QImage&); | 
|---|
| 423 | void init(const QPixmap& pixmap, int hx, int hy); | 
|---|
| 424 |  | 
|---|
| 425 | friend class QCanvasSprite; | 
|---|
| 426 | friend class QCanvasPixmapArray; | 
|---|
| 427 | friend bool qt_testCollision(const QCanvasSprite* s1, const QCanvasSprite* s2); | 
|---|
| 428 |  | 
|---|
| 429 | int hotx,hoty; | 
|---|
| 430 |  | 
|---|
| 431 | QImage* collision_mask; | 
|---|
| 432 | }; | 
|---|
| 433 |  | 
|---|
| 434 |  | 
|---|
| 435 | class QM_EXPORT_CANVAS QCanvasPixmapArray | 
|---|
| 436 | { | 
|---|
| 437 | public: | 
|---|
| 438 | QCanvasPixmapArray(); | 
|---|
| 439 | #ifndef QT_NO_IMAGEIO | 
|---|
| 440 | QCanvasPixmapArray(const QString& datafilenamepattern, int framecount=0); | 
|---|
| 441 | #endif | 
|---|
| 442 | // this form is deprecated | 
|---|
| 443 | QCanvasPixmapArray(QPtrList<QPixmap>, QPtrList<QPoint> hotspots); | 
|---|
| 444 |  | 
|---|
| 445 | QCanvasPixmapArray(QValueList<QPixmap>, QPointArray hotspots = QPointArray() ); | 
|---|
| 446 | ~QCanvasPixmapArray(); | 
|---|
| 447 |  | 
|---|
| 448 | #ifndef QT_NO_IMAGEIO | 
|---|
| 449 | bool readPixmaps(const QString& datafilenamepattern, int framecount=0); | 
|---|
| 450 | bool readCollisionMasks(const QString& filenamepattern); | 
|---|
| 451 | #endif | 
|---|
| 452 |  | 
|---|
| 453 | // deprecated | 
|---|
| 454 | bool operator!(); // Failure check. | 
|---|
| 455 | bool isValid() const; | 
|---|
| 456 |  | 
|---|
| 457 | QCanvasPixmap* image(int i) const | 
|---|
| 458 | { return img ? img[i] : 0; } | 
|---|
| 459 | void setImage(int i, QCanvasPixmap* p); | 
|---|
| 460 | uint count() const | 
|---|
| 461 | { return (uint)framecount; } | 
|---|
| 462 |  | 
|---|
| 463 | private: | 
|---|
| 464 | #if defined(Q_DISABLE_COPY) | 
|---|
| 465 | QCanvasPixmapArray( const QCanvasPixmapArray & ); | 
|---|
| 466 | QCanvasPixmapArray &operator=( const QCanvasPixmapArray & ); | 
|---|
| 467 | #endif | 
|---|
| 468 | #ifndef QT_NO_IMAGEIO | 
|---|
| 469 | bool readPixmaps(const QString& datafilenamepattern, int framecount, bool maskonly); | 
|---|
| 470 | #endif | 
|---|
| 471 |  | 
|---|
| 472 | void reset(); | 
|---|
| 473 | int framecount; | 
|---|
| 474 | QCanvasPixmap** img; | 
|---|
| 475 | }; | 
|---|
| 476 |  | 
|---|
| 477 |  | 
|---|
| 478 | class QM_EXPORT_CANVAS QCanvasSprite : public QCanvasItem | 
|---|
| 479 | { | 
|---|
| 480 | public: | 
|---|
| 481 | QCanvasSprite(QCanvasPixmapArray* array, QCanvas* canvas); | 
|---|
| 482 |  | 
|---|
| 483 | void setSequence(QCanvasPixmapArray* seq); | 
|---|
| 484 |  | 
|---|
| 485 | virtual ~QCanvasSprite(); | 
|---|
| 486 |  | 
|---|
| 487 | void move(double x, double y); | 
|---|
| 488 | virtual void move(double x, double y, int frame); | 
|---|
| 489 | void setFrame(int); | 
|---|
| 490 | enum FrameAnimationType { Cycle, Oscillate }; | 
|---|
| 491 | virtual void setFrameAnimation(FrameAnimationType=Cycle, int step=1, int state=0); | 
|---|
| 492 | int frame() const | 
|---|
| 493 | { return frm; } | 
|---|
| 494 | int frameCount() const | 
|---|
| 495 | { return images->count(); } | 
|---|
| 496 |  | 
|---|
| 497 | int rtti() const; | 
|---|
| 498 | static int RTTI; | 
|---|
| 499 |  | 
|---|
| 500 | bool collidesWith( const QCanvasItem* ) const; | 
|---|
| 501 |  | 
|---|
| 502 | QRect boundingRect() const; | 
|---|
| 503 |  | 
|---|
| 504 | // is there a reason for these to be protected? Lars | 
|---|
| 505 | //protected: | 
|---|
| 506 |  | 
|---|
| 507 | int width() const; | 
|---|
| 508 | int height() const; | 
|---|
| 509 |  | 
|---|
| 510 | int leftEdge() const; | 
|---|
| 511 | int topEdge() const; | 
|---|
| 512 | int rightEdge() const; | 
|---|
| 513 | int bottomEdge() const; | 
|---|
| 514 |  | 
|---|
| 515 | int leftEdge(int nx) const; | 
|---|
| 516 | int topEdge(int ny) const; | 
|---|
| 517 | int rightEdge(int nx) const; | 
|---|
| 518 | int bottomEdge(int ny) const; | 
|---|
| 519 | QCanvasPixmap* image() const | 
|---|
| 520 | { return images->image(frm); } | 
|---|
| 521 | virtual QCanvasPixmap* imageAdvanced() const; | 
|---|
| 522 | QCanvasPixmap* image(int f) const | 
|---|
| 523 | { return images->image(f); } | 
|---|
| 524 | virtual void advance(int stage); | 
|---|
| 525 |  | 
|---|
| 526 | public: | 
|---|
| 527 | void draw(QPainter& painter); | 
|---|
| 528 |  | 
|---|
| 529 | private: | 
|---|
| 530 | #if defined(Q_DISABLE_COPY) | 
|---|
| 531 | QCanvasSprite( const QCanvasSprite & ); | 
|---|
| 532 | QCanvasSprite &operator=( const QCanvasSprite & ); | 
|---|
| 533 | #endif | 
|---|
| 534 | void addToChunks(); | 
|---|
| 535 | void removeFromChunks(); | 
|---|
| 536 | void changeChunks(); | 
|---|
| 537 |  | 
|---|
| 538 | int frm; | 
|---|
| 539 | ushort anim_val; | 
|---|
| 540 | uint anim_state:2; | 
|---|
| 541 | uint anim_type:14; | 
|---|
| 542 | bool collidesWith( const QCanvasSprite*, | 
|---|
| 543 | const QCanvasPolygonalItem*, | 
|---|
| 544 | const QCanvasRectangle*, | 
|---|
| 545 | const QCanvasEllipse*, | 
|---|
| 546 | const QCanvasText* ) const; | 
|---|
| 547 |  | 
|---|
| 548 | friend bool qt_testCollision( const QCanvasSprite* s1, | 
|---|
| 549 | const QCanvasSprite* s2 ); | 
|---|
| 550 |  | 
|---|
| 551 | QCanvasPixmapArray* images; | 
|---|
| 552 | }; | 
|---|
| 553 |  | 
|---|
| 554 | class QPolygonalProcessor; | 
|---|
| 555 |  | 
|---|
| 556 | class QM_EXPORT_CANVAS QCanvasPolygonalItem : public QCanvasItem | 
|---|
| 557 | { | 
|---|
| 558 | public: | 
|---|
| 559 | QCanvasPolygonalItem(QCanvas* canvas); | 
|---|
| 560 | virtual ~QCanvasPolygonalItem(); | 
|---|
| 561 |  | 
|---|
| 562 | bool collidesWith( const QCanvasItem* ) const; | 
|---|
| 563 |  | 
|---|
| 564 | virtual void setPen(QPen p); | 
|---|
| 565 | virtual void setBrush(QBrush b); | 
|---|
| 566 |  | 
|---|
| 567 | QPen pen() const | 
|---|
| 568 | { return pn; } | 
|---|
| 569 | QBrush brush() const | 
|---|
| 570 | { return br; } | 
|---|
| 571 |  | 
|---|
| 572 | virtual QPointArray areaPoints() const=0; | 
|---|
| 573 | virtual QPointArray areaPointsAdvanced() const; | 
|---|
| 574 | QRect boundingRect() const; | 
|---|
| 575 |  | 
|---|
| 576 | int rtti() const; | 
|---|
| 577 | static int RTTI; | 
|---|
| 578 |  | 
|---|
| 579 | protected: | 
|---|
| 580 | void draw(QPainter &); | 
|---|
| 581 | virtual void drawShape(QPainter &) = 0; | 
|---|
| 582 |  | 
|---|
| 583 | bool winding() const; | 
|---|
| 584 | void setWinding(bool); | 
|---|
| 585 |  | 
|---|
| 586 | void invalidate(); | 
|---|
| 587 | bool isValid() const | 
|---|
| 588 | { return (bool)val; } | 
|---|
| 589 |  | 
|---|
| 590 | private: | 
|---|
| 591 | #if !defined(Q_WS_PM) | 
|---|
| 592 | void scanPolygon( const QPointArray& pa, int winding, | 
|---|
| 593 | QPolygonalProcessor& process ) const; | 
|---|
| 594 | #endif | 
|---|
| 595 | QPointArray chunks() const; | 
|---|
| 596 |  | 
|---|
| 597 | bool collidesWith( const QCanvasSprite*, | 
|---|
| 598 | const QCanvasPolygonalItem*, | 
|---|
| 599 | const QCanvasRectangle*, | 
|---|
| 600 | const QCanvasEllipse*, | 
|---|
| 601 | const QCanvasText* ) const; | 
|---|
| 602 |  | 
|---|
| 603 | QBrush br; | 
|---|
| 604 | QPen pn; | 
|---|
| 605 | uint wind:1; | 
|---|
| 606 | }; | 
|---|
| 607 |  | 
|---|
| 608 |  | 
|---|
| 609 | class QM_EXPORT_CANVAS QCanvasRectangle : public QCanvasPolygonalItem | 
|---|
| 610 | { | 
|---|
| 611 | public: | 
|---|
| 612 | QCanvasRectangle(QCanvas* canvas); | 
|---|
| 613 | QCanvasRectangle(const QRect&, QCanvas* canvas); | 
|---|
| 614 | QCanvasRectangle(int x, int y, int width, int height, QCanvas* canvas); | 
|---|
| 615 |  | 
|---|
| 616 | ~QCanvasRectangle(); | 
|---|
| 617 |  | 
|---|
| 618 | int width() const; | 
|---|
| 619 | int height() const; | 
|---|
| 620 | void setSize(int w, int h); | 
|---|
| 621 | QSize size() const | 
|---|
| 622 | { return QSize(w,h); } | 
|---|
| 623 | QPointArray areaPoints() const; | 
|---|
| 624 | QRect rect() const | 
|---|
| 625 | { return QRect(int(x()),int(y()),w,h); } | 
|---|
| 626 |  | 
|---|
| 627 | bool collidesWith( const QCanvasItem* ) const; | 
|---|
| 628 |  | 
|---|
| 629 | int rtti() const; | 
|---|
| 630 | static int RTTI; | 
|---|
| 631 |  | 
|---|
| 632 | protected: | 
|---|
| 633 | void drawShape(QPainter &); | 
|---|
| 634 | QPointArray chunks() const; | 
|---|
| 635 |  | 
|---|
| 636 | private: | 
|---|
| 637 | bool collidesWith(   const QCanvasSprite*, | 
|---|
| 638 | const QCanvasPolygonalItem*, | 
|---|
| 639 | const QCanvasRectangle*, | 
|---|
| 640 | const QCanvasEllipse*, | 
|---|
| 641 | const QCanvasText* ) const; | 
|---|
| 642 |  | 
|---|
| 643 | int w, h; | 
|---|
| 644 | }; | 
|---|
| 645 |  | 
|---|
| 646 |  | 
|---|
| 647 | class QM_EXPORT_CANVAS QCanvasPolygon : public QCanvasPolygonalItem | 
|---|
| 648 | { | 
|---|
| 649 | public: | 
|---|
| 650 | QCanvasPolygon(QCanvas* canvas); | 
|---|
| 651 | ~QCanvasPolygon(); | 
|---|
| 652 | void setPoints(QPointArray); | 
|---|
| 653 | QPointArray points() const; | 
|---|
| 654 | void moveBy(double dx, double dy); | 
|---|
| 655 |  | 
|---|
| 656 | QPointArray areaPoints() const; | 
|---|
| 657 |  | 
|---|
| 658 | int rtti() const; | 
|---|
| 659 | static int RTTI; | 
|---|
| 660 |  | 
|---|
| 661 | protected: | 
|---|
| 662 | void drawShape(QPainter &); | 
|---|
| 663 | QPointArray poly; | 
|---|
| 664 | }; | 
|---|
| 665 |  | 
|---|
| 666 |  | 
|---|
| 667 | class QM_EXPORT_CANVAS QCanvasSpline : public QCanvasPolygon | 
|---|
| 668 | { | 
|---|
| 669 | public: | 
|---|
| 670 | QCanvasSpline(QCanvas* canvas); | 
|---|
| 671 | ~QCanvasSpline(); | 
|---|
| 672 |  | 
|---|
| 673 | void setControlPoints(QPointArray, bool closed=TRUE); | 
|---|
| 674 | QPointArray controlPoints() const; | 
|---|
| 675 | bool closed() const; | 
|---|
| 676 |  | 
|---|
| 677 | int rtti() const; | 
|---|
| 678 | static int RTTI; | 
|---|
| 679 |  | 
|---|
| 680 | private: | 
|---|
| 681 | void recalcPoly(); | 
|---|
| 682 | QPointArray bez; | 
|---|
| 683 | bool cl; | 
|---|
| 684 | }; | 
|---|
| 685 |  | 
|---|
| 686 |  | 
|---|
| 687 | class QM_EXPORT_CANVAS QCanvasLine : public QCanvasPolygonalItem | 
|---|
| 688 | { | 
|---|
| 689 | public: | 
|---|
| 690 | QCanvasLine(QCanvas* canvas); | 
|---|
| 691 | ~QCanvasLine(); | 
|---|
| 692 | void setPoints(int x1, int y1, int x2, int y2); | 
|---|
| 693 |  | 
|---|
| 694 | QPoint startPoint() const | 
|---|
| 695 | { return QPoint(x1,y1); } | 
|---|
| 696 | QPoint endPoint() const | 
|---|
| 697 | { return QPoint(x2,y2); } | 
|---|
| 698 |  | 
|---|
| 699 | int rtti() const; | 
|---|
| 700 | static int RTTI; | 
|---|
| 701 |  | 
|---|
| 702 | void setPen(QPen p); | 
|---|
| 703 | void moveBy(double dx, double dy); | 
|---|
| 704 |  | 
|---|
| 705 | protected: | 
|---|
| 706 | void drawShape(QPainter &); | 
|---|
| 707 | QPointArray areaPoints() const; | 
|---|
| 708 |  | 
|---|
| 709 | private: | 
|---|
| 710 | int x1,y1,x2,y2; | 
|---|
| 711 | }; | 
|---|
| 712 |  | 
|---|
| 713 |  | 
|---|
| 714 | class QM_EXPORT_CANVAS QCanvasEllipse : public QCanvasPolygonalItem | 
|---|
| 715 | { | 
|---|
| 716 |  | 
|---|
| 717 | public: | 
|---|
| 718 | QCanvasEllipse( QCanvas* canvas ); | 
|---|
| 719 | QCanvasEllipse( int width, int height, QCanvas* canvas ); | 
|---|
| 720 | QCanvasEllipse( int width, int height, int startangle, int angle, | 
|---|
| 721 | QCanvas* canvas ); | 
|---|
| 722 |  | 
|---|
| 723 | ~QCanvasEllipse(); | 
|---|
| 724 |  | 
|---|
| 725 | int width() const; | 
|---|
| 726 | int height() const; | 
|---|
| 727 | void setSize(int w, int h); | 
|---|
| 728 | void setAngles(int start, int length); | 
|---|
| 729 | int angleStart() const | 
|---|
| 730 | { return a1; } | 
|---|
| 731 | int angleLength() const | 
|---|
| 732 | { return a2; } | 
|---|
| 733 | QPointArray areaPoints() const; | 
|---|
| 734 |  | 
|---|
| 735 | bool collidesWith( const QCanvasItem* ) const; | 
|---|
| 736 |  | 
|---|
| 737 | int rtti() const; | 
|---|
| 738 | static int RTTI; | 
|---|
| 739 |  | 
|---|
| 740 | protected: | 
|---|
| 741 | void drawShape(QPainter &); | 
|---|
| 742 |  | 
|---|
| 743 | private: | 
|---|
| 744 | bool collidesWith( const QCanvasSprite*, | 
|---|
| 745 | const QCanvasPolygonalItem*, | 
|---|
| 746 | const QCanvasRectangle*, | 
|---|
| 747 | const QCanvasEllipse*, | 
|---|
| 748 | const QCanvasText* ) const; | 
|---|
| 749 | int w, h; | 
|---|
| 750 | int a1, a2; | 
|---|
| 751 | }; | 
|---|
| 752 |  | 
|---|
| 753 |  | 
|---|
| 754 | class QCanvasTextExtra; | 
|---|
| 755 |  | 
|---|
| 756 | class QM_EXPORT_CANVAS QCanvasText : public QCanvasItem | 
|---|
| 757 | { | 
|---|
| 758 | public: | 
|---|
| 759 | QCanvasText(QCanvas* canvas); | 
|---|
| 760 | QCanvasText(const QString&, QCanvas* canvas); | 
|---|
| 761 | QCanvasText(const QString&, QFont, QCanvas* canvas); | 
|---|
| 762 |  | 
|---|
| 763 | virtual ~QCanvasText(); | 
|---|
| 764 |  | 
|---|
| 765 | void setText( const QString& ); | 
|---|
| 766 | void setFont( const QFont& ); | 
|---|
| 767 | void setColor( const QColor& ); | 
|---|
| 768 | QString text() const; | 
|---|
| 769 | QFont font() const; | 
|---|
| 770 | QColor color() const; | 
|---|
| 771 |  | 
|---|
| 772 | void moveBy(double dx, double dy); | 
|---|
| 773 |  | 
|---|
| 774 | int textFlags() const | 
|---|
| 775 | { return flags; } | 
|---|
| 776 | void setTextFlags(int); | 
|---|
| 777 |  | 
|---|
| 778 | QRect boundingRect() const; | 
|---|
| 779 |  | 
|---|
| 780 | bool collidesWith( const QCanvasItem* ) const; | 
|---|
| 781 |  | 
|---|
| 782 | int rtti() const; | 
|---|
| 783 | static int RTTI; | 
|---|
| 784 |  | 
|---|
| 785 | protected: | 
|---|
| 786 | virtual void draw(QPainter&); | 
|---|
| 787 |  | 
|---|
| 788 | private: | 
|---|
| 789 | #if defined(Q_DISABLE_COPY) | 
|---|
| 790 | QCanvasText( const QCanvasText & ); | 
|---|
| 791 | QCanvasText &operator=( const QCanvasText & ); | 
|---|
| 792 | #endif | 
|---|
| 793 | void addToChunks(); | 
|---|
| 794 | void removeFromChunks(); | 
|---|
| 795 | void changeChunks(); | 
|---|
| 796 |  | 
|---|
| 797 | void setRect(); | 
|---|
| 798 | QRect brect; | 
|---|
| 799 | QString txt; | 
|---|
| 800 | int flags; | 
|---|
| 801 | QFont fnt; | 
|---|
| 802 | QColor col; | 
|---|
| 803 | QCanvasTextExtra* extra; | 
|---|
| 804 |  | 
|---|
| 805 | bool collidesWith(   const QCanvasSprite*, | 
|---|
| 806 | const QCanvasPolygonalItem*, | 
|---|
| 807 | const QCanvasRectangle*, | 
|---|
| 808 | const QCanvasEllipse*, | 
|---|
| 809 | const QCanvasText* ) const; | 
|---|
| 810 | }; | 
|---|
| 811 |  | 
|---|
| 812 | #define Q_DEFINED_QCANVAS | 
|---|
| 813 | #include "qwinexport.h" | 
|---|
| 814 | #endif // QT_NO_CANVAS | 
|---|
| 815 |  | 
|---|
| 816 | #endif // QCANVAS_H | 
|---|