summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-03-30 00:51:06 -0400
committerBen Boeckel <MathStuf@gmail.com>2009-03-30 00:51:06 -0400
commit42d73b43e1ded1a5c85fe4161b1efb66dcb973e3 (patch)
treec55cfdf44e3f53921ae87e1706fb2c6f7a87c634
parentdd34e949dc86f26b77809c6b0a0c06593da4e8e3 (diff)
Cache the mask
-rw-r--r--sigmodr/widgets/mapeditor/TileItem.cpp15
-rw-r--r--sigmodr/widgets/mapeditor/TileItem.h1
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;
};
}
}