#include <q3canvas.h>
Inheritance diagram for Q3CanvasPixmap:


If you want to show a single pixmap on a Q3Canvas use a Q3CanvasSprite with just one pixmap.
When pixmaps are inserted into a Q3CanvasPixmapArray they are held as Q3CanvasPixmaps. {Q3CanvasSprite}s are used to show pixmaps on {Q3Canvas}es and hold their pixmaps in a Q3CanvasPixmapArray. If you retrieve a frame (pixmap) from a Q3CanvasSprite it will be returned as a Q3CanvasPixmap.
The pixmap is a QPixmap and can only be set in the constructor. There are three different constructors, one taking a QPixmap, one a QImage and one a file name that refers to a file in any supported file format (see QImageReader).
Q3CanvasPixmap can have a hotspot which is defined in terms of an (x, y) offset. When you create a Q3CanvasPixmap from a PNG file or from a QImage that has a QImage::offset(), the offset() is initialized appropriately, otherwise the constructor leaves it at (0, 0). You can set it later using setOffset(). When the Q3CanvasPixmap is used in a Q3CanvasSprite, the offset position is the point at Q3CanvasItem::x() and Q3CanvasItem::y(), not the top-left corner of the pixmap.
Note that for Q3CanvasPixmap objects created by a Q3CanvasSprite, the position of each Q3CanvasPixmap object is set so that the hotspot stays in the same position.
Definition at line 362 of file q3canvas.h.
Public Member Functions | |
| Q3CanvasPixmap (const QString &datafilename) | |
| Q3CanvasPixmap (const QImage &image) | |
| Q3CanvasPixmap (const QPixmap &, const QPoint &hotspot) | |
| ~Q3CanvasPixmap () | |
| int | offsetX () const |
| int | offsetY () const |
| void | setOffset (int x, int y) |
Private Member Functions | |
| void | init (const QImage &) |
| void | init (const QPixmap &pixmap, int hx, int hy) |
Private Attributes | |
| int | hotx |
| int | hoty |
| QImage * | collision_mask |
Friends | |
| class | Q3CanvasSprite |
| class | Q3CanvasPixmapArray |
| bool | qt_testCollision (const Q3CanvasSprite *s1, const Q3CanvasSprite *s2) |
| Q3CanvasPixmap::Q3CanvasPixmap | ( | const QString & | datafilename | ) |
Constructs a Q3CanvasPixmap that uses the image stored in datafilename.
Definition at line 2687 of file q3canvas.cpp.
Here is the call graph for this function:

| Q3CanvasPixmap::Q3CanvasPixmap | ( | const QImage & | image | ) |
Constructs a Q3CanvasPixmap from the image image.
Definition at line 2698 of file q3canvas.cpp.
Here is the call graph for this function:

Constructs a Q3CanvasPixmap from the pixmap pm using the offset offset.
Definition at line 2706 of file q3canvas.cpp.
References init(), QPoint::x(), and QPoint::y().
Here is the call graph for this function:

