Changeset View
Changeset View
Standalone View
Standalone View
source/blender/modifiers/intern/MOD_ui_common.c
| Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
| /** \name Panel Drag and Drop, Expansion Saving | /** \name Panel Drag and Drop, Expansion Saving | ||||
| * \{ */ | * \{ */ | ||||
| /** | /** | ||||
| * Move a modifier to the index it's moved to after a drag and drop. | * Move a modifier to the index it's moved to after a drag and drop. | ||||
| */ | */ | ||||
| static void modifier_reorder(bContext *C, Panel *panel, int new_index) | static void modifier_reorder(bContext *C, Panel *panel, int new_index) | ||||
| { | { | ||||
| Object *ob = ED_object_active_context(C); | PointerRNA *md_ptr = UI_panel_custom_data_get(panel); | ||||
| ModifierData *md = (ModifierData *)md_ptr->data; | |||||
| ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); | |||||
| PointerRNA props_ptr; | PointerRNA props_ptr; | ||||
| wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_modifier_move_to_index", false); | wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_modifier_move_to_index", false); | ||||
| WM_operator_properties_create_ptr(&props_ptr, ot); | WM_operator_properties_create_ptr(&props_ptr, ot); | ||||
| RNA_string_set(&props_ptr, "modifier", md->name); | RNA_string_set(&props_ptr, "modifier", md->name); | ||||
| RNA_int_set(&props_ptr, "index", new_index); | RNA_int_set(&props_ptr, "index", new_index); | ||||
| WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr); | WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr); | ||||
| WM_operator_properties_free(&props_ptr); | WM_operator_properties_free(&props_ptr); | ||||
| } | } | ||||
| static short get_modifier_expand_flag(const bContext *C, Panel *panel) | static short get_modifier_expand_flag(const bContext *UNUSED(C), Panel *panel) | ||||
| { | { | ||||
| Object *ob = ED_object_active_context(C); | PointerRNA *md_ptr = UI_panel_custom_data_get(panel); | ||||
| ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); | ModifierData *md = (ModifierData *)md_ptr->data; | ||||
| return md->ui_expand_flag; | return md->ui_expand_flag; | ||||
| } | } | ||||
| static void set_modifier_expand_flag(const bContext *C, Panel *panel, short expand_flag) | static void set_modifier_expand_flag(const bContext *UNUSED(C), Panel *panel, short expand_flag) | ||||
| { | { | ||||
| Object *ob = ED_object_active_context(C); | PointerRNA *md_ptr = UI_panel_custom_data_get(panel); | ||||
| ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); | ModifierData *md = (ModifierData *)md_ptr->data; | ||||
| md->ui_expand_flag = expand_flag; | md->ui_expand_flag = expand_flag; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Modifier Panel Layouts | /** \name Modifier Panel Layouts | ||||
| * \{ */ | * \{ */ | ||||
| /** | /** | ||||
| * Draw modifier error message. | * Draw modifier error message. | ||||
| */ | */ | ||||
| void modifier_panel_end(uiLayout *layout, PointerRNA *ptr) | void modifier_panel_end(uiLayout *layout, PointerRNA *ptr) | ||||
| { | { | ||||
| ModifierData *md = ptr->data; | ModifierData *md = ptr->data; | ||||
| if (md->error) { | if (md->error) { | ||||
| uiLayout *row = uiLayoutRow(layout, false); | uiLayout *row = uiLayoutRow(layout, false); | ||||
| uiItemL(row, IFACE_(md->error), ICON_ERROR); | uiItemL(row, IFACE_(md->error), ICON_ERROR); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Gets RNA pointers for the active object and the panel's modifier data. Also locks | * Gets RNA pointers for the active object and the panel's modifier data. Also locks | ||||
| * the layout if the modifier 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. | ||||
| * | |||||
| * \note The modifier #PointerRNA is owned by the panel so we only need a pointer to it. | |||||
| */ | */ | ||||
| #define ERROR_LIBDATA_MESSAGE TIP_("External library data") | #define ERROR_LIBDATA_MESSAGE TIP_("External library data") | ||||
| void modifier_panel_get_property_pointers(const bContext *C, | PointerRNA *modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr) | ||||
| Panel *panel, | |||||
| PointerRNA *r_ob_ptr, | |||||
| PointerRNA *r_md_ptr) | |||||
| { | { | ||||
| Object *ob = ED_object_active_context(C); | PointerRNA *ptr = UI_panel_custom_data_get(panel); | ||||
| BLI_assert(!RNA_pointer_is_null(ptr)); | |||||
| ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index); | BLI_assert(RNA_struct_is_a(ptr->type, &RNA_Modifier)); | ||||
| RNA_pointer_create(&ob->id, &RNA_Modifier, md, r_md_ptr); | |||||
| if (r_ob_ptr != NULL) { | if (r_ob_ptr != NULL) { | ||||
| RNA_pointer_create(&ob->id, &RNA_Object, ob, r_ob_ptr); | RNA_pointer_create(ptr->owner_id, &RNA_Object, ptr->owner_id, r_ob_ptr); | ||||
| } | } | ||||
| uiBlock *block = uiLayoutGetBlock(panel->layout); | uiBlock *block = uiLayoutGetBlock(panel->layout); | ||||
| UI_block_lock_set(block, ID_IS_LINKED(ob), ERROR_LIBDATA_MESSAGE); | UI_block_lock_set(block, ID_IS_LINKED((Object *)ptr->owner_id), ERROR_LIBDATA_MESSAGE); | ||||
| uiLayoutSetContextPointer(panel->layout, "modifier", r_md_ptr); | uiLayoutSetContextPointer(panel->layout, "modifier", ptr); | ||||
| return ptr; | |||||
| } | } | ||||
| /** | /** | ||||
| * Helper function for modifier layouts to draw vertex group settings. | * Helper function for modifier layouts to draw vertex group settings. | ||||
| */ | */ | ||||
| void modifier_vgroup_ui(uiLayout *layout, | void modifier_vgroup_ui(uiLayout *layout, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| PointerRNA *ob_ptr, | PointerRNA *ob_ptr, | ||||
| ▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | static void modifier_ops_extra_draw(bContext *C, uiLayout *layout, void *md_v) | ||||
| } | } | ||||
| } | } | ||||
| static void modifier_panel_header(const bContext *C, Panel *panel) | static void modifier_panel_header(const bContext *C, Panel *panel) | ||||
| { | { | ||||
| uiLayout *row, *sub, *name_row; | uiLayout *row, *sub, *name_row; | ||||
| uiLayout *layout = panel->layout; | uiLayout *layout = panel->layout; | ||||
| PointerRNA ptr; | |||||
| Object *ob = ED_object_active_context(C); | |||||
| /* Don't use #modifier_panel_get_property_pointers, we don't want to lock the header. */ | /* 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); | PointerRNA *ptr = UI_panel_custom_data_get(panel); | ||||
| RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr); | ModifierData *md = (ModifierData *)ptr->data; | ||||
| uiLayoutSetContextPointer(panel->layout, "modifier", &ptr); | Object *ob = (Object *)ptr->owner_id; | ||||
| uiLayoutSetContextPointer(panel->layout, "modifier", ptr); | |||||
| const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); | const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| int index = panel->runtime.list_index; | int index = BLI_findindex(&ob->modifiers, md); | ||||
| /* Modifier Icon. */ | /* Modifier Icon. */ | ||||
| sub = uiLayoutRow(layout, true); | sub = uiLayoutRow(layout, true); | ||||
| if (mti->isDisabled && mti->isDisabled(scene, md, 0)) { | if (mti->isDisabled && mti->isDisabled(scene, md, 0)) { | ||||
| uiLayoutSetRedAlert(sub, true); | uiLayoutSetRedAlert(sub, true); | ||||
| } | } | ||||
| uiItemL(sub, "", RNA_struct_ui_icon(ptr.type)); | uiItemL(sub, "", RNA_struct_ui_icon(ptr->type)); | ||||
| row = uiLayoutRow(layout, true); | row = uiLayoutRow(layout, true); | ||||
| /* Modifier Name. | /* Modifier Name. | ||||
| * Count how many buttons are added to the header to check if there is enough space. */ | * Count how many buttons are added to the header to check if there is enough space. */ | ||||
| int buttons_number = 0; | int buttons_number = 0; | ||||
| name_row = uiLayoutRow(row, true); | name_row = uiLayoutRow(row, true); | ||||
| /* Display mode switching buttons. */ | /* Display mode switching buttons. */ | ||||
| if (ob->type == OB_MESH) { | if (ob->type == OB_MESH) { | ||||
| int last_cage_index; | int last_cage_index; | ||||
| int cage_index = BKE_modifiers_get_cage_index(scene, ob, &last_cage_index, 0); | int cage_index = BKE_modifiers_get_cage_index(scene, ob, &last_cage_index, 0); | ||||
| if (BKE_modifier_supports_cage(scene, md) && (index <= last_cage_index)) { | if (BKE_modifier_supports_cage(scene, md) && (index <= last_cage_index)) { | ||||
| sub = uiLayoutRow(row, true); | sub = uiLayoutRow(row, true); | ||||
| if (index < cage_index || !BKE_modifier_couldbe_cage(scene, md)) { | if (index < cage_index || !BKE_modifier_couldbe_cage(scene, md)) { | ||||
| uiLayoutSetActive(sub, false); | uiLayoutSetActive(sub, false); | ||||
| } | } | ||||
| uiItemR(sub, &ptr, "show_on_cage", 0, "", ICON_NONE); | uiItemR(sub, ptr, "show_on_cage", 0, "", ICON_NONE); | ||||
| buttons_number++; | buttons_number++; | ||||
| } | } | ||||
| } /* Tessellation point for curve-typed objects. */ | } /* Tessellation point for curve-typed objects. */ | ||||
| else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { | else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { | ||||
| if (mti->type != eModifierTypeType_Constructive) { | if (mti->type != eModifierTypeType_Constructive) { | ||||
| /* Constructive modifiers tessellates curve before applying. */ | /* Constructive modifiers tessellates curve before applying. */ | ||||
| uiItemR(row, &ptr, "use_apply_on_spline", 0, "", ICON_NONE); | uiItemR(row, ptr, "use_apply_on_spline", 0, "", ICON_NONE); | ||||
| buttons_number++; | buttons_number++; | ||||
| } | } | ||||
| } | } | ||||
| /* Collision and Surface are always enabled, hide buttons. */ | /* Collision and Surface are always enabled, hide buttons. */ | ||||
| if (((md->type != eModifierType_Collision) || !(ob->pd && ob->pd->deflect)) && | if (((md->type != eModifierType_Collision) || !(ob->pd && ob->pd->deflect)) && | ||||
| (md->type != eModifierType_Surface)) { | (md->type != eModifierType_Surface)) { | ||||
| if (mti->flags & eModifierTypeFlag_SupportsEditmode) { | if (mti->flags & eModifierTypeFlag_SupportsEditmode) { | ||||
| sub = uiLayoutRow(row, true); | sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetActive(sub, (md->mode & eModifierMode_Realtime)); | uiLayoutSetActive(sub, (md->mode & eModifierMode_Realtime)); | ||||
| uiItemR(sub, &ptr, "show_in_editmode", 0, "", ICON_NONE); | uiItemR(sub, ptr, "show_in_editmode", 0, "", ICON_NONE); | ||||
| buttons_number++; | buttons_number++; | ||||
| } | } | ||||
| uiItemR(row, &ptr, "show_viewport", 0, "", ICON_NONE); | uiItemR(row, ptr, "show_viewport", 0, "", ICON_NONE); | ||||
| uiItemR(row, &ptr, "show_render", 0, "", ICON_NONE); | uiItemR(row, ptr, "show_render", 0, "", ICON_NONE); | ||||
| buttons_number += 2; | buttons_number += 2; | ||||
| } | } | ||||
| /* Extra operators menu. */ | /* Extra operators menu. */ | ||||
| uiItemMenuF(row, "", ICON_DOWNARROW_HLT, modifier_ops_extra_draw, md); | uiItemMenuF(row, "", ICON_DOWNARROW_HLT, modifier_ops_extra_draw, md); | ||||
| /* Delete button. */ | /* Delete button. */ | ||||
| if (modifier_can_delete(md) && !modifier_is_simulation(md)) { | if (modifier_can_delete(md) && !modifier_is_simulation(md)) { | ||||
| Show All 12 Lines | static void modifier_panel_header(const bContext *C, Panel *panel) | ||||
| else if (modifier_is_simulation(md) == 2) { | else if (modifier_is_simulation(md) == 2) { | ||||
| uiItemStringO( | uiItemStringO( | ||||
| row, "", ICON_PROPERTIES, "WM_OT_properties_context_change", "context", "PARTICLES"); | row, "", ICON_PROPERTIES, "WM_OT_properties_context_change", "context", "PARTICLES"); | ||||
| buttons_number++; | buttons_number++; | ||||
| } | } | ||||
| bool display_name = (panel->sizex / UI_UNIT_X - buttons_number > 5) || (panel->sizex == 0); | bool display_name = (panel->sizex / UI_UNIT_X - buttons_number > 5) || (panel->sizex == 0); | ||||
| if (display_name) { | if (display_name) { | ||||
| uiItemR(name_row, &ptr, "name", 0, "", ICON_NONE); | uiItemR(name_row, ptr, "name", 0, "", ICON_NONE); | ||||
| } | } | ||||
| else { | else { | ||||
| uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT); | uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT); | ||||
| } | } | ||||
| /* Extra padding for delete button. */ | /* Extra padding for delete button. */ | ||||
| uiItemS(layout); | uiItemS(layout); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines | |||||