diff options
author | Hans Goudey <h.goudey@me.com> | 2020-06-19 22:07:13 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-06-19 22:07:13 +0300 |
commit | bb4cef71eeaf36aa61187d47b8a8ae06ba55f7c0 (patch) | |
tree | 35700820beee851c984c9162d40952387cca5e39 /source/blender/editors | |
parent | 702e00f91088031f83cfed1528d5ed22069a9d35 (diff) |
UI: ShaderFx Drag and Drop, Layout Updates
This patch implements the list panel system D7490 for grease pencil
shader effects. It also moves their drawing to a callback in
ShaderFxTypeInfo in line with the extensible architecture refactoring
goal T75724.
The implementation is basically exactly the same as for the modifier
patch (9b099c86123fc82).
Thanks to Matias Mendiola (@mendio) for helping to develop the layout
changes.
Differential Revision: https://developer.blender.org/D7985
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_object.h | 4 | ||||
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 3 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 141 | ||||
-rw-r--r-- | source/blender/editors/object/object_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/object/object_ops.c | 1 | ||||
-rw-r--r-- | source/blender/editors/object/object_shader_fx.c | 86 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/space_buttons.c | 10 |
7 files changed, 139 insertions, 107 deletions
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index 0cc926987b2..73c58753531 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -453,6 +453,10 @@ int ED_object_shaderfx_move_down(struct ReportList *reports, int ED_object_shaderfx_move_up(struct ReportList *reports, struct Object *ob, struct ShaderFxData *fx); +bool ED_object_shaderfx_move_to_index(struct ReportList *reports, + struct Object *ob, + struct ShaderFxData *fx, + const int index); /* object_select.c */ void ED_object_select_linked_by_id(struct bContext *C, struct ID *id); diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 8e9591c1963..bcbee51246e 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -2005,6 +2005,7 @@ void uiTemplatePathBuilder(uiLayout *layout, const char *text); void uiTemplateModifiers(uiLayout *layout, struct bContext *C); void uiTemplateGpencilModifiers(uiLayout *layout, struct bContext *C); +void uiTemplateShaderFx(uiLayout *layout, struct bContext *C); void uiTemplateConstraints(uiLayout *layout, struct bContext *C, bool use_bone_constraints); uiLayout *uiTemplateGpencilModifier(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr); @@ -2017,8 +2018,6 @@ void uiTemplateGpencilColorPreview(uiLayout *layout, float scale, int filter); -uiLayout *uiTemplateShaderFx(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr); - void uiTemplateOperatorRedoProperties(uiLayout *layout, const struct bContext *C); void uiTemplateConstraintHeader(uiLayout *layout, struct PointerRNA *ptr); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 56a71970f90..c3a432d6bcc 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2090,123 +2090,52 @@ void uiTemplateGpencilModifiers(uiLayout *UNUSED(layout), bContext *C) #define ERROR_LIBDATA_MESSAGE TIP_("Can't edit external library data") /* -------------------------------------------------------------------- */ -/** \name Grease Pencil Shader FX Template +/** \name ShaderFx Template + * + * Template for building the panel layout for the active object's grease pencil shader effects. * \{ */ -static uiLayout *gpencil_draw_shaderfx(uiLayout *layout, Object *ob, ShaderFxData *md) +/** + * Function with void * argument for #uiListPanelIDFromDataFunc. + */ +static void shaderfx_panel_id(void *fx_v, char *r_idname) { - const ShaderFxTypeInfo *mti = BKE_shaderfx_get_info(md->type); - PointerRNA ptr; - uiBlock *block; - uiLayout *box, *column, *row, *sub; - uiLayout *result = NULL; - - /* create RNA pointer */ - RNA_pointer_create(&ob->id, &RNA_ShaderFx, md, &ptr); - - column = uiLayoutColumn(layout, true); - uiLayoutSetContextPointer(column, "shaderfx", &ptr); - - /* rounded header ------------------------------------------------------------------- */ - box = uiLayoutBox(column); - - row = uiLayoutRow(box, false); - block = uiLayoutGetBlock(row); - - UI_block_emboss_set(block, UI_EMBOSS_NONE); - /* Open/Close ................................. */ - uiItemR(row, &ptr, "show_expanded", 0, "", ICON_NONE); - - /* shader-type icon */ - uiItemL(row, "", RNA_struct_ui_icon(ptr.type)); - UI_block_emboss_set(block, UI_EMBOSS); - - /* effect name */ - if (mti->isDisabled && mti->isDisabled(md, 0)) { - uiLayoutSetRedAlert(row, true); - } - uiItemR(row, &ptr, "name", 0, "", ICON_NONE); - uiLayoutSetRedAlert(row, false); - - /* mode enabling buttons */ - UI_block_align_begin(block); - uiItemR(row, &ptr, "show_render", 0, "", ICON_NONE); - uiItemR(row, &ptr, "show_viewport", 0, "", ICON_NONE); - - if (mti->flags & eShaderFxTypeFlag_SupportsEditmode) { - sub = uiLayoutRow(row, true); - uiLayoutSetActive(sub, false); - uiItemR(sub, &ptr, "show_in_editmode", 0, "", ICON_NONE); - } - - UI_block_align_end(block); - - /* Up/Down + Delete ........................... */ - UI_block_align_begin(block); - uiItemO(row, "", ICON_TRIA_UP, "OBJECT_OT_shaderfx_move_up"); - uiItemO(row, "", ICON_TRIA_DOWN, "OBJECT_OT_shaderfx_move_down"); - UI_block_align_end(block); - - UI_block_emboss_set(block, UI_EMBOSS_NONE); - uiItemO(row, "", ICON_X, "OBJECT_OT_shaderfx_remove"); - UI_block_emboss_set(block, UI_EMBOSS); - - /* effect settings (under the header) --------------------------------------------------- */ - if (md->mode & eShaderFxMode_Expanded) { - /* apply/convert/copy */ - box = uiLayoutBox(column); - row = uiLayoutRow(box, false); - - /* only here obdata, the rest of effect is ob level */ - UI_block_lock_set(block, BKE_object_obdata_is_libdata(ob), ERROR_LIBDATA_MESSAGE); - - /* result is the layout block inside the box, - * that we return so that effect settings can be drawn */ - result = uiLayoutColumn(box, false); - block = uiLayoutAbsoluteBlock(box); - } - - /* error messages */ - if (md->error) { - box = uiLayoutBox(column); - row = uiLayoutRow(box, false); - uiItemL(row, md->error, ICON_ERROR); - } - - return result; + ShaderFxData *fx = (ShaderFxData *)fx_v; + BKE_shaderfxType_panel_id(fx->type, r_idname); } -uiLayout *uiTemplateShaderFx(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +/** + * Check if the shader effect panels don't match the data and rebuild the panels if so. + */ +void uiTemplateShaderFx(uiLayout *UNUSED(layout), bContext *C) { - Object *ob; - ShaderFxData *fx, *vfx; - int i; + ScrArea *sa = CTX_wm_area(C); + ARegion *region = CTX_wm_region(C); + Object *ob = get_context_object(C); + ListBase *shaderfx = &ob->shader_fx; - /* verify we have valid data */ - if (!RNA_struct_is_a(ptr->type, &RNA_ShaderFx)) { - RNA_warning("Expected shader fx on object"); - return NULL; - } + bool panels_match = UI_panel_list_matches_data(region, shaderfx, shaderfx_panel_id); - ob = (Object *)ptr->owner_id; - fx = ptr->data; + if (!panels_match) { + UI_panels_free_instanced(C, region); + ShaderFxData *fx = shaderfx->first; + for (int i = 0; fx; i++, fx = fx->next) { + char panel_idname[MAX_NAME]; + shaderfx_panel_id(fx, panel_idname); - if (!ob || !(GS(ob->id.name) == ID_OB)) { - RNA_warning("Expected shader fx on object"); - return NULL; + Panel *new_panel = UI_panel_add_instanced(sa, region, ®ion->panels, panel_idname, i); + if (new_panel != NULL) { + UI_panel_set_expand_from_list_data(C, new_panel); + } + } } - - UI_block_lock_set(uiLayoutGetBlock(layout), (ob && ID_IS_LINKED(ob)), ERROR_LIBDATA_MESSAGE); - - /* find modifier and draw it */ - vfx = ob->shader_fx.first; - for (i = 0; vfx; i++, vfx = vfx->next) { - if (fx == vfx) { - return gpencil_draw_shaderfx(layout, ob, fx); + else { + /* The expansion might have been changed elsewhere, so we still need to set it. */ + LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { + if ((panel->type != NULL) && (panel->type->flag & PNL_INSTANCED)) + UI_panel_set_expand_from_list_data(C, panel); } } - - return NULL; } /** \} */ @@ -2515,6 +2444,8 @@ void uiTemplateOperatorRedoProperties(uiLayout *layout, const bContext *C) /** \name Constraint Header Template * \{ */ +#define ERROR_LIBDATA_MESSAGE TIP_("Can't edit external library data") + static void constraint_active_func(bContext *UNUSED(C), void *ob_v, void *con_v) { ED_object_constraint_active_set(ob_v, con_v); diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 8feeb3b6067..3dbd1de123d 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -199,6 +199,7 @@ void OBJECT_OT_shaderfx_add(struct wmOperatorType *ot); void OBJECT_OT_shaderfx_remove(struct wmOperatorType *ot); void OBJECT_OT_shaderfx_move_up(struct wmOperatorType *ot); void OBJECT_OT_shaderfx_move_down(struct wmOperatorType *ot); +void OBJECT_OT_shaderfx_move_to_index(struct wmOperatorType *ot); /* object_constraint.c */ void OBJECT_OT_constraint_add(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 1060a808cfe..29058175e25 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -161,6 +161,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_shaderfx_remove); WM_operatortype_append(OBJECT_OT_shaderfx_move_up); WM_operatortype_append(OBJECT_OT_shaderfx_move_down); + WM_operatortype_append(OBJECT_OT_shaderfx_move_to_index); WM_operatortype_append(OBJECT_OT_correctivesmooth_bind); WM_operatortype_append(OBJECT_OT_meshdeform_bind); diff --git a/source/blender/editors/object/object_shader_fx.c b/source/blender/editors/object/object_shader_fx.c index 5db4a5a4f57..5abba70e008 100644 --- a/source/blender/editors/object/object_shader_fx.c +++ b/source/blender/editors/object/object_shader_fx.c @@ -200,6 +200,40 @@ int ED_object_shaderfx_move_down(ReportList *UNUSED(reports), Object *ob, Shader return 1; } +bool ED_object_shaderfx_move_to_index(ReportList *reports, + Object *ob, + ShaderFxData *fx, + const int index) +{ + BLI_assert(fx != NULL); + BLI_assert(index >= 0); + if (index >= BLI_listbase_count(&ob->shader_fx)) { + BKE_report(reports, RPT_WARNING, "Cannot move effect beyond the end of the stack"); + return false; + } + + int fx_index = BLI_findindex(&ob->shader_fx, fx); + BLI_assert(fx_index != -1); + if (fx_index < index) { + /* Move shaderfx down in list. */ + for (; fx_index < index; fx_index++) { + if (!ED_object_shaderfx_move_down(reports, ob, fx)) { + break; + } + } + } + else { + /* Move shaderfx up in list. */ + for (; fx_index > index; fx_index--) { + if (!ED_object_shaderfx_move_up(reports, ob, fx)) { + break; + } + } + } + + return true; +} + /************************ add effect operator *********************/ static int shaderfx_add_exec(bContext *C, wmOperator *op) @@ -487,3 +521,55 @@ void OBJECT_OT_shaderfx_move_down(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; edit_shaderfx_properties(ot); } + +/************************ move shaderfx to index operator *********************/ + +static bool shaderfx_move_to_index_poll(bContext *C) +{ + return edit_shaderfx_poll_generic(C, &RNA_ShaderFx, 0); +} + +static int shaderfx_move_to_index_exec(bContext *C, wmOperator *op) +{ + Object *ob = ED_object_active_context(C); + ShaderFxData *fx = edit_shaderfx_property_get(op, ob, 0); + int index = RNA_int_get(op->ptr, "index"); + + if (!fx || !ED_object_shaderfx_move_to_index(op->reports, ob, fx, index)) { + return OPERATOR_CANCELLED; + } + + DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); + + return OPERATOR_FINISHED; +} + +static int shaderfx_move_to_index_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) +{ + if (edit_shaderfx_invoke_properties(C, op)) { + return shaderfx_move_to_index_exec(C, op); + } + else { + return OPERATOR_CANCELLED; + } +} + +void OBJECT_OT_shaderfx_move_to_index(wmOperatorType *ot) +{ + ot->name = "Move Effect to Index"; + ot->idname = "OBJECT_OT_shaderfx_move_to_index"; + ot->description = + "Change the effect's position in the list so it evaluates after the set number of " + "others"; + + ot->invoke = shaderfx_move_to_index_invoke; + ot->exec = shaderfx_move_to_index_exec; + ot->poll = shaderfx_move_to_index_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; + edit_shaderfx_properties(ot); + RNA_def_int( + ot->srna, "index", 0, 0, INT_MAX, "Index", "The index to move the effect to", 0, INT_MAX); +} diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index 2cc9679dd3f..71b86996989 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -33,6 +33,7 @@ #include "BKE_gpencil_modifier.h" /* Types for registering panels. */ #include "BKE_modifier.h" #include "BKE_screen.h" +#include "BKE_shader_fx.h" #include "ED_screen.h" #include "ED_space_api.h" @@ -648,6 +649,15 @@ void ED_spacetype_buttons(void) mti->panelRegister(art); } } + for (int i = 0; i < NUM_SHADER_FX_TYPES; i++) { + if (i == eShaderFxType_Light_deprecated) { + continue; + } + const ShaderFxTypeInfo *fxti = BKE_shaderfx_get_info(i); + if (fxti != NULL && fxti->panelRegister != NULL) { + fxti->panelRegister(art); + } + } /* regions: header */ art = MEM_callocN(sizeof(ARegionType), "spacetype buttons region"); |