add missing GPL information in guicast program files
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / vtimebar.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 "edl.h"
23 #include "localsession.h"
24 #include "mwindow.h"
25 #include "theme.h"
26 #include "vtimebar.h"
27 #include "vwindow.h"
28 #include "vwindowgui.h"
29
30
31 VTimeBar::VTimeBar(MWindow *mwindow,
32                 VWindowGUI *gui,
33                 int x,
34                 int y,
35                 int w,
36                 int h)
37  : TimeBar(mwindow,
38                 gui,
39                 x,
40                 y,
41                 w,
42                 h)
43 {
44         this->mwindow = mwindow;
45         this->gui = gui;
46 // *** CONTEXT_HELP ***
47         context_help_set_keyword("Preview Region Usage");
48 }
49
50 int VTimeBar::resize_event()
51 {
52         reposition_window(mwindow->theme->vtimebar_x,
53                 mwindow->theme->vtimebar_y,
54                 mwindow->theme->vtimebar_w,
55                 mwindow->theme->vtimebar_h);
56         update(0);
57         return 1;
58 }
59
60 EDL* VTimeBar::get_edl()
61 {
62         return gui->vwindow->get_edl();
63 }
64
65 void VTimeBar::draw_time()
66 {
67         draw_range();
68 }
69
70 void VTimeBar::select_label(double position)
71 {
72         EDL *edl = get_edl();
73         if( edl ) {
74                 gui->stop_transport();
75                 position = mwindow->edl->align_to_frame(position, 1);
76
77                 if(shift_down())
78                 {
79                         if(position > edl->local_session->get_selectionend(1) / 2 +
80                                 edl->local_session->get_selectionstart(1) / 2)
81                         {
82
83                                 edl->local_session->set_selectionend(position);
84                         }
85                         else
86                         {
87                                 edl->local_session->set_selectionstart(position);
88                         }
89                 }
90                 else
91                 {
92                         edl->local_session->set_selectionstart(position);
93                         edl->local_session->set_selectionend(position);
94                 }
95
96 // Que the CWindow
97                 gui->vwindow->update_position();
98                 update(1);
99         }
100 }
101
102 double VTimeBar::pixel_to_position(int pixel)
103 {
104         double start = 0, end = get_edl_length();
105         EDL *edl = get_edl();
106         if( edl ) {
107                 double preview_start = edl->local_session->preview_start;
108                 double preview_end = edl->local_session->preview_end;
109                 if( preview_end >= 0 || preview_start > 0 )
110                         start = preview_start;
111                 if( preview_end >= 0 && preview_end < end )
112                         end = preview_end;
113         }
114         if( start > end ) start = end;
115         return start + (double)pixel * (end - start) / get_w();
116 }
117
118
119 void VTimeBar::update_cursor()
120 {
121         int rx = get_relative_cursor_x();
122         double position = pixel_to_position(rx);
123         gui->vwindow->update_position(position);
124         update(1);
125 }
126
127 double VTimeBar::test_highlight()
128 {
129         return gui->edit_panel->get_position();
130 }
131