Skip to content

Commit

Permalink
Added params::addText() and params::setOptions()
Browse files Browse the repository at this point in the history
  • Loading branch information
fieldOfView committed Jan 13, 2011
1 parent 6872485 commit 392583f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/cinder/params/Params.h
Expand Up @@ -54,8 +54,10 @@ class InterfaceGl {
//! Adds enumerated parameter. The value corresponds to the indices of \a enumNames.
void addParam( const std::string &name, const std::vector<std::string> &enumNames, int *param, const std::string &optionsStr = "", bool readOnly = false );
void addSeparator( const std::string &name = "", const std::string &optionsStr = "" );
void addText( const std::string &name = "", const std::string &optionsStr = "" );
void addButton( const std::string &name, const std::function<void()> &callback, const std::string &optionsStr = "" );

void setOptions( const std::string &name = "", const std::string &optionsStr = "" );

protected:
void implAddParam( const std::string &name, void *param, int type, const std::string &optionsStr, bool readOnly );

Expand Down
2 changes: 2 additions & 0 deletions samples/ParamsBasic/src/ParamsBasicApp.cpp
Expand Up @@ -37,11 +37,13 @@ void TweakBarApp::setup()
mParams.addSeparator();
mParams.addParam( "Light Direction", &mLightDirection, "" );
mParams.addButton( "Button!", std::bind( &TweakBarApp::button, this ) );
mParams.addText( "text", "label=`This is a label without a parameter.`" );
}

void TweakBarApp::button()
{
app::console() << "Clicked!" << std::endl;
mParams.setOptions( "text", "label=`Clicked!`" );
}

void TweakBarApp::resize( ResizeEvent event )
Expand Down
14 changes: 14 additions & 0 deletions src/cinder/params/Params.cpp
Expand Up @@ -220,6 +220,11 @@ void InterfaceGl::addSeparator( const std::string &name, const std::string &opti
TwAddSeparator( mBar.get(), name.c_str(), optionsStr.c_str() );
}

void InterfaceGl::addText( const std::string &name, const std::string &optionsStr )
{
TwAddButton( mBar.get(), name.c_str(), NULL, NULL, optionsStr.c_str() );
}

namespace { // anonymous namespace
void TW_CALL implButtonCallback( void *clientData )
{
Expand All @@ -235,4 +240,13 @@ void InterfaceGl::addButton( const std::string &name, const std::function<void (
TwAddButton( mBar.get(), name.c_str(), implButtonCallback, (void*)callbackPtr.get(), optionsStr.c_str() );
}

void InterfaceGl::setOptions( const std::string &name, const std::string &optionsStr )
{
std::string target = "`" + (std::string)TwGetBarName( mBar.get() ) + "`";
if( !( name.empty() ) )
target += "/`" + name + "`";

TwDefine( ( target + " " + optionsStr ).c_str() );
}

} } // namespace cinder::params

0 comments on commit 392583f

Please sign in to comment.