add bluray dv, misc fixes
[goodguy/history.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
34
35 CTimeBar::CTimeBar(MWindow *mwindow,
36                 CWindowGUI *gui,
37                 int x,
38                 int y,
39                 int w,
40                 int h)
41  : TimeBar(mwindow,
42                 gui,
43                 x,
44                 y,
45                 w,
46                 h)
47 {
48         this->mwindow = mwindow;
49         this->gui = gui;
50 }
51
52 int CTimeBar::resize_event()
53 {
54         reposition_window(mwindow->theme->ctimebar_x,
55                 mwindow->theme->ctimebar_y,
56                 mwindow->theme->ctimebar_w,
57                 mwindow->theme->ctimebar_h);
58         update(0);
59         return 1;
60 }
61
62
63 EDL* CTimeBar::get_edl()
64 {
65         return mwindow->edl;
66 }
67
68 void CTimeBar::draw_time()
69 {
70         draw_range();
71 }
72
73
74 double CTimeBar::pixel_to_position(int pixel)
75 {
76         double start = 0, length = 0;
77         EDL *edl = get_edl();
78         if(edl)
79         {
80                 start = edl->local_session->preview_start;
81                 if(start >= 0)
82                         length = edl->local_session->preview_end - start;
83         }
84         if(length <= 0)
85                 length = get_edl_length();
86         return start + (double)pixel * length / get_w();
87 }
88
89
90 void CTimeBar::update_cursor()
91 {
92         int rx = get_relative_cursor_x();
93         double position = pixel_to_position(rx);
94         mwindow->cwindow->update_position(position);
95 }
96
97
98
99 void CTimeBar::select_label(double position)
100 {
101         EDL *edl = mwindow->edl;
102
103         gui->unlock_window();
104         mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
105         gui->lock_window();
106
107         position = mwindow->edl->align_to_frame(position, 1);
108
109         if(shift_down())
110         {
111                 if(position > edl->local_session->get_selectionend(1) / 2 +
112                         edl->local_session->get_selectionstart(1) / 2)
113                 {
114
115                         edl->local_session->set_selectionend(position);
116                 }
117                 else
118                 {
119                         edl->local_session->set_selectionstart(position);
120                 }
121         }
122         else
123         {
124                 edl->local_session->set_selectionstart(position);
125                 edl->local_session->set_selectionend(position);
126         }
127
128 // Que the CWindow
129         mwindow->cwindow->update(1, 0, 0, 0, 1);
130
131 //printf("CTimeBar::select_label 1\n");
132
133         mwindow->gui->lock_window();
134         mwindow->gui->hide_cursor(0);
135         mwindow->gui->draw_cursor(1);
136         mwindow->gui->update(0,
137                 1,      // 1 for incremental drawing.  2 for full refresh
138                 1,
139                 0,
140                 1,
141                 1,
142                 0);
143         mwindow->gui->unlock_window();
144         mwindow->update_plugin_guis();
145 //printf("CTimeBar::select_label 2\n");
146 }
147
148
149
150
151