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