Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
| Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | typedef struct DialInteraction { | ||||
| /* Number of full rotations. */ | /* Number of full rotations. */ | ||||
| int rotations; | int rotations; | ||||
| bool has_drag; | bool has_drag; | ||||
| /* 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 189 Lines • ▼ Show 20 Lines | static void dial_ghostarc_draw_with_helplines( | ||||
| GPU_line_width(1.0f); | GPU_line_width(1.0f); | ||||
| dial_ghostarc_draw_helpline(angle_ofs, co_outer, color_helpline); | dial_ghostarc_draw_helpline(angle_ofs, co_outer, color_helpline); | ||||
| if (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE) { | if (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE) { | ||||
| GPU_line_width(3.0f); | GPU_line_width(3.0f); | ||||
| } | } | ||||
| dial_ghostarc_draw_helpline(angle_ofs + angle_delta, co_outer, color_helpline); | dial_ghostarc_draw_helpline(angle_ofs + angle_delta, co_outer, color_helpline); | ||||
| } | } | ||||
| static void dial_ghostarc_draw_with_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_draw_intern( | static void dial_draw_intern( | ||||
| const bContext *C, wmGizmo *gz, | const bContext *C, wmGizmo *gz, | ||||
| const bool select, const bool highlight, float clip_plane[4]) | const bool select, const bool highlight, float clip_plane[4]) | ||||
| { | { | ||||
| float matrix_final[4][4]; | float matrix_final[4][4]; | ||||
| float color[4]; | float color[4]; | ||||
| BLI_assert(CTX_wm_area(C)->spacetype == SPACE_VIEW3D); | BLI_assert(CTX_wm_area(C)->spacetype == SPACE_VIEW3D); | ||||
| gizmo_color_get(gz, highlight, color); | gizmo_color_get(gz, highlight, color); | ||||
| WM_gizmo_calc_matrix_final(gz, matrix_final); | WM_gizmo_calc_matrix_final(gz, matrix_final); | ||||
| GPU_matrix_push(); | GPU_matrix_push(); | ||||
| GPU_matrix_mul(matrix_final); | GPU_matrix_mul(matrix_final); | ||||
| /* FIXME(campbell): look into removing this. */ | |||||
| if ((gz->flag & WM_GIZMO_DRAW_VALUE) && | |||||
| (gz->state & WM_GIZMO_STATE_MODAL)) | |||||
| { | |||||
| /* XXX, View3D rotation gizmo doesn't call modal. */ | |||||
| if (!WM_gizmo_target_property_is_valid_any(gz)) { | |||||
| wmWindow *win = CTX_wm_window(C); | |||||
| gizmo_dial_modal((bContext *)C, gz, win->eventstate, 0); | |||||
| } | |||||
| } | |||||
| GPU_polygon_smooth(false); | GPU_polygon_smooth(false); | ||||
| 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"); | ||||
| if (select == false) { | if (select == false) { | ||||
| float angle_ofs = 0.0f; | float angle_ofs = 0.0f; | ||||
| float angle_delta = 0.0f; | float angle_delta = 0.0f; | ||||
| Show All 14 Lines | else if ((gz->flag & WM_GIZMO_DRAW_VALUE) && | ||||
| (gz->state & WM_GIZMO_STATE_MODAL)) | (gz->state & WM_GIZMO_STATE_MODAL)) | ||||
| { | { | ||||
| DialInteraction *inter = gz->interaction_data; | DialInteraction *inter = gz->interaction_data; | ||||
| angle_ofs = inter->output.angle_ofs; | angle_ofs = inter->output.angle_ofs; | ||||
| angle_delta = inter->output.angle_delta; | angle_delta = inter->output.angle_delta; | ||||
| show_ghostarc = true; | show_ghostarc = true; | ||||
| } | } | ||||
| if (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_INVERT) { | |||||
| angle_delta *= -1; | |||||
| } | |||||
| if (show_ghostarc) { | if (show_ghostarc) { | ||||
| dial_ghostarc_draw_with_helplines(angle_ofs, angle_delta, arc_inner_factor, color, draw_options); | dial_ghostarc_draw_with_helplines(angle_ofs, angle_delta, 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) { | ||||
| angle_ofs += M_PI; | angle_ofs += M_PI; | ||||
| dial_ghostarc_draw_with_helplines(angle_ofs, angle_delta, arc_inner_factor, color, draw_options); | dial_ghostarc_draw_with_helplines(angle_ofs, angle_delta, arc_inner_factor, color, draw_options); | ||||
| } | } | ||||
| const float incremental_angle = RNA_float_get(gz->ptr, "incremental_angle"); | |||||
| if (incremental_angle != 0.0f) { | |||||
| dial_ghostarc_draw_with_incremental_angle(incremental_angle); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| /* Draw actual dial gizmo. */ | /* Draw actual dial gizmo. */ | ||||
| dial_geom_draw(gz, color, select, gz->matrix_basis, clip_plane, arc_partial_angle, arc_inner_factor); | dial_geom_draw(gz, color, select, gz->matrix_basis, clip_plane, arc_partial_angle, arc_inner_factor); | ||||
| GPU_matrix_pop(); | GPU_matrix_pop(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | static int gizmo_dial_modal( | ||||
| 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; | ||||
| 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); | const double snap = DEG2RAD(5); | ||||
| angle_delta = (float)roundf((double)angle_delta / snap) * snap; | angle_delta = (float)roundf((double)angle_delta / snap) * snap; | ||||
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_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; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | static void GIZMO_GT_dial_3d(wmGizmoType *gzt) | ||||
| /* rna */ | /* rna */ | ||||
| static EnumPropertyItem rna_enum_draw_options[] = { | static EnumPropertyItem rna_enum_draw_options[] = { | ||||
| {ED_GIZMO_DIAL_DRAW_FLAG_CLIP, "CLIP", 0, "Clipped", ""}, | {ED_GIZMO_DIAL_DRAW_FLAG_CLIP, "CLIP", 0, "Clipped", ""}, | ||||
| {ED_GIZMO_DIAL_DRAW_FLAG_FILL, "FILL", 0, "Filled", ""}, | {ED_GIZMO_DIAL_DRAW_FLAG_FILL, "FILL", 0, "Filled", ""}, | ||||
| {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_MIRROR, "ANGLE_MIRROR", 0, "Angle Mirror", ""}, | {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_MIRROR, "ANGLE_MIRROR", 0, "Angle Mirror", ""}, | ||||
| {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", ""}, | ||||
| {ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_INVERT, "ANGLE_INVERT", 0, "Invert Angle Direction", ""}, | |||||
| {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", 0.0f, 0.0f, M_PI * 2, "Show position of incremental angles", "", 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