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