[shaderz] r21 committed - Shader parameter - Work in progress...

0 views
Skip to first unread message

sha...@googlecode.com

unread,
Mar 27, 2010, 11:07:44 PM3/27/10
to shade...@googlegroups.com
Revision: 21
Author: vijay.michaeljoseph
Date: Sat Mar 27 20:07:00 2010
Log: Shader parameter - Work in progress

Updates to container widget
* Added a grid based layout for container widget for cleaner and tabular
display
* Added layout and wrapping control
* Added a bunch of utility functions related to determining the position of
a child on the grid.

Shader param UI widgets
* Added an Initialize() function that allows proper setting of parent of
the widget (as this info is missing in the constructor)
* Overloaded the setupUI function in the container to allow populating
based on struct params also.

http://code.google.com/p/shaderz/source/detail?r=21

Added:
/trunk/src/shparameterwidgetui.cpp
Modified:
/trunk/Makefile
/trunk/include/qtwidgets/shcontainerwidget.h
/trunk/include/shdefs.h
/trunk/include/shparameterwidgetui.h
/trunk/include/shshaderparametercontainer.h
/trunk/src/qtwidgets/shcontainerwidget.cpp
/trunk/src/shshaderparametercontainer.cpp

=======================================
--- /dev/null
+++ /trunk/src/shparameterwidgetui.cpp Sat Mar 27 20:07:00 2010
@@ -0,0 +1,65 @@
+#include "include/shparameterwidgetui.h"
+#include "shlogger.h"
+
+using namespace Shaderz;
+
+shParameterWidgetUI::shParameterWidgetUI(Shaderz::shWidget* pParent, const
Shaderz::shShaderInfo::shShaderParameter& paramInfo)
+ : ParentClass(pParent)
+ ,m_paramInfo(paramInfo)
+ ,m_iBorder(5)
+ ,m_pLabel(0)
+{
+}
+
+shParameterWidgetUI::~shParameterWidgetUI()
+{
+ unsigned int i;
+ // delete struct members if any were created
+ for( i=0; i<m_members.size(); ++i )
+ {
+ delete m_members[i];
+ }
+ m_members.clear();
+
+ // delete the label
+ if( m_pLabel )
+ {
+ delete m_pLabel;
+ }
+}
+
+void shParameterWidgetUI::initialize()
+{
+ if( !m_pLabel )
+ {
+ LOG<<"creating label for "<<"\n";
+ shString labelStr = m_paramInfo.name;
+ if( SH_PARAMETERCLASS_STRUCT == m_paramInfo.paramClass )
+ {
+ labelStr = shString("Struct::") + labelStr;
+ }
+ m_pLabel = new shLabel( labelStr, this );
+ m_pLabel->setVisible(true);
+ }
+}
+
+void shParameterWidgetUI::resizeEvent( Shaderz::shResizeEvent* pEventInfo )
+{
+ ParentClass::resizeEvent(pEventInfo);
+}
+
+void shParameterWidgetUI::handleStructParameters(const
Shaderz::shShaderInfo::shShaderParameter& paramInfo)
+{
+ if( SH_PARAMETERCLASS_STRUCT != paramInfo.paramClass )
+ {
+ return;
+ }
+
+ unsigned int i;
+ for( i=0; i<paramInfo.memberList.size(); ++i )
+ {
+ shParameterWidgetUI* pNewWidget = new shParameterWidgetUI( this,
paramInfo.memberList[i] );
+ pNewWidget->initialize();
+ m_members.push_back(pNewWidget);
+ }
+}
=======================================
--- /trunk/Makefile Sun Mar 21 14:48:06 2010
+++ /trunk/Makefile Sat Mar 27 20:07:00 2010
@@ -1,6 +1,6 @@

#############################################################################
# Makefile for building: shaderz.app/Contents/MacOS/shaderz
-# Generated by qmake (2.01a) (Qt 4.5.3) on: Wed Mar 17 22:48:13 2010
+# Generated by qmake (2.01a) (Qt 4.5.3) on: Sat Mar 27 08:53:48 2010
# Project: shaderz.pro
# Template: app
# Command: /usr/bin/qmake -spec /usr/local/Qt4.5/mkspecs/macx-g++ -macx -o
Makefile shaderz.pro
@@ -266,6 +266,7 @@

