[Bf-blender-cvs] [94f986edd4f] modifier-panels-ui: Generalize recreate panel lists, add functionality

Hans Goudey noreply at git.blender.org
Fri Apr 3 23:47:18 CEST 2020


Commit: 94f986edd4faf9d278715b3001175141df7e5368
Author: Hans Goudey
Date:   Fri Apr 3 16:15:45 2020 -0500
Branches: modifier-panels-ui
https://developer.blender.org/rB94f986edd4faf9d278715b3001175141df7e5368

Generalize recreate panel lists, add functionality

The recreate panel list concept should be MUCH easier to use
in different situations, as now it makes use of callbacks for any
modifier-specific functionality.

This commit also enables storing the panel expansion in modifiers
so it is remembered even when the panels are replaced.

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

M	source/blender/blenkernel/BKE_screen.h
M	source/blender/blenkernel/intern/modifier.c
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesdna/DNA_screen_types.h
M	source/blender/makesrna/intern/rna_boid.c
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_ui_common.c

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

diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 2231cc36861..6b5667e79ec 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -225,6 +225,25 @@ typedef struct PanelType {
   /* draw entirely, view changes should be handled here */
   void (*draw)(const struct bContext *C, struct Panel *pa);
 
+  /* For recreate panels corresponding to a list. */
+
+  /** Reorder function, called when drag and drop finishes. */
+  void (*re_order)(struct bContext *C, struct Panel *pa, int new_index);
+  /**
+   * Set the panel and subpanel's expansion state from the corresponding expansion flag. Called
+   * on draw updates.
+   * NOTE: Subpanels are indexed in depth first order, the visual order you would see if all panels
+   * were expanded.
+   */
+  void (*set_expand_from_flag)(const struct bContext *C, struct Panel *pa);
+  /**
+   * Set the expand bitfield from the closed / open state of this panel and its subpanels. Called
+   * when the expansion state of the panel changes by user input.
+   * NOTE: Subpanels are indexed in depth first order, the visual order you would see if all panels
+   * were expanded.
+   */
+  void (*set_expand_flag_from_panel)(const struct bContext *C, struct Panel *pa);
+
   /* sub panels */
   struct PanelType *parent;
   ListBase children;
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index 0a76b61cdb1..f2053c390ea 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -126,8 +126,9 @@ ModifierData *modifier_new(int type)
   BLI_strncpy(md->name, DATA_(mti->name), sizeof(md->name));
 
   md->type = type;
-  md->mode = eModifierMode_Realtime | eModifierMode_Render | eModifierMode_Expanded;
+  md->mode = eModifierMode_Realtime | eModifierMode_Render;
   md->flag = eModifierFlag_OverrideLibrary_Local;
+  md->ui_expand_flag = 1; /* Only open the main panel at the beginning, not the subpanels. */
 
   if (mti->flags & eModifierTypeFlag_EnableInEditmode) {
     md->mode |= eModifierMode_Editmode;
@@ -341,6 +342,7 @@ void modifier_copyData_ex(ModifierData *md, ModifierData *target, const int flag
 
   target->mode = md->mode;
   target->flag = md->flag;
+  target->ui_expand_flag = md->ui_expand_flag;
 
   if (mti->copyData) {
     mti->copyData(md, target, flag);
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 1e2bba24cd2..2f4e4aad312 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -39,9 +39,7 @@
 
 #include "BLT_translation.h"
 
-#include "DNA_modifier_types.h"
 #include "DNA_userdef_types.h"
-/* HANS-TODO: Generalize this and move re-ordering code elsewhere. */
 
 #include "BKE_context.h"
 #include "BKE_screen.h"
@@ -61,8 +59,6 @@
 #include "GPU_immediate.h"
 #include "GPU_state.h"
 
-#include "RNA_access.h"
-
 #include "interface_intern.h"
 
 /*********************** defines and structs ************************/
@@ -239,7 +235,32 @@ static bool panels_need_realign(ScrArea *sa, ARegion *region, Panel **r_pa_anima
 
 /****************************** panels ******************************/
 
-static void panels_collapse_all(ScrArea *sa, ARegion *region, const Panel *from_pa)
+/**
+ * Call the callback to store the panel and subpanel expansion settings in the list item that
+ * corresponds to this panel.
+ *
+ * NOTE: This needs to iterate through all of the regions panels because that panel with changed
+ * expansion could have been the subpanel of a recreate panel and might not know about its
+ * corresponding list item.
+ */
+static void set_list_panel_item_expansion_flag(const bContext *C, ARegion *region)
+{
+  LISTBASE_FOREACH (Panel *, panel, &region->panels) {
+    PanelType *panel_type = panel->type;
+    if (panel_type == NULL) {
+      continue;
+    }
+
+    if (panel->type->flag & PANELTYPE_RECREATE) {
+      panel->type->set_expand_flag_from_panel(C, panel);
+    }
+  }
+}
+
+static void panels_collapse_all(const bContext *C,
+                                ScrArea *sa,
+                                ARegion *region,
+                                const Panel *from_pa)
 {
   const bool has_category_tabs = UI_panel_category_is_visible(region);
   const char *category = has_category_tabs ? UI_panel_category_active_get(region, false) : NULL;
@@ -261,6 +282,7 @@ static void panels_collapse_all(ScrArea *sa, ARegion *region, const Panel *from_
       }
     }
   }
+  set_list_panel_item_expansion_flag(C, region);
 }
 
 Panel *UI_panel_find_by_type(ListBase *lb, PanelType *pt)
@@ -467,16 +489,6 @@ Panel *UI_panel_add_recreate(
   panel->type = panel_type;
   BLI_strncpy(panel->panelname, panel_type->idname, sizeof(panel->panelname));
 
-  if (panel_type->flag & PNL_DEFAULT_CLOSED) {
-    int align = panel_aligned(sa, region);
-    if (align == BUT_VERTICAL) {
-      panel->flag |= PNL_CLOSEDY;
-    }
-    else {
-      panel->flag |= PNL_CLOSEDX;
-    }
-  }
-
   panel->ofsx = 0;
   panel->ofsy = 0;
   panel->sizex = 0;
@@ -485,7 +497,7 @@ Panel *UI_panel_add_recreate(
   panel->blocksizey = 0;
   panel->runtime_flag |= PNL_NEW_ADDED;
 
-  panel->list_index = modifier_index;
+  panel->runtime.list_index = modifier_index;
 
   /* Add the panel's children too. */
   for (LinkData *link = panel_type->children.first; link; link = link->next) {
@@ -500,7 +512,7 @@ Panel *UI_panel_add_recreate(
 
 void UI_panel_set_list_index(Panel *panel, int i)
 {
-  panel->list_index = i;
+  panel->runtime.list_index = i;
 
   Panel *child = panel->children.first;
   while (child != NULL) {
@@ -1443,7 +1455,7 @@ static void check_panel_overlap(ARegion *region, Panel *panel)
 
 static void reorder_recreate_panel_list(bContext *C, ARegion *region, Panel *panel)
 {
-  if (panel->type == NULL) {
+  if (panel->type == NULL || !(panel->type->flag & PANELTYPE_RECREATE)) {
     return;
   }
   char *context = panel->type->context;
@@ -1483,17 +1495,17 @@ static void reorder_recreate_panel_list(bContext *C, ARegion *region, Panel *pan
       break;
     }
   }
+  // for (int i = 0; i < list_panels_len; i++) {
+  //   MEM_freeN(&panel_sort[i].pa);
+  // }
+  // MEM_freeN(panel_sort);
 
-  /* Move this panel's list item to the corresponding index in its list. */
-  Object *ob = CTX_data_active_object(C);
-  ModifierData *md = BLI_findlink(&ob->modifiers, panel->list_index);
-  PointerRNA props_ptr;
-  wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_modifier_move_to_index", false);
-  WM_operator_properties_create_ptr(&props_ptr, ot);
-  RNA_string_set(&props_ptr, "modifier", md->name);
-  RNA_int_set(&props_ptr, "index", move_to_index);
-  WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr);
-  WM_operator_properties_free(&props_ptr);
+  /* Move this panel's list item to the new index in its list. */
+  if (move_to_index == panel->runtime.list_index) {
+    return;
+  }
+  BLI_assert(panel->type->re_order != NULL);
+  panel->type->re_order(C, panel, move_to_index);
 }
 
 static void ui_do_drag(const bContext *C, const wmEvent *event, Panel *panel)
@@ -1634,6 +1646,7 @@ static void ui_panel_drag_collapse(bContext *C,
       /* force panel to close */
       if (dragcol_data->was_first_open == true) {
         pa->flag |= (is_horizontal ? PNL_CLOSEDX : PNL_CLOSEDY);
+        set_list_panel_item_expansion_flag(C, region);
       }
       /* force panel to open */
       else {
@@ -1772,7 +1785,7 @@ static void ui_handle_panel_header(
     }
     else { /* collapse */
       if (ctrl) {
-        panels_collapse_all(sa, region, block->panel);
+        panels_collapse_all(C, sa, region, block->panel);
 
         /* reset the view - we don't want to display a view without content */
         UI_view2d_offset(&region->v2d, 0.0f, 1.0f);
@@ -1807,6 +1820,8 @@ static void ui_handle_panel_header(
           ui_panel_drag_collapse_handler_add(C, true);
         }
       }
+
+      set_list_panel_item_expansion_flag(C, region);
     }
 
     if (align) {
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index f0972f9b909..cb0f6b97415 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -1897,15 +1897,16 @@ void uiTemplateModifiers(uiLayout *UNUSED(layout), bContext *C)
         modifiers_changed = true;
         break;
       }
-
       if (panel_type_from_modifier_type(region, md->type) != panel->type) {
         /* The types of the corresponding panel and modifier don't match. */
         modifiers_changed = true;
         break;
       }
 
+      /* Set the list index of the panel anyway, two modifiers of the same type might have
+       * switched. */
       UI_panel_set_list_index(panel, i);
-      panel->list_index = i;
+      panel->runtime.list_index = i;
       md = md->next;
       i++;
     }
@@ -1928,12 +1929,7 @@ void uiTemplateModifiers(uiLayout *UNUSED(layout), bContext *C)
         BLI_assert(panel_type != NULL);
 
         Panel *new_panel = UI_panel_add_recreate(sa, region, &region->panels, panel_type, i);
-        if (md->mode & eModifierMode_Expanded) {
-          new_panel->flag |= PNL_CLOSEDY;
-        }
-        else {
-          new_panel->flag &= ~PNL_CLOSEDY;
-        }
+        new_panel->type->set_expand_from_flag(C, new_panel);
       }
     }
   }
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 855bf8434be..7f23f8f7ff3 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -102,7 +102,7 @@ typedef enum ModifierMode {
   eModifierMode_Render = (1 << 1),
   eModifierMode_Editmode = (1 << 2),
   eModifierMode_OnCage = (1 << 3),
-  eModifierMode_Expanded = (1 << 4),
+  /* UNUSED = (1 << 4), */
   eModifierMode_Virtual = (1 << 5),
   eModifierMode_ApplyOnSpline = (1 << 6),
   eModifierMode_DisableTemporary = (1u << 31),
@@ -114,7 +114,7 @@ typedef struct ModifierData {
   int type, mode;
   int stacki

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list