Adding / Removing properties will now work.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 94fe455a1a
commit 832178a83f

@ -59,6 +59,10 @@ namespace NL3D
void getName( std::string &n ) const { n = name; }
void serial( NLMISC::IStream &f );
uint32 count(){ return properties.size(); }
void clear(){ properties.clear(); }
const SDynMaterialProp* getProperty( uint32 i ) const;
private:
std::vector< SDynMaterialProp > properties;
std::string name;
@ -82,6 +86,8 @@ namespace NL3D
void movePassDown( const std::string &name );
SRenderPass* getPass( const std::string &name );
SRenderPass* getPass( uint32 i );
uint32 count(){ return passes.size(); }
void getPassList( std::vector< std::string > &l );
private:

@ -134,6 +134,13 @@ namespace NL3D
}
const SDynMaterialProp* SRenderPass::getProperty( uint32 i ) const
{
if( i >= properties.size() )
return NULL;
return &( properties[ i ] );
}
CDynMaterial::CDynMaterial()
{
@ -310,6 +317,14 @@ namespace NL3D
return *itr;
}
SRenderPass* CDynMaterial::getPass( uint32 i )
{
if( i >= passes.size() )
return NULL;
else
return passes[ i ];
}
void CDynMaterial::getPassList( std::vector< std::string > &l )
{
std::vector< SRenderPass* >::iterator itr = passes.begin();

@ -16,6 +16,7 @@
#include "material_properties.h"
#include "material_property_editor.h"
#include "nel3d_interface.h"
namespace MaterialEditor
{
@ -27,16 +28,143 @@ namespace MaterialEditor
matPropEditWidget = new MatPropEditWidget();
setupConnections();
edit = false;
proxy = NULL;
}
MatPropWidget::~MatPropWidget()
{
clear();
delete matPropEditWidget;
matPropEditWidget = NULL;
}
void MatPropWidget::load( CRenderPassProxy *proxy )
{
clear();
this->proxy = new CRenderPassProxy( *proxy );
std::string n;
proxy->getName( n );
nameEdit->setText( n.c_str() );
std::vector< SMatProp > v;
proxy->getProperties( v );
std::vector< SMatProp >::iterator itr = v.begin();
while( itr != v.end() )
{
SMatProp &mp = *itr;
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setData( 0, Qt::DisplayRole, QString( mp.id.c_str() ) );
item->setData( 1, Qt::DisplayRole, QString( mp.label.c_str() ) );
QString type;
switch( mp.type )
{
case SMatProp::Color:
type = "Color";
break;
case SMatProp::Double:
type = "Double";
break;
case SMatProp::Float:
type = "Float";
break;
case SMatProp::Int:
type = "Int";
break;
case SMatProp::Matrix4:
type = "Matrix4";
break;
case SMatProp::Texture:
type = "Texture";
break;
case SMatProp::Uint:
type = "UInt";
break;
case SMatProp::Vector4:
type = "Vector4";
break;
default:
type = "";
break;
}
item->setData( 2, Qt::DisplayRole, type );
treeWidget->addTopLevelItem( item );
++itr;
}
}
void MatPropWidget::clear()
{
treeWidget->clear();
nameEdit->clear();
if( this->proxy != NULL )
{
delete this->proxy;
this->proxy = NULL;
}
}
void MatPropWidget::onOKClicked()
{
if( proxy != NULL )
{
std::vector< SMatProp > v;
SMatProp p;
QTreeWidgetItem *item = NULL;
for( int i = 0; i < treeWidget->topLevelItemCount(); i++ )
{
item = treeWidget->topLevelItem( i );
p.id = item->text( 0 ).toUtf8().data();
p.label = item->text( 1 ).toUtf8().data();
std::string t = item->text( 2 ).toUtf8().data();
if( t == "Color" )
p.type = SMatProp::Color;
else
if( t == "Double" )
p.type = SMatProp::Double;
else
if( t == "Float" )
p.type = SMatProp::Float;
else
if( t == "Int" )
p.type = SMatProp::Int;
else
if( t == "Matrix4" )
p.type = SMatProp::Matrix4;
else
if( t == "Texture" )
p.type = SMatProp::Texture;
else
if( t == "UInt" )
p.type = SMatProp::Uint;
else
if( t == "Vector4" )
p.type = SMatProp::Vector4;
else
p.type = SMatProp::Int;
v.push_back( p );
}
proxy->setProperties( v );
}
clear();
close();
}
void MatPropWidget::onCancelClicked()
{
clear();
close();
}
@ -98,6 +226,7 @@ namespace MaterialEditor
void MatPropWidget::setupConnections()
{
connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOKClicked() ) );
connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( onCancelClicked() ) );
connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) );
connect( editButton, SIGNAL( clicked( bool ) ), this, SLOT( onEditClicked() ) );
connect( removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) );

