summaryrefslogtreecommitdiff
path: root/src/gui/floatinput.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/floatinput.cpp')
-rw-r--r--src/gui/floatinput.cpp53
1 files changed, 32 insertions, 21 deletions
diff --git a/src/gui/floatinput.cpp b/src/gui/floatinput.cpp
index 095c562..8e3fc2c 100644
--- a/src/gui/floatinput.cpp
+++ b/src/gui/floatinput.cpp
@@ -169,6 +169,7 @@ void gui_floatinput_input_bound( GUI_FLOATINPUT* input ) {
return;
F32 oldval = *input->pval;
+ F32 val = oldval;
I32 x = gui_relx( input );
I32 w = gui_floatinput_content_w( input );
@@ -184,9 +185,13 @@ void gui_floatinput_input_bound( GUI_FLOATINPUT* input ) {
F32 nval = min + (max - min) * progress;
F32 rmn = remainderf( nval, input->step );
- *input->pval = nval - rmn;
- if( oldval != *input->pval )
- input->lastchange = *input->pval - oldval;
+ val = nval - rmn;
+ if( oldval != val ) {
+ if( input->pre_cb ) input->pre_cb( input );
+ input->lastchange = val - oldval;
+ *input->pval = val;
+ if( input->cb ) input->cb( input );
+ }
}
void gui_floatinput_input_unbound( GUI_FLOATINPUT* input ) {
@@ -197,22 +202,28 @@ void gui_floatinput_input_unbound( GUI_FLOATINPUT* input ) {
gui_cursor_pos( &mx, &my );
F32 oldval = *input->pval;
+ F32 val = oldval;
I32 dx = mx - input->lastmx;
if( dx )
- *input->pval += dx * input->step;
+ val += dx * input->step;
F32 min = input->min;
F32 max = input->max;
- if( isfinite( min ) && *input->pval < min )
- *input->pval = input->wraparound? max : min;
- if( isfinite( max ) && *input->pval > max )
- *input->pval = input->wraparound? min : max;
+ if( isfinite( min ) && val < min )
+ val = input->wraparound? max : min;
+ if( isfinite( max ) && val > max )
+ val = input->wraparound? min : max;
- F32 rmn = remainderf( *input->pval, input->step );
- *input->pval -= rmn;
- if( oldval != *input->pval )
- input->lastchange = *input->pval - oldval;
+ F32 rmn = remainderf( val, input->step );
+ val -= rmn;
+
+ if( val != oldval ) {
+ if( input->pre_cb ) input->pre_cb( input );
+ input->lastchange = val - oldval;
+ *input->pval = val;
+ if( input->cb ) input->cb( input );
+ }
}
void gui_floatinput_input_scroll( GUI_FLOATINPUT* input ) {
@@ -234,12 +245,12 @@ void gui_floatinput_input_scroll( GUI_FLOATINPUT* input ) {
if( isfinite( input->max ) && nval > input->max )
nval = input->wraparound? input->min : input->max;
+ if( input->pre_cb ) input->pre_cb( input );
F32 rmn = remainderf( nval, input->step );
*input->pval = nval - rmn;
input->lastchange = *input->pval - oldval;
- if( input->cb )
- input->cb( input );
+ if( input->cb ) input->cb( input );
}
void gui_floatinput_input_fn( void* ptr ) {
@@ -276,11 +287,13 @@ void gui_floatinput_input_fn( void* ptr ) {
U8 inc = my < split_y;
F32 step = fine ? 0.1f : 1.f;
F32 val = *input->pval;
+
+ if( input->pre_cb ) input->pre_cb( input );
*input->pval += inc ? step : -step;
gui_floatinput_clamp_and_snap( input );
input->lastchange = *input->pval - val;
- if( input->cb )
- input->cb( input );
+ if( input->cb ) input->cb( input );
+
input->held = 1;
}
return;
@@ -298,6 +311,8 @@ void gui_floatinput_input_fn( void* ptr ) {
if( !m1 ) {
input->heldoutbounds = 0;
+ if( input->release_cb && input->held )
+ input->release_cb( input );
input->held = 0;
return;
}
@@ -305,17 +320,12 @@ void gui_floatinput_input_fn( void* ptr ) {
if( input->heldoutbounds )
return;
- F32 oldv = *input->pval;
if( !gui_floatinput_is_bound_val( input ) )
gui_floatinput_input_unbound( input );
else
gui_floatinput_input_bound( input );
gui_floatinput_clamp_and_snap( input );
- if( input->cb && oldv != *input->pval ) {
- input->cb( input );
- }
-
input->lastmx = mx;
}
@@ -333,6 +343,7 @@ struct GUI_FLOATINPUT* gui_floatinput( I32 x, I32 y, I32 w, const char* title, F
input->lastchange = 0;
input->cb = 0;
+ input->release_cb = 0;
input->pval = pval;
input->min = min;
input->max = max;