From 4d76ed2e81154119f8335aeb70724468e08dbb94 Mon Sep 17 00:00:00 2001 From: Good Guy Date: Sun, 11 Oct 2020 15:52:16 -0600 Subject: [PATCH] add deselect to editpopup menu, drag edit select/deselect --- cinelerra-5.1/cinelerra/editpopup.C | 16 +++- cinelerra-5.1/cinelerra/editpopup.h | 10 +++ cinelerra-5.1/cinelerra/mainsession.inc | 1 + cinelerra-5.1/cinelerra/mwindow.h | 2 +- cinelerra-5.1/cinelerra/mwindowedit.C | 4 +- cinelerra-5.1/cinelerra/mwindowgui.C | 2 +- cinelerra-5.1/cinelerra/trackcanvas.C | 101 +++++++++++++++++++++++- cinelerra-5.1/cinelerra/trackcanvas.h | 1 + cinelerra-5.1/cinelerra/tracks.C | 4 +- cinelerra-5.1/cinelerra/tracks.h | 2 +- cinelerra-5.1/doc/shortcuts.html | 12 +++ 11 files changed, 143 insertions(+), 12 deletions(-) diff --git a/cinelerra-5.1/cinelerra/editpopup.C b/cinelerra-5.1/cinelerra/editpopup.C index 60dcafb8..b1fef22f 100644 --- a/cinelerra-5.1/cinelerra/editpopup.C +++ b/cinelerra-5.1/cinelerra/editpopup.C @@ -68,6 +68,7 @@ void EditPopup::create_objects() add_item(open_edl = new EditPopupOpenEDL(mwindow, this)); add_item(new EditPopupClearSelect(mwindow, this)); add_item(new EditPopupSelectEdits(mwindow, this)); + add_item(new EditPopupDeselectEdits(mwindow, this)); add_item(new EditPopupCopy(mwindow, this)); add_item(new EditPopupCut(mwindow, this)); add_item(new EditPopupMute(mwindow, this)); @@ -171,7 +172,20 @@ EditPopupSelectEdits::EditPopupSelectEdits(MWindow *mwindow, EditPopup *popup) int EditPopupSelectEdits::handle_event() { - mwindow->select_edits(); + mwindow->select_edits(1); + return 1; +} + +EditPopupDeselectEdits::EditPopupDeselectEdits(MWindow *mwindow, EditPopup *popup) + : BC_MenuItem(_("Deselect Edits")) +{ + this->mwindow = mwindow; + this->popup = popup; +} + +int EditPopupDeselectEdits::handle_event() +{ + mwindow->select_edits(0); return 1; } diff --git a/cinelerra-5.1/cinelerra/editpopup.h b/cinelerra-5.1/cinelerra/editpopup.h index ed3fe2f8..6a859bb3 100644 --- a/cinelerra-5.1/cinelerra/editpopup.h +++ b/cinelerra-5.1/cinelerra/editpopup.h @@ -83,6 +83,16 @@ public: EditPopup *popup; }; +class EditPopupDeselectEdits : public BC_MenuItem +{ +public: + EditPopupDeselectEdits(MWindow *mwindow, EditPopup *popup); + int handle_event(); + + MWindow *mwindow; + EditPopup *popup; +}; + class EditPopupCopy : public BC_MenuItem { public: diff --git a/cinelerra-5.1/cinelerra/mainsession.inc b/cinelerra-5.1/cinelerra/mainsession.inc index 754183c2..e16e82bc 100644 --- a/cinelerra-5.1/cinelerra/mainsession.inc +++ b/cinelerra-5.1/cinelerra/mainsession.inc @@ -67,6 +67,7 @@ enum DRAG_GROUP, GROUP_TOGGLE, DROP_TARGETING, + DRAG_EDIT_SELECT, }; diff --git a/cinelerra-5.1/cinelerra/mwindow.h b/cinelerra-5.1/cinelerra/mwindow.h index c636d787..73cdcfac 100644 --- a/cinelerra-5.1/cinelerra/mwindow.h +++ b/cinelerra-5.1/cinelerra/mwindow.h @@ -448,7 +448,7 @@ public: void clear_hard_edges(); int clear_hard_edges(double start, double end); void clear_select(); - void select_edits(); + void select_edits(int v); void concatenate_tracks(); int copy_flags(int copy_flags=COPY_CLIPBOARD); void copy(); diff --git a/cinelerra-5.1/cinelerra/mwindowedit.C b/cinelerra-5.1/cinelerra/mwindowedit.C index b35cd335..6f74435b 100644 --- a/cinelerra-5.1/cinelerra/mwindowedit.C +++ b/cinelerra-5.1/cinelerra/mwindowedit.C @@ -426,11 +426,11 @@ void MWindow::clear_select() gui->draw_overlays(1); } -void MWindow::select_edits() +void MWindow::select_edits(int v) { double start = edl->local_session->get_selectionstart(); double end = edl->local_session->get_selectionend(); - edl->tracks->select_edits(start, end); + edl->tracks->select_edits(start, end, v); gui->draw_overlays(1); } diff --git a/cinelerra-5.1/cinelerra/mwindowgui.C b/cinelerra-5.1/cinelerra/mwindowgui.C index 5f9edd92..17078ba4 100644 --- a/cinelerra-5.1/cinelerra/mwindowgui.C +++ b/cinelerra-5.1/cinelerra/mwindowgui.C @@ -1098,7 +1098,7 @@ int MWindowGUI::keypress_event() result = 1; } else if( ctrl_down() && alt_down() ) { - mwindow->select_edits(); + mwindow->select_edits(1); result = 1; } break; diff --git a/cinelerra-5.1/cinelerra/trackcanvas.C b/cinelerra-5.1/cinelerra/trackcanvas.C index 098090a6..536fabc6 100644 --- a/cinelerra-5.1/cinelerra/trackcanvas.C +++ b/cinelerra-5.1/cinelerra/trackcanvas.C @@ -188,6 +188,7 @@ int TrackCanvas::drag_motion( Track **over_track, Edit **over_edit, PluginSet **over_pluginset, Plugin **over_plugin) { + int update_scroll = 0; int cursor_x = get_relative_cursor_x(); int cursor_y = get_relative_cursor_y(); if( get_cursor_over_window() ) { @@ -196,6 +197,28 @@ int TrackCanvas::drag_motion( } if( over_track && !*over_track ) *over_track = pane->over_patchbay(); + + switch( mwindow->session->current_operation ) { + case DRAG_EDIT_SELECT: { + Edit *edit = over_edit ? *over_edit : 0; + double position = mwindow->edl->get_cursor_position(cursor_x, pane->number); + mwindow->session->drag_position = mwindow->edl->align_to_frame(position, 0); + drag_edit_select(edit, 0, 1); + update_scroll = 1; + break; } + } + + if( update_scroll ) { + if( !drag_scroll && + (cursor_x >= get_w() || cursor_x < 0 || + cursor_y >= get_h() || cursor_y < 0)) + start_dragscroll(); + else if( drag_scroll && + cursor_x < get_w() && cursor_x >= 0 && + cursor_y < get_h() && cursor_y >= 0 ) + stop_dragscroll(); + } + return 0; } @@ -500,7 +523,7 @@ int TrackCanvas::drag_stop(int *redraw) result = 1; } break; - case DRAG_GROUP: + case DRAG_GROUP: { mwindow->session->current_operation = NO_OPERATION; EDL *drag_group = mwindow->session->drag_group; if( drag_group ) { @@ -532,10 +555,21 @@ int TrackCanvas::drag_stop(int *redraw) } } result = 1; + break; } + case DRAG_EDIT_SELECT: + int select = ctrl_down() ? -1 : 1; + drag_edit_select(mwindow->session->edit_highlighted, select, 0); break; } } + switch( mwindow->session->current_operation ) { + case DRAG_EDIT_SELECT: + mwindow->session->current_operation = NO_OPERATION; + result = 1; + break; + } + return result; } @@ -4293,6 +4327,53 @@ void TrackCanvas::update_drag_caption() } +void TrackCanvas::drag_edit_select(Edit *over_edit, int select, int draw) +{ + if( !over_edit ) return; + if( !mwindow->session->drag_edit ) return; + Track *drag_track = mwindow->session->drag_edit->track; + Track *over_track = over_edit->track; + if( !drag_track || !over_track ) return; + if( drag_track->number_of() > over_track->number_of() ) { + Track *trk = drag_track; + drag_track = over_track; + over_track = trk; + } + double start_pos = mwindow->session->drag_start; + double end_pos = mwindow->session->drag_position; + if( start_pos > end_pos ) { + double pos = start_pos; + start_pos = end_pos; + end_pos = pos; + } + int done = 0, do_flash = 0; + for( Track *track=drag_track; !done; track=track->next ) { + if( !track->is_armed() ) continue; + for( Edit *edit=track->edits->first; edit; edit=edit->next ) { + int64_t pos = edit->startproject; + int64_t end = pos + edit->length; + double edit_start = track->from_units(pos); + double edit_end = track->from_units(end); + if( start_pos >= edit_end ) continue; + if( edit_start > end_pos ) continue; + if( select > 0 ) + edit->is_selected = 1; + else if( select < 0 ) + edit->is_selected = 0; + if( draw ) { + int64_t edit_x, edit_y, edit_w, edit_h; + edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h); + set_color(YELLOW); + draw_rectangle(edit_x, edit_y, edit_w, edit_h); + do_flash = 1; + } + } + if( track == over_track ) done = 1; + } + if( do_flash ) + flash(); +} + int TrackCanvas::cursor_update(int in_motion) { @@ -4306,7 +4387,7 @@ int TrackCanvas::cursor_update(int in_motion) int update_cursor = 0; int rerender = 0; double position = 0.; -//printf("TrackCanvas::cursor_update %d\n", __LINE__); +//printf("TrackCanvas::cursor_update %d %d,%d\n", __LINE__, get_cursor_x(), get_cursor_y()); // Default cursor int new_cursor = @@ -4577,6 +4658,7 @@ int TrackCanvas::repeat_event(int64_t duration) int result = 0; switch(mwindow->session->current_operation) { + case DRAG_EDIT_SELECT: case SELECT_REGION: //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start); if(get_cursor_x() > get_w()) { @@ -4774,6 +4856,10 @@ int TrackCanvas::button_release_event() drag_scroll = 0; break; } + case DRAG_EDIT_SELECT: + //result = 0; + break; + default: if( mwindow->session->current_operation ) { // if(mwindow->session->current_operation == SELECT_REGION) { @@ -5185,8 +5271,15 @@ int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag mwindow->session->drag_origin_x = cursor_x; mwindow->session->drag_origin_y = cursor_y; // Where the drag started, so we know relative position inside the edit later - mwindow->session->drag_position = - mwindow->edl->get_cursor_position(cursor_x, pane->number); + double position = mwindow->edl->get_cursor_position(cursor_x, pane->number); + mwindow->session->drag_position = mwindow->edl->align_to_frame(position, 1); + if( get_buttonpress() == LEFT_BUTTON && alt_down() ) { + mwindow->session->drag_start = mwindow->session->drag_position; + drag_edit_select(edit, 0, 1); + mwindow->session->current_operation = DRAG_EDIT_SELECT; + result = 1; + continue; + } drag_start = 0; // if unselected "fast" drag if( !edit->silence() && !edit->is_selected ) { mwindow->edl->tracks->clear_selected_edits(); diff --git a/cinelerra-5.1/cinelerra/trackcanvas.h b/cinelerra-5.1/cinelerra/trackcanvas.h index 3d1ded19..15f8db63 100644 --- a/cinelerra-5.1/cinelerra/trackcanvas.h +++ b/cinelerra-5.1/cinelerra/trackcanvas.h @@ -308,6 +308,7 @@ public: // Update status bar to reflect drag operation void update_drag_caption(); + void drag_edit_select(Edit *over_edit, int select, int draw); int get_title_h(); diff --git a/cinelerra-5.1/cinelerra/tracks.C b/cinelerra-5.1/cinelerra/tracks.C index 07524f1f..8cbf92ce 100644 --- a/cinelerra-5.1/cinelerra/tracks.C +++ b/cinelerra-5.1/cinelerra/tracks.C @@ -126,7 +126,7 @@ void Tracks::get_selected_edits(ArrayList *drag_edits) } } -void Tracks::select_edits(double start, double end) +void Tracks::select_edits(double start, double end, int v) { for( Track *track=first; track; track=track->next ) { if( !track->is_armed() ) continue; @@ -135,7 +135,7 @@ void Tracks::select_edits(double start, double end) for( Edit *edit=track->edits->first; edit; edit=edit->next ) { if( start_pos >= edit->startproject+edit->length ) continue; if( edit->startproject >= end_pos ) continue; - edit->is_selected = 1; + edit->is_selected = v > 1 ? 1 : v < 0 ? 0 : !edit->is_selected ; } } } diff --git a/cinelerra-5.1/cinelerra/tracks.h b/cinelerra-5.1/cinelerra/tracks.h index cc1486d8..0f4b9647 100644 --- a/cinelerra-5.1/cinelerra/tracks.h +++ b/cinelerra-5.1/cinelerra/tracks.h @@ -59,7 +59,7 @@ public: void clear_selected_edits(); int clear_hard_edges(double start, double end); void get_selected_edits(ArrayList *drag_edits); - void select_edits(double start, double end); + void select_edits(double start, double end, int v); int next_group_id(); int new_group(int id); int set_group_selected(int id, int v); diff --git a/cinelerra-5.1/doc/shortcuts.html b/cinelerra-5.1/doc/shortcuts.html index a5bbc041..57abd089 100644 --- a/cinelerra-5.1/doc/shortcuts.html +++ b/cinelerra-5.1/doc/shortcuts.html @@ -1188,6 +1188,18 @@ Ctrl-Alt-a Add highlighted to selected edits + +
+ LMB + Alt + Drag + Drag Select + + +
+ LMB + Ctrl+Alt + Drag + Drag Deselect +
Copy -- 2.26.2