moc_shshaderparametercontainer.cpp: include/qtwidgets/shcontainerwidget.h \
include/shshaderinfo.h \
+ include/shdefs.h \
include/shshaderparametercontainer.h
/Developer/Tools/Qt/moc $(DEFINES) $(INCPATH) -D__APPLE__ -D__GNUC__
include/shshaderparametercontainer.h -o moc_shshaderparametercontainer.cpp

@@ -335,11 +336,13 @@

obj/shshaderparametercontainer.o: src/shshaderparametercontainer.cpp
include/shshaderparametercontainer.h \
include/qtwidgets/shcontainerwidget.h \
- include/shshaderinfo.h
+ include/shshaderinfo.h \
+ include/shdefs.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/shshaderparametercontainer.o
src/shshaderparametercontainer.cpp

obj/shparameterwidgetui.o: src/shparameterwidgetui.cpp
include/shparameterwidgetui.h \
- include/shdefs.h
+ include/shdefs.h \
+ include/shshaderinfo.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/shparameterwidgetui.o
src/shparameterwidgetui.cpp

obj/moc_shaderzmain.o: moc_shaderzmain.cpp
=======================================
--- /trunk/include/qtwidgets/shcontainerwidget.h Thu Mar 11 14:28:24 2010
+++ /trunk/include/qtwidgets/shcontainerwidget.h Sat Mar 27 20:07:00 2010
@@ -12,18 +12,60 @@
Q_OBJECT

public:
- shContainerWidget(Shaderz::shWidget* pParent,
- const char * pName = 0,
- Qt::WindowFlags f = 0 );
+ enum shContainerLayout { SHCONTAINERLAYOUT_LeftToRight,
SHCONTAINERLAYOUT_TopToBottom };
+ enum shContainerWrap { SHCONTAINERWRAP_On, SHCONTAINERWRAP_Off };
+
+ shContainerWidget(Shaderz::shWidget* pParent);

~shContainerWidget();
- Shaderz::shWidget* getContainer(void){ return &m_mainContainer; }
void addChildWidget(Shaderz::shWidget* pNewChild);
+ void resizeToFitChildren();
+ void updateChildrenPositions();
+ void getNextRowColumn(int currentCol, int currentRow, int& nextCol,
int& nextRow );
+ Shaderz::shRect getGeometryForCell( int col, int row, int width=-1,
int height=-1 )
+ {
+ return Shaderz::shRect( col*gridSizeX(),
+ row*gridSizeY(),
+ width > 0 ? width : gridSizeX(),
+ height > 0 ? height : gridSizeY() );
+ }
+
+ // getters
+ Shaderz::shWidget* container(void){ return &m_mainContainer; }
+ shContainerWrap wrap() const { return m_wrap; }
+ shContainerLayout layout() const { return m_layout; }
+ int gridSizeX() const { return m_gridSizeX; }
+ int gridSizeY() const { return m_gridSizeY; }
+
+ // setters
+ void setWrap( shContainerWrap newMode, bool updateChildren=true ){
m_wrap = newMode; if(updateChildren)updateChildrenPositions(); }
+ void setLayout( shContainerLayout newLayout, bool updateChildren=true
){ m_layout = newLayout; if(updateChildren)updateChildrenPositions(); }
+ void setGridSizeX(int newSize, bool updateChildren=true ){ m_gridSizeX
= newSize; if(updateChildren)updateChildrenPositions(); }
+ void setGridSizeY(int newSize, bool updateChildren=true ){ m_gridSizeY
= newSize; if(updateChildren)updateChildrenPositions(); }
+ void alterGridSize(int deltaX, int deltaY, bool updateChildren=true )
+ {
+ setGridSizeX( gridSizeX()+deltaX, false );
+ setGridSizeY( gridSizeY()+deltaY, false );
+ if(updateChildren)
+ {
+ updateChildrenPositions();
+ }
+ }