| Q3CanvasPixmap::~Q3CanvasPixmap | ( | ) |
Destroys the pixmap.
Definition at line 2740 of file q3canvas.cpp.
References collision_mask.
02741 { 02742 delete collision_mask; 02743 }
| int Q3CanvasPixmap::offsetX | ( | ) | const [inline] |
Returns the x-offset of the pixmap's hotspot.
Definition at line 372 of file q3canvas.h.
00373 { return hotx; }
| int Q3CanvasPixmap::offsetY | ( | ) | const [inline] |
Returns the y-offset of the pixmap's hotspot.
Definition at line 374 of file q3canvas.h.
00375 { return hoty; }
| void Q3CanvasPixmap::setOffset | ( | int | x, | |
| int | y | |||
| ) | [inline] |
| void Q3CanvasPixmap::init | ( | const QImage & | ) | [private] |
Definition at line 2711 of file q3canvas.cpp.
References collision_mask, hotx, hoty, i, and image.
Referenced by Q3CanvasPixmap().
02712 { 02713 convertFromImage(image); 02714 hotx = image.offset().x(); 02715 hoty = image.offset().y(); 02716 #ifndef QT_NO_IMAGE_DITHER_TO_1 02717 if(image.hasAlphaBuffer()) { 02718 QImage i = image.createAlphaMask(); 02719 collision_mask = new QImage(i); 02720 } else 02721 #endif 02722 collision_mask = 0; 02723 }
| void Q3CanvasPixmap::init | ( | const QPixmap & | pixmap, | |
| int | hx, | |||
| int | hy | |||
| ) | [private] |
Definition at line 2725 of file q3canvas.cpp.
References collision_mask, QPixmap::hasAlphaChannel(), hotx, hoty, i, and QPixmap::mask().
02726 { 02727 (QPixmap&)*this = pixmap; 02728 hotx = hx; 02729 hoty = hy; 02730 if(pixmap.hasAlphaChannel()) { 02731 QImage i = mask().convertToImage(); 02732 collision_mask = new QImage(i); 02733 } else 02734 collision_mask = 0; 02735 }
Here is the call graph for this function:

friend class Q3CanvasSprite [friend] |
Definition at line 384 of file q3canvas.h.
friend class Q3CanvasPixmapArray [friend] |
Definition at line 385 of file q3canvas.h.
| bool qt_testCollision | ( | const Q3CanvasSprite * | s1, | |
| const Q3CanvasSprite * | s2 | |||
| ) | [friend] |
Definition at line 2171 of file q3canvas.cpp.
02172 { 02173 const QImage* s2image = s2->imageAdvanced()->collision_mask; 02174 QRect s2area = s2->boundingRectAdvanced(); 02175 02176 QRect cyourarea(s2area.x(),s2area.y(), 02177 s2area.width(),s2area.height()); 02178 02179 QImage* s1image=s1->imageAdvanced()->collision_mask; 02180 02181 QRect s1area = s1->boundingRectAdvanced(); 02182 02183 QRect ourarea = s1area.intersected(cyourarea); 02184 02185 if (ourarea.isEmpty()) 02186 return false; 02187 02188 int x2=ourarea.x()-cyourarea.x(); 02189 int y2=ourarea.y()-cyourarea.y(); 02190 int x1=ourarea.x()-s1area.x(); 02191 int y1=ourarea.y()-s1area.y(); 02192 int w=ourarea.width(); 02193 int h=ourarea.height(); 02194 02195 if (!s2image) { 02196 if (!s1image) 02197 return w>0 && h>0; 02198 // swap everything around 02199 int t; 02200 t=x1; x1=x2; x2=t; 02201 t=y1; x1=y2; y2=t; 02202 s2image = s1image; 02203 s1image = 0; 02204 } 02205 02206 // s2image != 0 02207 02208 // A non-linear search may be more efficient. 02209 // Perhaps spiralling out from the center, or a simpler 02210 // vertical expansion from the centreline. 02211 02212 // We assume that sprite masks don't have 02213 // different bit orders. 02214 // 02215 // Q_ASSERT(s1image->bitOrder()==s2image->bitOrder()); 02216 02217 if (s1image) { 02218 if (s1image->bitOrder() == QImage::LittleEndian) { 02219 for (int j=0; j<h; j++) { 02220 uchar* ml = s1image->scanLine(y1+j); 02221 const uchar* yl = s2image->scanLine(y2+j); 02222 for (int i=0; i<w; i++) { 02223 if (*(yl + ((x2+i) >> 3)) & (1 << ((x2+i) & 7)) 02224 && *(ml + ((x1+i) >> 3)) & (1 << ((x1+i) & 7))) 02225 { 02226 return true; 02227 } 02228 } 02229 } 02230 } else { 02231 for (int j=0; j<h; j++) { 02232 uchar* ml = s1image->scanLine(y1+j); 02233 const uchar* yl = s2image->scanLine(y2+j); 02234 for (int i=0; i<w; i++) { 02235 if (*(yl + ((x2+i) >> 3)) & (1 << (7-((x2+i) & 7))) 02236 && *(ml + ((x1+i) >> 3)) & (1 << (7-((x1+i) & 7)))) 02237 { 02238 return true; 02239 } 02240 } 02241 } 02242 } 02243 } else { 02244 if (s2image->bitOrder() == QImage::LittleEndian) { 02245 for (int j=0; j<h; j++) { 02246 const uchar* yl = s2image->scanLine(y2+j); 02247 for (int i=0; i<w; i++) { 02248 if (*(yl + ((x2+i) >> 3)) & (1 << ((x2+i) & 7))) 02249 { 02250 return true; 02251 } 02252 } 02253 } 02254 } else { 02255 for (int j=0; j<h; j++) { 02256 const uchar* yl = s2image->scanLine(y2+j); 02257 for (int i=0; i<w; i++) { 02258 if (*(yl + ((x2+i) >> 3)) & (1 << (7-((x2+i) & 7)))) 02259 { 02260 return true; 02261 } 02262 } 02263 } 02264 } 02265 } 02266 02267 return false; 02268 }
int Q3CanvasPixmap::hotx [private] |
int Q3CanvasPixmap::hoty [private] |
QImage* Q3CanvasPixmap::collision_mask [private] |
Definition at line 390 of file q3canvas.h.
Referenced by init(), Q3CanvasPixmapArray::readPixmaps(), and ~Q3CanvasPixmap().
1.5.1