Action Group Colors for Bones (Part 2)
authorJoshua Leung <aligorith@gmail.com>
Fri, 1 Jun 2012 13:54:44 +0000 (13:54 +0000)
committerJoshua Leung <aligorith@gmail.com>
Fri, 1 Jun 2012 13:54:44 +0000 (13:54 +0000)
Colors used by Bone Groups are now copied/assigned to Action Groups too when
they're created now. This completes the work started in r.46960 to restore this
functionality from 2.48.

Currently, there is no control over when/whether these colors are copied over
(although it is possible to disable the display of these colors for relevant
animation editors if desired). Originally I was going to make this a more
generic Keying Sets feature, though that turned out to be a bit too complex to
manage.

Other notes:
* Split out the code for copying colors to a common library function

source/blender/blenkernel/BKE_action.h
source/blender/blenkernel/intern/action.c
source/blender/editors/animation/anim_channels_defines.c
source/blender/editors/animation/keyframes_general.c
source/blender/editors/animation/keyframing.c
source/blender/editors/include/ED_keyframing.h
source/blender/editors/object/object_relations.c
source/blender/makesrna/intern/rna_action.c
source/blender/makesrna/intern/rna_pose.c

index c1361788379c28acb4ba9e52124fcf3f310abfd4..527d85c7cf3ed5c415b8f8737d19f93502c002c9 100644 (file)
@@ -112,6 +112,9 @@ struct bActionGroup *get_active_actiongroup(struct bAction *act);
 /* Make the given Action Group the active one */
 void set_active_action_group(struct bAction *act, struct bActionGroup *agrp, short select);
 
+/* Sync colors used for action/bone group with theme settings */
+void action_group_colors_sync(struct bActionGroup *grp);
+
 /* Add a new action group with the given name to the action */
 struct bActionGroup *action_groups_add_new(struct bAction *act, const char name[]);
 
index 233647c9ec6598aadeca60e79eb239da06b432f8..b3d2e3371f49f2eb32743f4409bfb6dc20fad018 100644 (file)
@@ -252,6 +252,31 @@ void set_active_action_group(bAction *act, bActionGroup *agrp, short select)
        }
 }
 
