From 249c082e9fb0c5e51de26a8b6dd9dbce53ad7e05 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 5 Jul 2014 02:55:46 +0200 Subject: [PATCH] Prototype of the texture chooser. --- .../src/plugins/gui_editor/CMakeLists.txt | 2 + .../plugins/gui_editor/gui_editor_window.cpp | 16 +++ .../plugins/gui_editor/gui_editor_window.h | 5 + .../plugins/gui_editor/texture_chooser.cpp | 98 +++++++++++++++ .../src/plugins/gui_editor/texture_chooser.h | 26 ++++ .../src/plugins/gui_editor/texture_chooser.ui | 116 ++++++++++++++++++ 6 files changed, 263 insertions(+) create mode 100644 code/studio/src/plugins/gui_editor/texture_chooser.cpp create mode 100644 code/studio/src/plugins/gui_editor/texture_chooser.h create mode 100644 code/studio/src/plugins/gui_editor/texture_chooser.ui diff --git a/code/studio/src/plugins/gui_editor/CMakeLists.txt b/code/studio/src/plugins/gui_editor/CMakeLists.txt index 33b016bd6..31d83ae83 100644 --- a/code/studio/src/plugins/gui_editor/CMakeLists.txt +++ b/code/studio/src/plugins/gui_editor/CMakeLists.txt @@ -31,6 +31,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR editor_selection_watcher.h editor_message_processor.h action_list.h + texture_chooser.h ) SET(OVQT_PLUGIN_GUI_EDITOR_UIS @@ -47,6 +48,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_UIS new_widget_widget.ui add_widget_widget.ui action_list.ui + texture_chooser.ui ) SET(QT_USE_QTGUI TRUE) diff --git a/code/studio/src/plugins/gui_editor/gui_editor_window.cpp b/code/studio/src/plugins/gui_editor/gui_editor_window.cpp index 9f6568936..3f4e318db 100644 --- a/code/studio/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/studio/src/plugins/gui_editor/gui_editor_window.cpp @@ -44,6 +44,7 @@ #include "editor_selection_watcher.h" #include "editor_message_processor.h" #include "add_widget_widget.h" +#include "texture_chooser.h" namespace GUIEditor { @@ -70,6 +71,8 @@ namespace GUIEditor widgetInfoTree = new CWidgetInfoTree; + tc = new TextureChooser(); + createMenus(); readSettings(); @@ -115,6 +118,9 @@ namespace GUIEditor removeMenus(); + delete tc; + tc = NULL; + delete messageProcessor; messageProcessor = NULL; @@ -353,6 +359,12 @@ namespace GUIEditor GUICtrl->show(); } + void GUIEditorWindow::onTCClicked() + { + tc->load(); + tc->exec(); + } + void GUIEditorWindow::createMenus() { Core::MenuManager *mm = Core::ICore::instance()->menuManager(); @@ -399,6 +411,10 @@ namespace GUIEditor connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onAddWidgetClicked() ) ); m->addAction( a ); + a = new QAction( "Texture Chooser", this ); + connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onTCClicked() ) ); + m->addAction( a ); + menu = m; } } diff --git a/code/studio/src/plugins/gui_editor/gui_editor_window.h b/code/studio/src/plugins/gui_editor/gui_editor_window.h index 15935fe74..d18a24813 100644 --- a/code/studio/src/plugins/gui_editor/gui_editor_window.h +++ b/code/studio/src/plugins/gui_editor/gui_editor_window.h @@ -28,6 +28,8 @@ class QtTreePropertyBrowser; class QMenu; +class TextureChooser; + namespace GUIEditor { @@ -65,6 +67,7 @@ private Q_SLOTS: void onGUILoaded(); void onAddWidgetClicked(); void onTreeChanged(); + void onTCClicked(); protected: @@ -98,6 +101,8 @@ private: QString currentProjectFile; QMenu *menu; + + TextureChooser *tc; }; } diff --git a/code/studio/src/plugins/gui_editor/texture_chooser.cpp b/code/studio/src/plugins/gui_editor/texture_chooser.cpp new file mode 100644 index 000000000..11e5a30fd --- /dev/null +++ b/code/studio/src/plugins/gui_editor/texture_chooser.cpp @@ -0,0 +1,98 @@ +#include "texture_chooser.h" +#include "nel/misc/path.h" +#include "nel/misc/bitmap.h" +#include "nel/misc/file.h" +#include +#include +#include +#include + +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 ) ) ); +} + + + diff --git a/code/studio/src/plugins/gui_editor/texture_chooser.h b/code/studio/src/plugins/gui_editor/texture_chooser.h new file mode 100644 index 000000000..fecd0aa1e --- /dev/null +++ b/code/studio/src/plugins/gui_editor/texture_chooser.h @@ -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 + diff --git a/code/studio/src/plugins/gui_editor/texture_chooser.ui b/code/studio/src/plugins/gui_editor/texture_chooser.ui new file mode 100644 index 000000000..0f635e96f --- /dev/null +++ b/code/studio/src/plugins/gui_editor/texture_chooser.ui @@ -0,0 +1,116 @@ + + + TextureChooser + + + Qt::ApplicationModal + + + + 0 + 0 + 686 + 300 + + + + Texture Chooser + + + + + + + + + + 0 + 0 + + + + + 351 + 231 + + + + + + + + + + + 6 + + + 0 + + + + + Qt::Horizontal + + + + 131 + 31 + + + + + + + + OK + + + + + + + Cancel + + + + + + + + + + + okButton + clicked() + TextureChooser + accept() + + + 278 + 253 + + + 96 + 254 + + + + + cancelButton + clicked() + TextureChooser + reject() + + + 369 + 253 + + + 179 + 282 + + + + +