diff options
Diffstat (limited to 'source/blender/modifiers/intern/MOD_ui_common.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_ui_common.c | 178 |
1 files changed, 114 insertions, 64 deletions
diff --git a/source/blender/modifiers/intern/MOD_ui_common.c b/source/blender/modifiers/intern/MOD_ui_common.c index cc0d3d8ccee..01b9e972086 100644 --- a/source/blender/modifiers/intern/MOD_ui_common.c +++ b/source/blender/modifiers/intern/MOD_ui_common.c @@ -33,7 +33,6 @@ #include "DNA_particle_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" -#include "DNA_space_types.h" #include "ED_object.h" @@ -50,24 +49,13 @@ #include "MOD_modifiertypes.h" #include "MOD_ui_common.h" /* Self include */ -static Object *get_modifier_object(const bContext *C) -{ - SpaceProperties *sbuts = CTX_wm_space_properties(C); - if (sbuts != NULL && (sbuts->pinid != NULL) && GS(sbuts->pinid->name) == ID_OB) { - return (Object *)sbuts->pinid; - } - else { - return CTX_data_active_object(C); - } -} - /** * Poll function so these modifier panels don't show for other object types with modifiers (only * grease pencil currently). */ static bool modifier_ui_poll(const bContext *C, PanelType *UNUSED(pt)) { - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); return (ob != NULL) && (ob->type != OB_GPENCIL); } @@ -81,7 +69,7 @@ static bool modifier_ui_poll(const bContext *C, PanelType *UNUSED(pt)) */ static void modifier_reorder(bContext *C, Panel *panel, int new_index) { - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); PointerRNA props_ptr; @@ -95,14 +83,14 @@ static void modifier_reorder(bContext *C, Panel *panel, int new_index) static short get_modifier_expand_flag(const bContext *C, Panel *panel) { - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); return md->ui_expand_flag; } static void set_modifier_expand_flag(const bContext *C, Panel *panel, short expand_flag) { - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); md->ui_expand_flag = expand_flag; } @@ -127,7 +115,7 @@ void modifier_panel_end(uiLayout *layout, PointerRNA *ptr) /** * Gets RNA pointers for the active object and the panel's modifier data. Also locks - * the layout if the modifer is from a linked object, and sets the context pointer. + * the layout if the modifier is from a linked object, and sets the context pointer. */ #define ERROR_LIBDATA_MESSAGE TIP_("External library data") void modifier_panel_get_property_pointers(const bContext *C, @@ -135,7 +123,7 @@ void modifier_panel_get_property_pointers(const bContext *C, PointerRNA *r_ob_ptr, PointerRNA *r_md_ptr) { - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); @@ -146,8 +134,7 @@ void modifier_panel_get_property_pointers(const bContext *C, } uiBlock *block = uiLayoutGetBlock(panel->layout); - UI_block_lock_set( - block, BKE_object_obdata_is_libdata(ob) || ID_IS_LINKED(ob), ERROR_LIBDATA_MESSAGE); + UI_block_lock_set(block, ID_IS_LINKED(ob), ERROR_LIBDATA_MESSAGE); uiLayoutSetContextPointer(panel->layout, "modifier", r_md_ptr); } @@ -222,28 +209,44 @@ static bool modifier_can_delete(ModifierData *md) return true; } -static void modifier_ops_extra_draw(bContext *UNUSED(C), uiLayout *layout, void *md_v) +static void modifier_ops_extra_draw(bContext *C, uiLayout *layout, void *md_v) { + PointerRNA op_ptr; + uiLayout *row; ModifierData *md = (ModifierData *)md_v; + PointerRNA ptr; + Object *ob = ED_object_active_context(C); + RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr); + uiLayoutSetContextPointer(layout, "modifier", &ptr); uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT); - uiItemEnumO(layout, - "OBJECT_OT_modifier_apply", - CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply"), - 0, - "apply_as", - MODIFIER_APPLY_DATA); + uiLayoutSetUnitsX(layout, 4.0f); + /* Apply. */ + uiItemO(layout, + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply"), + ICON_CHECKMARK, + "OBJECT_OT_modifier_apply"); + + /* Apply as shapekey. */ if (BKE_modifier_is_same_topology(md) && !BKE_modifier_is_non_geometrical(md)) { - uiItemEnumO(layout, - "OBJECT_OT_modifier_apply", - CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply As Shapekey"), - ICON_SHAPEKEY_DATA, - "apply_as", - MODIFIER_APPLY_SHAPE); + uiItemBooleanO(layout, + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply As Shapekey"), + ICON_SHAPEKEY_DATA, + "OBJECT_OT_modifier_apply_as_shapekey", + "keep_modifier", + false); + + uiItemBooleanO(layout, + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Save As Shapekey"), + ICON_SHAPEKEY_DATA, + "OBJECT_OT_modifier_apply_as_shapekey", + "keep_modifier", + true); } + /* Duplicate. */ if (!ELEM(md->type, eModifierType_Fluidsim, eModifierType_Softbody, @@ -256,21 +259,46 @@ static void modifier_ops_extra_draw(bContext *UNUSED(C), uiLayout *layout, void "OBJECT_OT_modifier_copy"); } - if (modifier_can_delete(md) && !modifier_is_simulation(md)) { - uiItemO(layout, - CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Delete"), - ICON_X, - "OBJECT_OT_modifier_remove"); + uiItemS(layout); + + /* Move to first. */ + row = uiLayoutColumn(layout, false); + uiItemFullO(row, + "OBJECT_OT_modifier_move_to_index", + IFACE_("Move to First"), + ICON_TRIA_UP, + NULL, + WM_OP_INVOKE_DEFAULT, + 0, + &op_ptr); + RNA_int_set(&op_ptr, "index", 0); + if (!md->prev) { + uiLayoutSetEnabled(row, false); + } + + /* Move to last. */ + row = uiLayoutColumn(layout, false); + uiItemFullO(row, + "OBJECT_OT_modifier_move_to_index", + IFACE_("Move to Last"), + ICON_TRIA_DOWN, + NULL, + WM_OP_INVOKE_DEFAULT, + 0, + &op_ptr); + RNA_int_set(&op_ptr, "index", BLI_listbase_count(&ob->modifiers) - 1); + if (!md->next) { + uiLayoutSetEnabled(row, false); } } static void modifier_panel_header(const bContext *C, Panel *panel) { - uiLayout *row, *sub; + uiLayout *row, *sub, *name_row; uiLayout *layout = panel->layout; PointerRNA ptr; - Object *ob = get_modifier_object(C); + Object *ob = ED_object_active_context(C); /* Don't use #modifier_panel_get_property_pointers, we don't want to lock the header. */ ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); @@ -280,32 +308,22 @@ static void modifier_panel_header(const bContext *C, Panel *panel) const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); Scene *scene = CTX_data_scene(C); int index = panel->runtime.list_index; - bool narrow_panel = (panel->sizex < UI_UNIT_X * 8 && panel->sizex != 0); /* Modifier Icon. */ - row = uiLayoutRow(layout, false); + sub = uiLayoutRow(layout, true); if (mti->isDisabled && mti->isDisabled(scene, md, 0)) { - uiLayoutSetRedAlert(row, true); + uiLayoutSetRedAlert(sub, true); } - uiItemL(row, "", RNA_struct_ui_icon(ptr.type)); + uiItemL(sub, "", RNA_struct_ui_icon(ptr.type)); - /* Modifier Name. */ - if (!narrow_panel) { - uiItemR(layout, &ptr, "name", 0, "", ICON_NONE); - } + row = uiLayoutRow(layout, true); - /* Switch context buttons. */ - if (modifier_is_simulation(md) == 1) { - uiItemStringO( - layout, "", ICON_PROPERTIES, "WM_OT_properties_context_change", "context", "PHYSICS"); - } - else if (modifier_is_simulation(md) == 2) { - uiItemStringO( - layout, "", ICON_PROPERTIES, "WM_OT_properties_context_change", "context", "PARTICLES"); - } + /* Modifier Name. + * Count how many buttons are added to the header to check if there is enough space. */ + int buttons_number = 0; + name_row = uiLayoutRow(row, true); - /* Mode switching buttons. */ - row = uiLayoutRow(layout, true); + /* Display mode switching buttons. */ if (ob->type == OB_MESH) { int last_cage_index; int cage_index = BKE_modifiers_get_cage_index(scene, ob, &last_cage_index, 0); @@ -315,12 +333,14 @@ static void modifier_panel_header(const bContext *C, Panel *panel) uiLayoutSetActive(sub, false); } uiItemR(sub, &ptr, "show_on_cage", 0, "", ICON_NONE); + buttons_number++; } } /* Tessellation point for curve-typed objects. */ else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { if (mti->type != eModifierTypeType_Constructive) { /* Constructive modifiers tessellates curve before applying. */ - uiItemR(layout, &ptr, "use_apply_on_spline", 0, "", ICON_NONE); + uiItemR(row, &ptr, "use_apply_on_spline", 0, "", ICON_NONE); + buttons_number++; } } /* Collision and Surface are always enabled, hide buttons. */ @@ -330,15 +350,45 @@ static void modifier_panel_header(const bContext *C, Panel *panel) sub = uiLayoutRow(row, true); uiLayoutSetActive(sub, (md->mode & eModifierMode_Realtime)); uiItemR(sub, &ptr, "show_in_editmode", 0, "", ICON_NONE); + buttons_number++; } uiItemR(row, &ptr, "show_viewport", 0, "", ICON_NONE); uiItemR(row, &ptr, "show_render", 0, "", ICON_NONE); + buttons_number += 2; } - row = uiLayoutRow(layout, false); + /* Extra operators menu. */ uiItemMenuF(row, "", ICON_DOWNARROW_HLT, modifier_ops_extra_draw, md); - /* Some padding at the end, so the buttons aren't too close to the drag button. */ + /* Delete button. */ + if (modifier_can_delete(md) && !modifier_is_simulation(md)) { + sub = uiLayoutRow(row, false); + uiLayoutSetEmboss(sub, UI_EMBOSS_NONE); + uiItemO(sub, "", ICON_X, "OBJECT_OT_modifier_remove"); + buttons_number++; + } + + /* Switch context buttons. */ + if (modifier_is_simulation(md) == 1) { + uiItemStringO( + row, "", ICON_PROPERTIES, "WM_OT_properties_context_change", "context", "PHYSICS"); + buttons_number++; + } + else if (modifier_is_simulation(md) == 2) { + uiItemStringO( + row, "", ICON_PROPERTIES, "WM_OT_properties_context_change", "context", "PARTICLES"); + buttons_number++; + } + + bool display_name = (panel->sizex / UI_UNIT_X - buttons_number > 5) || (panel->sizex == 0); + if (display_name) { + uiItemR(name_row, &ptr, "name", 0, "", ICON_NONE); + } + else { + uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT); + } + + /* Extra padding for delete button. */ uiItemS(layout); } @@ -369,7 +419,7 @@ PanelType *modifier_panel_register(ARegionType *region_type, ModifierType type, panel_type->poll = modifier_ui_poll; /* Give the panel the special flag that says it was built here and corresponds to a - * modifer rather than a PanelType. */ + * modifier rather than a #PanelType. */ panel_type->flag = PNL_LAYOUT_HEADER_EXPAND | PNL_DRAW_BOX | PNL_INSTANCED; panel_type->reorder = modifier_reorder; panel_type->get_list_data_expand_flag = get_modifier_expand_flag; @@ -381,7 +431,7 @@ PanelType *modifier_panel_register(ARegionType *region_type, ModifierType type, } /** - * Add a shild panel to the parent. + * Add a child panel to the parent. * * \note To create the panel type's idname, it appends the \a name argument to the \a parent's * idname. |