initial commit
[goodguy/history.git] / cinelerra-5.0 / 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 }
47
48 int VTimeBar::resize_event()
49 {
50         reposition_window(mwindow->theme->vtimebar_x,
51                 mwindow->theme->vtimebar_y,
52                 mwindow->theme->vtimebar_w,
53                 mwindow->theme->vtimebar_h);
54         update(0);
55         return 1;
56 }
57
58 EDL* VTimeBar::get_edl()
59 {
60         return gui->vwindow->get_edl();
61 }
62
63 void VTimeBar::draw_time()
64 {
65         draw_range();
66 }
67
68 void VTimeBar::select_label(double position)
69 {
70         EDL *edl = get_edl();
71
72         if(edl)
73         {
74                 unlock_window();
75                 gui->transport->handle_transport(STOP, 1, 0, 0);
76                 lock_window();
77
78                 position = mwindow->edl->align_to_frame(position, 1);
79
80                 if(shift_down())
81                 {
82                         if(position > edl->local_session->get_selectionend(1) / 2 + 
83                                 edl->local_session->get_selectionstart(1) / 2)
84                         {
85
86                                 edl->local_session->set_selectionend(position);
87                         }
88                         else
89                         {
90                                 edl->local_session->set_selectionstart(position);
91                         }
92                 }
93                 else
94                 {
95                         edl->local_session->set_selectionstart(position);
96                         edl->local_session->set_selectionend(position);
97                 }
98
99 // Que the CWindow
100                 gui->vwindow->update_position(CHANGE_NONE, 
101                         0, 
102                         1,
103                         0);
104                 update(1);
105         }
106 }
107
108 double VTimeBar::pixel_to_position(int pixel)
109 {
110         double start = 0, length = 0;
111         EDL *edl = get_edl();
112         if(edl)
113         {
114                 start = edl->local_session->preview_start;
115                 if(start >= 0)
116                         length = edl->local_session->preview_end - start;
117         }
118         if(length <= 0)
119                 length = get_edl_length();
120         return start + (double)pixel * length / get_w();
121 }
122
123 void VTimeBar::update_cursor()
124 {
125         int rx = get_relative_cursor_x();
126         double position = pixel_to_position(rx);
127         gui->vwindow->update_position(position);
128         update(1);
129 }
130
131