[Bf-blender-cvs] [320bc5360cf] fcurve-modifier-panels: Use panel custom data

Hans Goudey noreply at git.blender.org
Mon Oct 19 04:45:03 CEST 2020


Commit: 320bc5360cf5ba46c26b70657283915fb7a9d4eb
Author: Hans Goudey
Date:   Thu Aug 13 16:39:11 2020 -0400
Branches: fcurve-modifier-panels
https://developer.blender.org/rB320bc5360cf5ba46c26b70657283915fb7a9d4eb

Use panel custom data

Very unstable, and the delete button doesn't work. It's probably
best to just expose graph_panel_context and the equivalent NLA function.

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

M	source/blender/editors/animation/fmodifier_ui.c
M	source/blender/editors/include/ED_anim_api.h
M	source/blender/editors/space_graph/graph_buttons.c
M	source/blender/editors/space_nla/nla_buttons.c

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

diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c
index 93ecfe8223a..3b4aaefbcaa 100644
--- a/source/blender/editors/animation/fmodifier_ui.c
+++ b/source/blender/editors/animation/fmodifier_ui.c
@@ -69,167 +69,92 @@ static void fmodifier_panel_header(const bContext *C, Panel *panel);
 /** \name Panel Registering and Panel Callbacks
  * \{ */
 
-static bAnimListElem *get_active_fcurve_channel(bAnimContext *ac)
+static PointerRNA *fmodifier_get_pointers(const Panel *panel, ID **r_owner_id)
 {
-  ListBase anim_data = {NULL, NULL};
-  int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_ACTIVE);
-  size_t items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+  /* TODO(Hans): Use #UI_panel_custom_data_get. */
+  PointerRNA *ptr = panel->runtime.custom_data_ptr;
 
