diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-30 00:17:39 -0400 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-30 00:17:39 -0400 |
| commit | d58458d28850e6ac4cf4781e8723e689f0be43ec (patch) | |
| tree | 773173f9a6d1acaa83257459cd03c0fb8c8e7ae7 | |
| parent | 627cc844b8e91360432fd8cd650fe9e98aed1fbc (diff) | |
Allow drawing of a collision mask of the tiles
| -rw-r--r-- | sigmodr/widgets/mapeditor/MapScene.cpp | 7 | ||||
| -rw-r--r-- | sigmodr/widgets/mapeditor/MapScene.h | 4 | ||||
| -rw-r--r-- | sigmodr/widgets/mapeditor/TileItem.cpp | 20 | ||||
| -rw-r--r-- | sigmodr/widgets/mapeditor/TileItem.h | 3 |
4 files changed, 32 insertions, 2 deletions
diff --git a/sigmodr/widgets/mapeditor/MapScene.cpp b/sigmodr/widgets/mapeditor/MapScene.cpp index 885d7e3f..0152332e 100644 --- a/sigmodr/widgets/mapeditor/MapScene.cpp +++ b/sigmodr/widgets/mapeditor/MapScene.cpp @@ -66,6 +66,7 @@ MapScene::MapScene(Map* map, QObject* parent) : MapTile* tile = m_map->tile(i); TileItem* item = new TileItem(m_map, tile, this); connect(item, SIGNAL(changed()), this, SIGNAL(changed())); + connect(this, SIGNAL(maskTiles(bool)), item, SLOT(drawCollisionMask(bool))); m_tiles[tile] = item; addItem(item); } @@ -132,6 +133,7 @@ void MapScene::addTile() tile->setPosition(viewList[0]->mapToScene(QPoint(0, 0)).toPoint()); TileItem* item = new TileItem(m_map, tile, this); connect(item, SIGNAL(changed()), this, SIGNAL(changed())); + connect(this, SIGNAL(maskTiles(bool)), item, SLOT(drawCollisionMask(bool))); m_tiles[tile] = item; addItem(item); emit(changed()); @@ -279,6 +281,11 @@ void MapScene::showWarps(const int state) } } +void MapScene::tileMask(const bool mask) +{ + emit(maskTiles(mask)); +} + void MapScene::itemSelectionChanged() { QList<QGraphicsItem*> items = selectedItems(); diff --git a/sigmodr/widgets/mapeditor/MapScene.h b/sigmodr/widgets/mapeditor/MapScene.h index cc284175..dce59187 100644 --- a/sigmodr/widgets/mapeditor/MapScene.h +++ b/sigmodr/widgets/mapeditor/MapScene.h @@ -65,9 +65,13 @@ class SIGMODRWIDGETS_NO_EXPORT MapScene : public QGraphicsScene void showTiles(const int state); void showTrainers(const int state); void showWarps(const int state); + + void tileMask(const bool mask); signals: void changed(); + void maskTiles(const bool mask); + void itemsSelected(const bool selected); void tilesSelected(const bool selected); protected slots: diff --git a/sigmodr/widgets/mapeditor/TileItem.cpp b/sigmodr/widgets/mapeditor/TileItem.cpp index e5983c86..8954c534 100644 --- a/sigmodr/widgets/mapeditor/TileItem.cpp +++ b/sigmodr/widgets/mapeditor/TileItem.cpp @@ -39,7 +39,8 @@ using namespace Sigmodr::Widgets; TileItem::TileItem(Sigmod::Map* map, MapTile* tile, QGraphicsScene* parent) : MapItem(map, parent), m_tile(tile), - m_tileIndex(INT_MIN) + m_tileIndex(INT_MIN), + m_mask(false) { connect(m_tile, SIGNAL(changed()), this, SIGNAL(changed())); connect(m_tile, SIGNAL(changed()), this, SLOT(tileChanged())); @@ -68,7 +69,16 @@ void TileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, painter->drawPath(path); } else - painter->drawPixmap(0, 0, m_pixmap); + { + if (m_mask) + { + QPixmap pix = m_pixmap.alphaChannel(); + if (!pix.isNull()) + painter->drawPixmap(0, 0, pix); + } + else + painter->drawPixmap(0, 0, m_pixmap); + } painter->setBrush(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active)); painter->setOpacity(.25); MapItem::paint(painter, option, widget); @@ -84,6 +94,12 @@ int TileItem::type() const return Type; } +void TileItem::drawCollisionMask(const bool mask) +{ + m_mask = mask; + update(); +} + void TileItem::setSprite(const int spriteId) { if (spriteId == m_tileIndex) diff --git a/sigmodr/widgets/mapeditor/TileItem.h b/sigmodr/widgets/mapeditor/TileItem.h index c7d4fa14..9e8de0e1 100644 --- a/sigmodr/widgets/mapeditor/TileItem.h +++ b/sigmodr/widgets/mapeditor/TileItem.h @@ -51,6 +51,8 @@ class SIGMODRWIDGETS_NO_EXPORT TileItem : public MapItem int type() const; public slots: + void drawCollisionMask(const bool mask); + void setSprite(const int spriteId); protected: void moveTo(const QPoint& point); @@ -61,6 +63,7 @@ class SIGMODRWIDGETS_NO_EXPORT TileItem : public MapItem Sigmod::MapTile* m_tile; int m_tileIndex; + bool m_mask; QPixmap m_pixmap; }; } |
