Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
| Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | struct { | ||||
| /* Cache the last angle to detect rotations bigger than -/+ PI. */ | /* Cache the last angle to detect rotations bigger than -/+ PI. */ | ||||
| eWM_GizmoFlagTweak tweak_flag; | eWM_GizmoFlagTweak tweak_flag; | ||||
| float angle; | float angle; | ||||
| } prev; | } prev; | ||||
| /* Number of full rotations. */ | /* Number of full rotations. */ | ||||
| int rotations; | int rotations; | ||||
| bool has_drag; | bool has_drag; | ||||
| float angle_increment; | |||||
| /* Final output values, used for drawing. */ | /* Final output values, used for drawing. */ | ||||
| struct { | struct { | ||||
| float angle_ofs; | float angle_ofs; | ||||
| float angle_delta; | float angle_delta; | ||||
| } output; | } output; | ||||
campbellbarton: This isn't output as far as I can see, its a snap setting. Would move under `has_drag` | |||||
| } DialInteraction; | } DialInteraction; | ||||
| #define DIAL_WIDTH 1.0f | #define DIAL_WIDTH 1.0f | ||||
| #define DIAL_RESOLUTION 48 | #define DIAL_RESOLUTION 48 | ||||
| /* Could make option, negative to clip more (don't show when view aligned). */ | /* Could make option, negative to clip more (don't show when view aligned). */ | ||||
| #define DIAL_CLIP_BIAS 0.02 | #define DIAL_CLIP_BIAS 0.02 | ||||
| ▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | static void dial_ghostarc_draw_helpline( | ||||
| immVertex3fv(pos, co_outer); | immVertex3fv(pos, co_outer); | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| GPU_matrix_pop(); | GPU_matrix_pop(); | ||||
| } | } | ||||
| /** | |||||
| * Draws segments to indicate the position of each increment. | |||||
| */ | |||||
| static void dial_ghostarc_draw_incremental_angle(const float incremental_angle) | |||||
| { | |||||
| const int tot_incr = (2 * M_PI) / incremental_angle; | |||||
| GPU_line_width(1.0f); | |||||
| uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | |||||
| immUniformColor3f(1.0f, 1.0f, 1.0f); | |||||
| immBegin(GPU_PRIM_LINES, tot_incr * 2); | |||||
| float v[3] = { 0 }; | |||||
| for (int i = 0; i < tot_incr; i++) { | |||||
| v[0] = sinf(incremental_angle * i); | |||||
| v[1] = cosf(incremental_angle * i); | |||||
| mul_v2_fl(v, DIAL_WIDTH * 1.1f); | |||||
| immVertex3fv(pos, v); | |||||
| mul_v2_fl(v, 1.1f); | |||||
| immVertex3fv(pos, v); | |||||
| } | |||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| } | |||||
| static void dial_ghostarc_draw( | static void dial_ghostarc_draw( | ||||
| const float angle_ofs, const float angle_delta, | const float angle_ofs, const float angle_delta, | ||||
| const float arc_inner_factor, const float color[4]) | const float arc_inner_factor, const float color[4]) | ||||
| { | { | ||||
| const float width_inner = DIAL_WIDTH; | const float width_inner = DIAL_WIDTH; | ||||
| GPUVertFormat *format = immVertexFormat(); | GPUVertFormat *format = immVertexFormat(); | ||||
| uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | ||||
| ▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | static void dial_draw_intern( | ||||
| WM_gizmo_calc_matrix_final(gz, matrix_final); | WM_gizmo_calc_matrix_final(gz, matrix_final); | ||||
| const float arc_partial_angle = RNA_float_get(gz->ptr, "arc_partial_angle"); | const float arc_partial_angle = RNA_float_get(gz->ptr, "arc_partial_angle"); | ||||
| const float arc_inner_factor = RNA_float_get(gz->ptr, "arc_inner_factor"); | const float arc_inner_factor = RNA_float_get(gz->ptr, "arc_inner_factor"); | ||||
| int draw_options = RNA_enum_get(gz->ptr, "draw_options"); | int draw_options = RNA_enum_get(gz->ptr, "draw_options"); | ||||
| float angle_ofs = 0.0f; | float angle_ofs = 0.0f; | ||||
| float angle_delta = 0.0f; | float angle_delta = 0.0f; | ||||
| float angle_increment = 0.0f; | |||||
| if (select) { | if (select) { | ||||
| draw_options &= ~ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE; | draw_options &= ~ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE; | ||||
| } | } | ||||
| if (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE && | if (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE && | ||||
| (gz->flag & WM_GIZMO_DRAW_VALUE)) | (gz->flag & WM_GIZMO_DRAW_VALUE)) | ||||
| { | { | ||||
| DialInteraction *inter = gz->interaction_data; | DialInteraction *inter = gz->interaction_data; | ||||
| if (inter) { | if (inter) { | ||||
| angle_ofs = inter->output.angle_ofs; | angle_ofs = inter->output.angle_ofs; | ||||
| angle_delta = inter->output.angle_delta; | angle_delta = inter->output.angle_delta; | ||||
| angle_increment = inter->angle_increment; | |||||
| } | } | ||||
| else { | else { | ||||
| wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset"); | wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset"); | ||||
| if (WM_gizmo_target_property_is_valid(gz_prop)) { | if (WM_gizmo_target_property_is_valid(gz_prop)) { | ||||
| angle_delta = WM_gizmo_target_property_float_get(gz, gz_prop); | angle_delta = WM_gizmo_target_property_float_get(gz, gz_prop); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ED_gizmotypes_dial_3d_draw_util( | ED_gizmotypes_dial_3d_draw_util( | ||||
| gz->matrix_basis, matrix_final, gz->line_width, color, clip_plane, | gz->matrix_basis, matrix_final, gz->line_width, color, clip_plane, | ||||
| arc_partial_angle, arc_inner_factor, draw_options, angle_ofs, | arc_partial_angle, arc_inner_factor, draw_options, angle_ofs, | ||||
| angle_delta); | angle_delta, angle_increment); | ||||
| } | } | ||||
| static void gizmo_dial_draw_select(const bContext *C, wmGizmo *gz, int select_id) | static void gizmo_dial_draw_select(const bContext *C, wmGizmo *gz, int select_id) | ||||
| { | { | ||||
| float clip_plane_buf[4]; | float clip_plane_buf[4]; | ||||
| const int draw_options = RNA_enum_get(gz->ptr, "draw_options"); | const int draw_options = RNA_enum_get(gz->ptr, "draw_options"); | ||||
| float *clip_plane = (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_CLIP) ? clip_plane_buf : NULL; | float *clip_plane = (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_CLIP) ? clip_plane_buf : NULL; | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | static int gizmo_dial_modal( | ||||
| eWM_GizmoFlagTweak tweak_flag) | eWM_GizmoFlagTweak tweak_flag) | ||||
| { | { | ||||
| DialInteraction *inter = gz->interaction_data; | DialInteraction *inter = gz->interaction_data; | ||||
| if ((event->type != MOUSEMOVE) && (inter->prev.tweak_flag == tweak_flag)) { | if ((event->type != MOUSEMOVE) && (inter->prev.tweak_flag == tweak_flag)) { | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| } | } | ||||
| /* Coordinate at which the arc drawing will be started. */ | /* Coordinate at which the arc drawing will be started. */ | ||||
| const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f}; | const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f}; | ||||
| float angle_ofs, angle_delta; | float angle_ofs, angle_delta, angle_increment = 0.0f; | ||||
| dial_ghostarc_get_angles( | dial_ghostarc_get_angles( | ||||
| gz, event, CTX_wm_region(C), gz->matrix_basis, co_outer, &angle_ofs, &angle_delta); | gz, event, CTX_wm_region(C), gz->matrix_basis, co_outer, &angle_ofs, &angle_delta); | ||||
| if (tweak_flag & WM_GIZMO_TWEAK_SNAP) { | if (tweak_flag & WM_GIZMO_TWEAK_SNAP) { | ||||
| const double snap = DEG2RAD(5); | angle_increment = RNA_float_get(gz->ptr, "incremental_angle"); | ||||
| angle_delta = (float)roundf((double)angle_delta / snap) * snap; | angle_delta = (float)roundf((double)angle_delta / angle_increment) * angle_increment; | ||||
Done Inline ActionsThis should use the angle_increment setting for snapping. Not hard coded value. campbellbarton: This should use the angle_increment setting for snapping. Not hard coded value. | |||||
| } | } | ||||
| if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) { | if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) { | ||||
| angle_increment *= 0.2f; | |||||
| angle_delta *= 0.1f; | angle_delta *= 0.1f; | ||||
| } | } | ||||
| if (angle_delta != 0.0f) { | if (angle_delta != 0.0f) { | ||||
| inter->has_drag = true; | inter->has_drag = true; | ||||
| } | } | ||||
| inter->angle_increment = angle_increment; | |||||
| inter->output.angle_delta = angle_delta; | inter->output.angle_delta = angle_delta; | ||||
| inter->output.angle_ofs = angle_ofs; | inter->output.angle_ofs = angle_ofs; | ||||
| /* Set the property for the operator and call its modal function. */ | /* Set the property for the operator and call its modal function. */ | ||||
| wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset"); | wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset"); | ||||
| if (WM_gizmo_target_property_is_valid(gz_prop)) { | if (WM_gizmo_target_property_is_valid(gz_prop)) { | ||||
| WM_gizmo_target_property_float_set(C, gz, gz_prop, inter->init.prop_angle + angle_delta); | WM_gizmo_target_property_float_set(C, gz, gz_prop, inter->init.prop_angle + angle_delta); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | void ED_gizmotypes_dial_3d_draw_util( | ||||
| const float matrix_final[4][4], | const float matrix_final[4][4], | ||||
| const float line_width, | const float line_width, | ||||
| const float color[4], | const float color[4], | ||||
| const float clip_plane[4], | const float clip_plane[4], | ||||
| const float arc_partial_angle, | const float arc_partial_angle, | ||||
| const float arc_inner_factor, | const float arc_inner_factor, | ||||
| const int draw_options, | const int draw_options, | ||||
| const float angle_ofs, | const float angle_ofs, | ||||
| const float angle_delta) | const float angle_delta, | ||||
| const float angle_increment) | |||||
| { | { | ||||
| GPU_matrix_push(); | GPU_matrix_push(); | ||||
| GPU_matrix_mul(matrix_final); | GPU_matrix_mul(matrix_final); | ||||
| GPU_polygon_smooth(false); | GPU_polygon_smooth(false); | ||||
| if ((draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE) != 0) { | if ((draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE) != 0) { | ||||
| /* Draw rotation indicator arc first. */ | /* Draw rotation indicator arc first. */ | ||||
| dial_ghostarc_draw_with_helplines( | dial_ghostarc_draw_with_helplines( | ||||
| angle_ofs, angle_delta, | angle_ofs, angle_delta, | ||||
| arc_inner_factor, color, draw_options); | arc_inner_factor, color, draw_options); | ||||
| if ((draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_MIRROR) != 0) { | if ((draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_MIRROR) != 0) { | ||||
| dial_ghostarc_draw_with_helplines( | dial_ghostarc_draw_with_helplines( | ||||
| angle_ofs + M_PI, angle_delta, | angle_ofs + M_PI, angle_delta, | ||||
| arc_inner_factor, color, draw_options); | arc_inner_factor, color, draw_options); | ||||
| } | } | ||||
| } | } | ||||
| if (angle_increment) { | |||||
| dial_ghostarc_draw_incremental_angle(angle_increment); | |||||
| } | |||||
| /* Draw actual dial gizmo. */ | /* Draw actual dial gizmo. */ | ||||
| dial_geom_draw( | dial_geom_draw( | ||||
| color, line_width, false, matrix_basis, clip_plane, | color, line_width, false, matrix_basis, clip_plane, | ||||
| arc_partial_angle, arc_inner_factor, draw_options); | arc_partial_angle, arc_inner_factor, draw_options); | ||||
| GPU_matrix_pop(); | GPU_matrix_pop(); | ||||
| } | } | ||||
| Show All 20 Lines | static EnumPropertyItem rna_enum_draw_options[] = { | ||||
| {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_START_Y, "ANGLE_START_Y", 0, "Angle Start Y", ""}, | {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_START_Y, "ANGLE_START_Y", 0, "Angle Start Y", ""}, | ||||
| {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE, "ANGLE_VALUE", 0, "Show Angle Value", ""}, | {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE, "ANGLE_VALUE", 0, "Show Angle Value", ""}, | ||||
| {0, NULL, 0, NULL, NULL} | {0, NULL, 0, NULL, NULL} | ||||
| }; | }; | ||||
| RNA_def_enum_flag(gzt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", ""); | RNA_def_enum_flag(gzt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", ""); | ||||
| RNA_def_boolean(gzt->srna, "wrap_angle", true, "Wrap Angle", ""); | RNA_def_boolean(gzt->srna, "wrap_angle", true, "Wrap Angle", ""); | ||||
| RNA_def_float_factor(gzt->srna, "arc_inner_factor", 0.0f, 0.0f, 1.0f, "Arc Inner Factor", "", 0.0f, 1.0f); | RNA_def_float_factor(gzt->srna, "arc_inner_factor", 0.0f, 0.0f, 1.0f, "Arc Inner Factor", "", 0.0f, 1.0f); | ||||
| RNA_def_float_factor(gzt->srna, "arc_partial_angle", 0.0f, 0.0f, M_PI * 2, "Show Partial Dial", "", 0.0f, M_PI * 2); | RNA_def_float_factor(gzt->srna, "arc_partial_angle", 0.0f, 0.0f, M_PI * 2, "Show Partial Dial", "", 0.0f, M_PI * 2); | ||||
| RNA_def_float_factor(gzt->srna, "incremental_angle", DEG2RAD(5), 0.0f, M_PI * 2, "Angle to snap in steps", "", 0.0f, M_PI * 2); | |||||
| RNA_def_float( | RNA_def_float( | ||||
| gzt->srna, "click_value", 0.0f, -FLT_MAX, FLT_MAX, | gzt->srna, "click_value", 0.0f, -FLT_MAX, FLT_MAX, | ||||
| "Click Value", "Value to use for a single click action", | "Click Value", "Value to use for a single click action", | ||||
| -FLT_MAX, FLT_MAX); | -FLT_MAX, FLT_MAX); | ||||
| WM_gizmotype_target_property_def(gzt, "offset", PROP_FLOAT, 1); | WM_gizmotype_target_property_def(gzt, "offset", PROP_FLOAT, 1); | ||||
| } | } | ||||
| void ED_gizmotypes_dial_3d(void) | void ED_gizmotypes_dial_3d(void) | ||||
| { | { | ||||
| WM_gizmotype_append(GIZMO_GT_dial_3d); | WM_gizmotype_append(GIZMO_GT_dial_3d); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
This isn't output as far as I can see, its a snap setting. Would move under has_drag