Skip to content

Commit

Permalink
Recompute selection mask after manual edit
Browse files Browse the repository at this point in the history
This is the expected behavior I guess.

I added a new gui function to check if an input got deactivated.
  • Loading branch information
guillaumechereau committed Jul 4, 2024
1 parent b24398f commit cce0f60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -947,17 +950,20 @@ 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();
if (ImGui::Button(right_utf, button_size)) {
(*v) += step;
ret = true;
}
if (ImGui::IsItemDeactivated()) gui->item_deactivated = true;
} else {
ImGui::SetNextItemWidth(-1);
if (unbounded) {
Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion src/tools/selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit cce0f60

Please sign in to comment.