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,
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, 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();
72 int ZWindowGUI::resize_event(int w, int h)
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);
79 int ZWindowGUI::translation_event()
81 return resize_event(get_w(),get_h());
84 int ZWindowGUI::close_event()
90 int ZWindowGUI::keypress_event()
92 int key = get_keypress();
93 if( key == 'w' || key == 'W' ) {
101 if( mwindow->session->zwindow_fullscreen )
102 canvas->stop_fullscreen();
104 canvas->start_fullscreen();
107 if( mwindow->session->zwindow_fullscreen )
108 canvas->stop_fullscreen();
111 mwindow->gui->lock_window("ZWindowGUI::keypress_event");
112 result = mwindow->gui->mbuttons->transport->do_keypress(key);
113 mwindow->gui->unlock_window();
116 lock_window("ZWindowGUI::keypress_event 1");
120 int ZWindowGUI::button_press_event()
122 mwindow->select_zwindow(zwindow);
123 if( get_double_click() ) {
125 mwindow->gui->lock_window("ZWindowGUI::button_press_event 0");
126 LocalSession *local_session = mwindow->edl->local_session;
127 double start = local_session->get_selectionstart(1);
128 double end = local_session->get_selectionend(1);
129 if( EQUIV(start, end) ) {
130 start = mwindow->edl->tracks->total_recordable_length();
131 if( start < 0 ) start = end;
133 if( (end-start) > 1e-4 ) {
134 LocalSession *zlocal_session = zwindow->edl->local_session;
135 zlocal_session->set_selectionstart(end);
136 zlocal_session->set_selectionend(end);
137 zlocal_session->set_inpoint(start);
138 zlocal_session->set_outpoint(end);
139 double orig_inpoint = local_session->get_inpoint();
140 double orig_outpoint = local_session->get_outpoint();
141 local_session->set_selectionstart(end);
142 local_session->set_selectionend(end);
143 local_session->set_inpoint(start);
144 local_session->set_outpoint(end);
145 mwindow->overwrite(zwindow->edl, 0);
146 local_session->set_inpoint(orig_inpoint);
147 local_session->set_outpoint(orig_outpoint);
148 mwindow->gui->update_timebar(1);
150 mwindow->gui->unlock_window();
151 lock_window("ZWindowGUI::button_press_event 1");
153 if( !canvas->get_canvas() ) return 0;
154 return canvas->button_press_event_base(canvas->get_canvas());
157 int ZWindowGUI::cursor_leave_event()
159 if( !canvas->get_canvas() ) return 0;
160 return canvas->cursor_leave_event_base(canvas->get_canvas());
163 int ZWindowGUI::cursor_enter_event()
165 if( !canvas->get_canvas() ) return 0;
166 return canvas->cursor_enter_event_base(canvas->get_canvas());
169 int ZWindowGUI::button_release_event()
171 if( !canvas->get_canvas() ) return 0;
172 return canvas->button_release_event();
175 int ZWindowGUI::cursor_motion_event()
177 BC_WindowBase *cvs = canvas->get_canvas();
179 cvs->unhide_cursor();
180 return canvas->cursor_motion_event();
183 int ZWindowGUI::draw_overlays()
185 BC_WindowBase *cvs = canvas->get_canvas();
186 if( !cvs || cvs->get_video_on() ) return 0;
187 if( highlighted != zwindow->highlighted ) {
188 highlighted = zwindow->highlighted;
189 cvs->set_color(WHITE);
191 cvs->draw_rectangle(0, 0, cvs->get_w(), cvs->get_h());
192 cvs->draw_rectangle(1, 1, cvs->get_w() - 2, cvs->get_h() - 2);
198 ZWindowCanvas::ZWindowCanvas(MWindow *mwindow, ZWindowGUI *gui,
199 int x, int y, int w, int h)
200 : Canvas(mwindow, gui, x,y, w,h, 0,0,0)
202 this->mwindow = mwindow;
206 void ZWindowCanvas::close_source()
208 gui->unlock_window();
209 gui->zwindow->zgui->playback_engine->interrupt_playback(1);
210 gui->lock_window("ZWindowCanvas::close_source");
211 EDL *edl = gui->zwindow->edl;
213 gui->zwindow->edl = 0;
219 void ZWindowCanvas::draw_refresh(int flush)
221 EDL *edl = gui->zwindow->edl;
222 BC_WindowBase *cvs = get_canvas();
225 if( !cvs->get_video_on() ) {
226 cvs->clear_box(0, 0, cvs->get_w(), cvs->get_h());
227 gui->highlighted = 0;
230 if( !cvs->get_video_on() && refresh_frame && edl ) {
231 float in_x1, in_y1, in_x2, in_y2;
232 float out_x1, out_y1, out_x2, out_y2;
234 in_x1, in_y1, in_x2, in_y2,
235 out_x1, out_y1, out_x2, out_y2);
236 cvs->draw_vframe(refresh_frame,
237 (int)out_x1, (int)out_y1, (int)(out_x2 - out_x1), (int)(out_y2 - out_y1),
238 (int)in_x1, (int)in_y1, (int)(in_x2 - in_x1), (int)(in_y2 - in_y1), 0);
242 if( gui->draw_overlays() )
249 int ZWindowCanvas::get_fullscreen()
251 return mwindow->session->zwindow_fullscreen;
254 void ZWindowCanvas::set_fullscreen(int value)
256 mwindow->session->zwindow_fullscreen = value;