Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2015-04-03 13:33:32 +0300
committerJoshua Leung <aligorith@gmail.com>2015-04-03 15:39:54 +0300
commitf350e9f3fcfd5818e345a8c5b9f543a052940556 (patch)
tree1fb290a74a5f89dfc3a35b23714215beb1193231 /source/blender/editors/space_action/action_data.c
parentbcf1abbc83a6673b4111f52c83cfce88597f20d5 (diff)
Code Cleanup: Split out duplicate code for finding an available NLA strip above/below
Diffstat (limited to 'source/blender/editors/space_action/action_data.c')
-rw-r--r--source/blender/editors/space_action/action_data.c174
1 files changed, 82 insertions, 92 deletions
diff --git a/source/blender/editors/space_action/action_data.c b/source/blender/editors/space_action/action_data.c
index 111cb5257da..a3e189124fb 100644
--- a/source/blender/editors/space_action/action_data.c
+++ b/source/blender/editors/space_action/action_data.c
@@ -542,6 +542,31 @@ static NlaTrack *nla_tweak_track_get(AnimData *adt)
return NULL;
}
+/* Try to find NLA Strip to use for action layer up/down tool */
+static NlaStrip *action_layer_get_nlastrip(ListBase *strips, float ctime)
+{
+ NlaStrip *strip;
+
+ for (strip = strips->first; strip; strip = strip->next) {
+ /* Can we use this? */
+ if (IN_RANGE_INCL(ctime, strip->start, strip->end)) {
+ /* in range - use this one */
+ return strip;
+ }
+ else if ((ctime < strip->start) && (strip->prev == NULL)) {
+ /* before first - use this one */
+ return strip;
+ }
+ else if ((ctime > strip->end) && (strip->next == NULL)) {
+ /* after last - use this one */
+ return strip;
+ }
+ }
+
+ /* nothing suitable found... */
+ return NULL;
+}
+
/* ********************** One Layer Up Operator ************************** */
static int action_layer_next_poll(bContext *C)
@@ -599,54 +624,37 @@ static int action_layer_next_exec(bContext *C, wmOperator *op)
/* Find next action, and hook it up */
if (act_track->next) {
NlaTrack *nlt;
- NlaStrip *strip;
- bool found = false;
/* Find next action to use */
- for (nlt = act_track->next; nlt && !found; nlt = nlt->next) {
- for (strip = nlt->strips.first; strip; strip = strip->next) {
- /* Can we use this? */
- if (IN_RANGE_INCL(ctime, strip->start, strip->end)) {
- /* in range - use this one */
- found = true;
- }
- else if ((ctime < strip->start) && (strip->prev == NULL)) {
- /* before first - use this one */
- found = true;
- }
- else if ((ctime > strip->end) && (strip->next == NULL)) {
- /* after last - use this one */
- found = true;
- }
+ for (nlt = act_track->next; nlt; nlt = nlt->next) {
+ NlaStrip *strip = action_layer_get_nlastrip(&nlt->strips, ctime);
+
+ if (strip) {
+ NlaStrip *old_strip = adt->actstrip;
- /* Apply... */
- if (found) {
- NlaStrip *old_strip = adt->actstrip;
-
- /* Exit tweakmode on old strip
- * NOTE: We need to manually clear this stuff ourselves, as tweakmode exit doesn't do it
- */
- BKE_nla_tweakmode_exit(adt);
-
- old_strip->flag &= ~(NLASTRIP_FLAG_ACTIVE | NLASTRIP_FLAG_SELECT);
- act_track->flag &= ~(NLATRACK_ACTIVE | NLATRACK_SELECTED);
-
- /* Make this one the active one instead */
- strip->flag |= (NLASTRIP_FLAG_ACTIVE | NLASTRIP_FLAG_SELECT);
- nlt->flag |= NLATRACK_ACTIVE;
-
- /* Copy over "solo" flag - This is useful for stashed actions... */
- if (act_track->flag & NLATRACK_SOLO) {
- act_track->flag &= ~NLATRACK_SOLO;
- nlt->flag |= NLATRACK_SOLO;
- }
-
- /* Enter tweakmode again - hopefully we're now "it" */
- BKE_nla_tweakmode_enter(adt);
- BLI_assert(adt->actstrip == strip);
-
- break;
+ /* Exit tweakmode on old strip
+ * NOTE: We need to manually clear this stuff ourselves, as tweakmode exit doesn't do it
+ */
+ BKE_nla_tweakmode_exit(adt);
+
+ old_strip->flag &= ~(NLASTRIP_FLAG_ACTIVE | NLASTRIP_FLAG_SELECT);
+ act_track->flag &= ~(NLATRACK_ACTIVE | NLATRACK_SELECTED);
+
+ /* Make this one the active one instead */
+ strip->flag |= (NLASTRIP_FLAG_ACTIVE | NLASTRIP_FLAG_SELECT);
+ nlt->flag |= NLATRACK_ACTIVE;
+
+ /* Copy over "solo" flag - This is useful for stashed actions... */
+ if (act_track->flag & NLATRACK_SOLO) {
+ act_track->flag &= ~NLATRACK_SOLO;
+ nlt->flag |= NLATRACK_SOLO;
}
+
+ /* Enter tweakmode again - hopefully we're now "it" */
+ BKE_nla_tweakmode_enter(adt);
+ BLI_assert(adt->actstrip == strip);
+
+ break;
}
}
}
@@ -725,10 +733,7 @@ static int action_layer_prev_exec(bContext *C, wmOperator *op)
{
AnimData *adt = actedit_animdata_from_context(C);
NlaTrack *act_track;
-
NlaTrack *nlt;
- NlaStrip *strip;
- bool found = false;
Scene *scene = CTX_data_scene(C);
float ctime = BKE_scene_frame_get(scene);
@@ -753,56 +758,41 @@ static int action_layer_prev_exec(bContext *C, wmOperator *op)
}
/* Find previous action and hook it up */
- for (; nlt && !found; nlt = nlt->prev) {
- for (strip = nlt->strips.first; strip; strip = strip->next) {
- /* Can we use this? */
- if (IN_RANGE_INCL(ctime, strip->start, strip->end)) {
- /* in range - use this one */
- found = true;
- }
- else if ((ctime < strip->start) && (strip->prev == NULL)) {
- /* before first - use this one */
- found = true;
+ for (; nlt; nlt = nlt->prev) {
+ NlaStrip *strip = action_layer_get_nlastrip(&nlt->strips, ctime);
+
+ if (strip) {
+ NlaStrip *old_strip = adt->actstrip;
+
+ /* Exit tweakmode on old strip
+ * NOTE: We need to manually clear this stuff ourselves, as tweakmode exit doesn't do it
+ */
+ BKE_nla_tweakmode_exit(adt);
+
+ if (old_strip) {
+ old_strip->flag &= ~(NLASTRIP_FLAG_ACTIVE | NLASTRIP_FLAG_SELECT);
}
- else if ((ctime > strip->end) && (strip->next == NULL)) {
- /* after last - use this one */
- found = true;
+ if (act_track) {
+ act_track->flag &= ~(NLATRACK_ACTIVE | NLATRACK_SELECTED);
}
- /* Apply... */
- if (found) {
- NlaStrip *old_strip = adt->actstrip;
-
- /* Exit tweakmode on old strip
- * NOTE: We need to manually clear this stuff ourselves, as tweakmode exit doesn't do it
- */
- BKE_nla_tweakmode_exit(adt);
-
- if (old_strip) {
- old_strip->flag &= ~(NLASTRIP_FLAG_ACTIVE | NLASTRIP_FLAG_SELECT);
- }
- if (act_track) {
- act_track->flag &= ~(NLATRACK_ACTIVE | NLATRACK_SELECTED);
- }
-
- /* Make this one the active one instead */
- strip->flag |= (NLASTRIP_FLAG_ACTIVE | NLASTRIP_FLAG_SELECT);
- nlt->flag |= NLATRACK_ACTIVE;
-
- /* Copy over "solo" flag - This is useful for stashed actions... */
- if (act_track) {
- if (act_track->flag & NLATRACK_SOLO) {
- act_track->flag &= ~NLATRACK_SOLO;
- nlt->flag |= NLATRACK_SOLO;
- }
+ /* Make this one the active one instead */
+ strip->flag |= (NLASTRIP_FLAG_ACTIVE | NLASTRIP_FLAG_SELECT);
+ nlt->flag |= NLATRACK_ACTIVE;
+
+ /* Copy over "solo" flag - This is useful for stashed actions... */
+ if (act_track) {
+ if (act_track->flag & NLATRACK_SOLO) {
+ act_track->flag &= ~NLATRACK_SOLO;
+ nlt->flag |= NLATRACK_SOLO;
}
-
- /* Enter tweakmode again - hopefully we're now "it" */
- BKE_nla_tweakmode_enter(adt);
- BLI_assert(adt->actstrip == strip);
-
- break;
}
+
+ /* Enter tweakmode again - hopefully we're now "it" */
+ BKE_nla_tweakmode_enter(adt);
+ BLI_assert(adt->actstrip == strip);
+
+ break;
}
}