Changed: #1301 Class PixmapDatabase was moved to a separate file.
--HG-- branch : gsoc2011-worldeditorqthg/feature/sse2
parent
8f223b7950
commit
500fb8fdfd
@ -0,0 +1,132 @@
|
|||||||
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
#include "pixmap_database.h"
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/debug.h>
|
||||||
|
#include <nel/ligo/zone_region.h>
|
||||||
|
|
||||||
|
// STL includes
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QtCore/QDir>
|
||||||
|
#include <QtGui/QMessageBox>
|
||||||
|
#include <QtGui/QApplication>
|
||||||
|
#include <QtGui/QProgressDialog>
|
||||||
|
|
||||||
|
namespace LandscapeEditor
|
||||||
|
{
|
||||||
|
|
||||||
|
PixmapDatabase::PixmapDatabase(int textureSize)
|
||||||
|
: m_textureSize(textureSize)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PixmapDatabase::~PixmapDatabase()
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PixmapDatabase::loadPixmaps(const QString &zonePath, NLLIGO::CZoneBank &zoneBank, bool displayProgress)
|
||||||
|
{
|
||||||
|
QProgressDialog *progressDialog;
|
||||||
|
std::vector<std::string> listNames;
|
||||||
|
zoneBank.getCategoryValues ("zone", listNames);
|
||||||
|
if (displayProgress)
|
||||||
|
{
|
||||||
|
progressDialog = new QProgressDialog();
|
||||||
|
progressDialog->show();
|
||||||
|
progressDialog->setRange(0, listNames.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint i = 0; i < listNames.size(); ++i)
|
||||||
|
{
|
||||||
|
QApplication::processEvents();
|
||||||
|
|
||||||
|
if (displayProgress)
|
||||||
|
progressDialog->setValue(i);
|
||||||
|
|
||||||
|
NLLIGO::CZoneBankElement *zoneBankItem = zoneBank.getElementByZoneName (listNames[i]);
|
||||||
|
|
||||||
|
// Read the texture file
|
||||||
|
QString zonePixmapName(listNames[i].c_str());
|
||||||
|
uint8 sizeX = zoneBankItem->getSizeX();
|
||||||
|
uint8 sizeY = zoneBankItem->getSizeY();
|
||||||
|
|
||||||
|
QPixmap *pixmap = new QPixmap(zonePath + zonePixmapName + ".png");
|
||||||
|
if (pixmap->isNull())
|
||||||
|
{
|
||||||
|
// Generate filled pixmap
|
||||||
|
}
|
||||||
|
// All pixmaps must be have same size
|
||||||
|
if (pixmap->width() != sizeX * m_textureSize)
|
||||||
|
{
|
||||||
|
QPixmap *scaledPixmap = new QPixmap(pixmap->scaled(sizeX * m_textureSize, sizeY * m_textureSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||||
|
delete pixmap;
|
||||||
|
m_pixmapMap.insert(zonePixmapName, scaledPixmap);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_pixmapMap.insert(zonePixmapName, pixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap *pixmap = new QPixmap(zonePath + "_unused_.png");
|
||||||
|
QPixmap *scaledPixmap = new QPixmap(pixmap->scaled(m_textureSize, m_textureSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||||
|
delete pixmap;
|
||||||
|
m_pixmapMap.insert(QString(STRING_UNUSED), scaledPixmap);
|
||||||
|
|
||||||
|
if (displayProgress)
|
||||||
|
delete progressDialog;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PixmapDatabase::reset()
|
||||||
|
{
|
||||||
|
QStringList listNames(m_pixmapMap.keys());
|
||||||
|
Q_FOREACH(QString name, listNames)
|
||||||
|
{
|
||||||
|
QPixmap *pixmap = m_pixmapMap.value(name);
|
||||||
|
delete pixmap;
|
||||||
|
}
|
||||||
|
m_pixmapMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList PixmapDatabase::listPixmaps() const
|
||||||
|
{
|
||||||
|
return m_pixmapMap.keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap *PixmapDatabase::pixmap(const QString &zoneName) const
|
||||||
|
{
|
||||||
|
QPixmap *result = 0;
|
||||||
|
if (!m_pixmapMap.contains(zoneName))
|
||||||
|
nlwarning("QPixmap %s not found", zoneName.toStdString().c_str());
|
||||||
|
else
|
||||||
|
result = m_pixmapMap.value(zoneName);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PixmapDatabase::textureSize() const
|
||||||
|
{
|
||||||
|
return m_textureSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace LandscapeEditor */
|
@ -0,0 +1,69 @@
|
|||||||
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef PIXMAP_DATABASE_H
|
||||||
|
#define PIXMAP_DATABASE_H
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
#include "landscape_editor_global.h"
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/ligo/zone_bank.h>
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QtCore/QString>
|
||||||
|
#include <QtCore/QMap>
|
||||||
|
#include <QtGui/QPixmap>
|
||||||
|
|
||||||
|
namespace LandscapeEditor
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
@class PixmapDatabase
|
||||||
|
@brief PixmapDatabase contains the image database
|
||||||
|
@details
|
||||||
|
*/
|
||||||
|
class LANDSCAPE_EDITOR_EXPORT PixmapDatabase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PixmapDatabase(int textureSize = 256);
|
||||||
|
~PixmapDatabase();
|
||||||
|
|
||||||
|
/// Load all images(png) from zonePath, list images gets from zoneBank
|
||||||
|
bool loadPixmaps(const QString &zonePath, NLLIGO::CZoneBank &zoneBank, bool displayProgress = false);
|
||||||
|
|
||||||
|
/// Unload all images
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
/// Get list names all loaded pixmaps
|
||||||
|
QStringList listPixmaps() const;
|
||||||
|
|
||||||
|
/// Get original pixmap
|
||||||
|
/// @return QPixmap* if the image is in the database ; otherwise returns 0.
|
||||||
|
QPixmap *pixmap(const QString &zoneName) const;
|
||||||
|
|
||||||
|
int textureSize() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int m_textureSize;
|
||||||
|
QMap<QString, QPixmap*> m_pixmapMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* namespace LandscapeEditor */
|
||||||
|
|
||||||
|
#endif // PIXMAP_DATABASE_H
|
Loading…
Reference in New Issue