diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp index 9e3f6d36a..0268ad3e6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp @@ -172,7 +172,10 @@ namespace MaterialEditor { QDockWidget *dock = new QDockWidget( tr( "Material" ), this ); dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); - dock->setWidget( new MaterialWidget() ); + + MaterialWidget *mw = new MaterialWidget(); + passesWidget->setMaterialObserver( mw ); + dock->setWidget( mw ); addDockWidget( Qt::RightDockWidgetArea, dock ); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_observer.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_observer.h new file mode 100644 index 000000000..7f28b0b8b --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_observer.h @@ -0,0 +1,40 @@ +// Object Viewer Qt Material 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 MATERIAL_OBSERVER_H +#define MATERIAL_OBSERVER_H + +namespace MaterialEditor +{ + /// Observes material changes + class CMaterialObserver + { + public: + CMaterialObserver(){} + virtual ~CMaterialObserver(){} + + virtual void onPassAdded( const char *name ) = 0; + virtual void onPassRemoved( const char *name ) = 0; + virtual void onPassMovedUp( const char *name ) = 0; + virtual void onPassMovedDown( const char *name ) = 0; + virtual void onPassRenamed( const char *from, const char *to ) = 0; + }; + +} + + +#endif + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp index b6f6c38ff..e97836222 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp @@ -38,6 +38,56 @@ namespace MaterialEditor matPropWidget = NULL; } + void MaterialWidget::onPassAdded( const char *name ) + { + passCB->addItem( name ); + } + + void MaterialWidget::onPassRemoved( const char *name ) + { + int i = passCB->findText( name ); + if( i == -1 ) + return; + + passCB->removeItem( i ); + } + + void MaterialWidget::onPassMovedUp( const char *name ) + { + int i = passCB->findText( name ); + if( i == -1 ) + return; + if( i == 0 ) + return; + + QString t = passCB->itemText( i - 1 ); + passCB->setItemText( i - 1, name ); + passCB->setItemText( i, t ); + passCB->setCurrentIndex( i - 1 ); + } + + void MaterialWidget::onPassMovedDown( const char *name ) + { + int i = passCB->findText( name ); + if( i == -1 ) + return; + if( i == ( passCB->count() - 1 ) ) + return; + + QString t = passCB->itemText( i + 1 ); + passCB->setItemText( i + 1, name ); + passCB->setItemText( i, t ); + passCB->setCurrentIndex( i + 1 ); + } + + void MaterialWidget::onPassRenamed( const char *from, const char *to ) + { + int i = passCB->findText( from ); + if( i == -1 ) + return; + passCB->setItemText( i, to ); + } + void MaterialWidget::setupConnections() { connect( passButton, SIGNAL( clicked( bool ) ), this, SLOT( onPassEditClicked() ) ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h index 0cd3e1c21..a7e3a365d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h @@ -18,19 +18,26 @@ #define MATERIAL_WIDGET_H #include "ui_material_widget.h" +#include "material_observer.h" namespace MaterialEditor { class ShaderEditorWidget; class MatPropWidget; - class MaterialWidget : public QWidget, Ui::MaterialWidget + class MaterialWidget : public QWidget, public Ui::MaterialWidget, public CMaterialObserver { Q_OBJECT public: MaterialWidget( QWidget *parent = NULL ); ~MaterialWidget(); + void onPassAdded( const char *name ); + void onPassRemoved( const char *name ); + void onPassMovedUp( const char *name ); + void onPassMovedDown( const char *name ); + void onPassRenamed( const char *from, const char *to ); + private: void setupConnections(); ShaderEditorWidget *shaderEditorWidget; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.cpp index a44dd48c2..0673a6060 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.cpp @@ -16,6 +16,7 @@ #include "render_passes.h" #include "nel3d_interface.h" +#include "material_observer.h" #include #include @@ -27,6 +28,7 @@ namespace MaterialEditor setupUi( this ); setupConnections(); nl3dIface = NULL; + observer = NULL; } RenderPassesWidget::~RenderPassesWidget() @@ -109,6 +111,9 @@ namespace MaterialEditor CNelMaterialProxy material = nl3dIface->getMaterial(); material.addPass( label.toUtf8().data() ); + + if( observer != NULL ) + observer->onPassAdded( label.toUtf8().data() ); } void RenderPassesWidget::onRemoveClicked() @@ -124,6 +129,9 @@ namespace MaterialEditor CNelMaterialProxy material = nl3dIface->getMaterial(); material.removePass( pass.toUtf8().data() ); + + if( observer != NULL ) + observer->onPassRemoved( pass.toUtf8().data() ); } void RenderPassesWidget::onEditClicked() @@ -149,6 +157,9 @@ namespace MaterialEditor CNelMaterialProxy material = nl3dIface->getMaterial(); material.renamePass( from.toUtf8().data(), to.toUtf8().data() ); + + if( observer != NULL ) + observer->onPassRenamed( from.toUtf8().data(), to.toUtf8().data() ); } void RenderPassesWidget::onUpClicked() @@ -169,6 +180,9 @@ namespace MaterialEditor CNelMaterialProxy material = nl3dIface->getMaterial(); material.movePassUp( s.toUtf8().data() ); + + if( observer != NULL ) + observer->onPassMovedUp( s.toUtf8().data() ); } void RenderPassesWidget::onDownClicked() @@ -189,6 +203,9 @@ namespace MaterialEditor CNelMaterialProxy material = nl3dIface->getMaterial(); material.movePassDown( s.toUtf8().data() ); + + if( observer != NULL ) + observer->onPassMovedDown( s.toUtf8().data() ); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.h index a3748e371..7c7aa4fa2 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.h @@ -23,6 +23,7 @@ namespace MaterialEditor { class CNel3DInterface; + class CMaterialObserver; class RenderPassesWidget : public QWidget, public Ui::RenderPassesWidget { @@ -35,10 +36,13 @@ namespace MaterialEditor void clear(); void setNel3dIface( CNel3DInterface *iface ){ nl3dIface = iface; } + void setMaterialObserver( CMaterialObserver *obs ){ observer = obs; } + private: void setupConnections(); CNel3DInterface *nl3dIface; + CMaterialObserver *observer; private Q_SLOTS: void onOKClicked();