[Bf-blender-cvs] [ce170bdd4c3] active-fcurve-keyframe: Always draw active FCurve (and active keyframe) last (on top)

Hans Goudey noreply at git.blender.org
Thu Jul 16 20:16:24 CEST 2020


Commit: ce170bdd4c39f5dac0070a84a075448fc2a0b739
Author: Hans Goudey
Date:   Wed Jun 24 20:20:42 2020 -0400
Branches: active-fcurve-keyframe
https://developer.blender.org/rBce170bdd4c39f5dac0070a84a075448fc2a0b739

Always draw active FCurve (and active keyframe) last (on top)

===================================================================

M	source/blender/editors/space_graph/graph_draw.c

===================================================================

diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c
index 7b037fe439c..b13199f964f 100644
--- a/source/blender/editors/space_graph/graph_draw.c
+++ b/source/blender/editors/space_graph/graph_draw.c
@@ -51,6 +51,9 @@
 #include "UI_resources.h"
 #include "UI_view2d.h"
 
+/* Prototype for #draw_fcurve. */
+static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu);
+
 /* *************************** */
 /* Utility Drawing Defines */
 
@@ -911,6 +914,164 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2
   GPU_matrix_pop();
 }
 
+static void draw_fcurve(bAnimContext *ac, SpaceGraph *sipo, ARegion *region, bAnimListElem *ale)
+{
+  FCurve *fcu = (FCurve *)ale->key_data;
+  FModifier *fcm = find_active_fmodifier(&fcu->modifiers);
+  AnimData *adt = ANIM_nla_mapping_get(ac, ale);
+
+  /* map keyframes for drawing if scaled F-Curve */
+  if (adt) {
+    ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0);
+  }
+
+  /* draw curve:
+   * - curve line may be result of one or more destructive modifiers or just the raw data,
+   *   so we need to check which method should be used
+   * - controls from active modifier take precedence over keyframes
+   *   (XXX! editing tools need to take this into account!)
+   */
+
+  /* 1) draw curve line */
+  if (((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) ||
+      (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert))) {
+    /* set color/drawing style for curve itself */
+    /* draw active F-Curve thicker than the rest to make it stand out */
+    if (fcu->flag & FCURVE_ACTIVE) {
+      GPU_line_width(2.5);
+    }
+    else {
+      GPU_line_width(1.0);
+    }
+
+    /* anti-aliased lines for less jagged appearance */
+    if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) {
+      GPU_line_smooth(true);
+    }
+    GPU_blend(true);
+
+    const uint shdr_pos = GPU_vertformat_attr_add(
+        immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+
+    immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+    float viewport_size[4];
+    GPU_viewport_size_get_f(viewport_size);
+    immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+    immUniform1i("colors_len", 0); /* Simple dashes. */
+
+    if (BKE_fcurve_is_protected(fcu)) {
+      /* protected curves (non editable) are drawn with dotted lines */
+      immUniform1f("dash_width", 4.0f);
+      immUniform1f("dash_factor", 0.5f);
+    }
+    else {
+      immUniform1f("dash_factor", 2.0f); /* solid line */
+    }
+
+    if (((fcu->grp) && (fcu->grp->flag & AGRP_MUTED)) || (fcu->flag & FCURVE_MUTED)) {
+      /* muted curves are drawn in a grayish hue */
+      /* XXX should we have some variations? */
+      immUniformThemeColorShade(TH_HEADER, 50);
+    }
+    else {
+      /* set whatever color the curve has set
+       * - unselected curves draw less opaque to help distinguish the selected ones
+       */
+      immUniformColor3fvAlpha(fcu->color, fcurve_display_alpha(fcu));
+    }
+
+    /* draw F-Curve */
+    if ((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) {
+      /* draw a curve affected by modifiers or only allowed to have integer values
+       * by sampling it at various small-intervals over the visible region
+       */
+      draw_fcurve_curve(ac, ale->id, fcu, &region->v2d, shdr_pos);
+    }
+    else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) {
+      /* just draw curve based on defined data (i.e. no modifiers) */
+      if (fcu->bezt) {
+        if (fcurve_can_use_simple_bezt_drawing(fcu)) {
+          draw_fcurve_curve_bezts(ac, ale->id, fcu, &region->v2d, shdr_pos);
+        }
+        else {
+          draw_fcurve_curve(ac, ale->id, fcu, &region->v2d, shdr_pos);
+        }
+      }
+      else if (fcu->fpt) {
+        draw_fcurve_curve_samples(ac, ale->id, fcu, &region->v2d, shdr_pos);
+      }
+    }
+
+    immUnbindProgram();
+
+    if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) {
+      GPU_line_smooth(false);
+    }
+    GPU_blend(false);
+  }
+
+  /* 2) draw handles and vertices as appropriate based on active
+   * - If the option to only show controls if the F-Curve is selected is enabled,
+   *   we must obey this.
+   */
+  if (!(sipo->flag & SIPO_SELCUVERTSONLY) || (fcu->flag & FCURVE_SELECTED)) {
+    if (!BKE_fcurve_are_keyframes_usable(fcu) && !(fcu->fpt && fcu->totvert)) {
+      /* only draw controls if this is the active modifier */
+      if ((fcu->flag & FCURVE_ACTIVE) && (fcm)) {
+        switch (fcm->type) {
+          case FMODIFIER_TYPE_ENVELOPE: /* envelope */
+            draw_fcurve_modifier_controls_envelope(fcm, &region->v2d);
+            break;
+        }
+      }
+    }
+    else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) {
+      short mapping_flag = ANIM_get_normalization_flags(ac);
+      float offset;
+      float unit_scale = ANIM_unit_mapping_get_factor(
+          ac->scene, ale->id, fcu, mapping_flag, &offset);
+
+      /* apply unit-scaling to all values via OpenGL */
+      GPU_matrix_push();
+      GPU_matrix_scale_2f(1.0f, unit_scale);
+      GPU_matrix_translate_2f(0.0f, offset);
+
+      /* Set this once and for all -
+       * all handles and handle-verts should use the same thickness. */
+      GPU_line_width(1.0);
+
+      if (fcu->bezt) {
+        bool do_handles = draw_fcurve_handles_check(sipo, fcu);
+
+        if (do_handles) {
+          /* only draw handles/vertices on keyframes */
+          draw_fcurve_handles(sipo, fcu);
+        }
+
+        draw_fcurve_vertices(region, fcu, do_handles, (sipo->flag & SIPO_SELVHANDLESONLY));
+      }
+      else {
+        /* samples: only draw two indicators at either end as indicators */
+        draw_fcurve_samples(sipo, region, fcu);
+      }
+
+      GPU_matrix_pop();
+    }
+  }
+
+  /* 3) draw driver debugging stuff */
+  if ((ac->datatype == ANIMCONT_DRIVERS) && (fcu->flag & FCURVE_ACTIVE)) {
+    graph_draw_driver_debug(ac, ale->id, fcu);
+  }
+
+  /* undo mapping of keyframes for drawing if scaled F-Curve */
+  if (adt) {
+    ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0);
+  }
+}
+
 /* Debugging -------------------------------- */
 
 /* Draw indicators which show the value calculated from the driver,
@@ -1098,161 +1259,20 @@ void graph_draw_curves(bAnimContext *ac, SpaceGraph *sipo, ARegion *region, shor
    * draw curve, then handle-lines, and finally vertices in this order so that
    * the data will be layered correctly
    */
