Cleanup: Simplify outliner mode column drawing function

Move the checks for whether to draw the button to the beginning of the
function and return early. Also use a shorthand variable for ob_active.

Committing to 2.91 as a patch for an upcoming bug fix depends on these
changes.

Differential Revision: https://developer.blender.org/D9272
This commit is contained in:
Hans Goudey 2020-10-22 15:46:35 -05:00
parent 8432452f6f
commit 3d916c0a96
1 changed files with 53 additions and 48 deletions

View File

@ -1947,60 +1947,65 @@ static void outliner_draw_mode_column_toggle(uiBlock *block,
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) {
return;
}
if (tselem->type == 0 && te->idcode == ID_OB) {
Object *ob = (Object *)tselem->id;
Object *ob = (Object *)tselem->id;
Object *ob_active = tvc->obact;
/* 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;
}
/* Not all objects support particle systems. */
if (ob_active->mode == OB_MODE_PARTICLE_EDIT && !psys_get_current(ob)) {
return;
}
if (ob->type == tvc->obact->type) {
int icon;
const char *tip;
/* Only for objects with the same type. */
if (ob->type != ob_active->type) {
return;
}
if (draw_active_icon && ob->mode == tvc->obact->mode) {
icon = UI_icon_from_object_mode(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");
}
bool draw_active_icon = ob->mode == ob_active->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);
/* 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 != ob_active && !(tvc->ob_edit || tvc->ob_pose)) {
draw_active_icon = false;
}
if (ID_IS_LINKED(&ob->id)) {
UI_but_disable(but, TIP_("Can't edit external library data"));
}
}
int icon;
const char *tip;
if (draw_active_icon) {
icon = UI_icon_from_object_mode(ob_active->mode);
tip = TIP_("Remove from the current mode");
}
else {
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"));
}
}