+/* Sync colors used for action/bone group with theme settings */
+void action_group_colors_sync(bActionGroup *grp)
+{
+       /* only do color copying if using a custom color (i.e. not default color)  */
+       if (grp->customCol) {
+               if (grp->customCol > 0) {
+                       /* copy theme colors on-to group's custom color in case user tries to edit color */
+                       bTheme *btheme = U.themes.first;
+                       ThemeWireColor *col_set = &btheme->tarm[(grp->customCol - 1)];
+                       
+                       memcpy(&grp->cs, col_set, sizeof(ThemeWireColor));
+               }
+               else {
+                       /* init custom colors with a generic multi-color rgb set, if not initialized already
+                        * (for custom color set) */
+                       if (grp->cs.solid[0] == 0) {
+                               /* define for setting colors in theme below */
+                               rgba_char_args_set(grp->cs.solid, 0xff, 0x00, 0x00, 255);
+                               rgba_char_args_set(grp->cs.select, 0x81, 0xe6, 0x14, 255);
+                               rgba_char_args_set(grp->cs.active, 0x18, 0xb6, 0xe0, 255);
+                       }
+               }
+       }
+}
+
 /* Add a new action group with the given name to the action */
 bActionGroup *action_groups_add_new(bAction *act, const char name[])
 {
@@ -409,10 +434,9 @@ void action_groups_clear_tempflags(bAction *act)
 
 /* *************** Pose channels *************** */
 
-/* usually used within a loop, so we got a N^2 slowdown */
 bPoseChannel *BKE_pose_channel_find_name(const bPose *pose, const char *name)
 {
-       if (ELEM(NULL, pose, name) || (name[0] == 0))
+       if (ELEM(NULL, pose, name) || (name[0] == '\0'))
                return NULL;
        
        if (pose->chanhash)
index 08672a2266652310c74b367fb9acc00cb05f088b..386313b1d3c83e482b232508fac75ad7ebd67eaa 100644 (file)
@@ -3060,7 +3060,7 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi
                /* find or create new F-Curve */
                // XXX is the group name for this ok?
                bAction *act = verify_adt_action((ID *)key, 1);
-               FCurve *fcu = verify_fcurve(act, NULL, rna_path, 0, 1);
+               FCurve *fcu = verify_fcurve(act, NULL, &ptr, rna_path, 0, 1);
                
                /* set the special 'replace' flag if on a keyframe */
                if (fcurve_frame_has_keyframe(fcu, cfra, 0))
index 05c87e98f9b16031a31bd401d8987a57263057e5..ac37b6c4141de4cc2e656bb297d968afcf7c3eef 100644 (file)
@@ -671,7 +671,7 @@ static void paste_animedit_keys_fcurve(FCurve *fcu, tAnimCopybufItem *aci, float
        BezTriple *bezt;
        int i;
 
-       /* First de-select existing FCuvre */
+       /* First de-select existing FCurve's keyframes */
        for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) {
                bezt->f2 &= ~SELECT;
        }
index 2a68d32557a485e2913633ffe49a025c7dd93a28..b8601419d51c0a02f6eaa74105543e99dbca6e93 100644 (file)
@@ -150,9 +150,10 @@ bAction *verify_adt_action(ID *id, short add)
 /* Get (or add relevant data to be able to do so) F-Curve from the Active Action, 
  * for the given Animation Data block. This assumes that all the destinations are valid.
  */
-FCurve *verify_fcurve(bAction *act, const char group[], const char rna_path[], const int array_index, short add)
+FCurve *verify_fcurve(bAction *act, const char group[], PointerRNA *ptr, 
+                      const char rna_path[], const int array_index, short add)
 {
-       bActionGroup *grp;
+       bActionGroup *agrp;
        FCurve *fcu;
        
        /* sanity checks */
@@ -183,14 +184,30 @@ FCurve *verify_fcurve(bAction *act, const char group[], const char rna_path[], c
                /* if a group name has been provided, try to add or find a group, then add F-Curve to it */
                if (group) {
                        /* try to find group */
-                       grp = BKE_action_group_find_name(act, group);
+                       agrp = BKE_action_group_find_name(act, group);
                        
                        /* no matching groups, so add one */
-                       if (grp == NULL)
-                               grp = action_groups_add_new(act, group);
+                       if (agrp == NULL) {
+                               agrp = action_groups_add_new(act, group);
+                               
+                               /* sync bone group colors if applicable */
+                               if (ptr && (ptr->type == &RNA_PoseBone)) {
+                                       Object *ob = (Object *)ptr->id.data;
+                                       bPoseChannel *pchan = (bPoseChannel *)ptr->data;
+                                       bPose *pose = ob->pose;
+                                       bActionGroup *grp;
+                                       
+                                       /* find bone group (if present), and use the color from that */
+                                       grp = (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
+                                       if (grp) {
+                                               agrp->customCol = grp->customCol;
+                                               action_group_colors_sync(agrp);
+                                       }
+                               }
+                       }
                        
                        /* add F-Curve to group */
-                       action_groups_add_channel(act, grp, fcu);
+                       action_groups_add_channel(act, agrp, fcu);
                }
                else {
                        /* just add F-Curve to end of Action's list */
@@ -939,7 +956,7 @@ short insert_keyframe(ReportList *reports, ID *id, bAction *act, const char grou
                 *      - if we're replacing keyframes only, DO NOT create new F-Curves if they do not exist yet
                 *        but still try to get the F-Curve if it exists...
                 */
-               fcu = verify_fcurve(act, group, rna_path, array_index, (flag & INSERTKEY_REPLACE) == 0);
+               fcu = verify_fcurve(act, group, &ptr, rna_path, array_index, (flag & INSERTKEY_REPLACE) == 0);
                
                /* we may not have a F-Curve when we're replacing only... */
                if (fcu) {
@@ -1027,7 +1044,7 @@ short delete_keyframe(ReportList *reports, ID *id, bAction *act, const char grou
        
        /* will only loop once unless the array index was -1 */
        for (; array_index < array_index_max; array_index++) {
-               FCurve *fcu = verify_fcurve(act, group, rna_path, array_index, 0);
+               FCurve *fcu = verify_fcurve(act, group, &ptr, rna_path, array_index, 0);
                short found = -1;
                int i;
                
index be5ad5b0c70c23d53620081d837b13d92dd0c292..95fad17274e87ab4a71c3caeb792b762ce740704 100644 (file)
@@ -75,7 +75,8 @@ struct bAction *verify_adt_action(struct ID *id, short add);
 /* Get (or add relevant data to be able to do so) F-Curve from the given Action. 
  * This assumes that all the destinations are valid.
  */
-struct FCurve *verify_fcurve(struct bAction *act, const char group[], const char rna_path[], const int array_index, short add);
+struct FCurve *verify_fcurve(struct bAction *act, const char group[], struct PointerRNA *ptr,
+                             const char rna_path[], const int array_index, short add);
 
 /* -------- */
 
index 34fb2ca6c32496f14307de4aa49453713cfe0284..85b9d78c657d61506d25e7f13aee19b12b11ba91 100644 (file)
@@ -542,7 +542,7 @@ int ED_object_parent_set(ReportList *reports, Main *bmain, Scene *scene, Object
                        if (partype == PAR_FOLLOW) {
                                /* get or create F-Curve */
                                bAction *act = verify_adt_action(&cu->id, 1);
-                               FCurve *fcu = verify_fcurve(act, NULL, "eval_time", 0, 1);
+                               FCurve *fcu = verify_fcurve(act, NULL, NULL, "eval_time", 0, 1);
                                
                                /* setup dummy 'generator' modifier here to get 1-1 correspondence still working */
                                if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first)
index b63109ed13793ffd254e8e559324be5e29e7a8b5..00a257ab4f956d1dadb1ec74242b8e9f9f4411e6 100644 (file)
@@ -104,12 +104,12 @@ static FCurve *rna_Action_fcurve_new(bAction *act, ReportList *reports, const ch
        }
 
        /* annoying, check if this exists */
-       if (verify_fcurve(act, group, data_path, index, 0)) {
+       if (verify_fcurve(act, group, NULL, data_path, index, 0)) {
                BKE_reportf(reports, RPT_ERROR, "F-Curve '%s[%d]' already exists in action '%s'", data_path,
                            index, act->id.name + 2);
                return NULL;
        }
-       return verify_fcurve(act, group, data_path, index, 1);
+       return verify_fcurve(act, group, NULL, data_path, index, 1);
 }
 
 static void rna_Action_fcurve_remove(bAction *act, ReportList *reports, FCurve *fcu)
index 83d40b26cd042fc6125c6c3d032f402037566df8..5139e17b06ddb57efa13fd87686b045cbfd9b4b8 100644 (file)
@@ -139,31 +139,12 @@ void rna_ActionGroup_colorset_set(PointerRNA *ptr, int value)
 {
        bActionGroup *grp = ptr->data;
        
-       /* if valid value, set the new enum value, then copy the relevant colors? */
-       if ((value >= -1) && (value < 21))
+       /* ensure only valid values get set */
+       if ((value >= -1) && (value < 21)) {
                grp->customCol = value;
-       else
-               return;
        
-       /* only do color copying if using a custom color (i.e. not default color)  */
-       if (grp->customCol) {
-               if (grp->customCol > 0) {
-                       /* copy theme colors on-to group's custom color in case user tries to edit color */
-                       bTheme *btheme = U.themes.first;
-                       ThemeWireColor *col_set = &btheme->tarm[(grp->customCol - 1)];
-                       
-                       memcpy(&grp->cs, col_set, sizeof(ThemeWireColor));
-               }
-               else {
-                       /* init custom colors with a generic multi-color rgb set, if not initialized already
-                        * (for custom color set) */
-                       if (grp->cs.solid[0] == 0) {
-                               /* define for setting colors in theme below */
-                               rgba_char_args_set(grp->cs.solid, 0xff, 0x00, 0x00, 255);
-                               rgba_char_args_set(grp->cs.select, 0x81, 0xe6, 0x14, 255);
-                               rgba_char_args_set(grp->cs.active, 0x18, 0xb6, 0xe0, 255);
-                       }
-               }
+               /* sync colors stored with theme colors based on the index specified */
+               action_group_colors_sync(grp);
        }
 }