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)
86 // *** CONTEXT_HELP ***
87 context_help_set_keyword("Transport and Buttons Bar");
90 ManualGotoWindow::~ManualGotoWindow()
95 ManualGotoText::ManualGotoText(ManualGotoWindow *window, int x, int y, int w)
96 : BC_TextBox(x, y, w, 1, "")
98 this->window = window;
101 int ManualGotoText::keypress_event()
103 int key = get_keypress();
104 if( key == '+' || key == '-' || key == '=' ) {
105 char text[2]; text[0] = key; text[1] = 0;
106 window->direction->set_text(text);
109 if( key == RETURN ) {
111 window->mango->handle_done_event(0);
112 lock_window("ManualGotoText::handle_event");
115 return BC_TextBox::keypress_event();
118 void ManualGotoWindow::update(double position)
120 MWindow *mwindow = mango->mwindow;
121 format_text->update(Units::timetype_toformat(time_format));
122 char string[BCSTRLEN];
123 Units::totext(string, position, time_format,
124 mwindow->edl->session->sample_rate,
125 mwindow->edl->session->frame_rate,
126 mwindow->edl->session->frames_per_foot,
127 mwindow->get_timecode_offset());
128 time_text->update(string);
131 void ManualGotoWindow::update()
133 double position = mango->panel->get_position();
137 ManualGotoKeyItem::ManualGotoKeyItem(ManualGotoDirection *popup,
138 const char *text, const char *htxt)
139 : BC_MenuItem(text, htxt, htxt[0])
145 int ManualGotoKeyItem::handle_event()
147 popup->set_text(htxt);
151 ManualGotoDirection::ManualGotoDirection(ManualGotoWindow *window,
153 : BC_PopupMenu(x, y, w, "=", -1, 0, 1)
155 this->window = window;
158 void ManualGotoDirection::create_objects()
160 add_item(new ManualGotoKeyItem(this, _("Forward"), "+"));
161 add_item(new ManualGotoKeyItem(this, _("Position"), "="));
162 add_item(new ManualGotoKeyItem(this, _("Reverse"), "-"));
165 ManualGotoUnitItem::ManualGotoUnitItem(ManualGotoUnits *popup, int type)
166 : BC_MenuItem(Units::timetype_toformat(type))
172 int ManualGotoUnitItem::handle_event()
174 popup->window->time_format = type;
175 popup->window->update();
179 ManualGotoUnits::ManualGotoUnits(ManualGotoWindow *window, int x, int y, int w)
180 : BC_PopupMenu(x, y, w, "", 1, 0, 0)
182 this->window = window;
185 void ManualGotoUnits::create_objects()
187 add_item(new ManualGotoUnitItem(this, TIME_HMS));
188 add_item(new ManualGotoUnitItem(this, TIME_HMSF));
189 add_item(new ManualGotoUnitItem(this, TIME_TIMECODE));
190 add_item(new ManualGotoUnitItem(this, TIME_FRAMES));
191 add_item(new ManualGotoUnitItem(this, TIME_SAMPLES));
192 add_item(new ManualGotoUnitItem(this, TIME_SAMPLES_HEX));
193 add_item(new ManualGotoUnitItem(this, TIME_SECONDS));
194 add_item(new ManualGotoUnitItem(this, TIME_FEET_FRAMES));
197 void ManualGotoWindow::create_objects()
199 lock_window("ManualGotoWindow::create_objects");
200 MWindow *mwindow = mango->mwindow;
201 time_format = mwindow->edl->session->time_format;
202 int margin = mwindow->theme->widget_border;
203 int x = xS(10) + BC_OKButton::calculate_w() + margin, y = yS(10);
204 int pop_w = xS(24), x1 = x + pop_w + margin;
205 add_subwindow(format_text = new BC_Title(x1, y, ""));
206 y += format_text->get_h() + margin;
207 add_subwindow(direction = new ManualGotoDirection(this, x, y, pop_w));
208 direction->create_objects();
209 int tw = get_w() - x1 - xS(10) - BC_CancelButton::calculate_w() - margin - pop_w - margin;
210 add_subwindow(time_text = new ManualGotoText(this, x1, y, tw));
211 x1 += time_text->get_w() + margin;
212 add_subwindow(units = new ManualGotoUnits(this, x1, y, pop_w));
213 units->create_objects();
215 add_subwindow(new BC_OKButton(this));
216 add_subwindow(new BC_CancelButton(this));