b374c2deec73c39106585f2d0c88a8658814df01
[goodguy/history.git] / cinelerra-5.1 / cinelerra / zwindowgui.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2011 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 "bcwindow.h"
23 #include "canvas.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "keys.h"
27 #include "language.h"
28 #include "localsession.h"
29 #include "mainmenu.h"
30 #include "mainsession.h"
31 #include "mbuttons.h"
32 #include "mwindow.h"
33 #include "mwindowgui.h"
34 #include "playbackengine.h"
35 #include "theme.h"
36 #include "tracks.h"
37 #include "zwindow.h"
38 #include "zwindowgui.h"
39
40 ZWindowGUI::ZWindowGUI(MWindow *mwindow, ZWindow *zwindow, Mixer *mixer)
41  : BC_Window(mixer->title, mixer->x, mixer->y, mixer->w, mixer->h,
42         100, 100, 1, 1, 0)
43 {
44         this->mwindow = mwindow;
45         this->zwindow = zwindow;
46
47         canvas = 0;
48         playback_engine = 0;
49         highlighted = 0;
50 }
51
52 ZWindowGUI::~ZWindowGUI()
53 {
54         delete playback_engine;
55         delete canvas;
56 }
57
58 void ZWindowGUI::create_objects()
59 {
60         lock_window("ZWindowGUI::create_objects");
61
62         canvas = new ZWindowCanvas(mwindow, this, 10,10, get_w()-20,get_h()-20);
63         canvas->create_objects(mwindow->edl);
64         playback_engine = new PlaybackEngine(mwindow, canvas);
65         playback_engine->create_objects();
66
67         deactivate();
68         show_window();
69         unlock_window();
70 }
71
72 int ZWindowGUI::resize_event(int w, int h)
73 {
74         canvas->reposition_window(0, 10,10, w-20,h-20);
75         zwindow->reposition(get_x(), get_y(), w, h);
76         BC_WindowBase::resize_event(w, h);
77         return 1;
78 }
79
80 int ZWindowGUI::translation_event()
81 {
82         zwindow->reposition(get_x(), get_y(), get_w(), get_h());
83         return 0;
84 }
85
86 int ZWindowGUI::close_event()
87 {
88         mwindow->del_mixer(zwindow);
89         set_done(0);
90         return 1;
91 }
92
93 int ZWindowGUI::keypress_event()
94 {
95         int key = get_keypress();
96         if( key == 'w' || key == 'W' ) {
97                 close_event();
98                 return 1;
99         }
100         unlock_window();
101         int result = 1;
102         switch( key ) {
103         case 'f':
104                 if( mwindow->session->zwindow_fullscreen )
105                         canvas->stop_fullscreen();
106                 else
107                         canvas->start_fullscreen();
108                 break;
109         case ESC:
110                 if( mwindow->session->zwindow_fullscreen )
111                         canvas->stop_fullscreen();
112                 break;
113         default:
114                 mwindow->gui->lock_window("ZWindowGUI::keypress_event");
115                 result = mwindow->gui->mbuttons->transport->do_keypress(key);
116                 mwindow->gui->unlock_window();
117         }
118
119         lock_window("ZWindowGUI::keypress_event 1");
120         return result;
121 }
122
123 int ZWindowGUI::button_press_event()
124 {
125         mwindow->select_zwindow(zwindow);
126         if( get_double_click() ) {
127                 unlock_window();
128                 mwindow->gui->lock_window("ZWindowGUI::button_press_event 0");
129                 LocalSession *local_session = mwindow->edl->local_session;
130                 double start = local_session->get_selectionstart(1);
131                 double end = local_session->get_selectionend(1);
132                 if( EQUIV(start, end) ) {
133                         start = mwindow->edl->tracks->total_recordable_length();
134                         if( start < 0 ) start = end;
135                 }
136                 if( (end-start) > 1e-4 ) {
137                         LocalSession *zlocal_session = zwindow->edl->local_session;
138                         zlocal_session->set_selectionstart(end);
139                         zlocal_session->set_selectionend(end);
140                         zlocal_session->set_inpoint(start);
141                         zlocal_session->set_outpoint(end);
142                         double orig_inpoint = local_session->get_inpoint();
143                         double orig_outpoint = local_session->get_outpoint();
144                         local_session->set_selectionstart(end);
145                         local_session->set_selectionend(end);
146                         local_session->set_inpoint(start);
147                         local_session->set_outpoint(end);
148                         mwindow->overwrite(zwindow->edl);
149                         local_session->set_inpoint(orig_inpoint);
150                         local_session->set_outpoint(orig_outpoint);
151                         mwindow->gui->update_timebar(1);
152                 }
153                 mwindow->gui->unlock_window();
154                 lock_window("ZWindowGUI::button_press_event 1");
155         }
156         if( !canvas->get_canvas() ) return 0;
157         return canvas->button_press_event_base(canvas->get_canvas());
158 }
159
160 int ZWindowGUI::cursor_leave_event()
161 {
162         if( !canvas->get_canvas() ) return 0;
163         return canvas->cursor_leave_event_base(canvas->get_canvas());
164 }
165
166 int ZWindowGUI::cursor_enter_event()
167 {
168         if( !canvas->get_canvas() ) return 0;
169         return canvas->cursor_enter_event_base(canvas->get_canvas());
170 }
171
172 int ZWindowGUI::button_release_event()
173 {
174         if( !canvas->get_canvas() ) return 0;
175         return canvas->button_release_event();
176 }
177
178 int ZWindowGUI::cursor_motion_event()
179 {
180         BC_WindowBase *cvs = canvas->get_canvas();
181         if( !cvs ) return 0;
182         cvs->unhide_cursor();
183         return canvas->cursor_motion_event();
184 }
185
186 int ZWindowGUI::draw_overlays()
187 {
188         BC_WindowBase *cvs = canvas->get_canvas();
189         if( !cvs || cvs->get_video_on() ) return 0;
190         if( highlighted != zwindow->highlighted ) {
191                 highlighted = zwindow->highlighted;
192                 cvs->set_color(WHITE);
193                 cvs->set_inverse();
194                 cvs->draw_rectangle(0, 0, cvs->get_w(), cvs->get_h());
195                 cvs->draw_rectangle(1, 1, cvs->get_w() - 2, cvs->get_h() - 2);
196                 cvs->set_opaque();
197         }
198         return 1;
199 }
200
201 ZWindowCanvas::ZWindowCanvas(MWindow *mwindow, ZWindowGUI *gui,
202                 int x, int y, int w, int h)
203  : Canvas(mwindow, gui, x,y, w,h, 0,0,0)
204 {
205         this->mwindow = mwindow;
206         this->gui = gui;
207 }
208
209 void ZWindowCanvas::close_source()
210 {
211         gui->unlock_window();
212         gui->zwindow->zgui->playback_engine->interrupt_playback(1);
213         gui->lock_window("ZWindowCanvas::close_source");
214         EDL *edl = gui->zwindow->edl;
215         if( edl ) {
216                 gui->zwindow->edl = 0;
217                 edl->remove_user();
218         }
219 }
220
221
222 void ZWindowCanvas::draw_refresh(int flush)
223 {
224         EDL *edl = gui->zwindow->edl;
225         BC_WindowBase *cvs = get_canvas();
226         int dirty = 0;
227
228         if( !cvs->get_video_on() ) {
229                 cvs->clear_box(0, 0, cvs->get_w(), cvs->get_h());
230                 gui->highlighted = 0;
231                 dirty = 1;
232         }
233         if( !cvs->get_video_on() && refresh_frame && edl ) {
234                 float in_x1, in_y1, in_x2, in_y2;
235                 float out_x1, out_y1, out_x2, out_y2;
236                 get_transfers(edl,
237                         in_x1, in_y1, in_x2, in_y2,
238                         out_x1, out_y1, out_x2, out_y2);
239                 cvs->draw_vframe(refresh_frame,
240                         (int)out_x1, (int)out_y1, (int)(out_x2 - out_x1), (int)(out_y2 - out_y1),
241                         (int)in_x1, (int)in_y1, (int)(in_x2 - in_x1), (int)(in_y2 - in_y1), 0);
242                 dirty = 1;
243         }
244         
245         if( gui->draw_overlays() )
246                 dirty = 1;
247
248         if( dirty )
249                 cvs->flash(flush);
250 }
251
252 int ZWindowCanvas::get_fullscreen()
253 {
254         return mwindow->session->zwindow_fullscreen;
255 }
256
257 void ZWindowCanvas::set_fullscreen(int value)
258 {
259         mwindow->session->zwindow_fullscreen = value;
260 }
261