#include "base.h" const I32 VECTORINPUT_TITLE_OFFSET = 15; void gui_vectorinput_draw_fn( void* ptr ) { GUI_VECTORINPUT* input = (GUI_VECTORINPUT*)ptr; I32 x = gui_relx( input ); I32 y = gui_rely( input ); gui_draw_str( x, y, ALIGN_L, FNT_JPN12, ui_clr.txt, input->name ); GUI_VIEW* inputview = input->inputview; inputview->draw_fn( inputview ); } void gui_vectorinput_input_fn( void* ptr ) { GUI_VECTORINPUT* input = (GUI_VECTORINPUT*)ptr; GUI_VIEW* inputview = input->inputview; inputview->input_fn( inputview ); } void gui_vectorinput_child_cb( void* ptr ) { GUI_FLOATINPUT* child = (GUI_FLOATINPUT*)ptr; // slider -> child view -> vectorinput GUI_VECTORINPUT* parent = (GUI_VECTORINPUT*)child->parent->parent; for( auto& it : parent->lastchange ) it = 0.f; for( U32 i = 0; i < parent->inputs.size; ++i ) { if( parent->inputs.data[i] == child ) { parent->lastchange.data[i] = child->lastchange; break; } } if( parent->cb ) parent->cb( parent ); } void __gui_internal_vectorinput_init( GUI_VECTORINPUT *input, I32 x, I32 y, I32 w, const char *title, F32 *pval, U32 valc, F32 min, F32 max, F32 step, const char *letters, const char *printfmt ) { input->x = x; input->y = y; input->w = w; input->h = 20; strcpy( input->name, title ); input->xbound = input->w; input->ybound = input->h + VECTORINPUT_TITLE_OFFSET; input->draw_fn = gui_vectorinput_draw_fn; input->input_fn = gui_vectorinput_input_fn; GUI_VIEW* parent = gui_get_view(); parent->children.push( input ); input->parent = parent; input->lastchange.resize( valc ); gui_set_view( input ); input->cb = 0; input->pval = pval; input->letters = letters; input->inputview = gui_view( 0, VECTORINPUT_TITLE_OFFSET, w, input->h ); input->inputview->parent = input; I32 wdiv = (input->w - 5 * (valc - 1)) / valc; for( I32 i = 0; i < valc; ++i ) { char letter[2] = { input->letters[i], 0 }; GUI_FLOATINPUT* slider = gui_floatinput( (wdiv + 5) * i, 0, wdiv, letter, &pval[i], min, max, step, printfmt ); input->inputs.push( slider ); slider->cb = gui_vectorinput_child_cb; } gui_set_view( parent ); } GUI_VECTORINPUT* gui_vectorinput( I32 x, I32 y, I32 w, const char* title, F32* pval, U32 valc, F32 min, F32 max, F32 step, const char* letters, const char* printfmt, U8 showval ) { if( !gui_check_target() ) return 0; if( valc > 25 ) { dlog( "gui_vectorinput() : have you lost your mind?" ); return 0; } GUI_VECTORINPUT* input = new GUI_VECTORINPUT; __gui_internal_vectorinput_init( input, x, y, w, title, pval, valc, min, max, step, letters, printfmt ); if( !showval ) { for( auto& it : input->inputview->children ) { GUI_FLOATINPUT* f = (GUI_FLOATINPUT*)it; f->drawval = 0; } } return input; }