diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp index bdbe54f8c..bb2605b80 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp @@ -1,5 +1,4 @@ // Object Viewer Qt - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited // Copyright (C) 2011 Dzmitry Kamiahin // // This program is free software: you can redistribute it and/or modify @@ -100,14 +99,15 @@ QGraphicsItem *LandscapeScene::createItemZone(const LigoData &data, const ZonePo // Enable bilinear filtering item->setTransformationMode(Qt::SmoothTransformation); - NLLIGO::CZoneBankElement *zoneBankItem = m_zoneBuilder->getZoneBank().getElementByZoneName(data.zoneName); + sint32 sizeX = 1, sizeY = 1; + sizeX = float(pixmap->width()) / m_zoneBuilder->pixmapDatabase()->textureSize(); + sizeY = float(pixmap->width()) / m_zoneBuilder->pixmapDatabase()->textureSize(); sint32 deltaX = 0, deltaY = 0; // Calculate offset for graphics item (for items with size that are larger than 1) - if ((zoneBankItem->getSizeX() > 1) || (zoneBankItem->getSizeY() > 1)) + if ((sizeX > 1) || (sizeY > 1)) { - sint32 sizeX = zoneBankItem->getSizeX(), sizeY = zoneBankItem->getSizeY(); if (data.flip == 0) { switch (data.rot) @@ -165,6 +165,8 @@ QGraphicsItem *LandscapeScene::createItemZone(const LigoData &data, const ZonePo // for not full item zone item->setZValue(LAYER_ZONES); + item->setShapeMode(QGraphicsPixmapItem::BoundingRectShape); + return item; } @@ -178,6 +180,7 @@ QGraphicsItem *LandscapeScene::createItemEmptyZone(const ZonePosition &zonePos) // Get image from pixmap database QPixmap *pixmap = m_zoneBuilder->pixmapDatabase()->pixmap(QString(STRING_UNUSED)); + if (pixmap == 0) return 0; @@ -195,6 +198,8 @@ QGraphicsItem *LandscapeScene::createItemEmptyZone(const ZonePosition &zonePos) // for not full item zone item->setZValue(LAYER_EMPTY_ZONES); + item->setShapeMode(QGraphicsPixmapItem::BoundingRectShape); + return item; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene_base.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene_base.cpp index 7946fffbc..473b1ad95 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene_base.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene_base.cpp @@ -97,14 +97,15 @@ QGraphicsItem *LandscapeSceneBase::createItemZone(const LigoData &data, const Zo // Enable bilinear filtering item->setTransformationMode(Qt::SmoothTransformation); - NLLIGO::CZoneBankElement *zoneBankItem = m_zoneBuilderBase->getZoneBank().getElementByZoneName(data.zoneName); + sint32 sizeX = 1, sizeY = 1; + sizeX = float(pixmap->width()) / m_zoneBuilderBase->pixmapDatabase()->textureSize(); + sizeY = float(pixmap->width()) / m_zoneBuilderBase->pixmapDatabase()->textureSize(); sint32 deltaX = 0, deltaY = 0; // Calculate offset for graphics item (for items with size that are larger than 1) - if ((zoneBankItem->getSizeX() > 1) || (zoneBankItem->getSizeY() > 1)) + if ((sizeX > 1) || (sizeY > 1)) { - sint32 sizeX = zoneBankItem->getSizeX(), sizeY = zoneBankItem->getSizeY(); if (data.flip == 0) { switch (data.rot) @@ -162,6 +163,8 @@ QGraphicsItem *LandscapeSceneBase::createItemZone(const LigoData &data, const Zo // for not full item zone item->setZValue(LAYER_ZONES); + item->setShapeMode(QGraphicsPixmapItem::BoundingRectShape); + return item; } @@ -192,6 +195,8 @@ QGraphicsItem *LandscapeSceneBase::createItemEmptyZone(const ZonePosition &zoneP // for not full item zone item->setZValue(LAYER_EMPTY_ZONES); + item->setShapeMode(QGraphicsPixmapItem::BoundingRectShape); + return item; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/pixmap_database.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/pixmap_database.cpp index 52d8e04f3..d3dbd646d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/pixmap_database.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/pixmap_database.cpp @@ -27,6 +27,7 @@ // Qt includes #include +#include #include #include #include @@ -35,12 +36,23 @@ namespace LandscapeEditor { PixmapDatabase::PixmapDatabase(int textureSize) - : m_textureSize(textureSize) + : m_textureSize(textureSize), + m_errorPixmap(0) { + m_errorPixmap = new QPixmap(QSize(m_textureSize, m_textureSize)); + QPainter painter(m_errorPixmap); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.fillRect(m_errorPixmap->rect(), QBrush(QColor(Qt::black))); + painter.setFont(QFont("Helvetica [Cronyx]", 14)); + painter.setPen(QPen(Qt::red, 2, Qt::SolidLine)); + painter.drawText(m_errorPixmap->rect(), Qt::AlignCenter | Qt::TextWordWrap, + QObject::tr("Pixmap and LIGO files not found. Set the correct data path and reload landscape.")); + painter.end(); } PixmapDatabase::~PixmapDatabase() { + delete m_errorPixmap; reset(); } @@ -73,9 +85,19 @@ bool PixmapDatabase::loadPixmaps(const QString &zonePath, NLLIGO::CZoneBank &zon if (pixmap->isNull()) { // Generate filled pixmap + QPixmap *emptyPixmap = new QPixmap(QSize(sizeX * m_textureSize, sizeY * m_textureSize)); + QPainter painter(emptyPixmap); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.fillRect(emptyPixmap->rect(), QBrush(QColor(Qt::black))); + painter.setFont(QFont("Helvetica [Cronyx]", 18)); + painter.setPen(QPen(Qt::red, 2, Qt::SolidLine)); + painter.drawText(emptyPixmap->rect(), Qt::AlignCenter, QObject::tr("Pixmap not found")); + painter.end(); + delete pixmap; + m_pixmapMap.insert(zonePixmapName, emptyPixmap); } // All pixmaps must be have same size - if (pixmap->width() != sizeX * m_textureSize) + else if (pixmap->width() != sizeX * m_textureSize) { QPixmap *scaledPixmap = new QPixmap(pixmap->scaled(sizeX * m_textureSize, sizeY * m_textureSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); delete pixmap; @@ -114,7 +136,7 @@ QStringList PixmapDatabase::listPixmaps() const QPixmap *PixmapDatabase::pixmap(const QString &zoneName) const { - QPixmap *result = 0; + QPixmap *result = m_errorPixmap; if (!m_pixmapMap.contains(zoneName)) nlwarning("QPixmap %s not found", zoneName.toStdString().c_str()); else diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/pixmap_database.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/pixmap_database.h index 85b0f180e..a9d4383ad 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/pixmap_database.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/pixmap_database.h @@ -1,5 +1,4 @@ // Object Viewer Qt - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited // Copyright (C) 2011 Dzmitry Kamiahin // // This program is free software: you can redistribute it and/or modify @@ -61,6 +60,7 @@ public: private: int m_textureSize; + QPixmap *m_errorPixmap; QMap m_pixmapMap; };