@ -23,6 +23,7 @@ namespace MaterialEditor
{
class MatPropEditWidget;
class CRenderPassProxy;
class MatPropWidget : public QWidget, public Ui::MatPropWidget
{
@ -30,9 +31,12 @@ namespace MaterialEditor
public:
MatPropWidget( QWidget *parent = NULL );
~MatPropWidget();
void load( CRenderPassProxy *proxy );
void clear();
private Q_SLOTS:
void onOKClicked();
void onCancelClicked();
void onAddClicked();
void onEditClicked();
void onRemoveClicked();
@ -42,6 +46,7 @@ namespace MaterialEditor
void setupConnections();
bool edit;
MatPropEditWidget *matPropEditWidget;
CRenderPassProxy *proxy;
};
}

@ -27,7 +27,11 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="nameEdit"/>
<widget class="QLineEdit" name="nameEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
@ -144,6 +148,19 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">

@ -28,6 +28,7 @@ namespace MaterialEditor
setupUi( this );
shaderEditorWidget = new ShaderEditorWidget();
matPropWidget = new MatPropWidget();
setNel3DIface( NULL );
setupConnections();
}
@ -42,11 +43,12 @@ namespace MaterialEditor
void MaterialWidget::onNewMaterial()
{
passCB->clear();
passButton->setEnabled( false );
}
void MaterialWidget::onMaterialLoaded()
{
CNelMaterialProxy mat = this->nl3dIface->getMaterial();
CNelMaterialProxy mat = nl3dIface->getMaterial();
std::vector< std::string > l;
mat.getPassList( l );
@ -59,11 +61,15 @@ namespace MaterialEditor
passCB->addItem( itr->c_str() );
++itr;
}
if( passCB->count() > 0 )
passButton->setEnabled( true );
}
void MaterialWidget::onPassAdded( const char *name )
{
passCB->addItem( name );
passButton->setEnabled( true );
}
void MaterialWidget::onPassRemoved( const char *name )
@ -73,6 +79,8 @@ namespace MaterialEditor
return;
passCB->removeItem( i );
if( passCB->count() == 0 )
passButton->setEnabled( false );
}
void MaterialWidget::onPassMovedUp( const char *name )
@ -121,6 +129,11 @@ namespace MaterialEditor
void MaterialWidget::onPassEditClicked()
{
if( passCB->count() == 0 )
return;
CRenderPassProxy p = nl3dIface->getMaterial().getPass( passCB->currentText().toUtf8().data() );
matPropWidget->load( &p );
matPropWidget->show();
}

@ -28,6 +28,9 @@
</item>
<item>
<widget class="QPushButton" name="passButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>

@ -22,6 +22,57 @@
namespace MaterialEditor
{
void CRenderPassProxy::getProperties( std::vector< SMatProp > &v )
{
uint32 count = pass->count();
for( uint32 i = 0; i < count; i++ )
{
const NL3D::SDynMaterialProp &p = *( pass->getProperty( i ) );
SMatProp prop;
prop.id = p.prop;
prop.label = p.label;
prop.type = p.type;
prop.value = p.value;
v.push_back( prop );
}
}
void CRenderPassProxy::setProperties( std::vector< SMatProp > &v )
{
pass->clear();
NL3D::SDynMaterialProp p;
std::vector< SMatProp >::iterator itr = v.begin();
while( itr != v.end() )
{
p.prop = itr->id;
p.label = itr->label;
p.type = itr->type;
p.value = itr->value;
pass->addProperty( p );
++itr;
}
}
void CRenderPassProxy::getName( std::string &name )
{
pass->getName( name );
}
void CRenderPassProxy::setName( const std::string &name )
{
pass->setName( name );
}
void CNelMaterialProxy::getPassList( std::vector< std::string > &l )
{
material->getPassList( l );
@ -54,8 +105,18 @@ namespace MaterialEditor
material->renamePass( from, to );
}
CRenderPassProxy CNelMaterialProxy::getPass( unsigned long i )
{
if( material->count() >= i )
return CRenderPassProxy( NULL );
else
return CRenderPassProxy( material->getPass( i ) );
}
CRenderPassProxy CNelMaterialProxy::getPass( const char *name )
{
return CRenderPassProxy( material->getPass( name ) );
}
CNel3DInterface::CNel3DInterface()

@ -24,10 +24,52 @@
namespace NL3D
{
class CDynMaterial;
struct SRenderPass;
}
namespace MaterialEditor
{
struct SMatProp
{
enum EType
{
Color,
Vector4,
Float,
Double,
Int,
Uint,
Matrix4,
Texture
};
std::string id;
std::string label;
unsigned char type;
std::string value;
};
class CRenderPassProxy
{
public:
CRenderPassProxy( NL3D::SRenderPass *p )
{
pass = p;
}
~CRenderPassProxy(){}
void getProperties( std::vector< SMatProp > &v );
void setProperties( std::vector< SMatProp > &v );
void getName( std::string &name );
void setName( const std::string &name );
private:
NL3D::SRenderPass *pass;
};
class CNelMaterialProxy
{
public:
@ -46,6 +88,9 @@ namespace MaterialEditor
void movePassDown( const char *name );
void renamePass( const char *from, const char *to );
CRenderPassProxy getPass( unsigned long i );
CRenderPassProxy getPass( const char *name );
private:
NL3D::CDynMaterial *material;
};

Loading…
Cancel
Save