diff options
author | Hans Goudey <h.goudey@me.com> | 2020-06-05 17:41:03 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-06-05 17:41:03 +0300 |
commit | 9b099c86123fc828a194c59ce5b8bbf5a56f9cdb (patch) | |
tree | 38937711643f5816881710debd93df2d28cf9675 /source/blender/editors/object/object_modifier.c | |
parent | 4e70e0e384c08d2d4b021758347aeb5e7a1da0dc (diff) |
UI: Drag and Drop Modifiers, Layout Updates
This patch implements the list panel system D7490 for modifiers.
It also moves modifier drawing to a callback in ModifierTypeInfo
in line with the extensible architecture refactoring goal T75724.
This adds a PanelRegister callback and utilities for registering
panels and subpanels. It also adds the callbacks for expansion saving
and drag and drop reordering described in D7490.
These utilities, callbacks, and other common UI elements shared
between modifiers live in MOD_ui_common.c.
Because modifier buttons are now in panels, we can make use of
subpanels for organization. The UI layouts also use the single
column layout style consistently used elsewhere in Blender.
Additionally, the mode-setting buttons are aligned and ordered
consistently with the outliner.
However, the large number of UI changes in this patch may mean
that additional polishing is required in master.
Thanks to William Reynish (@billreynish) who did a fair amount of the
layout work and to Julian Eisel (@Severin) for consistent help.
Differential Revision: https://developer.blender.org/D7498
Diffstat (limited to 'source/blender/editors/object/object_modifier.c')
-rw-r--r-- | source/blender/editors/object/object_modifier.c | 108 |
1 files changed, 102 insertions, 6 deletions
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 9398a5f2ce7..0bd49f74db9 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -430,7 +430,7 @@ void ED_object_modifier_clear(Main *bmain, Object *ob) DEG_relations_tag_update(bmain); } -int ED_object_modifier_move_up(ReportList *reports, Object *ob, ModifierData *md) +bool ED_object_modifier_move_up(ReportList *reports, Object *ob, ModifierData *md) { if (md->prev) { const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); @@ -440,18 +440,22 @@ int ED_object_modifier_move_up(ReportList *reports, Object *ob, ModifierData *md if (nmti->flags & eModifierTypeFlag_RequiresOriginalData) { BKE_report(reports, RPT_WARNING, "Cannot move above a modifier requiring original data"); - return 0; + return false; } } BLI_remlink(&ob->modifiers, md); BLI_insertlinkbefore(&ob->modifiers, md->prev, md); } + else { + BKE_report(reports, RPT_WARNING, "Cannot move modifier beyond the start of the list"); + return false; + } - return 1; + return true; } -int ED_object_modifier_move_down(ReportList *reports, Object *ob, ModifierData *md) +bool ED_object_modifier_move_down(ReportList *reports, Object *ob, ModifierData *md) { if (md->next) { const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); @@ -461,15 +465,53 @@ int ED_object_modifier_move_down(ReportList *reports, Object *ob, ModifierData * if (nmti->type != eModifierTypeType_OnlyDeform) { BKE_report(reports, RPT_WARNING, "Cannot move beyond a non-deforming modifier"); - return 0; + return false; } } BLI_remlink(&ob->modifiers, md); BLI_insertlinkafter(&ob->modifiers, md->next, md); } + else { + BKE_report(reports, RPT_WARNING, "Cannot move modifier beyond the end of the list"); + return false; + } - return 1; + return true; +} + +bool ED_object_modifier_move_to_index(ReportList *reports, + Object *ob, + ModifierData *md, + const int index) +{ + BLI_assert(md != NULL); + BLI_assert(index >= 0); + if (index >= BLI_listbase_count(&ob->modifiers)) { + BKE_report(reports, RPT_WARNING, "Cannot move modifier beyond the end of the stack"); + return false; + } + + int md_index = BLI_findindex(&ob->modifiers, md); + BLI_assert(md_index != -1); + if (md_index < index) { + /* Move modifier down in list. */ + for (; md_index < index; md_index++) { + if (!ED_object_modifier_move_down(reports, ob, md)) { + break; + } + } + } + else { + /* Move modifier up in list. */ + for (; md_index > index; md_index--) { + if (!ED_object_modifier_move_up(reports, ob, md)) { + break; + } + } + } + + return true; } int ED_object_modifier_convert(ReportList *UNUSED(reports), @@ -1180,6 +1222,60 @@ void OBJECT_OT_modifier_move_down(wmOperatorType *ot) /** \} */ /* ------------------------------------------------------------------- */ +/** \name Move to Index Modifier Operator + * \{ */ + +static bool modifier_move_to_index_poll(bContext *C) +{ + return edit_modifier_poll(C); +} + +static int modifier_move_to_index_exec(bContext *C, wmOperator *op) +{ + Object *ob = ED_object_active_context(C); + ModifierData *md = edit_modifier_property_get(op, ob, 0); + int index = RNA_int_get(op->ptr, "index"); + + if (!ED_object_modifier_move_to_index(op->reports, ob, md, 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 modifier_move_to_index_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) +{ + if (edit_modifier_invoke_properties(C, op)) { + return modifier_move_to_index_exec(C, op); + } + else { + return OPERATOR_CANCELLED; + } +} + +void OBJECT_OT_modifier_move_to_index(wmOperatorType *ot) +{ + ot->name = "Move Active Modifier to Index"; + ot->description = "Move the active modifier to an index in the stack"; + ot->idname = "OBJECT_OT_modifier_move_to_index"; + + ot->invoke = modifier_move_to_index_invoke; + ot->exec = modifier_move_to_index_exec; + ot->poll = modifier_move_to_index_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; + edit_modifier_properties(ot); + RNA_def_int( + ot->srna, "index", 0, 0, INT_MAX, "Index", "The index to move the modifier to", 0, INT_MAX); +} + +/** \} */ + +/* ------------------------------------------------------------------- */ /** \name Apply Modifier Operator * \{ */ |