Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / gizmo_library / gizmo_types / dial3d_gizmo.c
index 8af936dd74e7961b3d624f7ce73d4a47889591f6..a6252cd55bdd07ac1743fe5be2949efd37934ddb 100644 (file)
@@ -106,7 +106,7 @@ typedef struct DialInteraction {
 
 static void dial_geom_draw(
         const wmGizmo *gz, const float color[4], const bool select,
-        float axis_modal_mat[4][4], float clip_plane[4])
+        float axis_modal_mat[4][4], float clip_plane[4], const float arc_inner_factor)
 {
 #ifdef USE_GIZMO_CUSTOM_DIAL
        UNUSED_VARS(gz, axis_modal_mat, clip_plane);
@@ -137,6 +137,9 @@ static void dial_geom_draw(
        }
        else {
                imm_draw_circle_wire_2d(pos, 0, 0, 1.0, DIAL_RESOLUTION);
+               if (arc_inner_factor != 0.0f) {
+                       imm_draw_circle_wire_2d(pos, 0, 0, arc_inner_factor, DIAL_RESOLUTION);
+               }
        }
 
        immUnbindProgram();
@@ -148,10 +151,9 @@ static void dial_geom_draw(
 /**
  * Draws a line from (0, 0, 0) to \a co_outer, at \a angle.
  */
-static void dial_ghostarc_draw_helpline(const float angle, const float co_outer[3], const float color[4])
+static void dial_ghostarc_draw_helpline(
+        const float angle, const float co_outer[3], const float color[4])
 {
-       GPU_line_width(1.0f);
-
        GPU_matrix_push();
        GPU_matrix_rotate_3f(RAD2DEGF(angle), 0.0f, 0.0f, -1.0f);
 
@@ -162,7 +164,7 @@ static void dial_ghostarc_draw_helpline(const float angle, const float co_outer[
        immUniformColor4fv(color);
 
        immBegin(GPU_PRIM_LINE_STRIP, 2);
-       immVertex3f(pos, 0.0f, 0.0f, 0.0f);
+       immVertex3f(pos, 0.0f, 0, 0.0f);
        immVertex3fv(pos, co_outer);
        immEnd();
 
@@ -172,24 +174,32 @@ static void dial_ghostarc_draw_helpline(const float angle, const float co_outer[
 }
 
 static void dial_ghostarc_draw(
-        const wmGizmo *gz, const float angle_ofs, const float angle_delta, const float color[4])
+        const float angle_ofs, const float angle_delta,
+        const float arc_inner_factor, const float color[4])
 {
-       const float width_inner = DIAL_WIDTH - gz->line_width * 0.5f / U.gizmo_size;
-
+       const float width_inner = DIAL_WIDTH;
        GPUVertFormat *format = immVertexFormat();
        uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
        immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+       if (arc_inner_factor != 0.0) {
+               float color_dark[4] = {0};
+               color_dark[3] = color[3] / 2;
+               immUniformColor4fv(color_dark);
+               imm_draw_disk_partial_fill_2d(
+                       pos, 0, 0, arc_inner_factor, width_inner, DIAL_RESOLUTION, RAD2DEGF(angle_ofs), RAD2DEGF(M_PI * 2));
+       }
+
        immUniformColor4fv(color);
        imm_draw_disk_partial_fill_2d(
-               pos, 0, 0, 0.0, width_inner, DIAL_RESOLUTION, RAD2DEGF(angle_ofs), RAD2DEGF(angle_delta));
+               pos, 0, 0, arc_inner_factor, width_inner, DIAL_RESOLUTION, RAD2DEGF(angle_ofs), RAD2DEGF(angle_delta));
        immUnbindProgram();
 }
 
 static void dial_ghostarc_get_angles(
-        struct Depsgraph *depsgraph,
         const wmGizmo *gz,
         const wmEvent *event,
-        const ARegion *ar, const View3D *v3d,
+        const ARegion *ar,
         float mat[4][4], const float co_outer[3],
         float *r_start, float *r_delta)
 {
@@ -209,25 +219,17 @@ static void dial_ghostarc_get_angles(
        float proj_mval_new_rel[3];
        float proj_mval_init_rel[3];
        float dial_plane[4];
-       float ray_co[3], ray_no[3];
-       float ray_lambda;
 
        plane_from_point_normal_v3(dial_plane, gz->matrix_basis[3], axis_vec);
 
-       if (!ED_view3d_win_to_ray(depsgraph, ar, v3d, inter->init.mval, ray_co, ray_no, false) ||
-           !isect_ray_plane_v3(ray_co, ray_no, dial_plane, &ray_lambda, false))
-       {
+       if (!ED_view3d_win_to_3d_on_plane(ar, dial_plane, inter->init.mval, false, proj_mval_init_rel)) {
                goto fail;
        }
-       madd_v3_v3v3fl(proj_mval_init_rel, ray_co, ray_no, ray_lambda);
        sub_v3_v3(proj_mval_init_rel, gz->matrix_basis[3]);
 
-       if (!ED_view3d_win_to_ray(depsgraph, ar, v3d, mval, ray_co, ray_no, false) ||
-           !isect_ray_plane_v3(ray_co, ray_no, dial_plane, &ray_lambda, false))
-       {
+       if (!ED_view3d_win_to_3d_on_plane(ar, dial_plane, mval, false, proj_mval_new_rel)) {
                goto fail;
        }
-       madd_v3_v3v3fl(proj_mval_new_rel, ray_co, ray_no, ray_lambda);
        sub_v3_v3(proj_mval_new_rel, gz->matrix_basis[3]);
 
        const int draw_options = RNA_enum_get(gz->ptr, "draw_options");
@@ -268,15 +270,19 @@ fail:
        *r_delta = 0.0;
 }
 
-static void dial_ghostarc_draw_with_helplines(wmGizmo *gz, float angle_ofs, float angle_delta, float color_helpline[4])
+static void dial_ghostarc_draw_with_helplines(
+        const float angle_ofs, const float angle_delta,
+        const float arc_inner_factor, const float color_helpline[4], const int draw_options)
 {
        /* Coordinate at which the arc drawing will be started. */
        const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f};
-       dial_ghostarc_draw(gz, angle_ofs, angle_delta, (const float[4]){0.8f, 0.8f, 0.8f, 0.4f});
-       GPU_polygon_smooth(true);
+       dial_ghostarc_draw(angle_ofs, angle_delta, arc_inner_factor, (const float[4]){0.8f, 0.8f, 0.8f, 0.4f});
+       GPU_line_width(1.0f);
        dial_ghostarc_draw_helpline(angle_ofs, co_outer, color_helpline);
+       if (draw_options & ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE) {
+               GPU_line_width(3.0f);
+       }
        dial_ghostarc_draw_helpline(angle_ofs + angle_delta, co_outer, color_helpline);
-       GPU_polygon_smooth(false);
 }
 
 static void dial_draw_intern(
@@ -306,7 +312,10 @@ static void dial_draw_intern(
                }
        }
 
-       {
+       GPU_polygon_smooth(false);
+
+       const float arc_inner_factor = RNA_float_get(gz->ptr, "arc_inner_factor");
+       if (select == false) {
                float angle_ofs = 0.0f;
                float angle_delta = 0.0f;
                bool show_ghostarc = false;
@@ -332,16 +341,16 @@ static void dial_draw_intern(
                }
 
                if (show_ghostarc) {
-                       dial_ghostarc_draw_with_helplines(gz, angle_ofs, angle_delta, color);
+                       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) {
                                angle_ofs += M_PI;
-                               dial_ghostarc_draw_with_helplines(gz, angle_ofs, angle_delta, color);
+                               dial_ghostarc_draw_with_helplines(angle_ofs, angle_delta, arc_inner_factor, color, draw_options);
                        }
                }
        }
 
        /* Draw actual dial gizmo. */
-       dial_geom_draw(gz, color, select, gz->matrix_basis, clip_plane);
+       dial_geom_draw(gz, color, select, gz->matrix_basis, clip_plane, arc_inner_factor);
 
        GPU_matrix_pop();
 }
@@ -411,8 +420,7 @@ static int gizmo_dial_modal(
        float angle_ofs, angle_delta;
 
        dial_ghostarc_get_angles(
-               CTX_data_depsgraph(C),
-               gz, event, CTX_wm_region(C), CTX_wm_view3d(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) {
                const double snap = DEG2RAD(5);
@@ -492,6 +500,7 @@ static void GIZMO_GT_dial_3d(wmGizmoType *gzt)
        };
        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_float_factor(gzt->srna, "arc_inner_factor", 0.0f, 0.0f, 1.0f, "Arc Inner Factor", "", 0.0f, 1.0f);
 
        WM_gizmotype_target_property_def(gzt, "offset", PROP_FLOAT, 1);
 }