protected:
- Shaderz::shWidget m_mainContainer;
- std::vector<Shaderz::shWidget*> m_childWidgets;
-
+ // the main container is the wrapping around the children, that
expands according to the children
+ // and forces the scroll bars to appear when required.
+ Shaderz::shWidget m_mainContainer;
+ std::vector<Shaderz::shWidget*> m_childWidgets;
+
+ // each child will be placed in a grid cell. The next cell is
determined on the layout of the container.
+ shContainerWrap m_wrap;
+ shContainerLayout m_layout;
+ int m_gridSizeX;
+ int m_gridSizeY;
+
+ // internal info indicating the last set row and column
+ int m_lastRow, m_lastCol;
private:
typedef Shaderz::shScrollAreaWidget ParentClass;
};
=======================================
--- /trunk/include/shdefs.h Sun Mar 21 14:48:06 2010
+++ /trunk/include/shdefs.h Sat Mar 27 20:07:00 2010
@@ -20,6 +20,6 @@
typedef QString shString;
typedef QLineEdit shLineEdit;
typedef QTreeWidget shTreeWidget;
- typedef QTreeWidgetItem shTreeItem;
+ typedef QTreeWidgetItem shTreeWidgetItem;
}
#endif // SHWIDGET_H
=======================================
--- /trunk/include/shparameterwidgetui.h Sun Mar 21 14:48:06 2010
+++ /trunk/include/shparameterwidgetui.h Sat Mar 27 20:07:00 2010
@@ -3,20 +3,25 @@

#include "shdefs.h"
#include "shshaderinfo.h"
+#include "qtwidgets/shcontainerwidget.h"

