4 * Copyright (C) 2004 Andraz Tori
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"
23 #include "editpanel.h"
25 #include "edlsession.h"
28 #include "manualgoto.h"
30 #include "mwindowgui.h"
36 ManualGoto::ManualGoto(MWindow *mwindow, EditPanel *panel)
39 this->mwindow = mwindow;
44 ManualGoto::~ManualGoto()
49 BC_Window *ManualGoto::new_gui()
51 BC_DisplayInfo dpy_info;
52 int x = dpy_info.get_abs_cursor_x() - MGT_W / 2;
53 int y = dpy_info.get_abs_cursor_y() - MGT_H / 2;
54 window = new ManualGotoWindow(this, x, y);
55 window->create_objects();
56 window->show_window();
60 void ManualGoto::handle_done_event(int result)
63 double current_position = panel->get_position();
64 const char *text = window->time_text->get_text();
65 double new_position = Units::text_to_seconds(text,
66 mwindow->edl->session->sample_rate,
68 mwindow->edl->session->frame_rate,
69 mwindow->edl->session->frames_per_foot);
70 char modifier = window->direction->get_text()[0];
72 case '+': new_position = current_position + new_position; break;
73 case '-': new_position = current_position - new_position; break;
76 panel->subwindow->lock_window("ManualGoto::handle_done_event");
77 panel->set_position(new_position);
78 panel->subwindow->unlock_window();
81 ManualGotoWindow::ManualGotoWindow(ManualGoto *mango, int x, int y)
82 : BC_Window(_(PROGRAM_NAME ": Goto position"), x, y,
83 MGT_W, MGT_H, MGT_W, MGT_H, 0, 0, 1)
88 ManualGotoWindow::~ManualGotoWindow()
93 ManualGotoText::ManualGotoText(ManualGotoWindow *window, int x, int y, int w)
94 : BC_TextBox(x, y, w, 1, "")
96 this->window = window;
99 int ManualGotoText::keypress_event()
101 int key = get_keypress();
102 if( key == '+' || key == '-' || key == '=' ) {
103 char text[2]; text[0] = key; text[1] = 0;
104 window->direction->set_text(text);
107 if( key == RETURN ) {
109 window->mango->handle_done_event(0);
110 lock_window("ManualGotoText::handle_event");
113 return BC_TextBox::keypress_event();
116 void ManualGotoWindow::update(double position)
118 MWindow *mwindow = mango->mwindow;
119 format_text->update(Units::timetype_toformat(time_format));
120 char string[BCSTRLEN];
121 Units::totext(string, position, time_format,
122 mwindow->edl->session->sample_rate,
123 mwindow->edl->session->frame_rate,
124 mwindow->edl->session->frames_per_foot,
125 mwindow->get_timecode_offset());
126 time_text->update(string);
129 void ManualGotoWindow::update()
131 double position = mango->panel->get_position();
135 ManualGotoKeyItem::ManualGotoKeyItem(ManualGotoDirection *popup,
136 const char *text, const char *htxt)
137 : BC_MenuItem(text, htxt, htxt[0])
143 int ManualGotoKeyItem::handle_event()
145 popup->set_text(htxt);
149 ManualGotoDirection::ManualGotoDirection(ManualGotoWindow *window,
151 : BC_PopupMenu(x, y, w, "=", -1, 0, 1)
153 this->window = window;
156 void ManualGotoDirection::create_objects()
158 add_item(new ManualGotoKeyItem(this, _("Forward"), "+"));
159 add_item(new ManualGotoKeyItem(this, _("Position"), "="));
160 add_item(new ManualGotoKeyItem(this, _("Reverse"), "-"));
163 ManualGotoUnitItem::ManualGotoUnitItem(ManualGotoUnits *popup, int type)
164 : BC_MenuItem(Units::timetype_toformat(type))
170 int ManualGotoUnitItem::handle_event()
172 popup->window->time_format = type;
173 popup->window->update();
177 ManualGotoUnits::ManualGotoUnits(ManualGotoWindow *window, int x, int y, int w)
178 : BC_PopupMenu(x, y, w, "", 1, 0, 0)
180 this->window = window;
183 void ManualGotoUnits::create_objects()
185 add_item(new ManualGotoUnitItem(this, TIME_HMS));
186 add_item(new ManualGotoUnitItem(this, TIME_HMSF));
187 add_item(new ManualGotoUnitItem(this, TIME_TIMECODE));
188 add_item(new ManualGotoUnitItem(this, TIME_FRAMES));
189 add_item(new ManualGotoUnitItem(this, TIME_SAMPLES));
190 add_item(new ManualGotoUnitItem(this, TIME_SAMPLES_HEX));
191 add_item(new ManualGotoUnitItem(this, TIME_SECONDS));
192 add_item(new ManualGotoUnitItem(this, TIME_FEET_FRAMES));
195 void ManualGotoWindow::create_objects()
197 lock_window("ManualGotoWindow::create_objects");
198 MWindow *mwindow = mango->mwindow;
199 time_format = mwindow->edl->session->time_format;
200 int margin = mwindow->theme->widget_border;
201 int x = xS(10) + BC_OKButton::calculate_w() + margin, y = yS(10);
202 int pop_w = xS(24), x1 = x + pop_w + margin;
203 add_subwindow(format_text = new BC_Title(x1, y, ""));
204 y += format_text->get_h() + margin;
205 add_subwindow(direction = new ManualGotoDirection(this, x, y, pop_w));
206 direction->create_objects();
207 int tw = get_w() - x1 - xS(10) - BC_CancelButton::calculate_w() - margin - pop_w - margin;
208 add_subwindow(time_text = new ManualGotoText(this, x1, y, tw));
209 x1 += time_text->get_w() + margin;
210 add_subwindow(units = new ManualGotoUnits(this, x1, y, pop_w));
211 units->create_objects();
213 add_subwindow(new BC_OKButton(this));
214 add_subwindow(new BC_CancelButton(this));