From d850a07e9e870c1e2ad35575b31e33613487ebad Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 9 Jul 2014 21:13:57 +0200 Subject: [PATCH] Copyright banner + line endings... I always mess this up somehow.. --HG-- branch : gsoc2014-dfighter --- .../plugins/gui_editor/texture_chooser.cpp | 386 +++++++++--------- .../src/plugins/gui_editor/texture_chooser.h | 100 +++-- 2 files changed, 259 insertions(+), 227 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/texture_chooser.cpp b/code/studio/src/plugins/gui_editor/texture_chooser.cpp index 1c5e692ee..57a0e8d51 100644 --- a/code/studio/src/plugins/gui_editor/texture_chooser.cpp +++ b/code/studio/src/plugins/gui_editor/texture_chooser.cpp @@ -1,185 +1,201 @@ -#include "texture_chooser.h" -#include "nel/misc/path.h" -#include "nel/misc/bitmap.h" -#include "nel/misc/file.h" -#include -#include -#include -#include -#include - -#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() -{ - // Load the file textures - d_ptr->fileTextures->clear(); - - std::vector< std::string > textures; - //NLMISC::CPath::getFileList( "tga", 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() ) - { - d_ptr->fileTextures->addItem( itr->c_str() ); - ++itr; - } - - // 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 = d_ptr->fileTextures->currentItem(); - if( item == NULL ) - return; - - selection = item->text(); - QDialog::accept(); -} - -void TextureChooser::reject() -{ - selection = ""; - - QDialog::reject(); -} - -void TextureChooser::onFileTxtRowChanged( int row ) -{ - if( row < 0 ) - return; - - QListWidgetItem *item = d_ptr->fileTextures->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(); - b = bm.convertToType( NLMISC::CBitmap::RGBA ); - if( !b ) - { - return; - } - - 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 ); - - /// 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 ) ); - - delete data; - data = NULL; -} - - - +// Ryzom Core Studio GUI Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// 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 . + +#include "texture_chooser.h" +#include "nel/misc/path.h" +#include "nel/misc/bitmap.h" +#include "nel/misc/file.h" +#include +#include +#include +#include +#include + +#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() +{ + // Load the file textures + d_ptr->fileTextures->clear(); + + std::vector< std::string > textures; + //NLMISC::CPath::getFileList( "tga", 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() ) + { + d_ptr->fileTextures->addItem( itr->c_str() ); + ++itr; + } + + // 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 = d_ptr->fileTextures->currentItem(); + if( item == NULL ) + return; + + selection = item->text(); + QDialog::accept(); +} + +void TextureChooser::reject() +{ + selection = ""; + + QDialog::reject(); +} + +void TextureChooser::onFileTxtRowChanged( int row ) +{ + if( row < 0 ) + return; + + QListWidgetItem *item = d_ptr->fileTextures->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(); + b = bm.convertToType( NLMISC::CBitmap::RGBA ); + if( !b ) + { + return; + } + + 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 ); + + /// 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 ) ); + + delete data; + data = NULL; +} + + + diff --git a/code/studio/src/plugins/gui_editor/texture_chooser.h b/code/studio/src/plugins/gui_editor/texture_chooser.h index 9a615c266..160b31481 100644 --- a/code/studio/src/plugins/gui_editor/texture_chooser.h +++ b/code/studio/src/plugins/gui_editor/texture_chooser.h @@ -1,42 +1,58 @@ -#ifndef TEXTURE_CHOOSER_H -#define TEXTURE_CHOOSER_H - -#include "ui_texture_chooser.h" - -namespace NLMISC -{ - class CBitmap; -} - -struct TextureChooserPrivate; - -class TextureChooser : public QDialog, public Ui::TextureChooser -{ - Q_OBJECT - -public: - TextureChooser( QDialog *parent = NULL ); - ~TextureChooser(); - - void load(); - QString getSelection(){ return selection; } - -public Q_SLOTS: - 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 - +// Ryzom Core Studio GUI Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// 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 . + +#ifndef TEXTURE_CHOOSER_H +#define TEXTURE_CHOOSER_H + +#include "ui_texture_chooser.h" + +namespace NLMISC +{ + class CBitmap; +} + +struct TextureChooserPrivate; + +class TextureChooser : public QDialog, public Ui::TextureChooser +{ + Q_OBJECT + +public: + TextureChooser( QDialog *parent = NULL ); + ~TextureChooser(); + + void load(); + QString getSelection(){ return selection; } + +public Q_SLOTS: + 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 +