Prototype of the texture chooser.
--HG-- branch : gsoc2014-dfighterhg/feature/cdb-packed
parent
e4e2a57b65
commit
1e6dc1cc37
@ -0,0 +1,98 @@
|
||||
#include "texture_chooser.h"
|
||||
#include "nel/misc/path.h"
|
||||
#include "nel/misc/bitmap.h"
|
||||
#include "nel/misc/file.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <QPixMap>
|
||||
#include <QImage>
|
||||
|
||||
TextureChooser::TextureChooser( QDialog *parent ) :
|
||||
QDialog( parent )
|
||||
{
|
||||
setupUi( this );
|
||||
setupConnections();
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
TextureChooser::~TextureChooser()
|
||||
{
|
||||
delete data;
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
|
||||
void TextureChooser::load()
|
||||
{
|
||||
listWidget->clear();
|
||||
|
||||
std::vector< std::string > textures;
|
||||
NLMISC::CPath::getFileList( "tga", textures );
|
||||
|
||||
std::vector< std::string >::const_iterator itr = textures.begin();
|
||||
while( itr != textures.end() )
|
||||
{
|
||||
listWidget->addItem( itr->c_str() );
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void TextureChooser::onCurrentRowChanged( int row )
|
||||
{
|
||||
if( row < 0 )
|
||||
return;
|
||||
|
||||
QListWidgetItem *item = listWidget->item( row );
|
||||
QString fn = item->text();
|
||||
|
||||
std::string rfn = fn.toUtf8().constData();
|
||||
rfn = NLMISC::CPath::lookup( rfn );
|
||||
|
||||
NLMISC::CIFile f;
|
||||
bool b = f.open( rfn );
|
||||
if( !b )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NLMISC::CBitmap bm;
|
||||
uint8 depth = bm.load( f );
|
||||
f.close();
|
||||
|
||||
uint32 size = bm.getSize() * ( 32 / 8 ); // should be depth, but CBitmap always uses 32 bit to store the image
|
||||
|
||||
if( data != NULL )
|
||||
delete data;
|
||||
|
||||
data = new uint8[ size ];
|
||||
bm.getData( data );
|
||||
|
||||
/// Convert from ABGR to ARGB
|
||||
{
|
||||
int i = 0;
|
||||
while( i < size )
|
||||
{
|
||||
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 ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TextureChooser::setupConnections()
|
||||
{
|
||||
connect( listWidget, SIGNAL( currentRowChanged( int ) ), this, SLOT( onCurrentRowChanged( int ) ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
#ifndef TEXTURE_CHOOSER_H
|
||||
#define TEXTURE_CHOOSER_H
|
||||
|
||||
#include "ui_texture_chooser.h"
|
||||
|
||||
class TextureChooser : public QDialog, public Ui::TextureChooser
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TextureChooser( QDialog *parent = NULL );
|
||||
~TextureChooser();
|
||||
|
||||
void load();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onCurrentRowChanged( int row );
|
||||
|
||||
private:
|
||||
void setupConnections();
|
||||
|
||||
unsigned char *data;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,116 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TextureChooser</class>
|
||||
<widget class="QDialog" name="TextureChooser">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::ApplicationModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>686</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Texture Chooser</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>351</width>
|
||||
<height>231</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>131</width>
|
||||
<height>31</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="okButton">
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancelButton">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>okButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>TextureChooser</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>278</x>
|
||||
<y>253</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>96</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>cancelButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>TextureChooser</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>369</x>
|
||||
<y>253</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>179</x>
|
||||
<y>282</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
Loading…
Reference in New Issue