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:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/editors/space_nla/nla_select.c
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/editors/space_nla/nla_select.c')
-rw-r--r--source/blender/editors/space_nla/nla_select.c984
1 files changed, 494 insertions, 490 deletions
diff --git a/source/blender/editors/space_nla/nla_select.c b/source/blender/editors/space_nla/nla_select.c
index f326637f1cd..0df0c5a99da 100644
--- a/source/blender/editors/space_nla/nla_select.c
+++ b/source/blender/editors/space_nla/nla_select.c
@@ -21,7 +21,6 @@
* \ingroup spnla
*/
-
#include <string.h>
#include <stdio.h>
@@ -49,28 +48,27 @@
#include "UI_view2d.h"
-#include "nla_intern.h" // own include
+#include "nla_intern.h" // own include
/* ******************** Utilities ***************************************** */
/* Convert SELECT_* flags to ACHANNEL_SETFLAG_* flags */
static short selmodes_to_flagmodes(short sel)
{
- /* convert selection modes to selection modes */
- switch (sel) {
- case SELECT_SUBTRACT:
- return ACHANNEL_SETFLAG_CLEAR;
-
- case SELECT_INVERT:
- return ACHANNEL_SETFLAG_INVERT;
-
- case SELECT_ADD:
- default:
- return ACHANNEL_SETFLAG_ADD;
- }
+ /* convert selection modes to selection modes */
+ switch (sel) {
+ case SELECT_SUBTRACT:
+ return ACHANNEL_SETFLAG_CLEAR;
+
+ case SELECT_INVERT:
+ return ACHANNEL_SETFLAG_INVERT;
+
+ case SELECT_ADD:
+ default:
+ return ACHANNEL_SETFLAG_ADD;
+ }
}
-
/* ******************** Deselect All Operator ***************************** */
/* This operator works in one of three ways:
* 1) (de)select all (AKEY) - test if select all or deselect all
@@ -79,9 +77,9 @@ static short selmodes_to_flagmodes(short sel)
*/
enum {
- DESELECT_STRIPS_NOTEST = 0,
- DESELECT_STRIPS_TEST,
- DESELECT_STRIPS_CLEARACTIVE,
+ DESELECT_STRIPS_NOTEST = 0,
+ DESELECT_STRIPS_TEST,
+ DESELECT_STRIPS_CLEARACTIVE,
} /*eDeselectNlaStrips*/;
/* Deselects strips in the NLA Editor
@@ -95,113 +93,113 @@ enum {
*/
static void deselect_nla_strips(bAnimContext *ac, short test, short sel)
{
- ListBase anim_data = {NULL, NULL};
- bAnimListElem *ale;
- int filter;
- short smode;
-
- /* determine type-based settings */
- // FIXME: double check whether ANIMFILTER_LIST_VISIBLE is needed!
- filter = (ANIMFILTER_DATA_VISIBLE);
-
- /* filter data */
- ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
-
- /* See if we should be selecting or deselecting */
- if (test == DESELECT_STRIPS_TEST) {
- for (ale = anim_data.first; ale; ale = ale->next) {
- NlaTrack *nlt = (NlaTrack *)ale->data;
- NlaStrip *strip;
-
- /* if any strip is selected, break out, since we should now be deselecting */
- for (strip = nlt->strips.first; strip; strip = strip->next) {
- if (strip->flag & NLASTRIP_FLAG_SELECT) {
- sel = SELECT_SUBTRACT;
- break;
- }
- }
-
- if (sel == SELECT_SUBTRACT)
- break;
- }
- }
-
- /* convert selection modes to selection modes */
- smode = selmodes_to_flagmodes(sel);
-
- /* Now set the flags */
- for (ale = anim_data.first; ale; ale = ale->next) {
- NlaTrack *nlt = (NlaTrack *)ale->data;
- NlaStrip *strip;
-
- /* apply same selection to all strips */
- for (strip = nlt->strips.first; strip; strip = strip->next) {
- /* set selection */
- if (test != DESELECT_STRIPS_CLEARACTIVE)
- ACHANNEL_SET_FLAG(strip, smode, NLASTRIP_FLAG_SELECT);
-
- /* clear active flag */
- // TODO: for clear active, do we want to limit this to only doing this on a certain set of tracks though?
- strip->flag &= ~NLASTRIP_FLAG_ACTIVE;
- }
- }
-
- /* Cleanup */
- ANIM_animdata_freelist(&anim_data);
+ ListBase anim_data = {NULL, NULL};
+ bAnimListElem *ale;
+ int filter;
+ short smode;
+
+ /* determine type-based settings */
+ // FIXME: double check whether ANIMFILTER_LIST_VISIBLE is needed!
+ filter = (ANIMFILTER_DATA_VISIBLE);
+
+ /* filter data */
+ ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+
+ /* See if we should be selecting or deselecting */
+ if (test == DESELECT_STRIPS_TEST) {
+ for (ale = anim_data.first; ale; ale = ale->next) {
+ NlaTrack *nlt = (NlaTrack *)ale->data;
+ NlaStrip *strip;
+
+ /* if any strip is selected, break out, since we should now be deselecting */
+ for (strip = nlt->strips.first; strip; strip = strip->next) {
+ if (strip->flag & NLASTRIP_FLAG_SELECT) {
+ sel = SELECT_SUBTRACT;
+ break;
+ }
+ }
+
+ if (sel == SELECT_SUBTRACT)
+ break;
+ }
+ }
+
+ /* convert selection modes to selection modes */
+ smode = selmodes_to_flagmodes(sel);
+
+ /* Now set the flags */
+ for (ale = anim_data.first; ale; ale = ale->next) {
+ NlaTrack *nlt = (NlaTrack *)ale->data;
+ NlaStrip *strip;
+
+ /* apply same selection to all strips */
+ for (strip = nlt->strips.first; strip; strip = strip->next) {
+ /* set selection */
+ if (test != DESELECT_STRIPS_CLEARACTIVE)
+ ACHANNEL_SET_FLAG(strip, smode, NLASTRIP_FLAG_SELECT);
+
+ /* clear active flag */
+ // TODO: for clear active, do we want to limit this to only doing this on a certain set of tracks though?
+ strip->flag &= ~NLASTRIP_FLAG_ACTIVE;
+ }
+ }
+
+ /* Cleanup */
+ ANIM_animdata_freelist(&anim_data);
}
/* ------------------- */
static int nlaedit_deselectall_exec(bContext *C, wmOperator *op)
{
- bAnimContext ac;
-
- /* get editor data */
- if (ANIM_animdata_get_context(C, &ac) == 0)
- return OPERATOR_CANCELLED;
-
- /* 'standard' behavior - check if selected, then apply relevant selection */
- const int action = RNA_enum_get(op->ptr, "action");
- switch (action) {
- case SEL_TOGGLE:
- deselect_nla_strips(&ac, DESELECT_STRIPS_TEST, SELECT_ADD);
- break;
- case SEL_SELECT:
- deselect_nla_strips(&ac, DESELECT_STRIPS_NOTEST, SELECT_ADD);
- break;
- case SEL_DESELECT:
- deselect_nla_strips(&ac, DESELECT_STRIPS_NOTEST, SELECT_SUBTRACT);
- break;
- case SEL_INVERT:
- deselect_nla_strips(&ac, DESELECT_STRIPS_NOTEST, SELECT_INVERT);
- break;
- default:
- BLI_assert(0);
- break;
- }
-
- /* set notifier that things have changed */
- WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_SELECTED, NULL);
-
- return OPERATOR_FINISHED;
+ bAnimContext ac;
+
+ /* get editor data */
+ if (ANIM_animdata_get_context(C, &ac) == 0)
+ return OPERATOR_CANCELLED;
+
+ /* 'standard' behavior - check if selected, then apply relevant selection */
+ const int action = RNA_enum_get(op->ptr, "action");
+ switch (action) {
+ case SEL_TOGGLE:
+ deselect_nla_strips(&ac, DESELECT_STRIPS_TEST, SELECT_ADD);
+ break;
+ case SEL_SELECT:
+ deselect_nla_strips(&ac, DESELECT_STRIPS_NOTEST, SELECT_ADD);
+ break;
+ case SEL_DESELECT:
+ deselect_nla_strips(&ac, DESELECT_STRIPS_NOTEST, SELECT_SUBTRACT);
+ break;
+ case SEL_INVERT:
+ deselect_nla_strips(&ac, DESELECT_STRIPS_NOTEST, SELECT_INVERT);
+ break;
+ default:
+ BLI_assert(0);
+ break;
+ }
+
+ /* set notifier that things have changed */
+ WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_SELECTED, NULL);
+
+ return OPERATOR_FINISHED;
}
void NLA_OT_select_all(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "(De)select All";
- ot->idname = "NLA_OT_select_all";
- ot->description = "Select or deselect all NLA-Strips";
+ /* identifiers */
+ ot->name = "(De)select All";
+ ot->idname = "NLA_OT_select_all";
+ ot->description = "Select or deselect all NLA-Strips";
- /* api callbacks */
- ot->exec = nlaedit_deselectall_exec;
- ot->poll = nlaop_poll_tweakmode_off;
+ /* api callbacks */
+ ot->exec = nlaedit_deselectall_exec;
+ ot->poll = nlaop_poll_tweakmode_off;
- /* flags */
- ot->flag = OPTYPE_REGISTER /*|OPTYPE_UNDO*/;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER /*|OPTYPE_UNDO*/;
- /* properties */
- WM_operator_properties_select_all(ot);
+ /* properties */
+ WM_operator_properties_select_all(ot);
}
/* ******************** Box Select Operator **************************** */
@@ -214,138 +212,134 @@ void NLA_OT_select_all(wmOperatorType *ot)
/* defines for box_select mode */
enum {
- NLA_BOXSEL_ALLSTRIPS = 0,
- NLA_BOXSEL_FRAMERANGE,
- NLA_BOXSEL_CHANNELS,
+ NLA_BOXSEL_ALLSTRIPS = 0,
+ NLA_BOXSEL_FRAMERANGE,
+ NLA_BOXSEL_CHANNELS,
} /* eNLAEDIT_BoxSelect_Mode */;
-
static void box_select_nla_strips(bAnimContext *ac, rcti rect, short mode, short selectmode)
{
- ListBase anim_data = {NULL, NULL};
- bAnimListElem *ale;
- int filter;
-
- SpaceNla *snla = (SpaceNla *)ac->sl;
- View2D *v2d = &ac->ar->v2d;
- rctf rectf;
- float ymin /* =(float)(-NLACHANNEL_HEIGHT(snla)) */ /* UNUSED */, ymax = 0;
-
- /* convert border-region to view coordinates */
- UI_view2d_region_to_view(v2d, rect.xmin, rect.ymin + 2, &rectf.xmin, &rectf.ymin);
- UI_view2d_region_to_view(v2d, rect.xmax, rect.ymax - 2, &rectf.xmax, &rectf.ymax);
-
- /* filter data */
- filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
- ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
-
- /* convert selection modes to selection modes */
- selectmode = selmodes_to_flagmodes(selectmode);
-
- /* loop over data, doing box select */
- for (ale = anim_data.first; ale; ale = ale->next) {
- ymin = ymax - NLACHANNEL_STEP(snla);
-
- /* perform vertical suitability check (if applicable) */
- if ((mode == NLA_BOXSEL_FRAMERANGE) ||
- !((ymax < rectf.ymin) || (ymin > rectf.ymax)))
- {
- /* loop over data selecting (only if NLA-Track) */
- if (ale->type == ANIMTYPE_NLATRACK) {
- NlaTrack *nlt = (NlaTrack *)ale->data;
- NlaStrip *strip;
-
- /* only select strips if they fall within the required ranges (if applicable) */
- for (strip = nlt->strips.first; strip; strip = strip->next) {
- if ((mode == NLA_BOXSEL_CHANNELS) ||
- BKE_nlastrip_within_bounds(strip, rectf.xmin, rectf.xmax))
- {
- /* set selection */
- ACHANNEL_SET_FLAG(strip, selectmode, NLASTRIP_FLAG_SELECT);
-
- /* clear active flag */
- strip->flag &= ~NLASTRIP_FLAG_ACTIVE;
- }
- }
- }
- }
-
- /* set minimum extent to be the maximum of the next channel */
- ymax = ymin;
- }
-
- /* cleanup */
- ANIM_animdata_freelist(&anim_data);
+ ListBase anim_data = {NULL, NULL};
+ bAnimListElem *ale;
+ int filter;
+
+ SpaceNla *snla = (SpaceNla *)ac->sl;
+ View2D *v2d = &ac->ar->v2d;
+ rctf rectf;
+ float ymin /* =(float)(-NLACHANNEL_HEIGHT(snla)) */ /* UNUSED */, ymax = 0;
+
+ /* convert border-region to view coordinates */
+ UI_view2d_region_to_view(v2d, rect.xmin, rect.ymin + 2, &rectf.xmin, &rectf.ymin);
+ UI_view2d_region_to_view(v2d, rect.xmax, rect.ymax - 2, &rectf.xmax, &rectf.ymax);
+
+ /* filter data */
+ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
+ ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+
+ /* convert selection modes to selection modes */
+ selectmode = selmodes_to_flagmodes(selectmode);
+
+ /* loop over data, doing box select */
+ for (ale = anim_data.first; ale; ale = ale->next) {
+ ymin = ymax - NLACHANNEL_STEP(snla);
+
+ /* perform vertical suitability check (if applicable) */
+ if ((mode == NLA_BOXSEL_FRAMERANGE) || !((ymax < rectf.ymin) || (ymin > rectf.ymax))) {
+ /* loop over data selecting (only if NLA-Track) */
+ if (ale->type == ANIMTYPE_NLATRACK) {
+ NlaTrack *nlt = (NlaTrack *)ale->data;
+ NlaStrip *strip;
+
+ /* only select strips if they fall within the required ranges (if applicable) */
+ for (strip = nlt->strips.first; strip; strip = strip->next) {
+ if ((mode == NLA_BOXSEL_CHANNELS) ||
+ BKE_nlastrip_within_bounds(strip, rectf.xmin, rectf.xmax)) {
+ /* set selection */
+ ACHANNEL_SET_FLAG(strip, selectmode, NLASTRIP_FLAG_SELECT);
+
+ /* clear active flag */
+ strip->flag &= ~NLASTRIP_FLAG_ACTIVE;
+ }
+ }
+ }
+ }
+
+ /* set minimum extent to be the maximum of the next channel */
+ ymax = ymin;
+ }
+
+ /* cleanup */
+ ANIM_animdata_freelist(&anim_data);
}
/* ------------------- */
static int nlaedit_box_select_exec(bContext *C, wmOperator *op)
{
- bAnimContext ac;
- rcti rect;
- short mode = 0;
-
- /* get editor data */
- if (ANIM_animdata_get_context(C, &ac) == 0)
- return OPERATOR_CANCELLED;
-
- const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
- const int selectmode = (sel_op != SEL_OP_SUB) ? SELECT_ADD : SELECT_SUBTRACT;
- if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
- deselect_nla_strips(&ac, DESELECT_STRIPS_TEST, SELECT_SUBTRACT);
- }
-
- /* get settings from operator */
- WM_operator_properties_border_to_rcti(op, &rect);
-
- /* selection 'mode' depends on whether box_select region only matters on one axis */
- if (RNA_boolean_get(op->ptr, "axis_range")) {
- /* mode depends on which axis of the range is larger to determine which axis to use
- * - checking this in region-space is fine, as it's fundamentally still going to be a different rect size
- * - the frame-range select option is favored over the channel one (x over y), as frame-range one is often
- * used for tweaking timing when "blocking", while channels is not that useful...
- */
- if (BLI_rcti_size_x(&rect) >= BLI_rcti_size_y(&rect))
- mode = NLA_BOXSEL_FRAMERANGE;
- else
- mode = NLA_BOXSEL_CHANNELS;
- }
- else
- mode = NLA_BOXSEL_ALLSTRIPS;
-
- /* apply box_select action */
- box_select_nla_strips(&ac, rect, mode, selectmode);
-
- /* set notifier that things have changed */
- WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_SELECTED, NULL);
-
- return OPERATOR_FINISHED;
+ bAnimContext ac;
+ rcti rect;
+ short mode = 0;
+
+ /* get editor data */
+ if (ANIM_animdata_get_context(C, &ac) == 0)
+ return OPERATOR_CANCELLED;
+
+ const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
+ const int selectmode = (sel_op != SEL_OP_SUB) ? SELECT_ADD : SELECT_SUBTRACT;
+ if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
+ deselect_nla_strips(&ac, DESELECT_STRIPS_TEST, SELECT_SUBTRACT);
+ }
+
+ /* get settings from operator */
+ WM_operator_properties_border_to_rcti(op, &rect);
+
+ /* selection 'mode' depends on whether box_select region only matters on one axis */
+ if (RNA_boolean_get(op->ptr, "axis_range")) {
+ /* mode depends on which axis of the range is larger to determine which axis to use
+ * - checking this in region-space is fine, as it's fundamentally still going to be a different rect size
+ * - the frame-range select option is favored over the channel one (x over y), as frame-range one is often
+ * used for tweaking timing when "blocking", while channels is not that useful...
+ */
+ if (BLI_rcti_size_x(&rect) >= BLI_rcti_size_y(&rect))
+ mode = NLA_BOXSEL_FRAMERANGE;
+ else
+ mode = NLA_BOXSEL_CHANNELS;
+ }
+ else
+ mode = NLA_BOXSEL_ALLSTRIPS;
+
+ /* apply box_select action */
+ box_select_nla_strips(&ac, rect, mode, selectmode);
+
+ /* set notifier that things have changed */
+ WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_SELECTED, NULL);
+
+ return OPERATOR_FINISHED;
}
void NLA_OT_select_box(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Box Select";
- ot->idname = "NLA_OT_select_box";
- ot->description = "Use box selection to grab NLA-Strips";
+ /* identifiers */
+ ot->name = "Box Select";
+ ot->idname = "NLA_OT_select_box";
+ ot->description = "Use box selection to grab NLA-Strips";
- /* api callbacks */
- ot->invoke = WM_gesture_box_invoke;
- ot->exec = nlaedit_box_select_exec;
- ot->modal = WM_gesture_box_modal;
- ot->cancel = WM_gesture_box_cancel;
+ /* api callbacks */
+ ot->invoke = WM_gesture_box_invoke;
+ ot->exec = nlaedit_box_select_exec;
+ ot->modal = WM_gesture_box_modal;
+ ot->cancel = WM_gesture_box_cancel;
- ot->poll = nlaop_poll_tweakmode_off;
+ ot->poll = nlaop_poll_tweakmode_off;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- RNA_def_boolean(ot->srna, "axis_range", 0, "Axis Range", "");
+ /* properties */
+ RNA_def_boolean(ot->srna, "axis_range", 0, "Axis Range", "");
- WM_operator_properties_gesture_box(ot);
- WM_operator_properties_select_operation_simple(ot);
+ WM_operator_properties_gesture_box(ot);
+ WM_operator_properties_select_operation_simple(ot);
}
/* ******************** Select Left/Right Operator ************************* */
@@ -353,266 +347,276 @@ void NLA_OT_select_box(wmOperatorType *ot)
/* defines for left-right select tool */
static const EnumPropertyItem prop_nlaedit_leftright_select_types[] = {
- {NLAEDIT_LRSEL_TEST, "CHECK", 0, "Check if Select Left or Right", ""},
- {NLAEDIT_LRSEL_LEFT, "LEFT", 0, "Before current frame", ""},
- {NLAEDIT_LRSEL_RIGHT, "RIGHT", 0, "After current frame", ""},
- {0, NULL, 0, NULL, NULL},
+ {NLAEDIT_LRSEL_TEST, "CHECK", 0, "Check if Select Left or Right", ""},
+ {NLAEDIT_LRSEL_LEFT, "LEFT", 0, "Before current frame", ""},
+ {NLAEDIT_LRSEL_RIGHT, "RIGHT", 0, "After current frame", ""},
+ {0, NULL, 0, NULL, NULL},
};
/* ------------------- */
-static void nlaedit_select_leftright(bContext *C, bAnimContext *ac, short leftright, short select_mode)
+static void nlaedit_select_leftright(bContext *C,
+ bAnimContext *ac,
+ short leftright,
+ short select_mode)
{
- ListBase anim_data = {NULL, NULL};
- bAnimListElem *ale;
- int filter;
-
- Scene *scene = ac->scene;
- float xmin, xmax;
-
- /* if currently in tweakmode, exit tweakmode first */
- if (scene->flag & SCE_NLA_EDIT_ON)
- WM_operator_name_call(C, "NLA_OT_tweakmode_exit", WM_OP_EXEC_DEFAULT, NULL);
-
- /* if select mode is replace, deselect all keyframes (and channels) first */
- if (select_mode == SELECT_REPLACE) {
- select_mode = SELECT_ADD;
-
- /* - deselect all other keyframes, so that just the newly selected remain
- * - channels aren't deselected, since we don't re-select any as a consequence
- */
- deselect_nla_strips(ac, 0, SELECT_SUBTRACT);
- }
-
- /* get range, and get the right flag-setting mode */
- if (leftright == NLAEDIT_LRSEL_LEFT) {
- xmin = MINAFRAMEF;
- xmax = (float)(CFRA + 0.1f);
- }
- else {
- xmin = (float)(CFRA - 0.1f);
- xmax = MAXFRAMEF;
- }
-
- select_mode = selmodes_to_flagmodes(select_mode);
-
-
- /* filter data */
- filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE);
- ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
-
- /* select strips on the side where most data occurs */
- for (ale = anim_data.first; ale; ale = ale->next) {
- NlaTrack *nlt = (NlaTrack *)ale->data;
- NlaStrip *strip;
-
- /* check each strip to see if it is appropriate */
- for (strip = nlt->strips.first; strip; strip = strip->next) {
- if (BKE_nlastrip_within_bounds(strip, xmin, xmax)) {
- ACHANNEL_SET_FLAG(strip, select_mode, NLASTRIP_FLAG_SELECT);
- }
- }
- }
-
- /* Cleanup */
- ANIM_animdata_freelist(&anim_data);
+ ListBase anim_data = {NULL, NULL};
+ bAnimListElem *ale;
+ int filter;
+
+ Scene *scene = ac->scene;
+ float xmin, xmax;
+
+ /* if currently in tweakmode, exit tweakmode first */
+ if (scene->flag & SCE_NLA_EDIT_ON)
+ WM_operator_name_call(C, "NLA_OT_tweakmode_exit", WM_OP_EXEC_DEFAULT, NULL);
+
+ /* if select mode is replace, deselect all keyframes (and channels) first */
+ if (select_mode == SELECT_REPLACE) {
+ select_mode = SELECT_ADD;
+
+ /* - deselect all other keyframes, so that just the newly selected remain
+ * - channels aren't deselected, since we don't re-select any as a consequence
+ */
+ deselect_nla_strips(ac, 0, SELECT_SUBTRACT);
+ }
+
+ /* get range, and get the right flag-setting mode */
+ if (leftright == NLAEDIT_LRSEL_LEFT) {
+ xmin = MINAFRAMEF;
+ xmax = (float)(CFRA + 0.1f);
+ }
+ else {
+ xmin = (float)(CFRA - 0.1f);
+ xmax = MAXFRAMEF;
+ }
+
+ select_mode = selmodes_to_flagmodes(select_mode);
+
+ /* filter data */
+ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE);
+ ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+
+ /* select strips on the side where most data occurs */
+ for (ale = anim_data.first; ale; ale = ale->next) {
+ NlaTrack *nlt = (NlaTrack *)ale->data;
+ NlaStrip *strip;
+
+ /* check each strip to see if it is appropriate */
+ for (strip = nlt->strips.first; strip; strip = strip->next) {
+ if (BKE_nlastrip_within_bounds(strip, xmin, xmax)) {
+ ACHANNEL_SET_FLAG(strip, select_mode, NLASTRIP_FLAG_SELECT);
+ }
+ }
+ }
+
+ /* Cleanup */
+ ANIM_animdata_freelist(&anim_data);
}
/* ------------------- */
static int nlaedit_select_leftright_exec(bContext *C, wmOperator *op)
{
- bAnimContext ac;
- short leftright = RNA_enum_get(op->ptr, "mode");
- short selectmode;
+ bAnimContext ac;
+ short leftright = RNA_enum_get(op->ptr, "mode");
+ short selectmode;
- /* get editor data */
- if (ANIM_animdata_get_context(C, &ac) == 0)
- return OPERATOR_CANCELLED;
+ /* get editor data */
+ if (ANIM_animdata_get_context(C, &ac) == 0)
+ return OPERATOR_CANCELLED;
- /* select mode is either replace (deselect all, then add) or add/extend */
- if (RNA_boolean_get(op->ptr, "extend"))
- selectmode = SELECT_INVERT;
- else
- selectmode = SELECT_REPLACE;
+ /* select mode is either replace (deselect all, then add) or add/extend */
+ if (RNA_boolean_get(op->ptr, "extend"))
+ selectmode = SELECT_INVERT;
+ else
+ selectmode = SELECT_REPLACE;
- /* if "test" mode is set, we don't have any info to set this with */
- if (leftright == NLAEDIT_LRSEL_TEST)
- return OPERATOR_CANCELLED;
+ /* if "test" mode is set, we don't have any info to set this with */
+ if (leftright == NLAEDIT_LRSEL_TEST)
+ return OPERATOR_CANCELLED;
- /* do the selecting now */
- nlaedit_select_leftright(C, &ac, leftright, selectmode);
+ /* do the selecting now */
+ nlaedit_select_leftright(C, &ac, leftright, selectmode);
- /* set notifier that keyframe selection (and channels too) have changed */
- WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
- WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_SELECTED, NULL);
+ /* set notifier that keyframe selection (and channels too) have changed */
+ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
+ WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_SELECTED, NULL);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int nlaedit_select_leftright_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- bAnimContext ac;
- short leftright = RNA_enum_get(op->ptr, "mode");
-
- /* get editor data */
- if (ANIM_animdata_get_context(C, &ac) == 0)
- return OPERATOR_CANCELLED;
-
- /* handle mode-based testing */
- if (leftright == NLAEDIT_LRSEL_TEST) {
- Scene *scene = ac.scene;
- ARegion *ar = ac.ar;
- View2D *v2d = &ar->v2d;
- float x;
-
- /* determine which side of the current frame mouse is on */
- x = UI_view2d_region_to_view_x(v2d, event->mval[0]);
- if (x < CFRA)
- RNA_enum_set(op->ptr, "mode", NLAEDIT_LRSEL_LEFT);
- else
- RNA_enum_set(op->ptr, "mode", NLAEDIT_LRSEL_RIGHT);
- }
-
- /* perform selection */
- return nlaedit_select_leftright_exec(C, op);
+ bAnimContext ac;
+ short leftright = RNA_enum_get(op->ptr, "mode");
+
+ /* get editor data */
+ if (ANIM_animdata_get_context(C, &ac) == 0)
+ return OPERATOR_CANCELLED;
+
+ /* handle mode-based testing */
+ if (leftright == NLAEDIT_LRSEL_TEST) {
+ Scene *scene = ac.scene;
+ ARegion *ar = ac.ar;
+ View2D *v2d = &ar->v2d;
+ float x;
+
+ /* determine which side of the current frame mouse is on */
+ x = UI_view2d_region_to_view_x(v2d, event->mval[0]);
+ if (x < CFRA)
+ RNA_enum_set(op->ptr, "mode", NLAEDIT_LRSEL_LEFT);
+ else
+ RNA_enum_set(op->ptr, "mode", NLAEDIT_LRSEL_RIGHT);
+ }
+
+ /* perform selection */
+ return nlaedit_select_leftright_exec(C, op);
}
void NLA_OT_select_leftright(wmOperatorType *ot)
{
- PropertyRNA *prop;
+ PropertyRNA *prop;
- /* identifiers */
- ot->name = "Select Left/Right";
- ot->idname = "NLA_OT_select_leftright";
- ot->description = "Select strips to the left or the right of the current frame";
+ /* identifiers */
+ ot->name = "Select Left/Right";
+ ot->idname = "NLA_OT_select_leftright";
+ ot->description = "Select strips to the left or the right of the current frame";
- /* api callbacks */
- ot->invoke = nlaedit_select_leftright_invoke;
- ot->exec = nlaedit_select_leftright_exec;
- ot->poll = ED_operator_nla_active;
+ /* api callbacks */
+ ot->invoke = nlaedit_select_leftright_invoke;
+ ot->exec = nlaedit_select_leftright_exec;
+ ot->poll = ED_operator_nla_active;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- /* properties */
- ot->prop = RNA_def_enum(ot->srna, "mode", prop_nlaedit_leftright_select_types, NLAEDIT_LRSEL_TEST, "Mode", "");
- RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE);
+ /* properties */
+ ot->prop = RNA_def_enum(
+ ot->srna, "mode", prop_nlaedit_leftright_select_types, NLAEDIT_LRSEL_TEST, "Mode", "");
+ RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", "");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", "");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
-
/* ******************** Mouse-Click Select Operator *********************** */
/* select strip directly under mouse */
static void mouse_nla_strips(bContext *C, bAnimContext *ac, const int mval[2], short select_mode)
{
- ListBase anim_data = {NULL, NULL};
- bAnimListElem *ale = NULL;
- int filter;
-
- SpaceNla *snla = (SpaceNla *)ac->sl;
- View2D *v2d = &ac->ar->v2d;
- Scene *scene = ac->scene;
- NlaStrip *strip = NULL;
- int channel_index;
- float xmin, xmax;
- float x, y;
-
-
- /* use View2D to determine the index of the channel
- * (i.e a row in the list) where keyframe was */
- UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
- UI_view2d_listview_view_to_cell(v2d, 0, NLACHANNEL_STEP(snla), 0, (float)NLACHANNEL_HEIGHT_HALF(snla), x, y, NULL, &channel_index);
-
- /* x-range to check is +/- 7 (in screen/region-space) on either side of mouse click
- * (that is the size of keyframe icons, so user should be expecting similar tolerances)
- */
- xmin = UI_view2d_region_to_view_x(v2d, mval[0] - 7);
- xmax = UI_view2d_region_to_view_x(v2d, mval[0] + 7);
-
- /* filter data */
- filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
- ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
-
- /* try to get channel */
- ale = BLI_findlink(&anim_data, channel_index);
- if (ale == NULL) {
- /* channel not found */
- printf("Error: animation channel (index = %d) not found in mouse_nla_strips()\n", channel_index);
- ANIM_animdata_freelist(&anim_data);
- return;
- }
- else {
- /* found some channel - we only really should do something when its an Nla-Track */
- if (ale->type == ANIMTYPE_NLATRACK) {
- NlaTrack *nlt = (NlaTrack *)ale->data;
-
- /* loop over NLA-strips in this track,
- * trying to find one which occurs in the necessary bounds */
- for (strip = nlt->strips.first; strip; strip = strip->next) {
- if (BKE_nlastrip_within_bounds(strip, xmin, xmax))
- break;
- }
- }
-
- /* remove active channel from list of channels for separate treatment
- * (since it's needed later on) */
- BLI_remlink(&anim_data, ale);
-
- /* free list of channels, since it's not used anymore */
- ANIM_animdata_freelist(&anim_data);
- }
-
- /* if currently in tweakmode, exit tweakmode before changing selection states
- * now that we've found our target...
- */
- if (scene->flag & SCE_NLA_EDIT_ON)
- WM_operator_name_call(C, "NLA_OT_tweakmode_exit", WM_OP_EXEC_DEFAULT, NULL);
-
- /* for replacing selection, firstly need to clear existing selection */
- if (select_mode == SELECT_REPLACE) {
- /* reset selection mode for next steps */
- select_mode = SELECT_ADD;
-
- /* deselect all strips */
- deselect_nla_strips(ac, 0, SELECT_SUBTRACT);
-
- /* deselect all other channels first */
- ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
- }
-
- /* only select strip if we clicked on a valid channel and hit something */
- if (ale) {
- /* select the strip accordingly (if a matching one was found) */
- if (strip) {
- select_mode = selmodes_to_flagmodes(select_mode);
- ACHANNEL_SET_FLAG(strip, select_mode, NLASTRIP_FLAG_SELECT);
-
- /* if we selected it, we can make it active too
- * - we always need to clear the active strip flag though...
- * - as well as selecting its track...
- */
- deselect_nla_strips(ac, DESELECT_STRIPS_CLEARACTIVE, 0);
-
- if (strip->flag & NLASTRIP_FLAG_SELECT) {
- strip->flag |= NLASTRIP_FLAG_ACTIVE;
-
- /* Highlight NLA-Track */
- if (ale->type == ANIMTYPE_NLATRACK) {
- NlaTrack *nlt = (NlaTrack *)ale->data;
-
- nlt->flag |= NLATRACK_SELECTED;
- ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, nlt, ANIMTYPE_NLATRACK);
- }
- }
- }
-
- /* free this channel */
- MEM_freeN(ale);
- }
+ ListBase anim_data = {NULL, NULL};
+ bAnimListElem *ale = NULL;
+ int filter;
+
+ SpaceNla *snla = (SpaceNla *)ac->sl;
+ View2D *v2d = &ac->ar->v2d;
+ Scene *scene = ac->scene;
+ NlaStrip *strip = NULL;
+ int channel_index;
+ float xmin, xmax;
+ float x, y;
+
+ /* use View2D to determine the index of the channel
+ * (i.e a row in the list) where keyframe was */
+ UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
+ UI_view2d_listview_view_to_cell(v2d,
+ 0,
+ NLACHANNEL_STEP(snla),
+ 0,
+ (float)NLACHANNEL_HEIGHT_HALF(snla),
+ x,
+ y,
+ NULL,
+ &channel_index);
+
+ /* x-range to check is +/- 7 (in screen/region-space) on either side of mouse click
+ * (that is the size of keyframe icons, so user should be expecting similar tolerances)
+ */
+ xmin = UI_view2d_region_to_view_x(v2d, mval[0] - 7);
+ xmax = UI_view2d_region_to_view_x(v2d, mval[0] + 7);
+
+ /* filter data */
+ filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
+ ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+
+ /* try to get channel */
+ ale = BLI_findlink(&anim_data, channel_index);
+ if (ale == NULL) {
+ /* channel not found */
+ printf("Error: animation channel (index = %d) not found in mouse_nla_strips()\n",
+ channel_index);
+ ANIM_animdata_freelist(&anim_data);
+ return;
+ }
+ else {
+ /* found some channel - we only really should do something when its an Nla-Track */
+ if (ale->type == ANIMTYPE_NLATRACK) {
+ NlaTrack *nlt = (NlaTrack *)ale->data;
+
+ /* loop over NLA-strips in this track,
+ * trying to find one which occurs in the necessary bounds */
+ for (strip = nlt->strips.first; strip; strip = strip->next) {
+ if (BKE_nlastrip_within_bounds(strip, xmin, xmax))
+ break;
+ }
+ }
+
+ /* remove active channel from list of channels for separate treatment
+ * (since it's needed later on) */
+ BLI_remlink(&anim_data, ale);
+
+ /* free list of channels, since it's not used anymore */
+ ANIM_animdata_freelist(&anim_data);
+ }
+
+ /* if currently in tweakmode, exit tweakmode before changing selection states
+ * now that we've found our target...
+ */
+ if (scene->flag & SCE_NLA_EDIT_ON)
+ WM_operator_name_call(C, "NLA_OT_tweakmode_exit", WM_OP_EXEC_DEFAULT, NULL);
+
+ /* for replacing selection, firstly need to clear existing selection */
+ if (select_mode == SELECT_REPLACE) {
+ /* reset selection mode for next steps */
+ select_mode = SELECT_ADD;
+
+ /* deselect all strips */
+ deselect_nla_strips(ac, 0, SELECT_SUBTRACT);
+
+ /* deselect all other channels first */
+ ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
+ }
+
+ /* only select strip if we clicked on a valid channel and hit something */
+ if (ale) {
+ /* select the strip accordingly (if a matching one was found) */
+ if (strip) {
+ select_mode = selmodes_to_flagmodes(select_mode);
+ ACHANNEL_SET_FLAG(strip, select_mode, NLASTRIP_FLAG_SELECT);
+
+ /* if we selected it, we can make it active too
+ * - we always need to clear the active strip flag though...
+ * - as well as selecting its track...
+ */
+ deselect_nla_strips(ac, DESELECT_STRIPS_CLEARACTIVE, 0);
+
+ if (strip->flag & NLASTRIP_FLAG_SELECT) {
+ strip->flag |= NLASTRIP_FLAG_ACTIVE;
+
+ /* Highlight NLA-Track */
+ if (ale->type == ANIMTYPE_NLATRACK) {
+ NlaTrack *nlt = (NlaTrack *)ale->data;
+
+ nlt->flag |= NLATRACK_SELECTED;
+ ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, nlt, ANIMTYPE_NLATRACK);
+ }
+ }
+ }
+
+ /* free this channel */
+ MEM_freeN(ale);
+ }
}
/* ------------------- */
@@ -620,56 +624,56 @@ static void mouse_nla_strips(bContext *C, bAnimContext *ac, const int mval[2], s
/* handle clicking */
static int nlaedit_clickselect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- bAnimContext ac;
- /* Scene *scene; */ /* UNUSED */
- /* ARegion *ar; */ /* UNUSED */
- // View2D *v2d; /*UNUSED*/
- short selectmode;
-
- /* get editor data */
- if (ANIM_animdata_get_context(C, &ac) == 0)
- return OPERATOR_CANCELLED;
-
- /* get useful pointers from animation context data */
- /* scene= ac.scene; */ /* UNUSED */
- /* ar= ac.ar; */ /* UNUSED */
- // v2d= &ar->v2d;
-
- /* select mode is either replace (deselect all, then add) or add/extend */
- if (RNA_boolean_get(op->ptr, "extend"))
- selectmode = SELECT_INVERT;
- else
- selectmode = SELECT_REPLACE;
-
- /* select strips based upon mouse position */
- mouse_nla_strips(C, &ac, event->mval, selectmode);
-
- /* set notifier that things have changed */
- WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_SELECTED, NULL);
-
- /* for tweak grab to work */
- return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
+ bAnimContext ac;
+ /* Scene *scene; */ /* UNUSED */
+ /* ARegion *ar; */ /* UNUSED */
+ // View2D *v2d; /*UNUSED*/
+ short selectmode;
+
+ /* get editor data */
+ if (ANIM_animdata_get_context(C, &ac) == 0)
+ return OPERATOR_CANCELLED;
+
+ /* get useful pointers from animation context data */
+ /* scene= ac.scene; */ /* UNUSED */
+ /* ar= ac.ar; */ /* UNUSED */
+ // v2d= &ar->v2d;
+
+ /* select mode is either replace (deselect all, then add) or add/extend */
+ if (RNA_boolean_get(op->ptr, "extend"))
+ selectmode = SELECT_INVERT;
+ else
+ selectmode = SELECT_REPLACE;
+
+ /* select strips based upon mouse position */
+ mouse_nla_strips(C, &ac, event->mval, selectmode);
+
+ /* set notifier that things have changed */
+ WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_SELECTED, NULL);
+
+ /* for tweak grab to work */
+ return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
}
void NLA_OT_click_select(wmOperatorType *ot)
{
- PropertyRNA *prop;
+ PropertyRNA *prop;
- /* identifiers */
- ot->name = "Select";
- ot->idname = "NLA_OT_click_select";
- ot->description = "Handle clicks to select NLA Strips";
+ /* identifiers */
+ ot->name = "Select";
+ ot->idname = "NLA_OT_click_select";
+ ot->description = "Handle clicks to select NLA Strips";
- /* api callbacks - absolutely no exec() this yet... */
- ot->invoke = nlaedit_clickselect_invoke;
- ot->poll = ED_operator_nla_active;
+ /* api callbacks - absolutely no exec() this yet... */
+ ot->invoke = nlaedit_clickselect_invoke;
+ ot->poll = ED_operator_nla_active;
- /* flags */
- ot->flag = OPTYPE_UNDO;
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
- /* properties */
- prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ /* properties */
+ prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
/* *********************************************** */