class shParameterWidgetUI : public Shaderz::shWidget
{
public:
shParameterWidgetUI(Shaderz::shWidget* pParent, const
Shaderz::shShaderInfo::shShaderParameter& paramInfo);
~shParameterWidgetUI();
+ void initialize();

public slots:
void resizeEvent( Shaderz::shResizeEvent* pEventInfo );

protected:
const Shaderz::shShaderInfo::shShaderParameter& m_paramInfo;
- int m_iBorder;
- Shaderz::shLabel* m_pLabel;
+ int m_iBorder;
+ Shaderz::shLabel* m_pLabel; // label
for the parameter.
+ std::vector<shParameterWidgetUI*> m_members; // members
of the widget if it is a struct
+
+ void handleStructParameters(const
Shaderz::shShaderInfo::shShaderParameter& paramInfo);

private:
typedef Shaderz::shWidget ParentClass;
=======================================
--- /trunk/include/shshaderparametercontainer.h Sun Mar 21 14:48:06 2010
+++ /trunk/include/shshaderparametercontainer.h Sat Mar 27 20:07:00 2010
@@ -12,6 +12,7 @@
shShaderParameterContainer(Shaderz::shWidget* pParent);

void setupUI( const Shaderz::shShaderInfo* pShaderInfo );
+ void setupUI( const Shaderz::shShaderInfo::shShaderParameter&
paramInfo );

private:
typedef shContainerWidget ParentClass;
=======================================
--- /trunk/src/qtwidgets/shcontainerwidget.cpp Thu Mar 11 14:28:24 2010
+++ /trunk/src/qtwidgets/shcontainerwidget.cpp Sat Mar 27 20:07:00 2010
@@ -1,16 +1,21 @@
#include "qtwidgets/shcontainerwidget.h"
+#include "shlogger.h"

using namespace Shaderz;

-shContainerWidget::shContainerWidget(shWidget* pParent,
- const char * pName,
- Qt::WindowFlags f)
+shContainerWidget::shContainerWidget(shWidget* pParent)
: ParentClass(pParent)
+ , m_wrap(SHCONTAINERWRAP_On)
+ , m_layout(SHCONTAINERLAYOUT_LeftToRight)
+ , m_gridSizeX(-1)
+ , m_gridSizeY(-1)
+ , m_lastRow(-1)
+ , m_lastCol(-1)
{
// set the main container widget
setWidget(&m_mainContainer);

- // make the container a little smaller than the actual widget
+ // make the wrapping container a little smaller than the actual widget
shRect containerGeometry = geometry();
containerGeometry.setRight(containerGeometry.right() - 5);
containerGeometry.setBottom(containerGeometry.bottom() - 5);
@@ -19,6 +24,13 @@

shContainerWidget::~shContainerWidget()
{
+ // cleanup the child widgets
+ unsigned int i;
+ for( i=0; i<m_childWidgets.size(); ++i )
+ {
+ delete m_childWidgets[i];
+ }
+ m_childWidgets.clear();
}

/**
@@ -30,24 +42,109 @@
m_childWidgets.push_back(pNewChild);

shRect childGeo = pNewChild->geometry();
- shRect containerGeometry = geometry();
-
+ shRect containerGeometry = container()->geometry(); // use the
internal wrapper of the children
+
+ // if the grid size if uninitialized, set it to the size of the first
child.
+ if( gridSizeX() < 0 )
+ {
+ m_gridSizeX = childGeo.width();
+ m_gridSizeY = childGeo.height();
+ }
+
+ // determine the col, row for new child in the grid
+ int newCol, newRow;
+ getNextRowColumn( m_lastCol, m_lastRow, newCol, newRow );
+
+ // update the cache
+ m_lastRow = newRow;
+ m_lastCol = newCol;
+
+ // set the child in the proper position
+ shRect newRect = getGeometryForCell( newCol, newRow, childGeo.width(),
childGeo.height() );
+ pNewChild->setGeometry(newRect);
+
+ childGeo = newRect;
+ LOG<<"New col, row = "<<newCol<<", "<<newRow<<" ";
+ LOG<<" SizeX,Y = "<< gridSizeX()<<", "<< gridSizeY()<<" ";
+ LOG<<" Left,Top
= "<<childGeo.left()<<", "<<childGeo.top()<<":: "<<childGeo.width()<<"
x "<<childGeo.height();
+ LOG<<"\n";
+
+ int border = 0;
+
+ // check for expansions of the internal container geometry
if( childGeo.left() < containerGeometry.left() )
{
- containerGeometry.setLeft(childGeo.left());
+ containerGeometry.setLeft(childGeo.left() - border);
}
if( childGeo.top() < containerGeometry.top() )
{
- containerGeometry.setTop(childGeo.top());
+ containerGeometry.setTop(childGeo.top() - border);
}
if( childGeo.right() > containerGeometry.right() )
{
- containerGeometry.setRight(childGeo.right());
+ containerGeometry.setRight(childGeo.right() + border);
}
if( childGeo.bottom() > containerGeometry.bottom() )
{
- containerGeometry.setBottom(childGeo.bottom());
+ containerGeometry.setBottom(childGeo.bottom() + border);
}

- m_mainContainer.setGeometry(containerGeometry);
-}
+ container()->setGeometry(containerGeometry);
+}
+
+/**
+ * Utility function to resize the container geometry to the cumulative
size of the children at this instant.
+ * Essentially, it expands the container widget to the size of the
internal wrapper container.
+ */
+void shContainerWidget::resizeToFitChildren()
+{
+ shRect geo = geometry();
+ geo.setWidth( container()->geometry().width() );
+ geo.setHeight(container()->geometry().height() );
+ setGeometry(geo);
+}
+
+void shContainerWidget::updateChildrenPositions()
+{
+ int row = -1;
+ int col = -1;
+ unsigned int i;
+
+ // loop thru all the children and set their geometries
+ for( i=0; i<m_childWidgets.size(); ++i )
+ {
+ shRect childGeo = m_childWidgets[i]->geometry();
+ getNextRowColumn( col, row, col, row );
+ childGeo = getGeometryForCell( col, row, childGeo.width(),
childGeo.height());
+ m_childWidgets[i]->setGeometry(childGeo);
+ }
+}
+
+void shContainerWidget::getNextRowColumn(int currentCol, int currentRow,
int& nextCol, int& nextRow )
+{
+ // cache the container's geometry for checking against overflows
+ shRect containerGeometry = geometry();
+
+ // determine the col, row for new child in the grid
+ nextCol = (currentCol == -1) ? 0 : (layout() ==
SHCONTAINERLAYOUT_LeftToRight) ? currentCol+1 : currentCol;
+ nextRow = (currentRow == -1) ? 0 : (layout() ==
SHCONTAINERLAYOUT_TopToBottom) ? currentRow+1 : currentRow;
+
+ // now check for overflows if wrapping is ON
+ if( wrap() == SHCONTAINERWRAP_On )
+ {
+ // check for overflow on left to right direction
+ if( layout() == SHCONTAINERLAYOUT_LeftToRight
+ && (nextCol+1)*gridSizeX() > containerGeometry.width() )
+ {
+ nextCol = 0;
+ nextRow++;
+ }
+ // check overflow on top to bottom dir
+ else if( layout() == SHCONTAINERLAYOUT_TopToBottom
+ && (nextRow+1)*gridSizeY() > containerGeometry.height() )
+ {
+ nextRow = 0;
+ nextCol++;
+ }
+ }
+}
=======================================
--- /trunk/src/shshaderparametercontainer.cpp Sun Mar 21 14:48:06 2010
+++ /trunk/src/shshaderparametercontainer.cpp Sat Mar 27 20:07:00 2010
@@ -8,6 +8,8 @@
shShaderParameterContainer::shShaderParameterContainer(shWidget* pParent)
: ParentClass(pParent)
{
+ setLayout(shContainerWidget::SHCONTAINERLAYOUT_TopToBottom);
+ setWrap(shContainerWidget::SHCONTAINERWRAP_Off);
}

void shShaderParameterContainer::setupUI( const shShaderInfo* pShaderInfo )
@@ -16,18 +18,71 @@
{
return;
}
+
+ // hack to prevent overwriting of parameter labels
+ setGridSizeX(100);
+ setGridSizeY(60);

const std::vector<shShaderInfo::shShaderParameter>& paramList =
pShaderInfo->getParameters();
unsigned int index;
- int widgetWidth = 30;
- int spacing = 10;
-
+ int maxWidth = 0;
+ int maxHeight = 0;
for( index=0; index<paramList.size(); ++index )
{
- shRect rect( 20, spacing + index*widgetWidth, 100, widgetWidth );
- shParameterWidgetUI* pLabel = new shParameterWidgetUI(
getContainer(), paramList[index]);
- pLabel->setGeometry(rect);
- pLabel->setVisible(true);
- addChildWidget( pLabel );
+ Shaderz::shWidget* pNewChild = 0;
+ if( SH_PARAMETERCLASS_STRUCT == paramList[index].paramClass )
+ {
+ shShaderParameterContainer* pNewContainer = new
shShaderParameterContainer(container());
+
pNewContainer->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ pNewContainer->setupUI( paramList[index] );
+ pNewContainer->resizeToFitChildren();
+ pNewChild = pNewContainer;
+ }
+ else
+ {
+ shParameterWidgetUI* pNewParamWidget = new
shParameterWidgetUI( container(), paramList[index]);
+ pNewParamWidget->initialize();
+ pNewChild = pNewParamWidget;
+ }
+ pNewChild->setVisible(true);
+ maxWidth = (maxWidth > pNewChild->geometry().width()) ? maxWidth :
pNewChild->geometry().width();
+ maxHeight = (maxHeight > pNewChild->geometry().height()) ?
maxHeight : pNewChild->geometry().height();
+ addChildWidget( pNewChild );
+ }
+
+ // todo: review the code for expansion to largest child
+/*
+ // expand the grid according to the largest child
+ bool updateRequired = false;
+ if( maxWidth > gridSizeX() )
+ {
+ setGridSizeX(maxWidth, false);
+ updateRequired = true;
+ }
+ if( maxHeight > gridSizeY() )
+ {
+ setGridSizeY(maxHeight, false);
+ updateRequired = true;
+ }
+ if( updateRequired )
+ {
+ updateChildrenPositions();
+ }
+ */
+}
+
+void shShaderParameterContainer::setupUI( const
Shaderz::shShaderInfo::shShaderParameter& paramInfo )
+{
+ if( SH_PARAMETERCLASS_STRUCT != paramInfo.paramClass )
+ {
+ return;
+ }
+
+ unsigned int i;
+ for( i=0; i<paramInfo.memberList.size(); ++i )
+ {
+ shParameterWidgetUI* pNewWidget = new shParameterWidgetUI(
container(), paramInfo.memberList[i] );
+ pNewWidget->initialize();
+ addChildWidget(pNewWidget);
}
}

Reply all
Reply to author
Forward
0 new messages