Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_nla/nla_select.c
| Show First 20 Lines • Show All 272 Lines • ▼ Show 20 Lines | static void box_select_nla_strips(bAnimContext *ac, rcti rect, short mode, short selectmode) | ||||
| } | } | ||||
| /* cleanup */ | /* cleanup */ | ||||
| ANIM_animdata_freelist(&anim_data); | ANIM_animdata_freelist(&anim_data); | ||||
| } | } | ||||
| /* ------------------- */ | /* ------------------- */ | ||||
| static void nlaedit_strip_at_region_position( | |||||
| bAnimContext *ac, float region_x, float region_y, bAnimListElem **r_ale, NlaStrip **r_strip) | |||||
| { | |||||
| *r_ale = NULL; | |||||
| *r_strip = NULL; | |||||
| SpaceNla *snla = (SpaceNla *)ac->sl; | |||||
| View2D *v2d = &ac->ar->v2d; | |||||
| float view_x, view_y; | |||||
| int channel_index; | |||||
| UI_view2d_region_to_view(v2d, region_x, region_y, &view_x, &view_y); | |||||
| UI_view2d_listview_view_to_cell( | |||||
| 0, NLACHANNEL_STEP(snla), 0, NLACHANNEL_FIRST_TOP(ac), view_x, view_y, NULL, &channel_index); | |||||
| ListBase anim_data = {NULL, NULL}; | |||||
| int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS); | |||||
| ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); | |||||
| /* 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) | |||||
| */ | |||||
| float xmin = UI_view2d_region_to_view_x(v2d, region_x - 7); | |||||
| float xmax = UI_view2d_region_to_view_x(v2d, region_x + 7); | |||||
| bAnimListElem *ale = BLI_findlink(&anim_data, channel_index); | |||||
| if (ale != NULL) { | |||||
| if (ale->type == ANIMTYPE_NLATRACK) { | |||||
| NlaTrack *nlt = (NlaTrack *)ale->data; | |||||
| for (NlaStrip *strip = nlt->strips.first; strip; strip = strip->next) { | |||||
| if (BKE_nlastrip_within_bounds(strip, xmin, xmax)) { | |||||
| *r_ale = ale; | |||||
| *r_strip = strip; | |||||
| BLI_remlink(&anim_data, ale); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| ANIM_animdata_freelist(&anim_data); | |||||
| } | |||||
| static bool nlaedit_mouse_is_over_strip(bAnimContext *ac, const int mval[2]) | |||||
| { | |||||
| bAnimListElem *ale; | |||||
| NlaStrip *strip; | |||||
| nlaedit_strip_at_region_position(ac, mval[0], mval[1], &ale, &strip); | |||||
| if (ale != NULL) { | |||||
| BLI_assert(strip != NULL); | |||||
| MEM_freeN(ale); | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| static int nlaedit_box_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) | |||||
| { | |||||
| bAnimContext ac; | |||||
| if (ANIM_animdata_get_context(C, &ac) == 0) { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| bool tweak = RNA_boolean_get(op->ptr, "tweak"); | |||||
| if (tweak && nlaedit_mouse_is_over_strip(&ac, event->mval)) { | |||||
| return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; | |||||
| } | |||||
| return WM_gesture_box_invoke(C, op, event); | |||||
| } | |||||
| static int nlaedit_box_select_exec(bContext *C, wmOperator *op) | static int nlaedit_box_select_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| bAnimContext ac; | bAnimContext ac; | ||||
| rcti rect; | rcti rect; | ||||
| short mode = 0; | short mode = 0; | ||||
| /* get editor data */ | /* get editor data */ | ||||
| if (ANIM_animdata_get_context(C, &ac) == 0) { | if (ANIM_animdata_get_context(C, &ac) == 0) { | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| void NLA_OT_select_box(wmOperatorType *ot) | void NLA_OT_select_box(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Box Select"; | ot->name = "Box Select"; | ||||
| ot->idname = "NLA_OT_select_box"; | ot->idname = "NLA_OT_select_box"; | ||||
| ot->description = "Use box selection to grab NLA-Strips"; | ot->description = "Use box selection to grab NLA-Strips"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->invoke = WM_gesture_box_invoke; | ot->invoke = nlaedit_box_select_invoke; | ||||
| ot->exec = nlaedit_box_select_exec; | ot->exec = nlaedit_box_select_exec; | ||||
| ot->modal = WM_gesture_box_modal; | ot->modal = WM_gesture_box_modal; | ||||
| ot->cancel = WM_gesture_box_cancel; | ot->cancel = WM_gesture_box_cancel; | ||||
| ot->poll = nlaop_poll_tweakmode_off; | ot->poll = nlaop_poll_tweakmode_off; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* properties */ | /* properties */ | ||||
| RNA_def_boolean(ot->srna, "axis_range", 0, "Axis Range", ""); | RNA_def_boolean(ot->srna, "axis_range", 0, "Axis Range", ""); | ||||
| PropertyRNA *prop = RNA_def_boolean( | |||||
| ot->srna, "tweak", 0, "Tweak", "Operator has been activated using a tweak event"); | |||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | |||||
| WM_operator_properties_gesture_box(ot); | WM_operator_properties_gesture_box(ot); | ||||
| WM_operator_properties_select_operation_simple(ot); | WM_operator_properties_select_operation_simple(ot); | ||||
| } | } | ||||
| /* ******************** Select Left/Right Operator ************************* */ | /* ******************** Select Left/Right Operator ************************* */ | ||||
| /* Select keyframes left/right of the current frame indicator */ | /* Select keyframes left/right of the current frame indicator */ | ||||
| /* defines for left-right select tool */ | /* defines for left-right select tool */ | ||||
| ▲ Show 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* ******************** Mouse-Click Select Operator *********************** */ | /* ******************** Mouse-Click Select Operator *********************** */ | ||||
| /* select strip directly under mouse */ | /* select strip directly under mouse */ | ||||
| static void mouse_nla_strips( | static void mouse_nla_strips( | ||||
| bContext *C, bAnimContext *ac, const int mval[2], short select_mode, const bool deselect_all) | bContext *C, bAnimContext *ac, const int mval[2], short select_mode, const bool deselect_all) | ||||
| { | { | ||||
| ListBase anim_data = {NULL, NULL}; | |||||
| bAnimListElem *ale = NULL; | |||||
| int filter; | |||||
| SpaceNla *snla = (SpaceNla *)ac->sl; | SpaceNla *snla = (SpaceNla *)ac->sl; | ||||
| View2D *v2d = &ac->ar->v2d; | |||||
| Scene *scene = ac->scene; | 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( | |||||
| 0, NLACHANNEL_STEP(snla), 0, NLACHANNEL_FIRST_TOP(ac), 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 */ | bAnimListElem *ale = NULL; | ||||
| filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS); | NlaStrip *strip = NULL; | ||||
| ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); | nlaedit_strip_at_region_position(ac, mval[0], mval[1], &ale, &strip); | ||||
| /* try to get channel */ | |||||
| ale = BLI_findlink(&anim_data, channel_index); | |||||
| if (ale != NULL) { | |||||
| /* 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 | /* if currently in tweakmode, exit tweakmode before changing selection states | ||||
| * now that we've found our target... | * now that we've found our target... | ||||
| */ | */ | ||||
| if (scene->flag & SCE_NLA_EDIT_ON) { | if (scene->flag & SCE_NLA_EDIT_ON) { | ||||
| WM_operator_name_call(C, "NLA_OT_tweakmode_exit", WM_OP_EXEC_DEFAULT, NULL); | WM_operator_name_call(C, "NLA_OT_tweakmode_exit", WM_OP_EXEC_DEFAULT, NULL); | ||||
| } | } | ||||
| Show All 27 Lines | if (strip != NULL) { | ||||
| if (strip->flag & NLASTRIP_FLAG_SELECT) { | if (strip->flag & NLASTRIP_FLAG_SELECT) { | ||||
| strip->flag |= NLASTRIP_FLAG_ACTIVE; | strip->flag |= NLASTRIP_FLAG_ACTIVE; | ||||
| /* Highlight NLA-Track */ | /* Highlight NLA-Track */ | ||||
| if (ale->type == ANIMTYPE_NLATRACK) { | if (ale->type == ANIMTYPE_NLATRACK) { | ||||
| NlaTrack *nlt = (NlaTrack *)ale->data; | NlaTrack *nlt = (NlaTrack *)ale->data; | ||||
| nlt->flag |= NLATRACK_SELECTED; | nlt->flag |= NLATRACK_SELECTED; | ||||
| int filter = ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | | |||||
| ANIMFILTER_LIST_CHANNELS; | |||||
| ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, nlt, ANIMTYPE_NLATRACK); | ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, nlt, ANIMTYPE_NLATRACK); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* free this channel */ | /* free this channel */ | ||||
| MEM_freeN(ale); | MEM_freeN(ale); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines | |||||