1 | /**********************************************************************
|
---|
2 | ** $Id: qcanvas.h 69 2006-03-18 18:13:09Z 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 | void scanPolygon( const QPointArray& pa, int winding,
|
---|
592 | QPolygonalProcessor& process ) const;
|
---|
593 | QPointArray chunks() const;
|
---|
594 |
|
---|
595 | bool collidesWith( const QCanvasSprite*,
|
---|
596 | const QCanvasPolygonalItem*,
|
---|
597 | const QCanvasRectangle*,
|
---|
598 | const QCanvasEllipse*,
|
---|
599 | const QCanvasText* ) const;
|
---|
600 |
|
---|
601 | QBrush br;
|
---|
602 | QPen pn;
|
---|
603 | uint wind:1;
|
---|
604 | };
|
---|
605 |
|
---|
606 |
|
---|
607 | class QM_EXPORT_CANVAS QCanvasRectangle : public QCanvasPolygonalItem
|
---|
608 | {
|
---|
609 | public:
|
---|
610 | QCanvasRectangle(QCanvas* canvas);
|
---|
611 | QCanvasRectangle(const QRect&, QCanvas* canvas);
|
---|
612 | QCanvasRectangle(int x, int y, int width, int height, QCanvas* canvas);
|
---|
613 |
|
---|
614 | ~QCanvasRectangle();
|
---|
615 |
|
---|
616 | int width() const;
|
---|
617 | int height() const;
|
---|
618 | void setSize(int w, int h);
|
---|
619 | QSize size() const
|
---|
620 | { return QSize(w,h); }
|
---|
621 | QPointArray areaPoints() const;
|
---|
622 | QRect rect() const
|
---|
623 | { return QRect(int(x()),int(y()),w,h); }
|
---|
624 |
|
---|
625 | bool collidesWith( const QCanvasItem* ) const;
|
---|
626 |
|
---|
627 | int rtti() const;
|
---|
628 | static int RTTI;
|
---|
629 |
|
---|
630 | protected:
|
---|
631 | void drawShape(QPainter &);
|
---|
632 | QPointArray chunks() const;
|
---|
633 |
|
---|
634 | private:
|
---|
635 | bool collidesWith( const QCanvasSprite*,
|
---|
636 | const QCanvasPolygonalItem*,
|
---|
637 | const QCanvasRectangle*,
|
---|
638 | const QCanvasEllipse*,
|
---|
639 | const QCanvasText* ) const;
|
---|
640 |
|
---|
641 | int w, h;
|
---|
642 | };
|
---|
643 |
|
---|
644 |
|
---|
645 | class QM_EXPORT_CANVAS QCanvasPolygon : public QCanvasPolygonalItem
|
---|
646 | {
|
---|
647 | public:
|
---|
648 | QCanvasPolygon(QCanvas* canvas);
|
---|
649 | ~QCanvasPolygon();
|
---|
650 | void setPoints(QPointArray);
|
---|
651 | QPointArray points() const;
|
---|
652 | void moveBy(double dx, double dy);
|
---|
653 |
|
---|
654 | QPointArray areaPoints() const;
|
---|
655 |
|
---|
656 | int rtti() const;
|
---|
657 | static int RTTI;
|
---|
658 |
|
---|
659 | protected:
|
---|
660 | void drawShape(QPainter &);
|
---|
661 | QPointArray poly;
|
---|
662 | };
|
---|
663 |
|
---|
664 |
|
---|
665 | class QM_EXPORT_CANVAS QCanvasSpline : public QCanvasPolygon
|
---|
666 | {
|
---|
667 | public:
|
---|
668 | QCanvasSpline(QCanvas* canvas);
|
---|
669 | ~QCanvasSpline();
|
---|
670 |
|
---|
671 | void setControlPoints(QPointArray, bool closed=TRUE);
|
---|
672 | QPointArray controlPoints() const;
|
---|
673 | bool closed() const;
|
---|
674 |
|
---|
675 | int rtti() const;
|
---|
676 | static int RTTI;
|
---|
677 |
|
---|
678 | private:
|
---|
679 | void recalcPoly();
|
---|
680 | QPointArray bez;
|
---|
681 | bool cl;
|
---|
682 | };
|
---|
683 |
|
---|
684 |
|
---|
685 | class QM_EXPORT_CANVAS QCanvasLine : public QCanvasPolygonalItem
|
---|
686 | {
|
---|
687 | public:
|
---|
688 | QCanvasLine(QCanvas* canvas);
|
---|
689 | ~QCanvasLine();
|
---|
690 | void setPoints(int x1, int y1, int x2, int y2);
|
---|
691 |
|
---|
692 | QPoint startPoint() const
|
---|
693 | { return QPoint(x1,y1); }
|
---|
694 | QPoint endPoint() const
|
---|
695 | { return QPoint(x2,y2); }
|
---|
696 |
|
---|
697 | int rtti() const;
|
---|
698 | static int RTTI;
|
---|
699 |
|
---|
700 | void setPen(QPen p);
|
---|
701 | void moveBy(double dx, double dy);
|
---|
702 |
|
---|
703 | protected:
|
---|
704 | void drawShape(QPainter &);
|
---|
705 | QPointArray areaPoints() const;
|
---|
706 |
|
---|
707 | private:
|
---|
708 | int x1,y1,x2,y2;
|
---|
709 | };
|
---|
710 |
|
---|
711 |
|
---|
712 | class QM_EXPORT_CANVAS QCanvasEllipse : public QCanvasPolygonalItem
|
---|
713 | {
|
---|
714 |
|
---|
715 | public:
|
---|
716 | QCanvasEllipse( QCanvas* canvas );
|
---|
717 | QCanvasEllipse( int width, int height, QCanvas* canvas );
|
---|
718 | QCanvasEllipse( int width, int height, int startangle, int angle,
|
---|
719 | QCanvas* canvas );
|
---|
720 |
|
---|
721 | ~QCanvasEllipse();
|
---|
722 |
|
---|
723 | int width() const;
|
---|
724 | int height() const;
|
---|
725 | void setSize(int w, int h);
|
---|
726 | void setAngles(int start, int length);
|
---|
727 | int angleStart() const
|
---|
728 | { return a1; }
|
---|
729 | int angleLength() const
|
---|
730 | { return a2; }
|
---|
731 | QPointArray areaPoints() const;
|
---|
732 |
|
---|
733 | bool collidesWith( const QCanvasItem* ) const;
|
---|
734 |
|
---|
735 | int rtti() const;
|
---|
736 | static int RTTI;
|
---|
737 |
|
---|
738 | protected:
|
---|
739 | void drawShape(QPainter &);
|
---|
740 |
|
---|
741 | private:
|
---|
742 | bool collidesWith( const QCanvasSprite*,
|
---|
743 | const QCanvasPolygonalItem*,
|
---|
744 | const QCanvasRectangle*,
|
---|
745 | const QCanvasEllipse*,
|
---|
746 | const QCanvasText* ) const;
|
---|
747 | int w, h;
|
---|
748 | int a1, a2;
|
---|
749 | };
|
---|
750 |
|
---|
751 |
|
---|
752 | class QCanvasTextExtra;
|
---|
753 |
|
---|
754 | class QM_EXPORT_CANVAS QCanvasText : public QCanvasItem
|
---|
755 | {
|
---|
756 | public:
|
---|
757 | QCanvasText(QCanvas* canvas);
|
---|
758 | QCanvasText(const QString&, QCanvas* canvas);
|
---|
759 | QCanvasText(const QString&, QFont, QCanvas* canvas);
|
---|
760 |
|
---|
761 | virtual ~QCanvasText();
|
---|
762 |
|
---|
763 | void setText( const QString& );
|
---|
764 | void setFont( const QFont& );
|
---|
765 | void setColor( const QColor& );
|
---|
766 | QString text() const;
|
---|
767 | QFont font() const;
|
---|
768 | QColor color() const;
|
---|
769 |
|
---|
770 | void moveBy(double dx, double dy);
|
---|
771 |
|
---|
772 | int textFlags() const
|
---|
773 | { return flags; }
|
---|
774 | void setTextFlags(int);
|
---|
775 |
|
---|
776 | QRect boundingRect() const;
|
---|
777 |
|
---|
778 | bool collidesWith( const QCanvasItem* ) const;
|
---|
779 |
|
---|
780 | int rtti() const;
|
---|
781 | static int RTTI;
|
---|
782 |
|
---|
783 | protected:
|
---|
784 | virtual void draw(QPainter&);
|
---|
785 |
|
---|
786 | private:
|
---|
787 | #if defined(Q_DISABLE_COPY)
|
---|
788 | QCanvasText( const QCanvasText & );
|
---|
789 | QCanvasText &operator=( const QCanvasText & );
|
---|
790 | #endif
|
---|
791 | void addToChunks();
|
---|
792 | void removeFromChunks();
|
---|
793 | void changeChunks();
|
---|
794 |
|
---|
795 | void setRect();
|
---|
796 | QRect brect;
|
---|
797 | QString txt;
|
---|
798 | int flags;
|
---|
799 | QFont fnt;
|
---|
800 | QColor col;
|
---|
801 | QCanvasTextExtra* extra;
|
---|
802 |
|
---|
803 | bool collidesWith( const QCanvasSprite*,
|
---|
804 | const QCanvasPolygonalItem*,
|
---|
805 | const QCanvasRectangle*,
|
---|
806 | const QCanvasEllipse*,
|
---|
807 | const QCanvasText* ) const;
|
---|
808 | };
|
---|
809 |
|
---|
810 | #define Q_DEFINED_QCANVAS
|
---|
811 | #include "qwinexport.h"
|
---|
812 | #endif // QT_NO_CANVAS
|
---|
813 |
|
---|
814 | #endif // QCANVAS_H
|
---|