Skip to content

Commit

Permalink
Fix bug with mouse wheel on export combo
Browse files Browse the repository at this point in the history
- Fix `gui_wants_capture_mouse` to check the value before we call
  ImGui::NewFrame.  It seems to work better like that.

- Ignore wheel event if the UI wants to capture the mouse.
  • Loading branch information
guillaumechereau committed Jul 12, 2024
1 parent f278847 commit 1ec3bf7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/goxel.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ static int on_zoom(const gesture_t *gest, void *user)
double zoom;
camera_t *camera = get_camera();

if (gui_want_capture_mouse()) return 0;
zoom = (gest->pos[1] - gest->last_pos[1]) / 10.0;
mat4_itranslate(camera->mat, 0, 0,
-camera->dist * (1 - pow(1.1, -zoom)));
Expand Down Expand Up @@ -901,7 +902,7 @@ void goxel_mouse_in_view(const float viewport[4], const inputs_t *inputs,
tool_iter(goxel.tool, &painter, viewport);
}

if (inputs->mouse_wheel) {
if (inputs->mouse_wheel && !gui_want_capture_mouse()) {
mat4_itranslate(camera->mat, 0, 0,
-camera->dist * (1 - pow(1.1, -inputs->mouse_wheel)));
camera->dist *= pow(1.1, -inputs->mouse_wheel);
Expand Down
6 changes: 3 additions & 3 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ typedef struct gui_t {
int scrolling;

int can_move_window;
bool want_capture_mouse;

int is_row;
float item_size;
Expand Down Expand Up @@ -604,6 +605,7 @@ static void gui_iter(inputs_t *inputs)
ImGuiIO& io = ImGui::GetIO();
ImGuiStyle& style = ImGui::GetStyle();

gui->want_capture_mouse = io.WantCaptureMouse;
io.DisplaySize = ImVec2((float)goxel.screen_size[0],
(float)goxel.screen_size[1]);

Expand Down Expand Up @@ -1928,9 +1930,7 @@ bool gui_icons_grid(int nb, const gui_icon_info_t *icons, int *current)

bool gui_want_capture_mouse(void)
{
gui_init();
ImGuiIO& io = ImGui::GetIO();
return io.WantCaptureMouse;
return gui && gui->want_capture_mouse;
}

bool gui_context_menu_begin(const char *label)
Expand Down

0 comments on commit 1ec3bf7

Please sign in to comment.