4 * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
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.
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.
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
25 #include "edlsession.h"
28 #include "localsession.h"
30 #include "mainsession.h"
33 #include "mwindowgui.h"
34 #include "playbackengine.h"
38 #include "zwindowgui.h"
40 ZWindowGUI::ZWindowGUI(MWindow *mwindow, ZWindow *zwindow, Mixer *mixer)
41 : BC_Window(zwindow->title, mixer->x, mixer->y, mixer->w, mixer->h,
42 xS(100), yS(75), 1, 1, 0)
44 this->mwindow = mwindow;
45 this->zwindow = zwindow;
52 ZWindowGUI::~ZWindowGUI()
54 delete playback_engine;
58 void ZWindowGUI::create_objects()
60 lock_window("ZWindowGUI::create_objects");
62 canvas = new ZWindowCanvas(mwindow, this,
63 xS(10),yS(10), get_w()-xS(20),get_h()-yS(20));
64 canvas->create_objects(mwindow->edl);
65 playback_engine = new PlaybackEngine(mwindow, canvas);
66 playback_engine->create_objects();
73 int ZWindowGUI::resize_event(int w, int h)
75 canvas->reposition_window(0,
76 xS(10),yS(10), w-xS(20),h-yS(20));
77 zwindow->reposition(get_x(), get_y(), w, h);
78 BC_WindowBase::resize_event(w, h);
81 int ZWindowGUI::translation_event()
83 return resize_event(get_w(),get_h());
86 int ZWindowGUI::close_event()
92 int ZWindowGUI::keypress_event()
94 int key = get_keypress();
95 if( key == 'w' || key == 'W' ) {
103 canvas->use_fullscreen(canvas->get_fullscreen() ? 0 : 1);
106 canvas->use_fullscreen(0);
109 mwindow->gui->lock_window("ZWindowGUI::keypress_event");
110 result = mwindow->gui->mbuttons->transport->do_keypress(key);
111 mwindow->gui->unlock_window();
114 lock_window("ZWindowGUI::keypress_event 1");
118 int ZWindowGUI::button_press_event()
120 mwindow->select_zwindow(zwindow);
121 if( get_double_click() ) {
123 mwindow->gui->lock_window("ZWindowGUI::button_press_event 0");
124 LocalSession *local_session = mwindow->edl->local_session;
125 double start = local_session->get_selectionstart(1);
126 double end = local_session->get_selectionend(1);
127 if( EQUIV(start, end) ) {
128 start = mwindow->edl->tracks->total_recordable_length();
129 if( start < 0 ) start = end;
131 if( (end-start) > 1e-4 ) {
132 LocalSession *zlocal_session = zwindow->edl->local_session;
133 zlocal_session->set_selectionstart(end);
134 zlocal_session->set_selectionend(end);
135 zlocal_session->set_inpoint(start);
136 zlocal_session->set_outpoint(end);
137 double orig_inpoint = local_session->get_inpoint();
138 double orig_outpoint = local_session->get_outpoint();
139 local_session->set_selectionstart(end);
140 local_session->set_selectionend(end);
141 local_session->set_inpoint(start);
142 local_session->set_outpoint(end);
143 mwindow->overwrite(zwindow->edl, 0);
144 local_session->set_inpoint(orig_inpoint);
145 local_session->set_outpoint(orig_outpoint);
146 mwindow->gui->update_timebar(1);
148 mwindow->gui->unlock_window();
149 lock_window("ZWindowGUI::button_press_event 1");
151 if( !canvas->get_canvas() ) return 0;
152 return canvas->button_press_event_base(canvas->get_canvas());
155 int ZWindowGUI::cursor_leave_event()
157 if( !canvas->get_canvas() ) return 0;
158 return canvas->cursor_leave_event_base(canvas->get_canvas());
161 int ZWindowGUI::cursor_enter_event()
163 if( !canvas->get_canvas() ) return 0;
164 return canvas->cursor_enter_event_base(canvas->get_canvas());
167 int ZWindowGUI::button_release_event()
169 if( !canvas->get_canvas() ) return 0;
170 return canvas->button_release_event();
173 int ZWindowGUI::cursor_motion_event()
175 BC_WindowBase *cvs = canvas->get_canvas();
177 cvs->unhide_cursor();
178 return canvas->cursor_motion_event();
181 int ZWindowGUI::draw_overlays()
183 BC_WindowBase *cvs = canvas->get_canvas();
184 if( !cvs || cvs->get_video_on() ) return 0;
185 if( highlighted != zwindow->highlighted ) {
186 highlighted = zwindow->highlighted;
187 cvs->set_color(WHITE);
189 cvs->draw_rectangle(0, 0, cvs->get_w(), cvs->get_h());
190 cvs->draw_rectangle(1, 1, cvs->get_w() - 2, cvs->get_h() - 2);
196 ZWindowCanvas::ZWindowCanvas(MWindow *mwindow, ZWindowGUI *gui,
197 int x, int y, int w, int h)
198 : Canvas(mwindow, gui, x,y, w,h, 0,0,0)
200 this->mwindow = mwindow;
204 void ZWindowCanvas::close_source()
206 gui->unlock_window();
207 gui->zwindow->zgui->playback_engine->interrupt_playback(1);
208 gui->lock_window("ZWindowCanvas::close_source");
209 EDL *edl = gui->zwindow->edl;
211 gui->zwindow->edl = 0;
217 void ZWindowCanvas::draw_refresh(int flush)
219 EDL *edl = gui->zwindow->edl;
220 BC_WindowBase *cvs = get_canvas();
223 if( !cvs->get_video_on() ) {
224 cvs->clear_box(0, 0, cvs->get_w(), cvs->get_h());
225 gui->highlighted = 0;
228 if( !cvs->get_video_on() && refresh_frame && edl ) {
229 float in_x1, in_y1, in_x2, in_y2;
230 float out_x1, out_y1, out_x2, out_y2;
232 in_x1, in_y1, in_x2, in_y2,
233 out_x1, out_y1, out_x2, out_y2);
234 cvs->draw_vframe(refresh_frame,
235 (int)out_x1, (int)out_y1, (int)(out_x2 - out_x1), (int)(out_y2 - out_y1),
236 (int)in_x1, (int)in_y1, (int)(in_x2 - in_x1), (int)(in_y2 - in_y1), 0);
240 if( gui->draw_overlays() )
247 float ZWindowCanvas::get_auto_zoom()
249 EDL *edl = gui->zwindow->edl;
250 if( !edl ) edl = mwindow->edl;
251 float conformed_w, conformed_h;
252 edl->calculate_conformed_dimensions(0, conformed_w, conformed_h);
253 BC_WindowBase *window = get_canvas();
254 int cw = window ? window->get_w() : w;
255 int ch = window ? window->get_h() : h;
256 float zoom_x = cw / conformed_w;
257 float zoom_y = ch / conformed_h;
258 return zoom_x < zoom_y ? zoom_x : zoom_y;