1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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;
}
|