mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-29 20:30:54 +00:00
Texture chooser now supports atlas textures as well.
--HG-- branch : gsoc2014-dfighter
This commit is contained in:
parent
a1b0f9d7e2
commit
012ad96806
5 changed files with 146 additions and 18 deletions
|
@ -286,6 +286,12 @@ namespace NLGUI
|
|||
*/
|
||||
void flush ();
|
||||
|
||||
/// Retrives a texture
|
||||
bool getTexture( NLMISC::CBitmap &bm, const std::string &name );
|
||||
|
||||
/// Retrieve the texture names
|
||||
void getTextureNames( std::vector< std::string > &textures );
|
||||
|
||||
/**
|
||||
* get a texture file pointer from a string name. O(logN)
|
||||
* \param id : the id of the texture
|
||||
|
|
|
@ -1064,6 +1064,46 @@ namespace NLGUI
|
|||
}
|
||||
}
|
||||
|
||||
bool CViewRenderer::getTexture( NLMISC::CBitmap &bm, const std::string &name )
|
||||
{
|
||||
TTextureMap::const_iterator itr = _TextureMap.find( name );
|
||||
if( itr == _TextureMap.end() )
|
||||
return false;
|
||||
|
||||
sint32 id = itr->second;
|
||||
SImage *si = getSImage( id );
|
||||
NLMISC::CBitmap *src = si->GlobalTexturePtr->Texture->generateDatas();
|
||||
|
||||
if( src->getPixelFormat() != NLMISC::CBitmap::RGBA )
|
||||
return false;
|
||||
|
||||
uint x0 = (uint)( si->UVMin.U * si->GlobalTexturePtr->Width );
|
||||
uint y0 = (uint)( si->UVMin.V * si->GlobalTexturePtr->Height );
|
||||
uint x1 = (uint)( si->UVMax.U * si->GlobalTexturePtr->Width );
|
||||
uint y1 = (uint)( si->UVMax.V * si->GlobalTexturePtr->Height );
|
||||
|
||||
if( x1 == x0 )
|
||||
return false;
|
||||
|
||||
if( y1 == y0 )
|
||||
return false;
|
||||
|
||||
bm.resize( x1 - x0, y1 - y0 );
|
||||
bm.blit( *src, x0, y0, ( x1 - x0 ), ( y1 - y0 ), 0, 0 );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CViewRenderer::getTextureNames( std::vector< std::string > &textures )
|
||||
{
|
||||
TTextureMap::const_iterator itr = _TextureMap.begin();
|
||||
while( itr != _TextureMap.end() )
|
||||
{
|
||||
textures.push_back( itr->first );
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* getTextureIdFromName
|
||||
*/
|
||||
|
|
|
@ -6,40 +6,81 @@
|
|||
#include <string>
|
||||
#include <QPixMap>
|
||||
#include <QImage>
|
||||
#include <QListWidget>
|
||||
|
||||
#include "nel/gui/view_renderer.h"
|
||||
|
||||
struct TextureChooserPrivate
|
||||
{
|
||||
QListWidget *fileTextures;
|
||||
QListWidget *atlasTextures;
|
||||
|
||||
TextureChooserPrivate()
|
||||
{
|
||||
fileTextures = new QListWidget();
|
||||
atlasTextures = new QListWidget();
|
||||
}
|
||||
};
|
||||
|
||||
TextureChooser::TextureChooser( QDialog *parent ) :
|
||||
QDialog( parent )
|
||||
{
|
||||
setupUi( this );
|
||||
|
||||
d_ptr = new TextureChooserPrivate;
|
||||
this->tabWidget->clear();
|
||||
this->tabWidget->addTab( d_ptr->fileTextures, tr( "File textures" ) );
|
||||
this->tabWidget->addTab( d_ptr->atlasTextures, tr( "Atlas texture" ) );
|
||||
|
||||
setupConnections();
|
||||
}
|
||||
|
||||
TextureChooser::~TextureChooser()
|
||||
{
|
||||
delete d_ptr;
|
||||
d_ptr = NULL;
|
||||
}
|
||||
|
||||
|
||||
void TextureChooser::load()
|
||||
{
|
||||
listWidget->clear();
|
||||
// Load the file textures
|
||||
d_ptr->fileTextures->clear();
|
||||
|
||||
std::vector< std::string > textures;
|
||||
//NLMISC::CPath::getFileList( "tga", textures );
|
||||
NLMISC::CPath::getFileListByPath( "tga", "interfaces", textures );
|
||||
NLMISC::CPath::getFileListByPath( "dds", "interfaces", textures );
|
||||
NLMISC::CPath::getFileListByPath( "dds", "gamedev", textures );
|
||||
|
||||
std::sort( textures.begin(), textures.end() );
|
||||
|
||||
std::vector< std::string >::const_iterator itr = textures.begin();
|
||||
while( itr != textures.end() )
|
||||
{
|
||||
listWidget->addItem( itr->c_str() );
|
||||
d_ptr->fileTextures->addItem( itr->c_str() );
|
||||
++itr;
|
||||
}
|
||||
|
||||
listWidget->setCurrentRow( 0 );
|
||||
// Now load the atlas textures
|
||||
d_ptr->atlasTextures->clear();
|
||||
textures.clear();
|
||||
|
||||
NLGUI::CViewRenderer::getInstance()->getTextureNames( textures );
|
||||
itr = textures.begin();
|
||||
while( itr != textures.end() )
|
||||
{
|
||||
d_ptr->atlasTextures->addItem( itr->c_str() );
|
||||
++itr;
|
||||
}
|
||||
|
||||
// set the file textures row after the atlas, because they are shown first
|
||||
d_ptr->atlasTextures->setCurrentRow( 0 );
|
||||
d_ptr->fileTextures->setCurrentRow( 0 );
|
||||
}
|
||||
|
||||
void TextureChooser::accept()
|
||||
{
|
||||
QListWidgetItem *item = listWidget->currentItem();
|
||||
QListWidgetItem *item = d_ptr->fileTextures->currentItem();
|
||||
if( item == NULL )
|
||||
return;
|
||||
|
||||
|
@ -54,12 +95,12 @@ void TextureChooser::reject()
|
|||
QDialog::reject();
|
||||
}
|
||||
|
||||
void TextureChooser::onCurrentRowChanged( int row )
|
||||
void TextureChooser::onFileTxtRowChanged( int row )
|
||||
{
|
||||
if( row < 0 )
|
||||
return;
|
||||
|
||||
QListWidgetItem *item = listWidget->item( row );
|
||||
QListWidgetItem *item = d_ptr->fileTextures->item( row );
|
||||
QString fn = item->text();
|
||||
|
||||
std::string rfn = fn.toUtf8().constData();
|
||||
|
@ -81,8 +122,39 @@ void TextureChooser::onCurrentRowChanged( int row )
|
|||
return;
|
||||
}
|
||||
|
||||
uint32 size = bm.getSize() * ( 32 / 8 ); // should be depth, but CBitmap always uses 32 bit to store the image
|
||||
setPreviewImage( bm );
|
||||
}
|
||||
|
||||
void TextureChooser::onAtlasTxtRowChanged( int row )
|
||||
{
|
||||
if( row < 0 )
|
||||
return;
|
||||
|
||||
QListWidgetItem *item = d_ptr->atlasTextures->item( row );
|
||||
QString fn = item->text();
|
||||
|
||||
std::string rfn = fn.toUtf8().constData();
|
||||
|
||||
NLMISC::CBitmap bm;
|
||||
|
||||
bool b = NLGUI::CViewRenderer::getInstance()->getTexture( bm, rfn );
|
||||
if( !b )
|
||||
return;
|
||||
|
||||
setPreviewImage( bm );
|
||||
}
|
||||
|
||||
|
||||
void TextureChooser::setupConnections()
|
||||
{
|
||||
connect( d_ptr->fileTextures, SIGNAL( currentRowChanged( int ) ), this, SLOT( onFileTxtRowChanged( int ) ) );
|
||||
connect( d_ptr->atlasTextures, SIGNAL( currentRowChanged( int ) ), this, SLOT( onAtlasTxtRowChanged( int ) ) );
|
||||
}
|
||||
|
||||
void TextureChooser::setPreviewImage( NLMISC::CBitmap &bm )
|
||||
{
|
||||
// should be depth, but CBitmap always uses 32 bit to store the image
|
||||
uint32 size = bm.getSize() * ( 32 / 8 );
|
||||
uint8 *data = new uint8[ size ];
|
||||
bm.getData( data );
|
||||
|
||||
|
@ -107,13 +179,6 @@ void TextureChooser::onCurrentRowChanged( int row )
|
|||
|
||||
delete data;
|
||||
data = NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TextureChooser::setupConnections()
|
||||
{
|
||||
connect( listWidget, SIGNAL( currentRowChanged( int ) ), this, SLOT( onCurrentRowChanged( int ) ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,13 @@
|
|||
|
||||
#include "ui_texture_chooser.h"
|
||||
|
||||
namespace NLMISC
|
||||
{
|
||||
class CBitmap;
|
||||
}
|
||||
|
||||
struct TextureChooserPrivate;
|
||||
|
||||
class TextureChooser : public QDialog, public Ui::TextureChooser
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -19,12 +26,16 @@ public Q_SLOTS:
|
|||
void reject();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onCurrentRowChanged( int row );
|
||||
void onFileTxtRowChanged( int row );
|
||||
void onAtlasTxtRowChanged( int row );
|
||||
|
||||
private:
|
||||
void setupConnections();
|
||||
void setPreviewImage( NLMISC::CBitmap &bm );
|
||||
|
||||
QString selection;
|
||||
|
||||
TextureChooserPrivate *d_ptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,7 +18,13 @@
|
|||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>tab</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
|
|
Loading…
Reference in a new issue