From 5314161491d41461fe09c4774229481dde93e250 Mon Sep 17 00:00:00 2001 From: Richard Antalik Date: Sun, 9 Feb 2020 17:59:13 +0100 Subject: VSE: Add option to select handles with box selection Patch adds an "Handle" option to the `SEQUENCER_OT_box_select` operator, that allows to select the handles instead of whole strips. Feature is mapped to Alt key modifier A difference from the proposed design in T70730 is that covering the entire strip with the box actually selects both handles. Reviewed By: iss Differential Revision: https://developer.blender.org/D6372 --- .../editors/space_sequencer/sequencer_draw.c | 4 +- .../editors/space_sequencer/sequencer_intern.h | 1 + .../editors/space_sequencer/sequencer_select.c | 52 +++++++++++++++++++--- 3 files changed, 50 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index ae1d63b5f93..6ebccf31355 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -449,7 +449,7 @@ static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1, } /* clamp handles to defined size in pixel space */ -static float draw_seq_handle_size_get_clamped(Sequence *seq, const float pixelx) +float sequence_handle_size_get_clamped(Sequence *seq, const float pixelx) { const float minhandle = pixelx * SEQ_HANDLE_SIZE_MIN; const float maxhandle = pixelx * SEQ_HANDLE_SIZE_MAX; @@ -806,7 +806,7 @@ static void draw_seq_strip(const bContext *C, View2D *v2d = &ar->v2d; float x1, x2, y1, y2; unsigned char col[4], background_col[4], is_single_image; - const float handsize_clamped = draw_seq_handle_size_get_clamped(seq, pixelx); + const float handsize_clamped = sequence_handle_size_get_clamped(seq, pixelx); /* we need to know if this is a single image/color or not for drawing */ is_single_image = (char)BKE_sequence_single_check(seq); diff --git a/source/blender/editors/space_sequencer/sequencer_intern.h b/source/blender/editors/space_sequencer/sequencer_intern.h index 0a51578da3b..ef5fed492e5 100644 --- a/source/blender/editors/space_sequencer/sequencer_intern.h +++ b/source/blender/editors/space_sequencer/sequencer_intern.h @@ -54,6 +54,7 @@ void sequencer_draw_preview(const struct bContext *C, void color3ubv_from_seq(struct Scene *curscene, struct Sequence *seq, unsigned char col[3]); void sequencer_special_update_set(Sequence *seq); +float sequence_handle_size_get_clamped(struct Sequence *seq, const float pixelx); /* UNUSED */ // void seq_reset_imageofs(struct SpaceSeq *sseq); diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c index a5bb66ca65f..bf06fa768ca 100644 --- a/source/blender/editors/space_sequencer/sequencer_select.c +++ b/source/blender/editors/space_sequencer/sequencer_select.c @@ -1018,15 +1018,17 @@ void SEQUENCER_OT_select_side(wmOperatorType *ot) static int sequencer_box_select_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); + View2D *v2d = UI_view2d_fromcontext(C); Editing *ed = BKE_sequencer_editing_get(scene, false); + if (ed == NULL) { return OPERATOR_CANCELLED; } - View2D *v2d = UI_view2d_fromcontext(C); - const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); + const bool handles = RNA_boolean_get(op->ptr, "handles"); const bool select = (sel_op != SEL_OP_SUB); + if (SEL_OP_USE_PRE_DESELECT(sel_op)) { ED_sequencer_deselect_all(scene); } @@ -1039,8 +1041,44 @@ static int sequencer_box_select_exec(bContext *C, wmOperator *op) rctf rq; seq_rectf(seq, &rq); if (BLI_rctf_isect(&rq, &rectf, NULL)) { - SET_FLAG_FROM_TEST(seq->flag, select, SELECT); - recurs_sel_seq(seq); + if (handles) { + /* Get the handles draw size. */ + float pixelx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask); + float handsize = sequence_handle_size_get_clamped(seq, pixelx) * 0.75f; + + /* Right handle. */ + if (rectf.xmax > (seq->enddisp - handsize)) { + if (select) { + seq->flag |= SELECT | SEQ_RIGHTSEL; + } + else { + /* Deselect the strip if it's left with no handles selected. */ + if ((seq->flag & SEQ_RIGHTSEL) && ((seq->flag & SEQ_LEFTSEL) == 0)) { + seq->flag &= ~SELECT; + } + seq->flag &= ~SEQ_RIGHTSEL; + } + } + /* Left handle. */ + if (rectf.xmin < (seq->startdisp + handsize)) { + if (select) { + seq->flag |= SELECT | SEQ_LEFTSEL; + } + else { + /* Deselect the strip if it's left with no handles selected. */ + if ((seq->flag & SEQ_LEFTSEL) && ((seq->flag & SEQ_RIGHTSEL) == 0)) { + seq->flag &= ~SELECT; + } + seq->flag &= ~SEQ_LEFTSEL; + } + } + } + + /* Regular box selection. */ + else { + SET_FLAG_FROM_TEST(seq->flag, select, SELECT); + seq->flag &= ~(SEQ_LEFTSEL | SEQ_RIGHTSEL); + } } } @@ -1072,6 +1110,8 @@ static int sequencer_box_select_invoke(bContext *C, wmOperator *op, const wmEven void SEQUENCER_OT_select_box(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Box Select"; ot->idname = "SEQUENCER_OT_select_box"; @@ -1092,9 +1132,11 @@ void SEQUENCER_OT_select_box(wmOperatorType *ot) WM_operator_properties_gesture_box(ot); WM_operator_properties_select_operation_simple(ot); - PropertyRNA *prop = RNA_def_boolean( + 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); + prop = RNA_def_boolean(ot->srna, "handles", 0, "Select Handles", "Select the strips' handles"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /* ****** Selected Grouped ****** */ -- cgit v1.2.3