fix for filebox apply btn on resize
[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 }
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         if( edl ) {
72                 gui->stop_transport("VTimeBar::select_label");
73
74                 position = mwindow->edl->align_to_frame(position, 1);
75
76                 if(shift_down())
77                 {
78                         if(position > edl->local_session->get_selectionend(1) / 2 +
79                                 edl->local_session->get_selectionstart(1) / 2)
80                         {
81
82                                 edl->local_session->set_selectionend(position);
83                         }
84                         else
85                         {
86                                 edl->local_session->set_selectionstart(position);
87                         }
88                 }
89                 else
90                 {
91                         edl->local_session->set_selectionstart(position);
92                         edl->local_session->set_selectionend(position);
93                 }
94
95 // Que the CWindow
96                 gui->vwindow->update_position(CHANGE_NONE,
97                         0,
98                         1,
99                         0);
100                 update(1);
101         }
102 }
103
104 double VTimeBar::pixel_to_position(int pixel)
105 {
106         double start = 0, end = get_edl_length();
107         EDL *edl = get_edl();
108         if( edl ) {
109                 double preview_start = edl->local_session->preview_start;
110                 double preview_end = edl->local_session->preview_end;
111                 if( preview_end >= 0 || preview_start > 0 )
112                         start = preview_start;
113                 if( preview_end >= 0 && preview_end < end )
114                         end = preview_end;
115         }
116         if( start > end ) start = end;
117         return start + (double)pixel * (end - start) / get_w();
118 }
119
120
121 void VTimeBar::update_cursor()
122 {
123         int rx = get_relative_cursor_x();
124         double position = pixel_to_position(rx);
125         gui->vwindow->update_position(position);
126         update(1);
127 }
128
129 double VTimeBar::test_highlight()
130 {
131         return gui->edit_panel->get_position();
132 }
133