diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-06-05 15:04:59 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-06-05 15:14:02 +0300 |
commit | 74fa600ede93852e031c73322a43e807d1b9daf0 (patch) | |
tree | 79355d24fedfb92ac83e766adcdd9ceb8af8e99c /source/blender/editors/space_sequencer | |
parent | d850daf416f75f1231d49cbf240151c13212a87a (diff) |
Sequencer: split select side of frame out of the select operator
The select operator was getting overloaded with functionality
unrelated to selecting the strip at the mouse position.
- Don't save settings, allowing the keymap only to include
non-default options.
- Fix selecting strips overlapping the current frame
overwrite all flags.
Diffstat (limited to 'source/blender/editors/space_sequencer')
3 files changed, 105 insertions, 59 deletions
diff --git a/source/blender/editors/space_sequencer/sequencer_intern.h b/source/blender/editors/space_sequencer/sequencer_intern.h index 0e7e691c748..25f3d087cb2 100644 --- a/source/blender/editors/space_sequencer/sequencer_intern.h +++ b/source/blender/editors/space_sequencer/sequencer_intern.h @@ -158,6 +158,7 @@ void SEQUENCER_OT_view_all_preview(struct wmOperatorType *ot); /* sequencer_select.c */ void SEQUENCER_OT_select_all(struct wmOperatorType *ot); void SEQUENCER_OT_select(struct wmOperatorType *ot); +void SEQUENCER_OT_select_side_of_frame(struct wmOperatorType *ot); void SEQUENCER_OT_select_more(struct wmOperatorType *ot); void SEQUENCER_OT_select_less(struct wmOperatorType *ot); void SEQUENCER_OT_select_linked(struct wmOperatorType *ot); @@ -186,14 +187,6 @@ enum { SEQ_UNSELECTED, }; -enum { - SEQ_SELECT_LR_NONE = 0, - SEQ_SELECT_LR_MOUSE, - SEQ_SELECT_LR_LEFT, - SEQ_SELECT_LR_RIGHT, - SEQ_SELECT_LR_OVERLAP, -}; - /* Defines used internally. */ #define SCE_MARKERS 0 /* XXX - dummy */ diff --git a/source/blender/editors/space_sequencer/sequencer_ops.c b/source/blender/editors/space_sequencer/sequencer_ops.c index ac00838a079..4fe1c953c74 100644 --- a/source/blender/editors/space_sequencer/sequencer_ops.c +++ b/source/blender/editors/space_sequencer/sequencer_ops.c @@ -99,6 +99,7 @@ void sequencer_operatortypes(void) WM_operatortype_append(SEQUENCER_OT_select_linked); WM_operatortype_append(SEQUENCER_OT_select_handles); WM_operatortype_append(SEQUENCER_OT_select_side); + WM_operatortype_append(SEQUENCER_OT_select_side_of_frame); WM_operatortype_append(SEQUENCER_OT_select_box); WM_operatortype_append(SEQUENCER_OT_select_grouped); diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c index 2e6cd7f7442..1b20cdbc782 100644 --- a/source/blender/editors/space_sequencer/sequencer_select.c +++ b/source/blender/editors/space_sequencer/sequencer_select.c @@ -363,8 +363,8 @@ static int sequencer_select_exec(bContext *C, wmOperator *op) const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); const bool linked_handle = RNA_boolean_get(op->ptr, "linked_handle"); const bool linked_time = RNA_boolean_get(op->ptr, "linked_time"); + bool side_of_frame = RNA_boolean_get(op->ptr, "side_of_frame"); bool wait_to_deselect_others = RNA_boolean_get(op->ptr, "wait_to_deselect_others"); - int left_right = RNA_enum_get(op->ptr, "left_right"); int mval[2]; int ret_value = OPERATOR_CANCELLED; @@ -387,9 +387,9 @@ static int sequencer_select_exec(bContext *C, wmOperator *op) seq = find_nearest_seq(scene, v2d, &hand, mval); - /* XXX - not nice, Ctrl+RMB needs to do left_right only when not over a strip */ - if (seq && linked_time && (left_right == SEQ_SELECT_LR_MOUSE)) { - left_right = SEQ_SELECT_LR_NONE; + /* XXX - not nice, Ctrl+RMB needs to do side_of_frame only when not over a strip */ + if (seq && linked_time) { + side_of_frame = false; } if (marker) { @@ -413,43 +413,23 @@ static int sequencer_select_exec(bContext *C, wmOperator *op) ret_value = OPERATOR_FINISHED; } /* Select left, right or overlapping the current frame. */ - else if (left_right != SEQ_SELECT_LR_NONE) { + else if (side_of_frame) { /* Use different logic for this. */ float x; if (extend == false) { ED_sequencer_deselect_all(scene); } - switch (left_right) { - case SEQ_SELECT_LR_MOUSE: { - /* 10px margin around current frame to select under the current frame with mouse. */ - float margin = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask) * 10; - x = UI_view2d_region_to_view_x(v2d, mval[0]); - if (x >= CFRA - margin && x <= CFRA + margin) { - x = CFRA; - } - break; - } - case SEQ_SELECT_LR_LEFT: - x = CFRA - 1.0f; - break; - case SEQ_SELECT_LR_RIGHT: - x = CFRA + 1.0f; - break; - case SEQ_SELECT_LR_OVERLAP: - default: - x = CFRA; - break; + /* 10px margin around current frame to select under the current frame with mouse. */ + float margin = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask) * 10; + x = UI_view2d_region_to_view_x(v2d, mval[0]); + if (x >= CFRA - margin && x <= CFRA + margin) { + x = CFRA; } SEQP_BEGIN (ed, seq) { - /* Select overlapping the current frame. */ - if ((x == CFRA) && (seq->startdisp <= CFRA) && (seq->enddisp >= CFRA)) { - seq->flag = SELECT; - recurs_sel_seq(seq); - } /* Select left or right. */ - else if ((x < CFRA && seq->enddisp <= CFRA) || (x > CFRA && seq->startdisp >= CFRA)) { + if ((x < CFRA && seq->enddisp <= CFRA) || (x > CFRA && seq->startdisp >= CFRA)) { seq->flag |= SELECT; recurs_sel_seq(seq); } @@ -640,14 +620,6 @@ static int sequencer_select_exec(bContext *C, wmOperator *op) void SEQUENCER_OT_select(wmOperatorType *ot) { - static const EnumPropertyItem sequencer_select_left_right_types[] = { - {SEQ_SELECT_LR_NONE, "NONE", 0, "None", "Don't do left-right selection"}, - {SEQ_SELECT_LR_MOUSE, "MOUSE", 0, "Mouse", "Use mouse position for selection"}, - {SEQ_SELECT_LR_LEFT, "LEFT", 0, "Left", "Select to the left of the current frame"}, - {SEQ_SELECT_LR_RIGHT, "RIGHT", 0, "Right", "Select to the right of the current frame"}, - {SEQ_SELECT_LR_OVERLAP, "OVERLAP", 0, "Overlap", "Select overlapping the current frame"}, - {0, NULL, 0, NULL, NULL}, - }; PropertyRNA *prop; /* Identifiers. */ @@ -666,24 +638,35 @@ void SEQUENCER_OT_select(wmOperatorType *ot) /* Properties. */ WM_operator_properties_generic_select(ot); - RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection"); + + prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_boolean(ot->srna, "deselect_all", false, "Deselect On Nothing", "Deselect all when nothing under the cursor"); RNA_def_property_flag(prop, PROP_SKIP_SAVE); - RNA_def_boolean( - ot->srna, "linked_handle", 0, "Linked Handle", "Select handles next to the active strip"); - /* For animation this is enum but atm having an enum isn't useful for us. */ - RNA_def_enum(ot->srna, - "left_right", - sequencer_select_left_right_types, - 0, - "Left/Right", - "Select based on the current frame side the cursor is on"); - RNA_def_boolean( - ot->srna, "linked_time", 0, "Linked Time", "Select other strips at the same time"); + + prop = RNA_def_boolean(ot->srna, + "linked_handle", + false, + "Linked Handle", + "Select handles next to the active strip"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean( + ot->srna, "linked_time", false, "Linked Time", "Select other strips at the same time"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean( + ot->srna, + "side_of_frame", + false, + "Side of Frame", + "Select all strips on same side of the current frame as the mouse cursor"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /* Run recursively to select linked. */ @@ -953,6 +936,75 @@ void SEQUENCER_OT_select_handles(wmOperatorType *ot) "The side of the handle that is selected"); } +static int sequencer_select_side_of_frame_exec(bContext *C, wmOperator *op) +{ + Scene *scene = CTX_data_scene(C); + Editing *ed = BKE_sequencer_editing_get(scene, false); + const bool extend = RNA_boolean_get(op->ptr, "extend"); + const int side = RNA_enum_get(op->ptr, "side"); + Sequence *seq; + + if (ed == NULL) { + return OPERATOR_CANCELLED; + } + if (extend == false) { + ED_sequencer_deselect_all(scene); + } + const int cfra = CFRA; + SEQP_BEGIN (ed, seq) { + bool test = false; + switch (side) { + case -1: + test = (cfra >= seq->startdisp); + break; + case 1: + test = (cfra <= seq->enddisp); + break; + case 0: + test = (cfra <= seq->enddisp) && (cfra >= seq->startdisp); + break; + } + + if (test) { + seq->flag |= SELECT; + recurs_sel_seq(seq); + } + } + SEQ_END; + + ED_outliner_select_sync_from_sequence_tag(C); + + WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER | NA_SELECTED, scene); + + return OPERATOR_FINISHED; +} + +void SEQUENCER_OT_select_side_of_frame(wmOperatorType *ot) +{ + static const EnumPropertyItem sequencer_select_left_right_types[] = { + {0, "OVERLAP", 0, "Overlap", "Select overlapping the current frame"}, + {-1, "LEFT", 0, "Left", "Select to the left of the current frame"}, + {1, "RIGHT", 0, "Right", "Select to the right of the current frame"}, + {0, NULL, 0, NULL, NULL}, + }; + + /* Identifiers. */ + ot->name = "Select Side of Frame"; + ot->idname = "SEQUENCER_OT_select_side_of_frame"; + ot->description = "Select strips relative to the current frame"; + + /* Api callbacks. */ + ot->exec = sequencer_select_side_of_frame_exec; + ot->poll = ED_operator_sequencer_active; + + /* Flags. */ + ot->flag = OPTYPE_UNDO; + + /* Properties. */ + RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection"); + ot->prop = RNA_def_enum(ot->srna, "side", sequencer_select_left_right_types, 0, "Side", ""); +} + static int sequencer_select_side_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); |