Fix T41467: Modifier view buttons changing positions.
authorBastien Montagne <montagne29@wanadoo.fr>
Sun, 17 Aug 2014 07:35:57 +0000 (09:35 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Sun, 17 Aug 2014 07:50:45 +0000 (09:50 +0200)
Commits early in this year (to save some space) broke this. Hopefully this time
it works in all cases - lastCageIndex is no more influenced by realtime/edit active states.
Also, inactivate buttons instead of hiding them, can be useful to set those data
even though it does not have any immediate effect.

Took the opportunity to switch cage buttons to RNA, btw.

source/blender/blenkernel/intern/modifier.c
source/blender/editors/interface/interface_templates.c
source/blender/makesrna/intern/rna_modifier.c

index 074a91ea2cf2a06086bbcb240ef0a4993d83ccdd..b4d9561ec5d072462638a7c84353840518a06159 100644 (file)
@@ -353,6 +353,7 @@ int modifiers_getCageIndex(struct Scene *scene, Object *ob, int *r_lastPossibleC
        /* Find the last modifier acting on the cage. */
        for (i = 0; md; i++, md = md->next) {
                ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+               bool supports_mapping;
 
                md->scene = scene;
 
@@ -360,16 +361,17 @@ int modifiers_getCageIndex(struct Scene *scene, Object *ob, int *r_lastPossibleC
                if (!(mti->flags & eModifierTypeFlag_SupportsEditmode)) continue;
                if (md->mode & eModifierMode_DisableTemporary) continue;
 
+               supports_mapping = modifier_supportsMapping(md);
+               if (r_lastPossibleCageIndex && supports_mapping) {
+                       *r_lastPossibleCageIndex = i;
+               }
+
                if (!(md->mode & eModifierMode_Realtime)) continue;
                if (!(md->mode & eModifierMode_Editmode)) continue;
 
-               if (!modifier_supportsMapping(md))
+               if (!supports_mapping)
                        break;
 
-               if (r_lastPossibleCageIndex) {
-                       *r_lastPossibleCageIndex = i;
-               }
-
                if (md->mode & eModifierMode_OnCage)
                        cageIndex = i;
        }
index 7f85a2314cafef789b2e6acb6f2421cbf9eeb5c5..028d34d1f80e39622a99f85b7362f16c2ed9638b 100644 (file)
@@ -756,28 +756,6 @@ void uiTemplatePathBuilder(uiLayout *layout, PointerRNA *ptr, const char *propna
 
 #define ERROR_LIBDATA_MESSAGE IFACE_("Can't edit external libdata")
 
-static void modifiers_setOnCage(bContext *C, void *ob_v, void *md_v)
-{
-       Scene *scene = CTX_data_scene(C);
-       Object *ob = ob_v;
-       ModifierData *md = md_v;
-       int i, cageIndex = modifiers_getCageIndex(scene, ob, NULL, 0);
-
-       /* undo button operation */
-       md->mode ^= eModifierMode_OnCage;
-
-       for (i = 0, md = ob->modifiers.first; md; ++i, md = md->next) {
-               if (md == md_v) {
-                       if (i >= cageIndex)
-                               md->mode ^= eModifierMode_OnCage;
-                       break;
-               }
-       }
-
-       WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
-       DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-}
-
 static void modifiers_convertToReal(bContext *C, void *ob_v, void *md_v)
 {
        Object *ob = ob_v;
@@ -834,7 +812,7 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
        PointerRNA ptr;
        uiBut *but;
        uiBlock *block;
-       uiLayout *box, *column, *row;
+       uiLayout *box, *column, *row, *sub;
        uiLayout *result = NULL;
        int isVirtual = (md->mode & eModifierMode_Virtual);
        char str[128];
@@ -886,29 +864,22 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
                        uiItemR(row, &ptr, "show_render", 0, "", ICON_NONE);
                        uiItemR(row, &ptr, "show_viewport", 0, "", ICON_NONE);
                        
-                       if (mti->flags & eModifierTypeFlag_SupportsEditmode)
-                               uiItemR(row, &ptr, "show_in_editmode", 0, "", ICON_NONE);
+                       if (mti->flags & eModifierTypeFlag_SupportsEditmode) {
+                               sub = uiLayoutRow(row, true);
+                               if (!(md->mode & eModifierMode_Realtime)) {
+                                       uiLayoutSetActive(sub, false);
+                               }
+                               uiItemR(sub, &ptr, "show_in_editmode", 0, "", ICON_NONE);
+                       }
                }
 
                if (ob->type == OB_MESH) {
-                       if (modifier_couldBeCage(scene, md) && (index <= lastCageIndex)) {
-                               /* -- convert to rna ? */
-                               but = uiDefIconButBitI(block, TOG, eModifierMode_OnCage, 0, ICON_MESH_DATA, 0, 0,
-                                                      UI_UNIT_X - 2, UI_UNIT_Y, &md->mode, 0.0, 0.0, 0.0, 0.0,
-                                                      TIP_("Adjust edit cage to modifier result"));
-                               if (index < cageIndex)
-                                       uiButSetFlag(but, UI_BUT_DISABLED);
-                               uiButSetFunc(but, modifiers_setOnCage, ob, md);
-                       }
-                       else if (modifier_supportsCage(scene, md) && (index <= lastCageIndex)) {
-                               uiBlockEndAlign(block);
-
-                               /* place holder button */
-                               uiBlockSetEmboss(block, UI_EMBOSSN);
-                               but = uiDefIconBut(block, BUT, 0, ICON_NONE, 0, 0, UI_UNIT_X - 2, UI_UNIT_Y,
-                                                  NULL, 0.0, 0.0, 0.0, 0.0, NULL);
-                               uiButSetFlag(but, UI_BUT_DISABLED);
-                               uiBlockSetEmboss(block, UI_EMBOSS);
+                       if (modifier_supportsCage(scene, md) && (index <= lastCageIndex)) {
+                               sub = uiLayoutRow(row, true);
+                               if (index < cageIndex || !modifier_couldBeCage(scene, md)) {
+                                       uiLayoutSetActive(sub, false);
+                               }
+                               uiItemR(sub, &ptr, "show_on_cage", 0, "", ICON_NONE);
                        }
                } /* tessellation point for curve-typed objects */
                else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
@@ -918,7 +889,7 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
                                 * message for this modifiers */
                                but = uiDefIconButBitI(block, TOG, eModifierMode_ApplyOnSpline, 0, ICON_SURFACE_DATA, 0, 0,
                                                       UI_UNIT_X - 2, UI_UNIT_Y, &md->mode, 0.0, 0.0, 0.0, 0.0,
-                                                      TIP_("This modifier could be applied on splines' points only"));
+                                                      TIP_("This modifier can only be applied on splines' points"));
                                uiButSetFlag(but, UI_BUT_DISABLED);
                        }
                        else if (mti->type != eModifierTypeType_Constructive) {
index 6fd89e53b431dd9f5b52a30bd9a42ec5a3475cfb..4911c106f53ab6ef931c6c6642d455353c58bef4 100644 (file)
@@ -3712,7 +3712,8 @@ void RNA_def_modifier(BlenderRNA *brna)
        
        prop = RNA_def_property(srna, "show_on_cage", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "mode", eModifierMode_OnCage);
-       RNA_def_property_ui_text(prop, "On Cage", "Enable direct editing of modifier control cage");
+       RNA_def_property_ui_text(prop, "On Cage", "Adjust edit cage to modifier result");
+       RNA_def_property_ui_icon(prop, ICON_MESH_DATA, 0);
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
        
        prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);