[Bf-blender-cvs] [2110af20f5e] master: Outliner: Move mode toggling to left column

Nathan Craddock noreply at git.blender.org
Thu Sep 10 17:02:44 CEST 2020


Commit: 2110af20f5e636cd4481152e8cbe920dfa1efa8c
Author: Nathan Craddock
Date:   Thu Sep 10 08:35:58 2020 -0600
Branches: master
https://developer.blender.org/rB2110af20f5e636cd4481152e8cbe920dfa1efa8c

Outliner: Move mode toggling to left column

Add a column of icons in the left gutter of the outliner for controlling
the interaction modes of objects. When an object is in a mode other than
object mode, the mode icon will draw to the left of that object. Any
other objects that are valid to be added or swapped into the mode are
drawn with a dot to the left of the object.

Clicking the dot to the left of an object will swap that object with the
current active object in the interaction mode. For edit and pose modes,
ctrl clicking the dot will add that object to the current mode.

Clicking the mode icon next to the active object removes it and all
other objects from the current mode.

The behavior is nearly identical to the previous edit/pose mode toggling
by selecting the mesh and armature datablocks, with additional support
for all interaction modes.

Currently two undo steps are pushed to prevent an assert.

Part of T77408

Manifest Task: https://developer.blender.org/T68498

Differential Revision: https://developer.blender.org/D8641

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

M	release/scripts/startup/bl_ui/space_outliner.py
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/editors/include/UI_interface_icons.h
M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/space_outliner/outliner_dragdrop.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/editors/space_outliner/outliner_intern.h
M	source/blender/editors/space_outliner/outliner_select.c
M	source/blender/editors/space_outliner/space_outliner.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/space_outliner.py b/release/scripts/startup/bl_ui/space_outliner.py
index 5a54d4ca2d8..e0764bc990c 100644
--- a/release/scripts/startup/bl_ui/space_outliner.py
+++ b/release/scripts/startup/bl_ui/space_outliner.py
@@ -358,6 +358,10 @@ class OUTLINER_PT_filter(Panel):
         row.prop(space, "use_sync_select", text="Sync Selection")
         layout.separator()
 
+        row = layout.row(align=True)
+        row.prop(space, "show_mode_column", text="Show Mode Column")
+        layout.separator()
+
         col = layout.column(align=True)
         col.label(text="Search:")
         col.prop(space, "use_filter_complete", text="Exact Match")
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index 73a4b1a9098..cf07e9acad3 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -585,6 +585,18 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
       do_versions_point_attributes(&pointcloud->pdata);
     }
 
+    /* Show outliner mode column by default. */
+    LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
+      LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+        LISTBASE_FOREACH (SpaceLink *, space, &area->spacedata) {
+          if (space->spacetype == SPACE_OUTLINER) {
+            SpaceOutliner *space_outliner = (SpaceOutliner *)space;
+
+            space_outliner->flag |= SO_MODE_COLUMN;
+          }
+        }
+      }
+    }
     /* Keep this block, even when empty. */
   }
 }
diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h
index 7b59d45b203..bbe66f7fd73 100644
--- a/source/blender/editors/include/UI_interface_icons.h
+++ b/source/blender/editors/include/UI_interface_icons.h
@@ -106,6 +106,7 @@ struct PreviewImage *UI_icon_to_preview(int icon_id);
 int UI_rnaptr_icon_get(struct bContext *C, struct PointerRNA *ptr, int rnaicon, const bool big);
 int UI_idcode_icon_get(const int idcode);
 int UI_library_icon_get(const struct ID *id);
+int UI_mode_icon_get(const int mode);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index b5f902adfb5..c91b4d826a7 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -2294,6 +2294,36 @@ int UI_idcode_icon_get(const int idcode)
   }
 }
 
