4 * Copyright (C) 2009 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
22 #include "bcdisplayinfo.h"
25 #include "editlength.h"
28 #include "edlsession.h"
30 #include "localsession.h"
32 #include "mwindowgui.h"
37 EditLengthThread::EditLengthThread(MWindow *mwindow)
40 this->mwindow = mwindow;
43 EditLengthThread::~EditLengthThread()
48 void EditLengthThread::start(Edit *edit)
55 double start = mwindow->edl->local_session->get_selectionstart();
56 double end = mwindow->edl->local_session->get_selectionend();
58 // get the default length from the first edit selected
63 for(track = mwindow->edl->tracks->first;
69 int64_t start_units = track->to_units(start, 0);
70 int64_t end_units = track->to_units(end, 0);
72 for(edit = track->edits->first;
76 if(edit->startproject >= start_units &&
77 edit->startproject < end_units)
81 track->from_units(edit->length);
89 BC_DialogThread::start();
95 BC_Window* EditLengthThread::new_gui()
97 BC_DisplayInfo display_info;
98 int x = display_info.get_abs_cursor_x() - ELW_W/2;
99 int y = display_info.get_abs_cursor_y() - ELW_H/2;
100 EditLengthDialog *gui = new EditLengthDialog(mwindow, this, x, y);
101 gui->create_objects();
105 void EditLengthThread::handle_close_event(int result)
109 // mwindow->set_edit_length(edit, length);
112 mwindow->set_edit_length(length);
118 EditLengthDialog::EditLengthDialog(MWindow *mwindow,
119 EditLengthThread *thread,
122 : BC_Window(_(PROGRAM_NAME ": Edit length"), x, y,
123 ELW_W, ELW_H, -1, -1, 0, 0, 1)
125 this->mwindow = mwindow;
126 this->thread = thread;
127 // *** CONTEXT_HELP ***
128 context_help_set_keyword("Edit Length");
131 EditLengthDialog::~EditLengthDialog()
136 void EditLengthDialog::create_objects()
138 int xs10 = xS(10), xs100 = xS(100);
140 lock_window("EditLengthDialog::create_objects");
141 add_subwindow(new BC_Title(xs10, ys10, _("Seconds:")));
142 text = new EditLengthText(mwindow, this, xs100, ys10);
143 text->create_objects();
144 add_subwindow(new BC_OKButton(this));
145 add_subwindow(new BC_CancelButton(this));
150 int EditLengthDialog::close_event()
157 EditLengthText::EditLengthText(MWindow *mwindow,
158 EditLengthDialog *gui, int x, int y)
159 : BC_TumbleTextBox(gui, (float)gui->thread->length,
160 0.f, 100.f, x, y, xS(100))
162 this->mwindow = mwindow;
166 int EditLengthText::handle_event()
168 double result = atof(get_text());
169 if(fabs(result - gui->thread->length) > 0.000001)
171 gui->thread->length = result;