Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
| Show First 20 Lines • Show All 62 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 gpencil_modifier_reorder(bContext *C, Panel *panel, int new_index) | static void gpencil_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); | ||||
| GpencilModifierData *md = (GpencilModifierData *)md_ptr->data; | |||||
| GpencilModifierData *md = BLI_findlink(&ob->greasepencil_modifiers, panel->runtime.list_index); | |||||
| PointerRNA props_ptr; | PointerRNA props_ptr; | ||||
| wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_gpencil_modifier_move_to_index", false); | wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_gpencil_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_gpencil_modifier_expand_flag(const bContext *C, Panel *panel) | static short get_gpencil_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); | ||||
| GpencilModifierData *md = BLI_findlink(&ob->greasepencil_modifiers, panel->runtime.list_index); | GpencilModifierData *md = (GpencilModifierData *)md_ptr->data; | ||||
| return md->ui_expand_flag; | return md->ui_expand_flag; | ||||
| return 0; | |||||
| } | } | ||||
| static void set_gpencil_modifier_expand_flag(const bContext *C, Panel *panel, short expand_flag) | static void set_gpencil_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); | ||||
| GpencilModifierData *md = BLI_findlink(&ob->greasepencil_modifiers, panel->runtime.list_index); | GpencilModifierData *md = (GpencilModifierData *)md_ptr->data; | ||||
| md->ui_expand_flag = expand_flag; | md->ui_expand_flag = expand_flag; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Modifier Panel Layouts | /** \name Modifier Panel Layouts | ||||
| * \{ */ | * \{ */ | ||||
| void gpencil_modifier_masking_panel_draw(const bContext *C, | void gpencil_modifier_masking_panel_draw(Panel *panel, bool use_material, bool use_vertex) | ||||
| Panel *panel, | |||||
| bool use_material, | |||||
| bool use_vertex) | |||||
| { | { | ||||
| uiLayout *row, *col, *sub; | uiLayout *row, *col, *sub; | ||||
| uiLayout *layout = panel->layout; | uiLayout *layout = panel->layout; | ||||
| PointerRNA ptr; | |||||
| PointerRNA ob_ptr; | PointerRNA ob_ptr; | ||||
| gpencil_modifier_panel_get_property_pointers(C, panel, &ob_ptr, &ptr); | PointerRNA *ptr = gpencil_modifier_panel_get_property_pointers(panel, &ob_ptr); | ||||
| PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); | PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data"); | ||||
| bool has_layer = RNA_string_length(&ptr, "layer") != 0; | bool has_layer = RNA_string_length(ptr, "layer") != 0; | ||||
| uiLayoutSetPropSep(layout, true); | uiLayoutSetPropSep(layout, true); | ||||
| col = uiLayoutColumn(layout, true); | col = uiLayoutColumn(layout, true); | ||||
| row = uiLayoutRow(col, true); | row = uiLayoutRow(col, true); | ||||
| uiItemPointerR(row, &ptr, "layer", &obj_data_ptr, "layers", NULL, ICON_GREASEPENCIL); | uiItemPointerR(row, ptr, "layer", &obj_data_ptr, "layers", NULL, ICON_GREASEPENCIL); | ||||
| sub = uiLayoutRow(row, true); | sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetActive(sub, has_layer); | uiLayoutSetActive(sub, has_layer); | ||||
| uiLayoutSetPropDecorate(sub, false); | uiLayoutSetPropDecorate(sub, false); | ||||
| uiItemR(sub, &ptr, "invert_layers", 0, "", ICON_ARROW_LEFTRIGHT); | uiItemR(sub, ptr, "invert_layers", 0, "", ICON_ARROW_LEFTRIGHT); | ||||
| row = uiLayoutRow(col, true); | row = uiLayoutRow(col, true); | ||||
| uiItemR(row, &ptr, "layer_pass", 0, NULL, ICON_NONE); | uiItemR(row, ptr, "layer_pass", 0, NULL, ICON_NONE); | ||||
| sub = uiLayoutRow(row, true); | sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetActive(sub, RNA_int_get(&ptr, "layer_pass") != 0); | uiLayoutSetActive(sub, RNA_int_get(ptr, "layer_pass") != 0); | ||||
| uiLayoutSetPropDecorate(sub, false); | uiLayoutSetPropDecorate(sub, false); | ||||
| uiItemR(sub, &ptr, "invert_layer_pass", 0, "", ICON_ARROW_LEFTRIGHT); | uiItemR(sub, ptr, "invert_layer_pass", 0, "", ICON_ARROW_LEFTRIGHT); | ||||
| if (use_material) { | if (use_material) { | ||||
| PointerRNA material_ptr = RNA_pointer_get(&ptr, "material"); | PointerRNA material_ptr = RNA_pointer_get(ptr, "material"); | ||||
| bool has_material = !RNA_pointer_is_null(&material_ptr); | bool has_material = !RNA_pointer_is_null(&material_ptr); | ||||
| /* Because the Gpencil modifier material property used to be a string in an earlier version of | /* Because the Gpencil modifier material property used to be a string in an earlier version of | ||||
| * Blender, we need to check if the material is valid and display it differently if so. */ | * Blender, we need to check if the material is valid and display it differently if so. */ | ||||
| bool valid = false; | bool valid = false; | ||||
| { | { | ||||
| if (!has_material) { | if (!has_material) { | ||||
| valid = true; | valid = true; | ||||
| Show All 10 Lines | bool valid = false; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| col = uiLayoutColumn(layout, true); | col = uiLayoutColumn(layout, true); | ||||
| row = uiLayoutRow(col, true); | row = uiLayoutRow(col, true); | ||||
| uiLayoutSetRedAlert(row, !valid); | uiLayoutSetRedAlert(row, !valid); | ||||
| uiItemPointerR(row, | uiItemPointerR(row, | ||||
| &ptr, | ptr, | ||||
| "material", | "material", | ||||
| &obj_data_ptr, | &obj_data_ptr, | ||||
| "materials", | "materials", | ||||
| NULL, | NULL, | ||||
| valid ? ICON_SHADING_TEXTURE : ICON_ERROR); | valid ? ICON_SHADING_TEXTURE : ICON_ERROR); | ||||
| sub = uiLayoutRow(row, true); | sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetActive(sub, has_material); | uiLayoutSetActive(sub, has_material); | ||||
| uiLayoutSetPropDecorate(sub, false); | uiLayoutSetPropDecorate(sub, false); | ||||
| uiItemR(sub, &ptr, "invert_materials", 0, "", ICON_ARROW_LEFTRIGHT); | uiItemR(sub, ptr, "invert_materials", 0, "", ICON_ARROW_LEFTRIGHT); | ||||
| row = uiLayoutRow(col, true); | row = uiLayoutRow(col, true); | ||||
| uiItemR(row, &ptr, "pass_index", 0, NULL, ICON_NONE); | uiItemR(row, ptr, "pass_index", 0, NULL, ICON_NONE); | ||||
| sub = uiLayoutRow(row, true); | sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetActive(sub, RNA_int_get(&ptr, "pass_index") != 0); | uiLayoutSetActive(sub, RNA_int_get(ptr, "pass_index") != 0); | ||||
| uiLayoutSetPropDecorate(sub, false); | uiLayoutSetPropDecorate(sub, false); | ||||
| uiItemR(sub, &ptr, "invert_material_pass", 0, "", ICON_ARROW_LEFTRIGHT); | uiItemR(sub, ptr, "invert_material_pass", 0, "", ICON_ARROW_LEFTRIGHT); | ||||
| } | } | ||||
| if (use_vertex) { | if (use_vertex) { | ||||
| bool has_vertex_group = RNA_string_length(&ptr, "vertex_group") != 0; | bool has_vertex_group = RNA_string_length(ptr, "vertex_group") != 0; | ||||
| row = uiLayoutRow(layout, true); | row = uiLayoutRow(layout, true); | ||||
| uiItemPointerR(row, &ptr, "vertex_group", &ob_ptr, "vertex_groups", NULL, ICON_NONE); | uiItemPointerR(row, ptr, "vertex_group", &ob_ptr, "vertex_groups", NULL, ICON_NONE); | ||||
| sub = uiLayoutRow(row, true); | sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetActive(sub, has_vertex_group); | uiLayoutSetActive(sub, has_vertex_group); | ||||
| uiLayoutSetPropDecorate(sub, false); | uiLayoutSetPropDecorate(sub, false); | ||||
| uiItemR(sub, &ptr, "invert_vertex", 0, "", ICON_ARROW_LEFTRIGHT); | uiItemR(sub, ptr, "invert_vertex", 0, "", ICON_ARROW_LEFTRIGHT); | ||||
| } | } | ||||
| } | } | ||||
| void gpencil_modifier_curve_header_draw(const bContext *C, Panel *panel) | void gpencil_modifier_curve_header_draw(const bContext *UNUSED(C), Panel *panel) | ||||
| { | { | ||||
| uiLayout *layout = panel->layout; | uiLayout *layout = panel->layout; | ||||
| PointerRNA ptr; | PointerRNA *ptr = gpencil_modifier_panel_get_property_pointers(panel, NULL); | ||||
| gpencil_modifier_panel_get_property_pointers(C, panel, NULL, &ptr); | |||||
| uiItemR(layout, &ptr, "use_custom_curve", 0, NULL, ICON_NONE); | uiItemR(layout, ptr, "use_custom_curve", 0, NULL, ICON_NONE); | ||||
| } | } | ||||
| void gpencil_modifier_curve_panel_draw(const bContext *C, Panel *panel) | void gpencil_modifier_curve_panel_draw(const bContext *UNUSED(C), Panel *panel) | ||||
| { | { | ||||
| uiLayout *layout = panel->layout; | uiLayout *layout = panel->layout; | ||||
| PointerRNA ptr; | PointerRNA *ptr = gpencil_modifier_panel_get_property_pointers(panel, NULL); | ||||
| gpencil_modifier_panel_get_property_pointers(C, panel, NULL, &ptr); | |||||
| uiTemplateCurveMapping(layout, &ptr, "curve", 0, false, false, false, false); | uiTemplateCurveMapping(layout, ptr, "curve", 0, false, false, false, false); | ||||
| } | } | ||||
| /** | /** | ||||
| * Draw modifier error message. | * Draw modifier error message. | ||||
| */ | */ | ||||
| void gpencil_modifier_panel_end(uiLayout *layout, PointerRNA *ptr) | void gpencil_modifier_panel_end(uiLayout *layout, PointerRNA *ptr) | ||||
| { | { | ||||
| GpencilModifierData *md = ptr->data; | GpencilModifierData *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. | * Gets RNA pointers for the active object and the panel's modifier data. | ||||
| */ | */ | ||||
| #define ERROR_LIBDATA_MESSAGE TIP_("External library data") | #define ERROR_LIBDATA_MESSAGE TIP_("External library data") | ||||
| void gpencil_modifier_panel_get_property_pointers(const bContext *C, | PointerRNA *gpencil_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); | ||||
| GpencilModifierData *md = BLI_findlink(&ob->greasepencil_modifiers, panel->runtime.list_index); | BLI_assert(RNA_struct_is_a(ptr->type, &RNA_GpencilModifier)); | ||||
| RNA_pointer_create(&ob->id, &RNA_GpencilModifier, 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_clear(block); | UI_block_lock_clear(block); | ||||
| UI_block_lock_set(block, ob && 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", ptr); | |||||
| uiLayoutSetContextPointer(panel->layout, "modifier", r_md_ptr); | return ptr; | ||||
| } | } | ||||
| static void gpencil_modifier_ops_extra_draw(bContext *C, uiLayout *layout, void *md_v) | static void gpencil_modifier_ops_extra_draw(bContext *C, uiLayout *layout, void *md_v) | ||||
| { | { | ||||
| PointerRNA op_ptr; | PointerRNA op_ptr; | ||||
| uiLayout *row; | uiLayout *row; | ||||
| GpencilModifierData *md = (GpencilModifierData *)md_v; | GpencilModifierData *md = (GpencilModifierData *)md_v; | ||||
| const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type); | const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type); | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | uiItemFullO(row, | ||||
| 0, | 0, | ||||
| &op_ptr); | &op_ptr); | ||||
| RNA_int_set(&op_ptr, "index", BLI_listbase_count(&ob->greasepencil_modifiers) - 1); | RNA_int_set(&op_ptr, "index", BLI_listbase_count(&ob->greasepencil_modifiers) - 1); | ||||
| if (!md->next) { | if (!md->next) { | ||||
| uiLayoutSetEnabled(row, false); | uiLayoutSetEnabled(row, false); | ||||
| } | } | ||||
| } | } | ||||
| static void gpencil_modifier_panel_header(const bContext *C, Panel *panel) | static void gpencil_modifier_panel_header(const bContext *UNUSED(C), Panel *panel) | ||||
| { | { | ||||
| uiLayout *row, *sub; | uiLayout *row, *sub; | ||||
| uiLayout *layout = panel->layout; | uiLayout *layout = panel->layout; | ||||
| Object *ob = ED_object_active_context(C); | PointerRNA *ptr = UI_panel_custom_data_get(panel); | ||||
| GpencilModifierData *md = BLI_findlink(&ob->greasepencil_modifiers, panel->runtime.list_index); | GpencilModifierData *md = (GpencilModifierData *)ptr->data; | ||||
| PointerRNA ptr; | |||||
| RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, &ptr); | uiLayoutSetContextPointer(panel->layout, "modifier", ptr); | ||||
| uiLayoutSetContextPointer(panel->layout, "modifier", &ptr); | |||||
| const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type); | const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type); | ||||
| bool narrow_panel = (panel->sizex < UI_UNIT_X * 9 && panel->sizex != 0); | bool narrow_panel = (panel->sizex < UI_UNIT_X * 9 && panel->sizex != 0); | ||||
| /* Modifier Icon. */ | /* Modifier Icon. */ | ||||
| row = uiLayoutRow(layout, false); | row = uiLayoutRow(layout, false); | ||||
| if (mti->isDisabled && mti->isDisabled(md, 0)) { | if (mti->isDisabled && mti->isDisabled(md, 0)) { | ||||
| uiLayoutSetRedAlert(row, true); | uiLayoutSetRedAlert(row, true); | ||||
| } | } | ||||
| uiItemL(row, "", RNA_struct_ui_icon(ptr.type)); | uiItemL(row, "", RNA_struct_ui_icon(ptr->type)); | ||||
| /* Modifier name. */ | /* Modifier 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); | ||||
| } | } | ||||
| else { | else { | ||||
| uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT); | uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT); | ||||
| } | } | ||||
| /* Display mode buttons. */ | /* Display mode buttons. */ | ||||
| if (mti->flags & eGpencilModifierTypeFlag_SupportsEditmode) { | if (mti->flags & eGpencilModifierTypeFlag_SupportsEditmode) { | ||||
| sub = uiLayoutRow(row, true); | sub = uiLayoutRow(row, true); | ||||
| 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); | ||||
| /* Extra operators. */ | /* Extra operators. */ | ||||
| // row = uiLayoutRow(layout, true); | // row = uiLayoutRow(layout, true); | ||||
| uiItemMenuF(row, "", ICON_DOWNARROW_HLT, gpencil_modifier_ops_extra_draw, md); | uiItemMenuF(row, "", ICON_DOWNARROW_HLT, gpencil_modifier_ops_extra_draw, md); | ||||
| /* Remove button. */ | /* Remove button. */ | ||||
| sub = uiLayoutRow(row, true); | sub = uiLayoutRow(row, true); | ||||
| uiLayoutSetEmboss(sub, UI_EMBOSS_NONE); | uiLayoutSetEmboss(sub, UI_EMBOSS_NONE); | ||||
| ▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines | |||||