no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / ctimebar.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #include "bcsignals.h"
24 #include "ctimebar.h"
25 #include "cwindow.h"
26 #include "cwindowgui.h"
27 #include "edl.h"
28 #include "localsession.h"
29 #include "maincursor.h"
30 #include "mbuttons.h"
31 #include "mwindow.h"
32 #include "mwindowgui.h"
33 #include "theme.h"
34 #include "trackcanvas.inc"
35
36
37 CTimeBar::CTimeBar(MWindow *mwindow, CWindowGUI *gui,
38                 int x, int y, int w, int h)
39  : TimeBar(mwindow, gui, x, y, w, h)
40 {
41         this->mwindow = mwindow;
42         this->gui = gui;
43 // *** CONTEXT_HELP ***
44         context_help_set_keyword("Preview Region Usage");
45 }
46
47 int CTimeBar::resize_event()
48 {
49         reposition_window(mwindow->theme->ctimebar_x,
50                 mwindow->theme->ctimebar_y,
51                 mwindow->theme->ctimebar_w,
52                 mwindow->theme->ctimebar_h);
53         update(0);
54         return 1;
55 }
56
57
58 EDL* CTimeBar::get_edl()
59 {
60         return mwindow->edl;
61 }
62
63 void CTimeBar::draw_time()
64 {
65         draw_range();
66 }
67
68
69 double CTimeBar::pixel_to_position(int pixel)
70 {
71         double start = 0, end = get_edl_length();
72         EDL *edl = get_edl();
73         if( edl ) {
74                 double preview_start = edl->local_session->preview_start;
75                 double preview_end = edl->local_session->preview_end;
76                 if( preview_end >= 0 || preview_start > 0 )
77                         start = preview_start;
78                 if( preview_end >= 0 && preview_end < end )
79                         end = preview_end;
80         }
81         if( start > end ) start = end;
82         return start + (double)pixel * (end - start) / get_w();
83 }
84
85
86 void CTimeBar::update_cursor()
87 {
88         int rx = get_relative_cursor_x();
89         double position = pixel_to_position(rx);
90         mwindow->cwindow->update_position(position);
91 }
92
93
94
95 void CTimeBar::select_label(double position)
96 {
97         gui->stop_transport("CTimeBar::select_label");
98
99         EDL *edl = mwindow->edl;
100         position = edl->align_to_frame(position, 1);
101
102         if( shift_down() ) {
103                 if( position > edl->local_session->get_selectionend(1) / 2 +
104                         edl->local_session->get_selectionstart(1) / 2 ) {
105
106                         edl->local_session->set_selectionend(position);
107                 }
108                 else {
109                         edl->local_session->set_selectionstart(position);
110                 }
111         }
112         else {
113                 edl->local_session->set_selectionstart(position);
114                 edl->local_session->set_selectionend(position);
115         }
116
117 // Que the CWindow
118         unlock_window();
119         mwindow->cwindow->update(1, 0, 0, 0, 1);
120         mwindow->gui->lock_window();
121         mwindow->gui->hide_cursor(0);
122         mwindow->gui->draw_cursor(1);
123         mwindow->gui->update(0, NORMAL_DRAW, 1, 0, 1, 1, 0);
124         mwindow->gui->unlock_window();
125         mwindow->update_plugin_guis();
126         lock_window("CTimeBar::select_label");
127 }
128