+int UI_mode_icon_get(const int mode)
+{
+  switch (mode) {
+    case OB_MODE_OBJECT:
+      return ICON_OBJECT_DATAMODE;
+    case OB_MODE_EDIT:
+    case OB_MODE_EDIT_GPENCIL:
+      return ICON_EDITMODE_HLT;
+    case OB_MODE_SCULPT:
+    case OB_MODE_SCULPT_GPENCIL:
+      return ICON_SCULPTMODE_HLT;
+    case OB_MODE_VERTEX_PAINT:
+    case OB_MODE_VERTEX_GPENCIL:
+      return ICON_VPAINT_HLT;
+    case OB_MODE_WEIGHT_PAINT:
+    case OB_MODE_WEIGHT_GPENCIL:
+      return ICON_WPAINT_HLT;
+    case OB_MODE_TEXTURE_PAINT:
+      return ICON_TPAINT_HLT;
+    case OB_MODE_PARTICLE_EDIT:
+      return ICON_PARTICLEMODE;
+    case OB_MODE_POSE:
+      return ICON_POSE_HLT;
+    case OB_MODE_PAINT_GPENCIL:
+      return ICON_GREASEPENCIL;
+    default:
+      return ICON_NONE;
+  }
+}
+
 /* draws icon with dpi scale factor */
 void UI_icon_draw(float x, float y, int icon_id)
 {
diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.c b/source/blender/editors/space_outliner/outliner_dragdrop.c
index 94052223e39..46a5f90f6c2 100644
--- a/source/blender/editors/space_outliner/outliner_dragdrop.c
+++ b/source/blender/editors/space_outliner/outliner_dragdrop.c
@@ -893,6 +893,9 @@ static int outliner_item_drag_drop_invoke(bContext *C,
   if (outliner_item_is_co_within_close_toggle(te, view_mval[0])) {
     return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
   }
+  if (outliner_is_co_within_mode_column(space_outliner, view_mval)) {
+    return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
+  }
 
   /* Scroll the view when dragging near edges, but not
    * when the drag goes too far outside the region. */
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index fbef3aa07d7..3de786ddd4d 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -53,6 +53,7 @@
 #include "BKE_main.h"
 #include "BKE_modifier.h"
 #include "BKE_object.h"
+#include "BKE_particle.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
 
@@ -1884,6 +1885,109 @@ static void outliner_buttons(const bContext *C,
   }
 }
 
+static void outliner_mode_toggle_fn(bContext *C, void *tselem_poin, void *UNUSED(arg2))
+{
+  SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
+  TreeStoreElem *tselem = (TreeStoreElem *)tselem_poin;
+  TreeViewContext tvc;
+  outliner_viewcontext_init(C, &tvc);
+
+  TreeElement *te = outliner_find_tree_element(&space_outliner->tree, tselem);
+  if (!te) {
+    return;
+  }
+
+  wmWindow *win = CTX_wm_window(C);
+  const bool do_extend = win->eventstate->ctrl != 0;
+  outliner_item_mode_toggle(C, &tvc, te, do_extend);
+}
+
+/* Draw icons for adding and removing objects from the current interation mode. */
+static void outliner_draw_mode_column_toggle(uiBlock *block,
+                                             TreeViewContext *tvc,
+                                             TreeElement *te,
+                                             TreeStoreElem *tselem,
+                                             const bool lock_object_modes)
+{
+  const int active_mode = tvc->obact->mode;
+  bool draw_active_icon = true;
+
+  if (tselem->type == 0 && te->idcode == ID_OB) {
+    Object *ob = (Object *)tselem->id;
+
+    /* When not locking object modes, objects can remain in non-object modes. For modes that do not
+     * allow multi-object editing, these other objects should still show be viewed as not in the
+     * mode. Otherwise multiple objects show the same mode icon in the outliner even though only
+     * one object is actually editable in the mode. */
+    if (!lock_object_modes && ob != tvc->obact && !(tvc->ob_edit || tvc->ob_pose)) {
+      draw_active_icon = false;
+    }
+
+    if (ob->type == tvc->obact->type) {
+      int icon;
+      const char *tip;
+
+      if (draw_active_icon && ob->mode == tvc->obact->mode) {
+        icon = UI_mode_icon_get(active_mode);
+        tip = TIP_("Remove from the current mode");
+      }
+      else {
+        /* Not all objects support particle systems */
+        if (active_mode == OB_MODE_PARTICLE_EDIT && !psys_get_current(ob)) {
+          return;
+        }
+        icon = ICON_DOT;
+        tip = TIP_(
+            "Change the object in the current mode\n"
+            "* Ctrl to add to the current mode");
+      }
+
+      uiBut *but = uiDefIconBut(block,
+                                UI_BTYPE_ICON_TOGGLE,
+                                0,
+                                icon,
+                                0,
+                                te->ys,
+                                UI_UNIT_X,
+                                UI_UNIT_Y,
+                                NULL,
+                                0.0,
+                                0.0,
+                                0.0,
+                                0.0,
+                                tip);
+      UI_but_func_set(but, outliner_mode_toggle_fn, tselem, NULL);
+      UI_but_flag_enable(but, UI_BUT_DRAG_LOCK);
+
+      if (ID_IS_LINKED(&ob->id)) {
+        UI_but_disable(but, TIP_("Can't edit external library data"));
+      }
+    }
+  }
+}
+
+static void outliner_draw_mode_column(const bContext *C,
+                                      uiBlock *block,
+                                      TreeViewContext *tvc,
+                                      SpaceOutliner *space_outliner,
+                                      ListBase *tree)
+{
+  TreeStoreElem *tselem;
+  const bool lock_object_modes = tvc->scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK;
+
+  LISTBASE_FOREACH (TreeElement *, te, tree) {
+    tselem = TREESTORE(te);
+
+    if (tvc->obact && tvc->obact->mode != OB_MODE_OBJECT) {
+      outliner_draw_mode_column_toggle(block, tvc, te, tselem, lock_object_modes);
+    }
+
+    if (TSELEM_OPEN(tselem, space_outliner)) {
+      outliner_draw_mode_column(C, block, tvc, space_outliner, &te->subtree);
+    }
+  }
+}
+
 /* ****************************************************** */
 /* Normal Drawing... */
 
@@ -3500,11 +3604,20 @@ static void outliner_draw_tree(bContext *C,
                                ARegion *region,
                                SpaceOutliner *space_outliner,
                                const float restrict_column_width,
+                               const bool use_mode_column,
                                TreeElement **te_edit)
 {
   const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
   int starty, startx;
 
+  /* Move the tree a unit left in view layer mode */
+  short mode_column_offset = (use_mode_column && (space_outliner->outlinevis == SO_SCENES)) ?
+                                 UI_UNIT_X :
+                                 0;
+  if (!use_mode_column && (space_outliner->outlinevis == SO_VIEW_LAYER)) {
+    mode_column_offset -= UI_UNIT_X;
+  }
+
   GPU_blend(GPU_BLEND_ALPHA); /* Only once. */
 
   if (space_outliner->outlinevis == SO_DATA_API) {
@@ -3530,12 +3643,12 @@ static void outliner_draw_tree(bContext *C,
 
   /* Gray hierarchy lines. */
   starty = (int)region->v2d.tot.ymax - UI_UNIT_Y / 2 - OL_Y_OFFSET;
-  startx = UI_UNIT_X / 2 - (U.pixelsize + 1) / 2;
+  startx = mode_column_offset + UI_UNIT_X / 2 - (U.pixelsize + 1) / 2;
   outliner_draw_hierarchy_lines(space_outliner, &space_outliner->tree, startx, &starty);
 
   /* Items themselves. */
   starty = (int)region->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
-  startx = 0;
+  startx = mode_column_offset;
   LISTBASE_FOREACH (TreeElement *, te, &space_outliner->tree) {
     outliner_draw_tree_element(C,
                                block,
@@ -3658,12 +3

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list