Changeset View
Changeset View
Standalone View
Standalone View
source/blender/shader_fx/intern/FX_ui_common.c
| Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
| /** \name Panel Drag and Drop, Expansion Saving | /** \name Panel Drag and Drop, Expansion Saving | ||||
| * \{ */ | * \{ */ | ||||
| /** | /** | ||||
| * Move an effect to the index it's moved to after a drag and drop. | * Move an effect to the index it's moved to after a drag and drop. | ||||
| */ | */ | ||||
| static void shaderfx_reorder(bContext *C, Panel *panel, int new_index) | static void shaderfx_reorder(bContext *C, Panel *panel, int new_index) | ||||
| { | { | ||||
| Object *ob = ED_object_active_context(C); | PointerRNA *fx_ptr = UI_panel_custom_data_get(panel); | ||||
| ShaderFxData *fx = (ShaderFxData *)fx_ptr->data; | |||||
| ShaderFxData *fx = BLI_findlink(&ob->shader_fx, panel->runtime.list_index); | |||||
| PointerRNA props_ptr; | PointerRNA props_ptr; | ||||
| wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_shaderfx_move_to_index", false); | wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_shaderfx_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, "shaderfx", fx->name); | RNA_string_set(&props_ptr, "shaderfx", fx->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); | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the expand flag from the active effect to use for the panel. | * Get the expand flag from the active effect to use for the panel. | ||||
| */ | */ | ||||
| static short get_shaderfx_expand_flag(const bContext *C, Panel *panel) | static short get_shaderfx_expand_flag(const bContext *UNUSED(C), Panel *panel) | ||||
| { | { | ||||
| Object *ob = ED_object_active_context(C); | PointerRNA *fx_ptr = UI_panel_custom_data_get(panel); | ||||
| ShaderFxData *fx = BLI_findlink(&ob->shader_fx, panel->runtime.list_index); | ShaderFxData *fx = (ShaderFxData *)fx_ptr->data; | ||||
| return fx->ui_expand_flag; | return fx->ui_expand_flag; | ||||
| } | } | ||||
| /** | /** | ||||
| * Save the expand flag for the panel and sub-panels to the effect. | * Save the expand flag for the panel and sub-panels to the effect. | ||||
| */ | */ | ||||
| static void set_shaderfx_expand_flag(const bContext *C, Panel *panel, short expand_flag) | static void set_shaderfx_expand_flag(const bContext *UNUSED(C), Panel *panel, short expand_flag) | ||||
| { | { | ||||
| Object *ob = ED_object_active_context(C); | PointerRNA *fx_ptr = UI_panel_custom_data_get(panel); | ||||
| ShaderFxData *fx = BLI_findlink(&ob->shader_fx, panel->runtime.list_index); | ShaderFxData *fx = (ShaderFxData *)fx_ptr->data; | ||||
| fx->ui_expand_flag = expand_flag; | fx->ui_expand_flag = expand_flag; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name ShaderFx Panel Layouts | /** \name ShaderFx Panel Layouts | ||||
| * \{ */ | * \{ */ | ||||
| /** | /** | ||||
| * Draw shaderfx error message. | * Draw shaderfx error message. | ||||
| */ | */ | ||||
| void shaderfx_panel_end(uiLayout *layout, PointerRNA *ptr) | void shaderfx_panel_end(uiLayout *layout, PointerRNA *ptr) | ||||
| { | { | ||||
| ShaderFxData *fx = ptr->data; | ShaderFxData *fx = ptr->data; | ||||
| if (fx->error) { | if (fx->error) { | ||||
| uiLayout *row = uiLayoutRow(layout, false); | uiLayout *row = uiLayoutRow(layout, false); | ||||
| uiItemL(row, IFACE_(fx->error), ICON_ERROR); | uiItemL(row, IFACE_(fx->error), ICON_ERROR); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Gets RNA pointers for the active object and the panel's shaderfx data. | * Gets RNA pointers for the active object and the panel's shaderfx data. | ||||
| */ | */ | ||||
| void shaderfx_panel_get_property_pointers(const bContext *C, | PointerRNA *shaderfx_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); | ||||
| ShaderFxData *md = BLI_findlink(&ob->shader_fx, panel->runtime.list_index); | BLI_assert(RNA_struct_is_a(ptr->type, &RNA_ShaderFx)); | ||||
| RNA_pointer_create(&ob->id, &RNA_ShaderFx, 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); | ||||
| } | } | ||||
| uiLayoutSetContextPointer(panel->layout, "shaderfx", r_md_ptr); | uiLayoutSetContextPointer(panel->layout, "shaderfx", ptr); | ||||
| return ptr; | |||||
| } | } | ||||
| #define ERROR_LIBDATA_MESSAGE TIP_("External library data") | #define ERROR_LIBDATA_MESSAGE TIP_("External library data") | ||||
| static void shaderfx_panel_header(const bContext *C, Panel *panel) | static void shaderfx_panel_header(const bContext *UNUSED(C), Panel *panel) | ||||
| { | { | ||||
| uiLayout *layout = panel->layout; | uiLayout *layout = panel->layout; | ||||
| bool narrow_panel = (panel->sizex < UI_UNIT_X * 7 && panel->sizex != 0); | bool narrow_panel = (panel->sizex < UI_UNIT_X * 7 && panel->sizex != 0); | ||||
| PointerRNA ptr; | PointerRNA *ptr = shaderfx_panel_get_property_pointers(panel, NULL); | ||||
| shaderfx_panel_get_property_pointers(C, panel, NULL, &ptr); | Object *ob = (Object *)ptr->owner_id; | ||||
| Object *ob = ED_object_active_context(C); | ShaderFxData *fx = (ShaderFxData *)ptr->data; | ||||
| ShaderFxData *fx = (ShaderFxData *)ptr.data; | |||||
| const ShaderFxTypeInfo *fxti = BKE_shaderfx_get_info(fx->type); | const ShaderFxTypeInfo *fxti = BKE_shaderfx_get_info(fx->type); | ||||
| UI_block_lock_set(uiLayoutGetBlock(layout), (ob && ID_IS_LINKED(ob)), ERROR_LIBDATA_MESSAGE); | UI_block_lock_set(uiLayoutGetBlock(layout), (ob && ID_IS_LINKED(ob)), ERROR_LIBDATA_MESSAGE); | ||||
| /* Effect type icon. */ | /* Effect type icon. */ | ||||
| uiLayout *row = uiLayoutRow(layout, false); | uiLayout *row = uiLayoutRow(layout, false); | ||||
| if (fxti->isDisabled && fxti->isDisabled(fx, 0)) { | if (fxti->isDisabled && fxti->isDisabled(fx, 0)) { | ||||
| uiLayoutSetRedAlert(row, true); | uiLayoutSetRedAlert(row, true); | ||||
| } | } | ||||
| uiItemL(row, "", RNA_struct_ui_icon(ptr.type)); | uiItemL(row, "", RNA_struct_ui_icon(ptr->type)); | ||||
| /* Effect name. */ | /* Effect name. */ | ||||
| row = uiLayoutRow(layout, true); | row = uiLayoutRow(layout, true); | ||||
| if (!narrow_panel) { | if (!narrow_panel) { | ||||
| uiItemR(row, &ptr, "name", 0, "", ICON_NONE); | uiItemR(row, ptr, "name", 0, "", ICON_NONE); | ||||
| } | } | ||||
| /* Mode enabling buttons. */ | /* Mode enabling buttons. */ | ||||
| if (fxti->flags & eShaderFxTypeFlag_SupportsEditmode) { | if (fxti->flags & eShaderFxTypeFlag_SupportsEditmode) { | ||||
| uiLayout *sub = uiLayoutRow(row, true); | uiLayout *sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetActive(sub, false); | uiLayoutSetActive(sub, false); | ||||
| uiItemR(sub, &ptr, "show_in_editmode", 0, "", ICON_NONE); | uiItemR(sub, ptr, "show_in_editmode", 0, "", ICON_NONE); | ||||
| } | } | ||||
| 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); | ||||
| row = uiLayoutRow(row, false); | row = uiLayoutRow(row, false); | ||||
| uiLayoutSetEmboss(row, UI_EMBOSS_NONE); | uiLayoutSetEmboss(row, UI_EMBOSS_NONE); | ||||
| uiItemO(row, "", ICON_X, "OBJECT_OT_shaderfx_remove"); | uiItemO(row, "", ICON_X, "OBJECT_OT_shaderfx_remove"); | ||||
| /* Some padding so the X isn't too close to the drag icon. */ | /* Some padding so the X isn't too close to the drag icon. */ | ||||
| uiItemS(layout); | uiItemS(layout); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines | |||||