From cce0f605193071267b26810e89de315e455198eb Mon Sep 17 00:00:00 2001 From: Guillaume Chereau Date: Thu, 4 Jul 2024 15:02:11 +0800 Subject: [PATCH] Recompute selection mask after manual edit This is the expected behavior I guess. I added a new gui function to check if an input got deactivated. --- src/gui.cpp | 11 +++++++++++ src/gui.h | 2 ++ src/tools/selection.c | 12 +++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/gui.cpp b/src/gui.cpp index 66c8ac5bb..e5829bb7d 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -183,6 +183,8 @@ typedef struct gui_t { bool opened; } popup[8]; // Stack of modal popups int popup_count; + + bool item_deactivated; } gui_t; static gui_t *gui = NULL; @@ -907,6 +909,7 @@ bool gui_input_float(const char *label, float *v, float step, GUI_ITEM_HEIGHT, ImGui::GetFontSize() + style.FramePadding.y * 2.0f); + gui->item_deactivated = false; if (minv == 0.f && maxv == 0.f) { minv = -FLT_MAX; maxv = +FLT_MAX; @@ -947,10 +950,12 @@ bool gui_input_float(const char *label, float *v, float step, (*v) -= step; ret = true; } + if (ImGui::IsItemDeactivated()) gui->item_deactivated = true; ImGui::SameLine(); ImGui::PushItemWidth( ImGui::GetContentRegionAvail().x - button_size.x - 4); ret = ImGui::DragFloat("", v, v_speed, minv, maxv, format) || ret; + if (ImGui::IsItemDeactivated()) gui->item_deactivated = true; is_active = ImGui::IsItemActive(); ImGui::PopItemWidth(); ImGui::SameLine(); @@ -958,6 +963,7 @@ bool gui_input_float(const char *label, float *v, float step, (*v) += step; ret = true; } + if (ImGui::IsItemDeactivated()) gui->item_deactivated = true; } else { ImGui::SetNextItemWidth(-1); if (unbounded) { @@ -1901,3 +1907,8 @@ void gui_context_menu_button(const char *label, int icon) ImGui::OpenPopup(label); } } + +bool gui_is_item_deactivated(void) +{ + return gui->item_deactivated; +} diff --git a/src/gui.h b/src/gui.h index f2598f9d9..cda00b58d 100644 --- a/src/gui.h +++ b/src/gui.h @@ -149,6 +149,8 @@ bool gui_layer_item(int idx, int icons_count, const int *icons, bool gui_is_key_down(int key); +bool gui_is_item_deactivated(void); + void gui_query_quit(void); enum { diff --git a/src/tools/selection.c b/src/tools/selection.c index 129e4a6f9..574cbf274 100644 --- a/src/tools/selection.c +++ b/src/tools/selection.c @@ -186,7 +186,7 @@ static int gui(tool_t *tool_) float x_mag, y_mag, z_mag; int x, y, z, w, h, d; float (*box)[4][4] = &goxel.selection; - + bool deactivated = false; tool_gui_mask_mode(&tool->mode); @@ -210,14 +210,20 @@ static int gui(tool_t *tool_) gui_group_begin("Origin"); gui_input_int("x", &x, 0, 0); + deactivated |= gui_is_item_deactivated(); gui_input_int("y", &y, 0, 0); + deactivated |= gui_is_item_deactivated(); gui_input_int("z", &z, 0, 0); + deactivated |= gui_is_item_deactivated(); gui_group_end(); gui_group_begin("Size"); gui_input_int("w", &w, 0, 0); + deactivated |= gui_is_item_deactivated(); gui_input_int("h", &h, 0, 0); + deactivated |= gui_is_item_deactivated(); gui_input_int("d", &d, 0, 0); + deactivated |= gui_is_item_deactivated(); w = max(1, w); h = max(1, h); d = max(1, d); @@ -226,6 +232,10 @@ static int gui(tool_t *tool_) bbox_from_extents(*box, VEC(x + w / 2., y + h / 2., z + d / 2.), w / 2., h / 2., d / 2.); + + if (deactivated) { + update_mask(tool); + } return 0; }