diff --git a/src/box_edit.c b/src/box_edit.c index 455ea3456..a9265b57c 100644 --- a/src/box_edit.c +++ b/src/box_edit.c @@ -91,19 +91,19 @@ static void highlight_face(const float box[4][4], int face) render_rect_fill(&goxel.rend, plane, color); } -static int on_hover(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_hover(gesture3d_t *gest, void *user) { data_t *data = (void*)user; goxel_set_help_text("Drag to move face"); data->flags |= FLAG_SNAPED; - data->snap_face = get_face(curs->normal); + data->snap_face = get_face(gest->normal); highlight_face(data->box, data->snap_face); render_gizmo(data->box, data->snap_face); return 0; } -static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_drag(gesture3d_t *gest, void *user) { data_t *data = (void*)user; float face_plane[4][4], v[3], pos[3], n[3], d[3], ofs[3], box[4][4]; @@ -114,17 +114,17 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) if (gest->state == GESTURE3D_STATE_BEGIN) { data->flags |= FLAG_FIRST; mat4_copy(data->box, data->start_box); - data->snap_face = get_face(curs->normal); + data->snap_face = get_face(gest->normal); mat4_mul(data->box, FACES_MATS[data->snap_face], face_plane); vec3_normalize(face_plane[0], v); gest->snap_mask = SNAP_SHAPE_PLANE; - plane_from_vectors(gest->snap_shape, curs->pos, curs->normal, v); + plane_from_vectors(gest->snap_shape, gest->pos, gest->normal, v); return 0; } mat4_mul(data->start_box, FACES_MATS[data->snap_face], face_plane); vec3_normalize(face_plane[2], n); - vec3_sub(curs->pos, gest->snap_shape[3], v); + vec3_sub(gest->pos, gest->snap_shape[3], v); vec3_project(v, n, v); vec3_add(gest->snap_shape[3], v, pos); pos[0] = round(pos[0]); diff --git a/src/gesture3d.c b/src/gesture3d.c index 8e8afaf6a..ed58d911a 100644 --- a/src/gesture3d.c +++ b/src/gesture3d.c @@ -18,9 +18,9 @@ #include "goxel.h" -int gesture3d(gesture3d_t *gest, cursor_t *curs, void *user) +int gesture3d(gesture3d_t *gest, void *user) { - bool pressed = curs->flags & GESTURE3D_FLAG_PRESSED; + bool pressed = gest->flags & GESTURE3D_FLAG_PRESSED; int r, ret = 0; const int btns_mask = GESTURE3D_FLAG_CTRL; @@ -30,9 +30,9 @@ int gesture3d(gesture3d_t *gest, cursor_t *curs, void *user) if (gest->type == GESTURE3D_TYPE_DRAG) { switch (gest->state) { case GESTURE3D_STATE_POSSIBLE: - if ((gest->buttons & btns_mask) != (curs->flags & btns_mask)) + if ((gest->buttons & btns_mask) != (gest->flags & btns_mask)) break; - if (curs->snaped && pressed) { + if (gest->snaped && pressed) { gest->state = GESTURE3D_STATE_BEGIN; } break; @@ -52,14 +52,14 @@ int gesture3d(gesture3d_t *gest, cursor_t *curs, void *user) if (gest->type == GESTURE3D_TYPE_CLICK) { switch (gest->state) { case GESTURE3D_STATE_POSSIBLE: - if (curs->snaped && !pressed) { + if (gest->snaped && !pressed) { gest->state = GESTURE3D_STATE_RECOGNISED; } break; case GESTURE3D_STATE_RECOGNISED: - if ((gest->buttons & btns_mask) != (curs->flags & btns_mask)) + if ((gest->buttons & btns_mask) != (gest->flags & btns_mask)) break; - if (curs->snaped && pressed) { + if (gest->snaped && pressed) { gest->state = GESTURE3D_STATE_TRIGGERED; } break; @@ -72,26 +72,26 @@ int gesture3d(gesture3d_t *gest, cursor_t *curs, void *user) if (!DEFINED(GOXEL_MOBILE) && gest->type == GESTURE3D_TYPE_HOVER) { switch (gest->state) { case GESTURE3D_STATE_POSSIBLE: - if ((gest->buttons & btns_mask) != (curs->flags & btns_mask)) + if ((gest->buttons & btns_mask) != (gest->flags & btns_mask)) break; - if (curs->snaped && !pressed && - !(curs->flags & GESTURE3D_FLAG_OUT)) { + if (gest->snaped && !pressed && + !(gest->flags & GESTURE3D_FLAG_OUT)) { gest->state = GESTURE3D_STATE_BEGIN; } break; case GESTURE3D_STATE_BEGIN: case GESTURE3D_STATE_UPDATE: gest->state = GESTURE3D_STATE_UPDATE; - if ((gest->buttons & btns_mask) != (curs->flags & btns_mask)) { + if ((gest->buttons & btns_mask) != (gest->flags & btns_mask)) { gest->state = GESTURE3D_STATE_END; } if (pressed) { gest->state = GESTURE3D_STATE_END; } - if (!curs->snaped) { + if (!gest->snaped) { gest->state = GESTURE3D_STATE_END; } - if (curs->flags & GESTURE3D_FLAG_OUT) { + if (gest->flags & GESTURE3D_FLAG_OUT) { gest->state = GESTURE3D_STATE_END; } break; @@ -106,7 +106,7 @@ int gesture3d(gesture3d_t *gest, cursor_t *curs, void *user) gest->state == GESTURE3D_STATE_END || gest->state == GESTURE3D_STATE_TRIGGERED) { - r = gest->callback(gest, curs, user); + r = gest->callback(gest, user); if (r == GESTURE3D_STATE_FAILED) { gest->state = GESTURE3D_STATE_FAILED; ret = 0; diff --git a/src/gesture3d.h b/src/gesture3d.h index 540eea204..b7bfe1d4c 100644 --- a/src/gesture3d.h +++ b/src/gesture3d.h @@ -37,37 +37,32 @@ enum { GESTURE3D_STATE_FAILED, }; -// Represent a 3d cursor. -// The program keeps track of two cursors, that are then used by the tools. enum { - // The state flags of the cursor. GESTURE3D_FLAG_PRESSED = 1 << 0, GESTURE3D_FLAG_SHIFT = 1 << 1, GESTURE3D_FLAG_CTRL = 1 << 2, GESTURE3D_FLAG_OUT = 1 << 3, // Outside of sensing area. }; -typedef struct cursor { - float pos[3]; - float normal[3]; - int snaped; - int flags; -} cursor_t; - // #### 3d gestures struct gesture3d { int type; - int state; - int buttons; // CURSOR_SHIFT | CURSOR_CTRL + int buttons; // GESTURE3D_FLAG_SHIFT | GESTURE3D_FLAG_CTRL int snap_mask; float snap_offset; float snap_shape[4][4]; // Used for plane snapping. - int (*callback)(gesture3d_t *gest, const cursor_t *curs, - void *user); + int (*callback)(gesture3d_t *gest, void *user); void *user; + + // Automatically updated attributes. + int state; + float pos[3]; + float normal[3]; + int snaped; + int flags; }; -int gesture3d(gesture3d_t *gest, cursor_t *curs, void *user); +int gesture3d(gesture3d_t *gest, void *user); #endif // GESTURE3D_H diff --git a/src/goxel.c b/src/goxel.c index af2d5027c..e3bd36d03 100644 --- a/src/goxel.c +++ b/src/goxel.c @@ -530,7 +530,6 @@ bool goxel_gesture3d(const gesture3d_t *gesture) bool ret; gesture3d_t *gest; typeof(goxel.gesture3ds[0]) *slot = NULL; - cursor_t *curs; // Search if we already have a different active gesture. for (i = 0; i < goxel.gesture3ds_count; i++) { @@ -562,12 +561,17 @@ bool goxel_gesture3d(const gesture3d_t *gesture) // Update the gesture data until it has started. That way we can // modify the gesture inside its callback function. if (slot->gesture.state == 0) { - slot->gesture = *gesture; + slot->gesture.type = gesture->type; + slot->gesture.buttons = gesture->buttons; + slot->gesture.snap_mask = gesture->snap_mask; + slot->gesture.snap_offset = gesture->snap_offset; + mat4_copy(gesture->snap_shape, slot->gesture.snap_shape); + slot->gesture.callback = gesture->callback; + slot->gesture.user = gesture->user; } slot->alive = true; - curs = &slot->cursor; - ret = gesture3d(&slot->gesture, curs, gesture->user); + ret = gesture3d(&slot->gesture, gesture->user); return ret; } @@ -670,35 +674,33 @@ int goxel_iter(const inputs_t *inputs) return goxel.quit ? 1 : 0; } -static void set_cursor_hint(cursor_t *curs) +static void set_cursor_hint(const gesture3d_t *gest) { - if (!curs->snaped) { + if (!gest->snaped) { goxel_set_hint_text(NULL); return; } goxel_set_hint_text("[%.0f %.0f %.0f]", - curs->pos[0] - 0.5, curs->pos[1] - 0.5, curs->pos[2] - 0.5); + gest->pos[0] - 0.5, gest->pos[1] - 0.5, gest->pos[2] - 0.5); } static int on_drag(const gesture_t *gest, void *user) { int i; gesture3d_t *gest3d; - cursor_t *c; for (i = 0; i < goxel.gesture3ds_count; i++) { gest3d = &goxel.gesture3ds[i].gesture; - c = &goxel.gesture3ds[i].cursor; if (gest->state == GESTURE_BEGIN) - c->flags |= GESTURE3D_FLAG_PRESSED; + gest3d->flags |= GESTURE3D_FLAG_PRESSED; if (gest->state == GESTURE_END) - c->flags &= ~GESTURE3D_FLAG_PRESSED; + gest3d->flags &= ~GESTURE3D_FLAG_PRESSED; - c->snaped = goxel_unproject( + gest3d->snaped = goxel_unproject( gest->viewport, gest->pos, gest3d->snap_mask, gest3d->snap_shape, gest3d->snap_offset, - c->pos, c->normal); - set_cursor_hint(c); + gest3d->pos, gest3d->normal); + set_cursor_hint(gest3d); } return 0; } @@ -809,18 +811,17 @@ static int on_hover(const gesture_t *gest, void *user) { int i; gesture3d_t *gest3d; - cursor_t *c; for (i = 0; i < goxel.gesture3ds_count; i++) { gest3d = &goxel.gesture3ds[i].gesture; - c = &goxel.gesture3ds[i].cursor; - c->snaped = goxel_unproject( + gest3d->snaped = goxel_unproject( gest->viewport, gest->pos, gest3d->snap_mask, gest3d->snap_shape, gest3d->snap_offset, - c->pos, c->normal); - set_cursor_hint(c); - c->flags &= ~GESTURE3D_FLAG_PRESSED; - set_flag(&c->flags, GESTURE3D_FLAG_OUT, gest->state == GESTURE_END); + gest3d->pos, gest3d->normal); + set_cursor_hint(gest3d); + gest3d->flags &= ~GESTURE3D_FLAG_PRESSED; + set_flag(&gest3d->flags, GESTURE3D_FLAG_OUT, + gest->state == GESTURE_END); } return 0; } @@ -831,19 +832,18 @@ void goxel_mouse_in_view(const float viewport[4], const inputs_t *inputs, { float p[3], n[3]; camera_t *camera = get_camera(); + gesture3d_t *gest3d; int i; - cursor_t *curs; - painter_t painter = goxel.painter; gesture_update(goxel.gestures_count, goxel.gestures, inputs, viewport, NULL); for (i = 0; i < goxel.gesture3ds_count; i++) { - curs = &goxel.gesture3ds[i].cursor; - set_flag(&curs->flags, GESTURE3D_FLAG_SHIFT, + gest3d = &goxel.gesture3ds[i].gesture; + set_flag(&gest3d->flags, GESTURE3D_FLAG_SHIFT, inputs->keys[KEY_LEFT_SHIFT]); - set_flag(&curs->flags, GESTURE3D_FLAG_CTRL, + set_flag(&gest3d->flags, GESTURE3D_FLAG_CTRL, inputs->keys[KEY_CONTROL]); } diff --git a/src/goxel.h b/src/goxel.h index 8f41afe67..2fdf34d47 100644 --- a/src/goxel.h +++ b/src/goxel.h @@ -526,7 +526,6 @@ typedef struct goxel // All the 3d gestures we listen to. struct { gesture3d_t gesture; - cursor_t cursor; bool alive; } gesture3ds[16]; int gesture3ds_count; diff --git a/src/tools.c b/src/tools.c index 5d4071b96..728f1adf6 100644 --- a/src/tools.c +++ b/src/tools.c @@ -48,21 +48,20 @@ const tool_t *tool_get(int id) return g_tools[id]; } -static int pick_color_gesture(gesture3d_t *gest, const cursor_t *curs, - void *user) +static int pick_color_gesture(gesture3d_t *gest, void *user) { const volume_t *volume = goxel_get_layers_volume(goxel.image); - int pi[3] = {floor(curs->pos[0]), - floor(curs->pos[1]), - floor(curs->pos[2])}; + int pi[3] = {floor(gest->pos[0]), + floor(gest->pos[1]), + floor(gest->pos[2])}; uint8_t color[4]; goxel_set_help_text("Click on a voxel to pick the color"); - if (!curs->snaped) return 0; + if (!gest->snaped) return 0; volume_get_at(volume, NULL, pi, color); color[3] = 255; goxel_set_help_text("pick: %d %d %d", color[0], color[1], color[2]); - if (curs->flags & GESTURE3D_FLAG_PRESSED) { + if (gest->flags & GESTURE3D_FLAG_PRESSED) { vec4_copy(color, goxel.painter.color); } return 0; diff --git a/src/tools/brush.c b/src/tools/brush.c index 57b7a80a0..0ccf8880e 100644 --- a/src/tools/brush.c +++ b/src/tools/brush.c @@ -39,21 +39,21 @@ typedef struct { } tool_brush_t; -static bool check_can_skip(tool_brush_t *brush, const cursor_t *curs, - int mode) +static bool check_can_skip( + tool_brush_t *brush, const gesture3d_t *gest, int mode) { volume_t *volume = goxel.tool_volume; - const bool pressed = curs->flags & GESTURE3D_FLAG_PRESSED; + const bool pressed = gest->flags & GESTURE3D_FLAG_PRESSED; if ( pressed == brush->last_op.pressed && mode == brush->last_op.mode && brush->last_op.volume_key == volume_get_key(volume) && - vec3_equal(curs->pos, brush->last_op.pos)) { + vec3_equal(gest->pos, brush->last_op.pos)) { return true; } brush->last_op.pressed = pressed; brush->last_op.mode = mode; brush->last_op.volume_key = volume_get_key(volume); - vec3_copy(curs->pos, brush->last_op.pos); + vec3_copy(gest->pos, brush->last_op.pos); return false; } @@ -103,12 +103,12 @@ static void get_box(const float p0[3], const float p1[3], const float n[3], mat4_copy(box, out); } -static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_drag(gesture3d_t *gest, void *user) { tool_brush_t *brush = USER_GET(user, 0); painter_t painter = *(painter_t*)USER_GET(user, 1); float box[4][4]; - bool shift = curs->flags & GESTURE3D_FLAG_SHIFT; + bool shift = gest->flags & GESTURE3D_FLAG_SHIFT; float r = goxel.tool_radius; int nb, i; float pos[3]; @@ -116,7 +116,7 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) if (gest->state == GESTURE3D_STATE_BEGIN) { volume_set(brush->volume_orig, goxel.image->active_layer->volume); brush->last_op.mode = 0; // Discard last op. - vec3_copy(curs->pos, brush->last_pos); + vec3_copy(gest->pos, brush->last_pos); image_history_push(goxel.image); volume_clear(brush->volume); @@ -124,14 +124,14 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) painter.shape = &shape_cylinder; painter.mode = MODE_MAX; vec4_set(painter.color, 255, 255, 255, 255); - get_box(brush->start_pos, curs->pos, curs->normal, r, NULL, box); + get_box(brush->start_pos, gest->pos, gest->normal, r, NULL, box); volume_op(brush->volume, &painter, box); } } painter = *(painter_t*)USER_GET(user, 1); if ( (gest->state == GESTURE3D_STATE_UPDATE) && - (check_can_skip(brush, curs, painter.mode))) { + (check_can_skip(brush, gest, painter.mode))) { return 0; } @@ -140,11 +140,11 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) // Render several times if the space between the current pos // and the last pos is larger than the size of the tool shape. - nb = ceil(vec3_dist(curs->pos, brush->last_pos) / (2 * r)); + nb = ceil(vec3_dist(gest->pos, brush->last_pos) / (2 * r)); nb = max(nb, 1); for (i = 0; i < nb; i++) { - vec3_mix(brush->last_pos, curs->pos, (i + 1.0) / nb, pos); - get_box(pos, NULL, curs->normal, r, NULL, box); + vec3_mix(brush->last_pos, gest->pos, (i + 1.0) / nb, pos); + get_box(pos, NULL, gest->normal, r, NULL, box); volume_op(brush->volume, &painter, box); } @@ -152,7 +152,7 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) if (!goxel.tool_volume) goxel.tool_volume = volume_new(); volume_set(goxel.tool_volume, brush->volume_orig); volume_merge(goxel.tool_volume, brush->volume, painter.mode, painter.color); - vec3_copy(curs->pos, brush->start_pos); + vec3_copy(gest->pos, brush->start_pos); brush->last_op.volume_key = volume_get_key(goxel.tool_volume); if (gest->state == GESTURE3D_STATE_END) { @@ -161,31 +161,31 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) volume_delete(goxel.tool_volume); goxel.tool_volume = NULL; } - vec3_copy(curs->pos, brush->last_pos); + vec3_copy(gest->pos, brush->last_pos); return 0; } -static int on_hover(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_hover(gesture3d_t *gest, void *user) { volume_t *volume = goxel.image->active_layer->volume; tool_brush_t *brush = USER_GET(user, 0); const painter_t *painter = USER_GET(user, 1); float box[4][4]; - bool shift = curs->flags & GESTURE3D_FLAG_SHIFT; + bool shift = gest->flags & GESTURE3D_FLAG_SHIFT; - if (gest->state == GESTURE3D_STATE_END || !curs->snaped) { + if (gest->state == GESTURE3D_STATE_END || !gest->snaped) { volume_delete(goxel.tool_volume); goxel.tool_volume = NULL; return 0; } if (shift) - render_line(&goxel.rend, brush->start_pos, curs->pos, NULL, 0); + render_line(&goxel.rend, brush->start_pos, gest->pos, NULL, 0); - if (goxel.tool_volume && check_can_skip(brush, curs, painter->mode)) + if (goxel.tool_volume && check_can_skip(brush, gest, painter->mode)) return 0; - get_box(curs->pos, NULL, curs->normal, goxel.tool_radius, NULL, box); + get_box(gest->pos, NULL, gest->normal, goxel.tool_radius, NULL, box); if (!goxel.tool_volume) goxel.tool_volume = volume_new(); volume_set(goxel.tool_volume, volume); diff --git a/src/tools/extrude.c b/src/tools/extrude.c index 4e4d9713c..b626b1283 100644 --- a/src/tools/extrude.c +++ b/src/tools/extrude.c @@ -67,7 +67,7 @@ static int get_face(const float n[3]) // XXX: this code is just too ugly. Needs a lot of cleanup. // The problem is that we should use some generic functions to handle // box resize, since we do it a lot, and the code is never very clear. -static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_drag(gesture3d_t *gest, void *user) { tool_extrude_t *tool = (tool_extrude_t*)user; volume_t *volume = goxel.image->active_layer->volume; @@ -78,13 +78,13 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) float delta; if (gest->state == GESTURE3D_STATE_BEGIN) { - tool->snap_face = get_face(curs->normal); + tool->snap_face = get_face(gest->normal); tmp_volume = volume_new(); tool->volume = volume_copy(volume); - pi[0] = floor(curs->pos[0]); - pi[1] = floor(curs->pos[1]); - pi[2] = floor(curs->pos[2]); + pi[0] = floor(gest->pos[0]); + pi[1] = floor(gest->pos[1]); + pi[2] = floor(gest->pos[2]); volume_select(volume, pi, select_cond, &tool->snap_face, tmp_volume); volume_merge(tool->volume, tmp_volume, MODE_MULT_ALPHA, NULL); volume_delete(tmp_volume); @@ -97,7 +97,7 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) mat4_mul(box, FACES_MATS[tool->snap_face], face_plane); vec3_normalize(face_plane[0], v); gest->snap_mask = SNAP_SHAPE_PLANE; - plane_from_vectors(gest->snap_shape, curs->pos, curs->normal, v); + plane_from_vectors(gest->snap_shape, gest->pos, gest->normal, v); tool->last_delta = 0; } @@ -108,7 +108,7 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) mat4_mul(box, FACES_MATS[tool->snap_face], face_plane); vec3_normalize(face_plane[2], n); // XXX: Is there a better way to compute the delta?? - vec3_sub(curs->pos, gest->snap_shape[3], v); + vec3_sub(gest->pos, gest->snap_shape[3], v); vec3_project(v, n, v); delta = vec3_dot(n, v); // render_box(&goxel.rend, &box, NULL, EFFECT_WIREFRAME); @@ -117,7 +117,7 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) if (round(delta) == tool->last_delta) goto end; tool->last_delta = round(delta); - vec3_sub(curs->pos, gest->snap_shape[3], v); + vec3_sub(gest->pos, gest->snap_shape[3], v); vec3_project(v, n, v); vec3_add(gest->snap_shape[3], v, pos); pos[0] = round(pos[0]); diff --git a/src/tools/fuzzy_select.c b/src/tools/fuzzy_select.c index cb35d851d..7477c1894 100644 --- a/src/tools/fuzzy_select.c +++ b/src/tools/fuzzy_select.c @@ -40,16 +40,16 @@ static int select_cond(void *user, const volume_t *volume, return d <= tool->threshold ? 255 : 0; } -static int on_click(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_click(gesture3d_t *gest, void *user) { volume_t *volume = goxel.image->active_layer->volume; volume_t *sel; int pi[3]; tool_fuzzy_select_t *tool = (void*)user; - pi[0] = floor(curs->pos[0]); - pi[1] = floor(curs->pos[1]); - pi[2] = floor(curs->pos[2]); + pi[0] = floor(gest->pos[0]); + pi[1] = floor(gest->pos[1]); + pi[2] = floor(gest->pos[2]); sel = volume_new(); volume_select(volume, pi, select_cond, tool, sel); if (goxel.mask == NULL) goxel.mask = volume_new(); diff --git a/src/tools/laser.c b/src/tools/laser.c index ef91c3126..792242eaf 100644 --- a/src/tools/laser.c +++ b/src/tools/laser.c @@ -25,7 +25,7 @@ typedef struct { } tool_laser_t; -static int on_hover(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_hover(gesture3d_t *gest, void *user) { tool_laser_t *laser = user; float v[4]; @@ -41,8 +41,8 @@ static int on_hover(gesture3d_t *gest, const cursor_t *curs, void *user) vec3_copy(v, laser->box[1]); mat4_mul_vec4(view_mat_inv, VEC(0, 0, 1, 0), v); vec3_copy(v, laser->box[2]); - vec3_neg(curs->normal, laser->box[2]); - vec3_copy(curs->pos, laser->box[3]); + vec3_neg(gest->normal, laser->box[2]); + vec3_copy(gest->pos, laser->box[3]); // Just a large value for the size of the laser box. mat4_itranslate(laser->box, 0, 0, -1024); mat4_iscale(laser->box, goxel.tool_radius, goxel.tool_radius, 1024); @@ -51,13 +51,13 @@ static int on_hover(gesture3d_t *gest, const cursor_t *curs, void *user) } -static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_drag(gesture3d_t *gest, void *user) { tool_laser_t *laser = (tool_laser_t*)USER_GET(user, 0); painter_t painter = *(painter_t*)USER_GET(user, 1); volume_t *volume = goxel.image->active_layer->volume; - on_hover(gest, curs, laser); + on_hover(gest, laser); painter.mode = MODE_SUB_CLAMP; painter.shape = &shape_cylinder; vec4_set(painter.color, 255, 255, 255, 255); diff --git a/src/tools/line.c b/src/tools/line.c index 2abfd7949..55cfceaf5 100644 --- a/src/tools/line.c +++ b/src/tools/line.c @@ -75,7 +75,7 @@ static void get_box(const float p0[3], const float p1[3], const float n[3], mat4_copy(box, out); } -static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_drag(gesture3d_t *gest, void *user) { tool_line_t *tool = USER_GET(user, 0); painter_t painter; @@ -83,7 +83,7 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) float box[4][4]; if (gest->state == GESTURE3D_STATE_BEGIN) { - vec3_copy(curs->pos, tool->start_pos); + vec3_copy(gest->pos, tool->start_pos); assert(tool->volume_orig); volume_set(tool->volume_orig, goxel.image->active_layer->volume); image_history_push(goxel.image); @@ -92,7 +92,7 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) painter = *(painter_t*)USER_GET(user, 1); painter.mode = MODE_MAX; vec4_set(painter.color, 255, 255, 255, 255); - get_box(tool->start_pos, curs->pos, curs->normal, radius, NULL, box); + get_box(tool->start_pos, gest->pos, gest->normal, radius, NULL, box); volume_clear(tool->volume); volume_op(tool->volume, &painter, box); @@ -111,7 +111,7 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) return 0; } -static int on_hover(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_hover(gesture3d_t *gest, void *user) { volume_t *volume = goxel.image->active_layer->volume; @@ -123,7 +123,7 @@ static int on_hover(gesture3d_t *gest, const cursor_t *curs, void *user) goxel.tool_volume = NULL; return 0; } - get_box(curs->pos, NULL, curs->normal, goxel.tool_radius, NULL, box); + get_box(gest->pos, NULL, gest->normal, goxel.tool_radius, NULL, box); if (!goxel.tool_volume) goxel.tool_volume = volume_new(); volume_set(goxel.tool_volume, volume); diff --git a/src/tools/plane.c b/src/tools/plane.c index 5fd74b4f2..409aec0a4 100644 --- a/src/tools/plane.c +++ b/src/tools/plane.c @@ -24,13 +24,13 @@ typedef struct { } tool_plane_t; -static int on_click(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_click(gesture3d_t *gest, void *user) { float pos[3]; - pos[0] = round(curs->pos[0]); - pos[1] = round(curs->pos[1]); - pos[2] = round(curs->pos[2]); - plane_from_normal(goxel.plane, pos, curs->normal); + pos[0] = round(gest->pos[0]); + pos[1] = round(gest->pos[1]); + pos[2] = round(gest->pos[2]); + plane_from_normal(goxel.plane, pos, gest->normal); mat4_itranslate(goxel.plane, 0, 0, -1); return 0; } diff --git a/src/tools/rect_select.c b/src/tools/rect_select.c index dac4d0a09..8ed9fc8ab 100644 --- a/src/tools/rect_select.c +++ b/src/tools/rect_select.c @@ -52,13 +52,13 @@ static void apply(const float rect_[4]) } } -static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_drag(gesture3d_t *gest, void *user) { tool_rect_select_t *tool = user; float pos[4]; const camera_t *cam = goxel.image->active_camera; - vec4_set(pos, curs->pos[0], curs->pos[1], curs->pos[2], 1.0); + vec4_set(pos, gest->pos[0], gest->pos[1], gest->pos[2], 1.0); mat4_mul_vec4(cam->view_mat, pos, pos); mat4_mul_vec4(cam->proj_mat, pos, pos); vec3_mul(pos, 1 / pos[3], pos); diff --git a/src/tools/selection.c b/src/tools/selection.c index 03e877124..22053edfc 100644 --- a/src/tools/selection.c +++ b/src/tools/selection.c @@ -39,18 +39,18 @@ static void get_rect(const float pos[3], const float normal[3], mat4_iscale(out, 0.5, 0.5, 0); } -static int on_hover(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_hover(gesture3d_t *gest, void *user) { float rect[4][4]; uint8_t rect_color[4] = {255, 255, 0, 255}; goxel_set_help_text("Click and drag to set selection."); - get_rect(curs->pos, curs->normal, rect); + get_rect(gest->pos, gest->normal, rect); render_box(&goxel.rend, rect, rect_color, EFFECT_WIREFRAME); return 0; } -static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_drag(gesture3d_t *gest, void *user) { tool_selection_t *tool = user; float rect[4][4]; @@ -59,15 +59,15 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) goxel_set_help_text("Drag."); - get_rect(curs->pos, curs->normal, rect); + get_rect(gest->pos, gest->normal, rect); if (gest->state == GESTURE3D_STATE_BEGIN) mat4_copy(rect, tool->start_rect); box_union(tool->start_rect, rect, goxel.selection); // If the selection is flat, we grow it one voxel. if (box_get_volume(goxel.selection) == 0) { - dir = curs->snaped == SNAP_VOLUME ? -1 : 1; - vec3_addk(curs->pos, curs->normal, dir, p); + dir = gest->snaped == SNAP_VOLUME ? -1 : 1; + vec3_addk(gest->pos, gest->normal, dir, p); bbox_extends_from_points(goxel.selection, 1, &p, goxel.selection); } return 0; diff --git a/src/tools/shape.c b/src/tools/shape.c index 9c54a3cad..492129311 100644 --- a/src/tools/shape.c +++ b/src/tools/shape.c @@ -43,18 +43,18 @@ static void get_box(const float p0[3], const float p1[3], const float n[3], mat4_copy(box, out); } -static int on_hover(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_hover(gesture3d_t *gest, void *user) { float box[4][4]; uint8_t box_color[4] = {255, 255, 0, 255}; goxel_set_help_text("Click and drag to draw."); - get_box(curs->pos, curs->pos, curs->normal, box); + get_box(gest->pos, gest->pos, gest->normal, box); render_box(&goxel.rend, box, box_color, EFFECT_WIREFRAME); return 0; } -static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) +static int on_drag(gesture3d_t *gest, void *user) { tool_shape_t *shape = USER_GET(user, 0); const painter_t *painter = USER_GET(user, 1); @@ -63,17 +63,17 @@ static int on_drag(gesture3d_t *gest, const cursor_t *curs, void *user) if (gest->state == GESTURE3D_STATE_BEGIN) { volume_set(shape->volume_orig, layer_volume); - vec3_copy(curs->pos, shape->start_pos); + vec3_copy(gest->pos, shape->start_pos); image_history_push(goxel.image); if (shape->planar) { - vec3_addk(curs->pos, curs->normal, -gest->snap_offset, pos); + vec3_addk(gest->pos, gest->normal, -gest->snap_offset, pos); gest->snap_mask = SNAP_SHAPE_PLANE; - plane_from_normal(gest->snap_shape, pos, curs->normal); + plane_from_normal(gest->snap_shape, pos, gest->normal); } } goxel_set_help_text("Drag."); - get_box(shape->start_pos, curs->pos, curs->normal, box); + get_box(shape->start_pos, gest->pos, gest->normal, box); if (!goxel.tool_volume) goxel.tool_volume = volume_new(); volume_set(goxel.tool_volume, shape->volume_orig); volume_op(goxel.tool_volume, painter, box);