mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-21 08:28:44 +00:00
Changed: #1301 Class PixmapDatabase was moved to a separate file.
This commit is contained in:
parent
54391eaebf
commit
423d6ae8b3
5 changed files with 202 additions and 120 deletions
|
@ -14,7 +14,6 @@ SET(OVQT_PLUGIN_LANDSCAPE_EDITOR_HDR landscape_editor_plugin.h
|
||||||
landscape_scene.h
|
landscape_scene.h
|
||||||
list_zones_model.h
|
list_zones_model.h
|
||||||
list_zones_widget.h
|
list_zones_widget.h
|
||||||
landscape_actions.h
|
|
||||||
landscape_view.h
|
landscape_view.h
|
||||||
project_settings_dialog.h
|
project_settings_dialog.h
|
||||||
snapshot_dialog.h
|
snapshot_dialog.h
|
||||||
|
|
|
@ -32,92 +32,6 @@
|
||||||
namespace LandscapeEditor
|
namespace LandscapeEditor
|
||||||
{
|
{
|
||||||
|
|
||||||
PixmapDatabase::PixmapDatabase()
|
|
||||||
: m_textureSize(256)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
PixmapDatabase::~PixmapDatabase()
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PixmapDatabase::loadPixmaps(const QString &zonePath, NLLIGO::CZoneBank &zoneBank)
|
|
||||||
{
|
|
||||||
QProgressDialog *progressDialog = new QProgressDialog();
|
|
||||||
progressDialog->show();
|
|
||||||
|
|
||||||
std::vector<std::string> listNames;
|
|
||||||
zoneBank.getCategoryValues ("zone", listNames);
|
|
||||||
progressDialog->setRange(0, listNames.size());
|
|
||||||
for (uint i = 0; i < listNames.size(); ++i)
|
|
||||||
{
|
|
||||||
QApplication::processEvents();
|
|
||||||
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);
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
ZoneBuilder::ZoneBuilder(ListZonesWidget *listZonesWidget, LandscapeScene *landscapeScene, QUndoStack *undoStack)
|
ZoneBuilder::ZoneBuilder(ListZonesWidget *listZonesWidget, LandscapeScene *landscapeScene, QUndoStack *undoStack)
|
||||||
: m_currentZoneRegion(-1),
|
: m_currentZoneRegion(-1),
|
||||||
m_pixmapDatabase(0),
|
m_pixmapDatabase(0),
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
// Project includes
|
// Project includes
|
||||||
#include "builder_zone_region.h"
|
#include "builder_zone_region.h"
|
||||||
#include "zone_region_editor.h"
|
#include "zone_region_editor.h"
|
||||||
|
#include "pixmap_database.h"
|
||||||
|
|
||||||
// NeL includes
|
// NeL includes
|
||||||
#include <nel/ligo/zone_bank.h>
|
#include <nel/ligo/zone_bank.h>
|
||||||
|
@ -67,39 +68,6 @@ struct ZonePosition
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
@class PixmapDatabase
|
|
||||||
@brief PixmapDatabase contains the image database
|
|
||||||
@details
|
|
||||||
*/
|
|
||||||
class PixmapDatabase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PixmapDatabase();
|
|
||||||
~PixmapDatabase();
|
|
||||||
|
|
||||||
/// Load all images(png) from zonePath, list images gets from zoneBank
|
|
||||||
bool loadPixmaps(const QString &zonePath, NLLIGO::CZoneBank &zoneBank);
|
|
||||||
|
|
||||||
/// 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;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@class ZoneBuilder
|
@class ZoneBuilder
|
||||||
@brief ZoneBuilder contains all the shared data between the tools and the engine.
|
@brief ZoneBuilder contains all the shared data between the tools and the engine.
|
||||||
|
|
|
@ -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 a new issue