diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-30 00:51:06 -0400 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-30 00:51:06 -0400 |
| commit | 42d73b43e1ded1a5c85fe4161b1efb66dcb973e3 (patch) | |
| tree | c55cfdf44e3f53921ae87e1706fb2c6f7a87c634 | |
| parent | dd34e949dc86f26b77809c6b0a0c06593da4e8e3 (diff) | |
Cache the mask
| -rw-r--r-- | sigmodr/widgets/mapeditor/TileItem.cpp | 15 | ||||
| -rw-r--r-- | sigmodr/widgets/mapeditor/TileItem.h | 1 |
2 files changed, 11 insertions, 5 deletions
diff --git a/sigmodr/widgets/mapeditor/TileItem.cpp b/sigmodr/widgets/mapeditor/TileItem.cpp index 8954c534..76a780c2 100644 --- a/sigmodr/widgets/mapeditor/TileItem.cpp +++ b/sigmodr/widgets/mapeditor/TileItem.cpp @@ -28,6 +28,7 @@ #include <KColorScheme> // Qt includes +#include <QtGui/QBitmap> #include <QtGui/QPainter> // Standard includes @@ -71,11 +72,7 @@ void TileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, else { if (m_mask) - { - QPixmap pix = m_pixmap.alphaChannel(); - if (!pix.isNull()) - painter->drawPixmap(0, 0, pix); - } + painter->drawPixmap(0, 0, m_masked); else painter->drawPixmap(0, 0, m_pixmap); } @@ -106,7 +103,15 @@ void TileItem::setSprite(const int spriteId) return; const Sprite* sprite = m_tile->game()->spriteById(spriteId); if (!sprite || !m_pixmap.loadFromData(sprite->sprite())) + { m_pixmap = QPixmap(); + m_masked = QPixmap(); + } + if (!m_pixmap.isNull()) + { + m_masked = m_pixmap.alphaChannel(); + m_masked.setMask(m_masked.createMaskFromColor(Qt::white)); + } prepareGeometryChange(); m_tileIndex = spriteId; } diff --git a/sigmodr/widgets/mapeditor/TileItem.h b/sigmodr/widgets/mapeditor/TileItem.h index 9e8de0e1..1cfe0b52 100644 --- a/sigmodr/widgets/mapeditor/TileItem.h +++ b/sigmodr/widgets/mapeditor/TileItem.h @@ -65,6 +65,7 @@ class SIGMODRWIDGETS_NO_EXPORT TileItem : public MapItem int m_tileIndex; bool m_mask; QPixmap m_pixmap; + QPixmap m_masked; }; } } |
