diff options
author | Richard Antalik <richardantalik@gmail.com> | 2020-01-22 16:54:44 +0300 |
---|---|---|
committer | Richard Antalik <richardantalik@gmail.com> | 2020-01-22 17:06:18 +0300 |
commit | 6a49161c8c60cb63d9e3ed8dbe700163ff858436 (patch) | |
tree | 501c050d13bdbcdff7c6152a0946bb99617d5dc5 /source/blender/editors/space_sequencer | |
parent | f559e3977e0773382cfb554956fe424f6050d495 (diff) |
VSE: Tool system integration
Add toolbar to sequencer regions.
A bit of refactoring has to be done in RNA space.
Currently there is only cut tool implemented to serve as template for
anybody who would like to add more.
Diffstat (limited to 'source/blender/editors/space_sequencer')
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_edit.c | 130 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/space_sequencer.c | 53 |
2 files changed, 153 insertions, 30 deletions
diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index f4d7e9d20ca..a1177454acd 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -103,6 +103,7 @@ EnumPropertyItem prop_side_types[] = { {SEQ_SIDE_LEFT, "LEFT", 0, "Left", ""}, {SEQ_SIDE_RIGHT, "RIGHT", 0, "Right", ""}, {SEQ_SIDE_BOTH, "BOTH", 0, "Both", ""}, + {SEQ_SIDE_NO_CHANGE, "NO_CHANGE", 0, "No change", ""}, {0, NULL, 0, NULL, NULL}, }; @@ -958,6 +959,8 @@ static bool cut_seq_list(Main *bmain, Scene *scene, ListBase *slist, int cutframe, + int channel, + bool use_cursor_position, Sequence *(*cut_seq)(Main *bmain, Scene *, Sequence *, ListBase *, int)) { Sequence *seq, *seq_next_iter; @@ -968,8 +971,8 @@ static bool cut_seq_list(Main *bmain, while (seq && seq != seq_first_new) { seq_next_iter = seq->next; /* we need this because we may remove seq */ seq->tmp = NULL; - if (seq->flag & SELECT) { - if (cutframe > seq->startdisp && cutframe < seq->enddisp) { + if (use_cursor_position) { + if (seq->machine == channel && seq->startdisp < cutframe && seq->enddisp > cutframe) { Sequence *seqn = cut_seq(bmain, scene, seq, slist, cutframe); if (seqn) { if (seq_first_new == NULL) { @@ -977,16 +980,28 @@ static bool cut_seq_list(Main *bmain, } } } - else if (seq->enddisp <= cutframe) { - /* do nothing */ - } - else if (seq->startdisp >= cutframe) { - /* move to tail */ - BLI_remlink(slist, seq); - BLI_addtail(slist, seq); + } + else { + if (seq->flag & SELECT) { + if (cutframe > seq->startdisp && cutframe < seq->enddisp) { + Sequence *seqn = cut_seq(bmain, scene, seq, slist, cutframe); + if (seqn) { + if (seq_first_new == NULL) { + seq_first_new = seqn; + } + } + } + else if (seq->enddisp <= cutframe) { + /* do nothing */ + } + else if (seq->startdisp >= cutframe) { + /* move to tail */ + BLI_remlink(slist, seq); + BLI_addtail(slist, seq); - if (seq_first_new == NULL) { - seq_first_new = seq; + if (seq_first_new == NULL) { + seq_first_new = seq; + } } } } @@ -2154,40 +2169,64 @@ static int sequencer_cut_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); Editing *ed = BKE_sequencer_editing_get(scene, false); - int cut_side, cut_hard, cut_frame; - - bool changed; + int cut_side, cut_hard, cut_frame, cut_channel; + bool changed, use_cursor_position, ignore_selection; + bool seq_selected = false; cut_frame = RNA_int_get(op->ptr, "frame"); + cut_channel = RNA_int_get(op->ptr, "channel"); + use_cursor_position = RNA_boolean_get(op->ptr, "use_cursor_position"); cut_hard = RNA_enum_get(op->ptr, "type"); cut_side = RNA_enum_get(op->ptr, "side"); + ignore_selection = RNA_boolean_get(op->ptr, "ignore_selection"); if (cut_hard == SEQ_CUT_HARD) { - changed = cut_seq_list(bmain, scene, ed->seqbasep, cut_frame, cut_seq_hard); + changed = cut_seq_list( + bmain, scene, ed->seqbasep, cut_frame, cut_channel, use_cursor_position, cut_seq_hard); } else { - changed = cut_seq_list(bmain, scene, ed->seqbasep, cut_frame, cut_seq_soft); + changed = cut_seq_list( + bmain, scene, ed->seqbasep, cut_frame, cut_channel, use_cursor_position, cut_seq_soft); } if (changed) { /* got new strips ? */ Sequence *seq; - if (cut_side != SEQ_SIDE_BOTH) { - SEQP_BEGIN (ed, seq) { - if (cut_side == SEQ_SIDE_LEFT) { - if (seq->startdisp >= cut_frame) { - seq->flag &= ~SEQ_ALLSEL; + if (ignore_selection) { + if (use_cursor_position) { + SEQP_BEGIN (ed, seq) { + if (seq->enddisp == cut_frame && seq->machine == cut_channel) { + seq_selected = seq->flag & SEQ_ALLSEL; } } - else { - if (seq->enddisp <= cut_frame) { - seq->flag &= ~SEQ_ALLSEL; + SEQ_END; + if (!seq_selected) { + SEQP_BEGIN (ed, seq) { + if (seq->startdisp == cut_frame && seq->machine == cut_channel) { + seq->flag &= ~SEQ_ALLSEL; + } } + SEQ_END; } } - SEQ_END; } - + else { + if (cut_side != SEQ_SIDE_BOTH) { + SEQP_BEGIN (ed, seq) { + if (cut_side == SEQ_SIDE_LEFT) { + if (seq->startdisp >= cut_frame) { + seq->flag &= ~SEQ_ALLSEL; + } + } + else { + if (seq->enddisp <= cut_frame) { + seq->flag &= ~SEQ_ALLSEL; + } + } + } + SEQ_END; + } + } SEQP_BEGIN (ed, seq) { if (seq->seq1 || seq->seq2 || seq->seq3) { BKE_sequence_calc(scene, seq); @@ -2204,7 +2243,8 @@ static int sequencer_cut_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } else { - return OPERATOR_CANCELLED; + /* Passthrough to selection if used as tool. */ + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; } } @@ -2224,7 +2264,17 @@ static int sequencer_cut_invoke(bContext *C, wmOperator *op, const wmEvent *even cut_side = SEQ_SIDE_BOTH; } } - RNA_int_set(op->ptr, "frame", cut_frame); + + float mouseloc[2]; + UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &mouseloc[0], &mouseloc[1]); + + if (RNA_boolean_get(op->ptr, "use_cursor_position")) { + RNA_int_set(op->ptr, "frame", mouseloc[0]); + } + else { + RNA_int_set(op->ptr, "frame", cut_frame); + } + RNA_int_set(op->ptr, "channel", mouseloc[1]); RNA_enum_set(op->ptr, "side", cut_side); /*RNA_enum_set(op->ptr, "type", cut_hard); */ /*This type is set from the key shortcut */ return sequencer_cut_exec(C, op); @@ -2255,19 +2305,43 @@ void SEQUENCER_OT_cut(struct wmOperatorType *ot) "Frame where selected strips will be cut", INT_MIN, INT_MAX); + RNA_def_int(ot->srna, + "channel", + 0, + INT_MIN, + INT_MAX, + "Channel", + "Channel in which strip will be cut", + INT_MIN, + INT_MAX); RNA_def_enum(ot->srna, "type", prop_cut_types, SEQ_CUT_SOFT, "Type", "The type of cut operation to perform on strips"); + RNA_def_boolean(ot->srna, + "use_cursor_position", + 0, + "Use Cursor Position", + "Cut at position of the cursor instead of playhead"); prop = RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_MOUSE, "Side", "The side that remains selected after cutting"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean( + ot->srna, + "ignore_selection", + false, + "Ignore Selection", + "Make cut event if strip is not selected preserving selection state after cut"); + + RNA_def_property_flag(prop, PROP_HIDDEN); } #undef SEQ_SIDE_MOUSE diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c index a06a90fa6e2..81783f9105c 100644 --- a/source/blender/editors/space_sequencer/space_sequencer.c +++ b/source/blender/editors/space_sequencer/space_sequencer.c @@ -110,6 +110,14 @@ static SpaceLink *sequencer_new(const ScrArea *UNUSED(sa), const Scene *scene) ar->alignment = RGN_ALIGN_RIGHT; ar->flag = RGN_FLAG_HIDDEN; + /* toolbar */ + ar = MEM_callocN(sizeof(ARegion), "tools for sequencer"); + + BLI_addtail(&sseq->regionbase, ar); + ar->regiontype = RGN_TYPE_TOOLS; + ar->alignment = RGN_ALIGN_LEFT; + ar->flag = RGN_FLAG_HIDDEN; + /* preview region */ /* NOTE: if you change values here, also change them in sequencer_init_preview_region */ ar = MEM_callocN(sizeof(ARegion), "preview region for sequencer"); @@ -618,6 +626,23 @@ static void sequencer_header_region_draw(const bContext *C, ARegion *ar) ED_region_header(C, ar); } +/* *********************** toolbar region ************************ */ +/* add handlers, stuff you only do once or on area/region changes */ +static void sequencer_tools_region_init(wmWindowManager *wm, ARegion *ar) +{ + wmKeyMap *keymap; + + ar->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE; + ED_region_panels_init(wm, ar); + + keymap = WM_keymap_ensure(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0); + WM_event_add_keymap_handler_v2d_mask(&ar->handlers, keymap); +} + +static void sequencer_tools_region_draw(const bContext *C, ARegion *ar) +{ + ED_region_panels(C, ar); +} /* *********************** preview region ************************ */ static void sequencer_preview_region_init(wmWindowManager *wm, ARegion *ar) { @@ -832,7 +857,7 @@ void ED_spacetype_sequencer(void) art->draw = sequencer_main_region_draw; art->listener = sequencer_main_region_listener; art->message_subscribe = sequencer_main_region_message_subscribe; - art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_ANIMATION; + art->keymapflag = ED_KEYMAP_TOOL | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_ANIMATION; BLI_addhead(&st->regiontypes, art); @@ -842,7 +867,8 @@ void ED_spacetype_sequencer(void) art->init = sequencer_preview_region_init; art->draw = sequencer_preview_region_draw; art->listener = sequencer_preview_region_listener; - art->keymapflag = ED_KEYMAP_GIZMO | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL; + art->keymapflag = ED_KEYMAP_TOOL | ED_KEYMAP_GIZMO | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | + ED_KEYMAP_GPENCIL; BLI_addhead(&st->regiontypes, art); /* regions: listview/buttons */ @@ -850,12 +876,35 @@ void ED_spacetype_sequencer(void) art->regionid = RGN_TYPE_UI; art->prefsizex = UI_SIDEBAR_PANEL_WIDTH * 1.3f; art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; + art->message_subscribe = ED_area_do_mgs_subscribe_for_tool_ui; art->listener = sequencer_buttons_region_listener; art->init = sequencer_buttons_region_init; art->draw = sequencer_buttons_region_draw; BLI_addhead(&st->regiontypes, art); sequencer_buttons_register(art); + /* regions: tool(bar) */ + art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer tools region"); + art->regionid = RGN_TYPE_TOOLS; + art->prefsizex = 58; /* XXX */ + art->prefsizey = 50; /* XXX */ + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; + art->message_subscribe = ED_region_generic_tools_region_message_subscribe; + art->snap_size = ED_region_generic_tools_region_snap_size; + art->init = sequencer_tools_region_init; + art->draw = sequencer_tools_region_draw; + BLI_addhead(&st->regiontypes, art); + + /* regions: tool header */ + art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer tool header region"); + art->regionid = RGN_TYPE_TOOL_HEADER; + art->prefsizey = HEADERY; + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER; + art->listener = sequencer_main_region_listener; + art->init = sequencer_header_region_init; + art->draw = sequencer_header_region_draw; + art->message_subscribe = ED_area_do_mgs_subscribe_for_tool_header; + BLI_addhead(&st->regiontypes, art); /* regions: header */ art = MEM_callocN(sizeof(ARegionType), "spacetype sequencer region"); |