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