summaryrefslogtreecommitdiff
path: root/src/gui/vectorinput.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/vectorinput.cpp')
-rw-r--r--src/gui/vectorinput.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/gui/vectorinput.cpp b/src/gui/vectorinput.cpp
new file mode 100644
index 0000000..9ebb0fa
--- /dev/null
+++ b/src/gui/vectorinput.cpp
@@ -0,0 +1,120 @@
+#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;
+ 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;
+
+ 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
+ );
+
+ 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
+) {
+ 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
+ );
+
+ return input;
+}