summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authoraura <nw@moneybot.cc>2026-07-28 19:11:34 +0200
committeraura <nw@moneybot.cc>2026-07-28 19:11:34 +0200
commit86d248ed2b033fe36ce53b0387b2cbdcb69c0b72 (patch)
treea70f32a0f44b927a6d137998efa405e330689c0f /src/gui
parent468813b133a6a3ff0b85d3b34f1009cfeae815e4 (diff)
finish undo/redo
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/base.h9
-rw-r--r--src/gui/button.cpp6
-rw-r--r--src/gui/checkbox.cpp4
-rw-r--r--src/gui/floatinput.cpp53
-rw-r--r--src/gui/list.cpp6
-rw-r--r--src/gui/textbox.cpp10
-rw-r--r--src/gui/vectorinput.cpp17
7 files changed, 73 insertions, 32 deletions
diff --git a/src/gui/base.h b/src/gui/base.h
index 1a1c4cb..108988d 100644
--- a/src/gui/base.h
+++ b/src/gui/base.h
@@ -169,10 +169,12 @@ struct GUI_LIST : GUI_BASE {
U8 held;
GUI_CALLBACK cb;
+ GUI_CALLBACK pre_cb;
};
struct GUI_BUTTON : GUI_BASE {
GUI_CALLBACK cb;
+ GUI_CALLBACK pre_cb;
U8 held;
void* extra;
};
@@ -182,6 +184,7 @@ struct GUI_CHECKBOX : GUI_BASE {
U8* pval;
GUI_CALLBACK cb;
+ GUI_CALLBACK pre_cb;
};
struct GUI_DROPDOWN : GUI_BASE {
@@ -190,6 +193,7 @@ struct GUI_DROPDOWN : GUI_BASE {
U8 held;
GUI_CALLBACK cb;
+ GUI_CALLBACK pre_cb;
GUI_WINDOW* listwnd;
GUI_VIEW* listview;
};
@@ -216,6 +220,7 @@ struct GUI_TEXTBOX : GUI_BASE {
U8 m1held;
GUI_CALLBACK cb;
+ GUI_CALLBACK pre_cb;
};
struct GUI_CONTEXTBOX : GUI_BASE {
@@ -243,6 +248,8 @@ struct GUI_FLOATINPUT : GUI_BASE {
U8 wraparound;
GUI_CALLBACK cb;
+ GUI_CALLBACK pre_cb;
+ GUI_CALLBACK release_cb;
void* cbextra;
};
@@ -261,6 +268,8 @@ struct GUI_VECTORINPUT : GUI_VIEW {
LIST<F32> lastchange;
GUI_CALLBACK cb;
+ GUI_CALLBACK pre_cb;
+ GUI_CALLBACK release_cb;
void* cbextra;
};
diff --git a/src/gui/button.cpp b/src/gui/button.cpp
index e66130b..7cf0524 100644
--- a/src/gui/button.cpp
+++ b/src/gui/button.cpp
@@ -48,8 +48,10 @@ void gui_button_input_fn( void* ptr ) {
// button could be destroyed by callback
U8 was_held = btn->held;
btn->held = 0;
- if( inbounds && was_held )
- btn->cb( btn );
+ if( inbounds && was_held ) {
+ if( btn->pre_cb ) btn->pre_cb( btn );
+ if( btn->cb ) btn->cb( btn );
+ }
return;
}
diff --git a/src/gui/checkbox.cpp b/src/gui/checkbox.cpp
index 02cadc6..97ce804 100644
--- a/src/gui/checkbox.cpp
+++ b/src/gui/checkbox.cpp
@@ -40,9 +40,9 @@ void gui_checkbox_input_fn( void* ptr ) {
U8 was_held = check->held;
check->held = 0;
if( inbounds && was_held ) {
+ if( check->pre_cb ) check->pre_cb( check );
*check->pval = !*check->pval;
- if( check->cb )
- check->cb( check );
+ if( check->cb ) check->cb( check );
}
return;
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;
diff --git a/src/gui/list.cpp b/src/gui/list.cpp
index 0a2a3d3..aa0992e 100644
--- a/src/gui/list.cpp
+++ b/src/gui/list.cpp
@@ -66,10 +66,10 @@ void gui_list_input_fn( void* ptr ) {
if( m1 ) {
if( !list->held ) {
GUI_LIST_ENTRY* e = &list->plist->data[idx];
- *list->pval = e->val;
- if( list->cb )
- list->cb( list );
+ if( list->pre_cb ) list->pre_cb( list );
+ *list->pval = e->val;
+ if( list->cb ) list->cb( list );
}
list->held = 1;
} else {
diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp
index 688450b..c367193 100644
--- a/src/gui/textbox.cpp
+++ b/src/gui/textbox.cpp
@@ -178,18 +178,20 @@ void gui_textbox_handle_repeat( GUI_TEXTBOX* tb ) {
if( gui_time() - tb->repeattime > 0.05f ) {
U32 len = strlen( tb->value );
if( is_printable_char( tb->heldkey ) && len < (tb->maxlen - 1) ) {
+ if( tb->pre_cb ) tb->pre_cb( tb );
+
if( tb->keys[SDLK_LSHIFT & 0xff] || tb->keys[SDLK_RSHIFT & 0xff] )
tb->value[len] = tb->heldkey + ('a' - 'A');
else
tb->value[len] = tb->heldkey;
tb->value[++len] = 0;
- if( tb->cb )
- tb->cb( tb );
+
+ if( tb->cb ) tb->cb( tb );
}
else if( tb->heldkey == '\b' && len > 0 ) {
+ if( tb->pre_cb ) tb->pre_cb( tb );
tb->value[--len] = 0;
- if( tb->cb )
- tb->cb( tb );
+ if( tb->cb ) tb->cb( tb );
}
tb->repeattime = gui_time();
diff --git a/src/gui/vectorinput.cpp b/src/gui/vectorinput.cpp
index ad28c0d..3e36e31 100644
--- a/src/gui/vectorinput.cpp
+++ b/src/gui/vectorinput.cpp
@@ -39,6 +39,20 @@ void gui_vectorinput_child_cb( void* ptr ) {
parent->cb( parent );
}
+void gui_vectorinput_child_pre_cb( void* ptr ) {
+ GUI_FLOATINPUT* child = (GUI_FLOATINPUT*)ptr;
+ GUI_VECTORINPUT* parent = (GUI_VECTORINPUT*)child->parent->parent;
+ if( parent->pre_cb )
+ parent->pre_cb( parent );
+}
+
+void gui_vectorinput_child_release_cb( void* ptr ) {
+ GUI_FLOATINPUT* child = (GUI_FLOATINPUT*)ptr;
+ GUI_VECTORINPUT* parent = (GUI_VECTORINPUT*)child->parent->parent;
+ if( parent->release_cb )
+ parent->release_cb( parent );
+}
+
void __gui_internal_vectorinput_init(
GUI_VECTORINPUT *input,
I32 x, I32 y, I32 w,
@@ -69,6 +83,7 @@ void __gui_internal_vectorinput_init(
gui_set_view( input );
input->cb = 0;
+ input->release_cb = 0;
input->pval = pval;
input->letters = letters;
input->inputview = gui_view( 0, VECTORINPUT_TITLE_OFFSET, w, input->h );
@@ -90,6 +105,8 @@ void __gui_internal_vectorinput_init(
input->inputs.push( slider );
slider->cb = gui_vectorinput_child_cb;
+ slider->pre_cb = gui_vectorinput_child_pre_cb;
+ slider->release_cb = gui_vectorinput_child_release_cb;
}
gui_set_view( parent );