+  bAnimListElem *ale_active_fcurve = NULL;
   for (ale = anim_data.first; ale; ale = ale->next) {
     FCurve *fcu = (FCurve *)ale->key_data;
-    FModifier *fcm = find_active_fmodifier(&fcu->modifiers);
-    AnimData *adt = ANIM_nla_mapping_get(ac, ale);
-
-    /* map keyframes for drawing if scaled F-Curve */
-    if (adt) {
-      ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0);
-    }
-
-    /* draw curve:
-     * - curve line may be result of one or more destructive modifiers or just the raw data,
-     *   so we need to check which method should be used
-     * - controls from active modifier take precedence over keyframes
-     *   (XXX! editing tools need to take this into account!)
-     */
-
-    /* 1) draw curve line */
-    if (((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) ||
-        (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert))) {
-      /* set color/drawing style for curve itself */
-      /* draw active F-Curve thicker than the rest to make it stand out */
-      if (fcu->flag & FCURVE_ACTIVE) {
-        GPU_line_width(2.5);
-      }
-      else {
-        GPU_line_width(1.0);
-      }
-
-      /* anti-aliased lines for less jagged appearance */
-      if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) {
-        GPU_line_smooth(true);
-      }
-      GPU_blend(true);
-
-      const uint shdr_pos = GPU_vertformat_attr_add(
-          immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
-
-      immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
-
-      float viewport_size[4];
-      GPU_viewport_size_get_f(viewport_size);
-      immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
-
-      immUniform1i("colors_len", 0); /* Simple dashes. */
-
-      if (BKE_fcurve_is_protected(fcu)) {
-        /* protected curves (non editable) are drawn with dotted lines */
-        immUniform1f("dash_width", 4.0f);
-        immUniform1f("dash_factor", 0.5f);
-      }
-      else {
-        immUniform1f("dash_factor", 2.0f); /* solid line */
-      }
-
-      if (((fcu->grp) && (fcu->grp->flag & AGRP_MUTED)) || (fcu->flag & FCURVE_MUTED)) {
-        /* muted curves are drawn in a grayish hue */
-        /* XXX should we have some variations? */
-        immUniformThemeColorShade(TH_HEADER, 50);
-      }
-      else {
-        /* set whatever color the curve has set
-         * - unselected curves draw less opaque to help distinguish the selected ones
-         */
-        immUniformColor3fvAlpha(fcu->color, fcurve_display_alpha(fcu));
-      }
-
-      /* draw F-Curve */
-      if ((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) {
-        /* draw a curve affected by modifiers or only allowed to have integer values
-         * by sampling it at various small-intervals over the visible region
-         */
-        draw_fcurve_curve(ac, ale->id, fcu, &region->v2d, shdr_pos);
-      }
-      else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) {
-        /* just draw curve based on defined data (i.e. no modifiers) */
-        if (fcu->bezt) {
-          if (fcurve_can_use_simple_bezt_drawing(fcu)) {
-            draw_fcurve_curve_bezts(ac, ale->id, fcu, &region->v2d, shdr_pos);
-          }
-          else {
-            draw_fcurve_curve(ac, ale->id, fcu, &region->v2d, shdr_pos);
-          }
-        }
-        else if (fcu->fpt) {
-          draw_fcurve_curve_samples(ac, ale->id, fcu, &region->v2d, shdr_pos);
-        }
-      }
-
-      immUnbindProgram();
-
-      if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) {
-        GPU_line_smooth(false);
-      }
-      GPU_blend(false);
-    }
-
-    /* 2) draw handles a

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list