-  /* We take the first F-Curve only, since some other ones may have had 'active' flag set
-   * if they were from linked data.
-   */
-  if (items) {
-    bAnimListElem *ale = (bAnimListElem *)anim_data.first;
-
-    /* remove first item from list, then free the rest of the list and return the stored one */
-    BLI_remlink(&anim_data, ale);
-    ANIM_animdata_freelist(&anim_data);
-
-    return ale;
-  }
-
-  /* no active F-Curve */
-  return NULL;
-}
-
-static int graph_panel_context(const bContext *C, bAnimListElem **ale, FCurve **fcu)
-{
-  bAnimContext ac;
-  bAnimListElem *elem = NULL;
-
-  /* For now, only draw if we could init the anim-context info
-   * (necessary for all animation-related tools)
-   * to work correctly is able to be correctly retrieved.
-   * There's no point showing empty panels?
-   */
-  if (ANIM_animdata_get_context(C, &ac) == 0) {
-    return 0;
-  }
-
-  /* try to find 'active' F-Curve */
-  elem = get_active_fcurve_channel(&ac);
-  if (elem == NULL) {
-    return 0;
+  if (r_owner_id != NULL) {
+    *r_owner_id = ptr->owner_id;
   }
 
-  if (fcu) {
-    *fcu = (FCurve *)elem->data;
-  }
-  if (ale) {
-    *ale = elem;
-  }
-  else {
-    MEM_freeN(elem);
-  }
-
-  return 1;
-}
-
-static void fmodifier_get_pointers(const bContext *C,
-                                   Panel *panel,
-                                   FModifier **r_fcm,
-                                   ID **r_owner_id)
-{
-  bAnimListElem *ale;
-  FCurve *fcu;
-  if (!graph_panel_context(C, &ale, &fcu)) {
-    return;
-  }
-  ListBase *modifiers = &fcu->modifiers;
-
-  *r_fcm = BLI_findlink(modifiers, panel->runtime.list_index);
-  *r_owner_id = ale->fcurve_owner_id;
-
-  MEM_freeN(ale);
-
-  uiLayoutSetActive(panel->layout, !(fcu->flag & FCURVE_MOD_OFF));
-}
+  // FModifier *fcm = (FModifier *)ptr->data;
+  // uiLayoutSetActive(panel->layout, !(fcu->flag & FCURVE_MOD_OFF));
 
-static bool graph_panel_poll(const bContext *C, PanelType *UNUSED(pt))
-{
-  return graph_panel_context(C, NULL, NULL);
+  return ptr;
 }
 
 /**
  * Move an FModifier to the index it's moved to after a drag and drop.
  */
-static void fmodifier_reorder(bContext *C, Panel *panel, int new_index)
+// static void fmodifier_reorder(bContext *C, Panel *panel, int new_index)
+// {
+//   bAnimListElem *ale;
+//   FCurve *fcu;
+//   // if (!graph_panel_context(C, &ale, &fcu)) {
+//   //   return;
+//   // }
+
+//   int current_index = panel->runtime.list_index;
+//   if (current_index == new_index) {
+//     return;
+//   }
+
+//   ListBase *modifiers = &fcu->modifiers;
+//   FModifier *fcm = BLI_findlink(modifiers, current_index);
+//   if (fcm == NULL) {
+//     return;
+//   }
+
+//   /* Cycles modifier has to be the first, so make sure it's kept that way. */
+//   if (fcm->type == FMODIFIER_TYPE_CYCLES) {
+//     return;
+//   }
+//   FModifier *fcm_first = modifiers->first;
+//   if (fcm_first->type == FMODIFIER_TYPE_CYCLES && new_index == 0) {
+//     return;
+//   }
+
+//   BLI_assert(current_index >= 0);
+//   BLI_assert(new_index >= 0);
+
+//   /* Move the FModifier in the list. */
+//   BLI_listbase_link_move(modifiers, fcm, new_index - current_index);
+
+//   ED_undo_push(C, "Move F-Curve Modifier");
+
+//   ID *fcurve_owner_id = ale->fcurve_owner_id;
+//   WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
+//   DEG_id_tag_update(fcurve_owner_id, ID_RECALC_ANIMATION);
+// }
+
+static short get_fmodifier_expand_flag(const bContext *UNUSED(C), Panel *panel)
 {
-  bAnimListElem *ale;
-  FCurve *fcu;
-  if (!graph_panel_context(C, &ale, &fcu)) {
-    return;
-  }
-
-  int current_index = panel->runtime.list_index;
-  if (current_index == new_index) {
-    return;
-  }
-
-  ListBase *modifiers = &fcu->modifiers;
-  FModifier *fcm = BLI_findlink(modifiers, current_index);
-  if (fcm == NULL) {
-    return;
-  }
-
-  /* Cycles modifier has to be the first, so make sure it's kept that way. */
-  if (fcm->type == FMODIFIER_TYPE_CYCLES) {
-    return;
-  }
-  FModifier *fcm_first = modifiers->first;
-  if (fcm_first->type == FMODIFIER_TYPE_CYCLES && new_index == 0) {
-    return;
-  }
-
-  BLI_assert(current_index >= 0);
-  BLI_assert(new_index >= 0);
-
-  /* Move the FModifier in the list. */
-  BLI_listbase_link_move(modifiers, fcm, new_index - current_index);
+  PointerRNA *ptr = fmodifier_get_pointers(panel, NULL);
+  FModifier *fcm = (FModifier *)ptr->data;
 
-  ED_undo_push(C, "Move F-Curve Modifier");
-
-  ID *fcurve_owner_id = ale->fcurve_owner_id;
-  WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
-  DEG_id_tag_update(fcurve_owner_id, ID_RECALC_ANIMATION);
-}
-
-#define FMODIFIER_TYPE_PANEL_PREFIX "ANIM_PT_"
-void ANIM_fmodifier_type_panel_id(int type, char *r_idname)
-{
-  const FModifierTypeInfo *fmi = get_fmodifier_typeinfo(type);
-
-  strcpy(r_idname, FMODIFIER_TYPE_PANEL_PREFIX);
-  strcat(r_idname, fmi->name);
-}
-
-static short get_fmodifier_expand_flag(const bContext *C, Panel *panel)
-{
-  FCurve *fcu;
-  if (!graph_panel_context(C, NULL, &fcu)) {
-    return 1;
-  }
-  FModifier *fcm = BLI_findlink(&fcu->modifiers, panel->runtime.list_index);
   return fcm->ui_expand_flag;
 }
 
-static void set_fmodifier_expand_flag(const bContext *C, Panel *panel, short expand_flag)
+static void set_fmodifier_expand_flag(const bContext *UNUSED(C), Panel *panel, short expand_flag)
 {
-  FCurve *fcu;
-  if (!graph_panel_context(C, NULL, &fcu)) {
-    return;
-  }
-  FModifier *fcm = BLI_findlink(&fcu->modifiers, panel->runtime.list_index);
+  PointerRNA *ptr = fmodifier_get_pointers(panel, NULL);
+  FModifier *fcm = (FModifier *)ptr->data;
+
   fcm->ui_expand_flag = expand_flag;
 }
 
 static PanelType *fmodifier_panel_register(ARegionType *region_type,
                                            eFModifier_Types type,
-                                           PanelDrawFn draw)
+                                           PanelDrawFn draw,
+                                           PanelTypePollFn poll,
+                                           const char *id_prefix)
 {
   /* Get the name for the modifier's panel. */
   char panel_idname[BKE_ST_MAXNAME];
-  ANIM_fmodifier_type_panel_id(type, panel_idname);
+  snprintf(panel_idname, BKE_ST_MAXNAME, "%s_PT_", id_prefix);
+  const FModifierTypeInfo *fmi = get_fmodifier_typeinfo(type);
+  strcat(panel_idname, fmi->name);
 
   PanelType *panel_type = MEM_callocN(sizeof(PanelType), panel_idname);
 
@@ -240,12 +165,12 @@ static PanelType *fmodifier_panel_register(ARegionType *region_type,
 
   panel_type->draw_header = fmodifier_panel_header;
   panel_type->draw = draw;
-  panel_type->poll = graph_panel_poll;
+  panel_type->poll = poll;
 
   /* Give the panel the special flag that says it was built here and corresponds to a
    * modifer rather than a PanelType. */
   panel_type->flag = PNL_LAYOUT_HEADER_EXPAND | PNL_DRAW_BOX | PNL_INSTANCED;
-  panel_type->reorder = fmodifier_reorder;
+  // panel_type->reorder = fmodifier_reorder;
   panel_type->get_list_data_expand_flag = get_fmodifier_expand_flag;
   panel_type->set_list_data_expand_flag = set_fmodifier_expand_flag;
 
@@ -265,6 +190,7 @@ static PanelType *fmodifier_subpanel_register(ARegionType *region_type,
                                               const char *label,
                                               PanelDrawFn draw_header,
                                               PanelDrawFn draw,
+                                              PanelTypePollFn poll,
                                               PanelType *parent)
 {
   /* Create the subpanel's ID name. */
@@ -282,7 +208,7 @@ static PanelType *fmodifier_subpanel_register(ARegionType *region_type,
 
   panel_type->draw_header = draw_header;
   panel_type->draw = draw;
-  panel_type->poll = graph_panel_poll;
+  panel_type->poll = poll;
   panel_type->flag = (PNL_DEFAULT_CLOSED | PNL_DRAW_BOX);
 
   BLI_assert(parent != NULL);
@@ -337,68 +263,56 @@ static void delete_fmodifier_cb(bContext *C, void *ctx_v, void *fcm_v)
   deg_update(C, ctx->fcurve_owner_id, NULL);
 }
 
-static void fmodifier_influence_draw(uiLayout *layout, ID *fcurve_owner_id, FModifier *fcm)
+static void fmodifier_influence_draw(uiLayout *layout, PointerRNA *ptr)
 {
-  PointerRNA ptr;
-  RNA_pointer_create(fcurve_owner_id, &RNA_FModifier, fcm, &ptr);
-
+  FModifier *fcm = (FModifier *)ptr->data;
   uiItemS(layout);
 
   uiLayout *row = uiLayoutRowWithHeading(layout, true, IFACE_("Influence"));
-  uiItemR(row, &ptr, "use_influence", 0, "", ICON_NONE);
+  uiItemR(row, ptr, "use_influence", 0, "", ICON_NONE);
   uiLayout *sub = uiLayoutRow(row, true);
+
   uiLayoutSetActive(sub, fcm->flag & FMODIFIER_FLAG_USEINFLUENCE);
-  uiItemR(sub, &ptr, "influence", 0, "", ICON_NONE);
+  uiItemR(sub, ptr, "influence", 0, "", ICON_NONE);
 }
 
-static void fmodifier_frame_range_header_draw(const bContext *C, Panel *panel)
+static void fmodifier_frame_range_header_draw(const bContext *UNUSED(C), Panel *panel)
 {
   uiLayout *layout = panel->layout;
 
-  FModifier *fcm;
-  ID *fcurve_owner_id;
-  fmodifier_get_pointers(C, panel, &fcm, &fcurve_owner_id);
+  PointerRNA *ptr = fmodifier_get_pointers(panel, NULL);
 
-  PointerRNA ptr;
-  RNA_pointer_create(fcurve_owner_id, &RNA_FModifier, fcm, &ptr);
-  uiItemR(layout, &ptr, "use_restricted_range", 0, "",

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list