demotool/syncoverrides.cc
Emmanuel BENOîT 422ab564f3 Overrides - Started work
+ Basic structures
+ Partial implementation in the sync manager
+ Partial implementation of the single float override
+ Silly hardcoded tests in the demo/main files
2017-11-16 12:20:21 +01:00

82 lines
1.6 KiB
C++

#include "externals.hh"
#include "globals.hh"
#include "syncoverrides.hh"
using namespace sov;
#define M_SETOPT_( FIELD , VAR ) \
if ( FIELD ) { return false; } \
FIELD = (VAR); \
return true
/*= T_Float ====================================================================*/
T_Float::T_Float(
T_String const& input ,
T_String const& title ) noexcept
: A_SyncOverride( T_String::Pooled( "float" ) , title ) ,
title_( title )
{
inputs_.add( input );
}
/*------------------------------------------------------------------------------*/
bool T_Float::setMin(
const float v ) noexcept
{
M_SETOPT_( min_ , v );
}
bool T_Float::setMax(
const float v ) noexcept
{
M_SETOPT_( max_ , v );
}
bool T_Float::setStep(
const float v ) noexcept
{
assert( v > 0 );
M_SETOPT_( step_ , v );
}
bool T_Float::setDecimals(
const uint32_t n ) noexcept
{
assert( n <= 100 );
if ( decimals_ ) {
return false;
}
T_StringBuilder sb;
sb << "%." << n << 'f' << '\0';
assert( sb.size( ) < 12 );
decimals_.setNew( );
for ( auto i = 0u ; i < sb.size( ) ; i ++ ) {
decimals_->add( sb.data( )[ i ] );
}
return true;
}
bool T_Float::setPower(
const float v ) noexcept
{
assert( v > 0 );
M_SETOPT_( power_ , v );
}
/*------------------------------------------------------------------------------*/
void T_Float::makeEditWidgets( ) noexcept
{
float v[ 1 ] = {
Globals::Sync( ).inputs( )[ inputPos_[ 0 ] ]
};
if ( ImGui::DragFloat( "" , v , step( ) ,
min( ) , max( ) , decimals( ) , power( ) ) ) {
// FIXME Globals::Sync( ).inputs( )[ inputPos_[ 0 ] ] = v[ 0 ];
}
}