mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-23 07:16:15 +00:00
Copyright banner + line endings... I always mess this up somehow..
This commit is contained in:
parent
2ca6c73d09
commit
f694cfdb8e
2 changed files with 259 additions and 227 deletions
|
@ -1,185 +1,201 @@
|
||||||
#include "texture_chooser.h"
|
// Ryzom Core Studio GUI Editor plugin <http://dev.ryzom.com/projects/ryzom/>
|
||||||
#include "nel/misc/path.h"
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
#include "nel/misc/bitmap.h"
|
//
|
||||||
#include "nel/misc/file.h"
|
// This program is free software: you can redistribute it and/or modify
|
||||||
#include <vector>
|
// it under the terms of the GNU Affero General Public License as
|
||||||
#include <string>
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
#include <QPixMap>
|
// License, or (at your option) any later version.
|
||||||
#include <QImage>
|
//
|
||||||
#include <QListWidget>
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
#include "nel/gui/view_renderer.h"
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
struct TextureChooserPrivate
|
//
|
||||||
{
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
QListWidget *fileTextures;
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
QListWidget *atlasTextures;
|
|
||||||
|
#include "texture_chooser.h"
|
||||||
TextureChooserPrivate()
|
#include "nel/misc/path.h"
|
||||||
{
|
#include "nel/misc/bitmap.h"
|
||||||
fileTextures = new QListWidget();
|
#include "nel/misc/file.h"
|
||||||
atlasTextures = new QListWidget();
|
#include <vector>
|
||||||
}
|
#include <string>
|
||||||
};
|
#include <QPixMap>
|
||||||
|
#include <QImage>
|
||||||
TextureChooser::TextureChooser( QDialog *parent ) :
|
#include <QListWidget>
|
||||||
QDialog( parent )
|
|
||||||
{
|
#include "nel/gui/view_renderer.h"
|
||||||
setupUi( this );
|
|
||||||
|
struct TextureChooserPrivate
|
||||||
d_ptr = new TextureChooserPrivate;
|
{
|
||||||
this->tabWidget->clear();
|
QListWidget *fileTextures;
|
||||||
this->tabWidget->addTab( d_ptr->fileTextures, tr( "File textures" ) );
|
QListWidget *atlasTextures;
|
||||||
this->tabWidget->addTab( d_ptr->atlasTextures, tr( "Atlas texture" ) );
|
|
||||||
|
TextureChooserPrivate()
|
||||||
setupConnections();
|
{
|
||||||
}
|
fileTextures = new QListWidget();
|
||||||
|
atlasTextures = new QListWidget();
|
||||||
TextureChooser::~TextureChooser()
|
}
|
||||||
{
|
};
|
||||||
delete d_ptr;
|
|
||||||
d_ptr = NULL;
|
TextureChooser::TextureChooser( QDialog *parent ) :
|
||||||
}
|
QDialog( parent )
|
||||||
|
{
|
||||||
|
setupUi( this );
|
||||||
void TextureChooser::load()
|
|
||||||
{
|
d_ptr = new TextureChooserPrivate;
|
||||||
// Load the file textures
|
this->tabWidget->clear();
|
||||||
d_ptr->fileTextures->clear();
|
this->tabWidget->addTab( d_ptr->fileTextures, tr( "File textures" ) );
|
||||||
|
this->tabWidget->addTab( d_ptr->atlasTextures, tr( "Atlas texture" ) );
|
||||||
std::vector< std::string > textures;
|
|
||||||
//NLMISC::CPath::getFileList( "tga", textures );
|
setupConnections();
|
||||||
NLMISC::CPath::getFileListByPath( "dds", "interfaces", textures );
|
}
|
||||||
NLMISC::CPath::getFileListByPath( "dds", "gamedev", textures );
|
|
||||||
|
TextureChooser::~TextureChooser()
|
||||||
std::sort( textures.begin(), textures.end() );
|
{
|
||||||
|
delete d_ptr;
|
||||||
std::vector< std::string >::const_iterator itr = textures.begin();
|
d_ptr = NULL;
|
||||||
while( itr != textures.end() )
|
}
|
||||||
{
|
|
||||||
d_ptr->fileTextures->addItem( itr->c_str() );
|
|
||||||
++itr;
|
void TextureChooser::load()
|
||||||
}
|
{
|
||||||
|
// Load the file textures
|
||||||
// Now load the atlas textures
|
d_ptr->fileTextures->clear();
|
||||||
d_ptr->atlasTextures->clear();
|
|
||||||
textures.clear();
|
std::vector< std::string > textures;
|
||||||
|
//NLMISC::CPath::getFileList( "tga", textures );
|
||||||
NLGUI::CViewRenderer::getInstance()->getTextureNames( textures );
|
NLMISC::CPath::getFileListByPath( "dds", "interfaces", textures );
|
||||||
itr = textures.begin();
|
NLMISC::CPath::getFileListByPath( "dds", "gamedev", textures );
|
||||||
while( itr != textures.end() )
|
|
||||||
{
|
std::sort( textures.begin(), textures.end() );
|
||||||
d_ptr->atlasTextures->addItem( itr->c_str() );
|
|
||||||
++itr;
|
std::vector< std::string >::const_iterator itr = textures.begin();
|
||||||
}
|
while( itr != textures.end() )
|
||||||
|
{
|
||||||
// set the file textures row after the atlas, because they are shown first
|
d_ptr->fileTextures->addItem( itr->c_str() );
|
||||||
d_ptr->atlasTextures->setCurrentRow( 0 );
|
++itr;
|
||||||
d_ptr->fileTextures->setCurrentRow( 0 );
|
}
|
||||||
}
|
|
||||||
|
// Now load the atlas textures
|
||||||
void TextureChooser::accept()
|
d_ptr->atlasTextures->clear();
|
||||||
{
|
textures.clear();
|
||||||
QListWidgetItem *item = d_ptr->fileTextures->currentItem();
|
|
||||||
if( item == NULL )
|
NLGUI::CViewRenderer::getInstance()->getTextureNames( textures );
|
||||||
return;
|
itr = textures.begin();
|
||||||
|
while( itr != textures.end() )
|
||||||
selection = item->text();
|
{
|
||||||
QDialog::accept();
|
d_ptr->atlasTextures->addItem( itr->c_str() );
|
||||||
}
|
++itr;
|
||||||
|
}
|
||||||
void TextureChooser::reject()
|
|
||||||
{
|
// set the file textures row after the atlas, because they are shown first
|
||||||
selection = "";
|
d_ptr->atlasTextures->setCurrentRow( 0 );
|
||||||
|
d_ptr->fileTextures->setCurrentRow( 0 );
|
||||||
QDialog::reject();
|
}
|
||||||
}
|
|
||||||
|
void TextureChooser::accept()
|
||||||
void TextureChooser::onFileTxtRowChanged( int row )
|
{
|
||||||
{
|
QListWidgetItem *item = d_ptr->fileTextures->currentItem();
|
||||||
if( row < 0 )
|
if( item == NULL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QListWidgetItem *item = d_ptr->fileTextures->item( row );
|
selection = item->text();
|
||||||
QString fn = item->text();
|
QDialog::accept();
|
||||||
|
}
|
||||||
std::string rfn = fn.toUtf8().constData();
|
|
||||||
rfn = NLMISC::CPath::lookup( rfn );
|
void TextureChooser::reject()
|
||||||
|
{
|
||||||
NLMISC::CIFile f;
|
selection = "";
|
||||||
bool b = f.open( rfn );
|
|
||||||
if( !b )
|
QDialog::reject();
|
||||||
{
|
}
|
||||||
return;
|
|
||||||
}
|
void TextureChooser::onFileTxtRowChanged( int row )
|
||||||
|
{
|
||||||
NLMISC::CBitmap bm;
|
if( row < 0 )
|
||||||
uint8 depth = bm.load( f );
|
return;
|
||||||
f.close();
|
|
||||||
b = bm.convertToType( NLMISC::CBitmap::RGBA );
|
QListWidgetItem *item = d_ptr->fileTextures->item( row );
|
||||||
if( !b )
|
QString fn = item->text();
|
||||||
{
|
|
||||||
return;
|
std::string rfn = fn.toUtf8().constData();
|
||||||
}
|
rfn = NLMISC::CPath::lookup( rfn );
|
||||||
|
|
||||||
setPreviewImage( bm );
|
NLMISC::CIFile f;
|
||||||
}
|
bool b = f.open( rfn );
|
||||||
|
if( !b )
|
||||||
void TextureChooser::onAtlasTxtRowChanged( int row )
|
{
|
||||||
{
|
return;
|
||||||
if( row < 0 )
|
}
|
||||||
return;
|
|
||||||
|
NLMISC::CBitmap bm;
|
||||||
QListWidgetItem *item = d_ptr->atlasTextures->item( row );
|
uint8 depth = bm.load( f );
|
||||||
QString fn = item->text();
|
f.close();
|
||||||
|
b = bm.convertToType( NLMISC::CBitmap::RGBA );
|
||||||
std::string rfn = fn.toUtf8().constData();
|
if( !b )
|
||||||
|
{
|
||||||
NLMISC::CBitmap bm;
|
return;
|
||||||
|
}
|
||||||
bool b = NLGUI::CViewRenderer::getInstance()->getTexture( bm, rfn );
|
|
||||||
if( !b )
|
setPreviewImage( bm );
|
||||||
return;
|
}
|
||||||
|
|
||||||
setPreviewImage( bm );
|
void TextureChooser::onAtlasTxtRowChanged( int row )
|
||||||
}
|
{
|
||||||
|
if( row < 0 )
|
||||||
|
return;
|
||||||
void TextureChooser::setupConnections()
|
|
||||||
{
|
QListWidgetItem *item = d_ptr->atlasTextures->item( row );
|
||||||
connect( d_ptr->fileTextures, SIGNAL( currentRowChanged( int ) ), this, SLOT( onFileTxtRowChanged( int ) ) );
|
QString fn = item->text();
|
||||||
connect( d_ptr->atlasTextures, SIGNAL( currentRowChanged( int ) ), this, SLOT( onAtlasTxtRowChanged( int ) ) );
|
|
||||||
}
|
std::string rfn = fn.toUtf8().constData();
|
||||||
|
|
||||||
void TextureChooser::setPreviewImage( NLMISC::CBitmap &bm )
|
NLMISC::CBitmap bm;
|
||||||
{
|
|
||||||
// should be depth, but CBitmap always uses 32 bit to store the image
|
bool b = NLGUI::CViewRenderer::getInstance()->getTexture( bm, rfn );
|
||||||
uint32 size = bm.getSize() * ( 32 / 8 );
|
if( !b )
|
||||||
uint8 *data = new uint8[ size ];
|
return;
|
||||||
bm.getData( data );
|
|
||||||
|
setPreviewImage( bm );
|
||||||
/// Convert from ABGR to ARGB
|
}
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
while( i < size )
|
void TextureChooser::setupConnections()
|
||||||
{
|
{
|
||||||
uint8 t = 0;
|
connect( d_ptr->fileTextures, SIGNAL( currentRowChanged( int ) ), this, SLOT( onFileTxtRowChanged( int ) ) );
|
||||||
|
connect( d_ptr->atlasTextures, SIGNAL( currentRowChanged( int ) ), this, SLOT( onAtlasTxtRowChanged( int ) ) );
|
||||||
/// ABGR
|
}
|
||||||
t = data[ i ];
|
|
||||||
data[ i ] = data[ i + 2 ];
|
void TextureChooser::setPreviewImage( NLMISC::CBitmap &bm )
|
||||||
data[ i + 2 ] = t;
|
{
|
||||||
|
// should be depth, but CBitmap always uses 32 bit to store the image
|
||||||
i += 4;
|
uint32 size = bm.getSize() * ( 32 / 8 );
|
||||||
}
|
uint8 *data = new uint8[ size ];
|
||||||
}
|
bm.getData( data );
|
||||||
|
|
||||||
QImage img( data, bm.getWidth(), bm.getHeight(), QImage::Format_ARGB32 );
|
/// Convert from ABGR to ARGB
|
||||||
label->setPixmap( QPixmap::fromImage( img ) );
|
{
|
||||||
|
int i = 0;
|
||||||
delete data;
|
while( i < size )
|
||||||
data = NULL;
|
{
|
||||||
}
|
uint8 t = 0;
|
||||||
|
|
||||||
|
/// ABGR
|
||||||
|
t = data[ i ];
|
||||||
|
data[ i ] = data[ i + 2 ];
|
||||||
|
data[ i + 2 ] = t;
|
||||||
|
|
||||||
|
i += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage img( data, bm.getWidth(), bm.getHeight(), QImage::Format_ARGB32 );
|
||||||
|
label->setPixmap( QPixmap::fromImage( img ) );
|
||||||
|
|
||||||
|
delete data;
|
||||||
|
data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,42 +1,58 @@
|
||||||
#ifndef TEXTURE_CHOOSER_H
|
// Ryzom Core Studio GUI Editor plugin <http://dev.ryzom.com/projects/ryzom/>
|
||||||
#define TEXTURE_CHOOSER_H
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
//
|
||||||
#include "ui_texture_chooser.h"
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
namespace NLMISC
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
{
|
// License, or (at your option) any later version.
|
||||||
class CBitmap;
|
//
|
||||||
}
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
struct TextureChooserPrivate;
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
class TextureChooser : public QDialog, public Ui::TextureChooser
|
//
|
||||||
{
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
Q_OBJECT
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
public:
|
#ifndef TEXTURE_CHOOSER_H
|
||||||
TextureChooser( QDialog *parent = NULL );
|
#define TEXTURE_CHOOSER_H
|
||||||
~TextureChooser();
|
|
||||||
|
#include "ui_texture_chooser.h"
|
||||||
void load();
|
|
||||||
QString getSelection(){ return selection; }
|
namespace NLMISC
|
||||||
|
{
|
||||||
public Q_SLOTS:
|
class CBitmap;
|
||||||
void accept();
|
}
|
||||||
void reject();
|
|
||||||
|
struct TextureChooserPrivate;
|
||||||
private Q_SLOTS:
|
|
||||||
void onFileTxtRowChanged( int row );
|
class TextureChooser : public QDialog, public Ui::TextureChooser
|
||||||
void onAtlasTxtRowChanged( int row );
|
{
|
||||||
|
Q_OBJECT
|
||||||
private:
|
|
||||||
void setupConnections();
|
public:
|
||||||
void setPreviewImage( NLMISC::CBitmap &bm );
|
TextureChooser( QDialog *parent = NULL );
|
||||||
|
~TextureChooser();
|
||||||
QString selection;
|
|
||||||
|
void load();
|
||||||
TextureChooserPrivate *d_ptr;
|
QString getSelection(){ return selection; }
|
||||||
};
|
|
||||||
|
public Q_SLOTS:
|
||||||
#endif
|
void accept();
|
||||||
|
void reject();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onFileTxtRowChanged( int row );
|
||||||
|
void onAtlasTxtRowChanged( int row );
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupConnections();
|
||||||
|
void setPreviewImage( NLMISC::CBitmap &bm );
|
||||||
|
|
||||||
|
QString selection;
|
||||||
|
|
||||||
|
TextureChooserPrivate *d_ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue