2 #include "awindowgui.h"
3 #include "manualgoto.h"
7 #include "localsession.h"
8 #include "mainsession.h"
10 #include "mwindowgui.h"
12 #include "vwindowgui.h"
14 #include "maincursor.h"
16 #include "mwindowgui.h"
17 #include "edlsession.h"
20 ManualGoto::ManualGoto(MWindow *mwindow, BC_WindowBase *masterwindow)
23 this->mwindow = mwindow;
24 this->masterwindow = masterwindow;
29 ManualGoto::~ManualGoto()
32 gotowindow->set_done(1);
38 void ManualGoto::open_window()
42 if ((masterwindow == (BC_WindowBase *)mwindow->cwindow->gui)||
43 (masterwindow == (BC_WindowBase *)mwindow->gui->mbuttons))
46 position = mwindow->edl->local_session->get_selectionstart(1);
47 position += mwindow->edl->session->get_frame_offset() /
48 mwindow->edl->session->frame_rate;;
51 if (mwindow->vwindow->get_edl())
52 position = mwindow->vwindow->get_edl()->local_session->get_selectionstart(1);
57 gotowindow = new ManualGotoWindow(mwindow, this);
58 gotowindow->create_objects();
59 gotowindow->reset_data(position);
62 gotowindow->reset_data(position);
65 void ManualGoto::run()
70 result = gotowindow->run_window();
71 gotowindow->lock_window();
72 gotowindow->hide_window();
73 gotowindow->unlock_window();
75 if (!done && result == 0) // ok button or return pressed
77 double new_position = gotowindow->get_entered_position_sec();
78 char modifier = gotowindow->signtitle->get_text()[0];
79 if ((masterwindow == (BC_WindowBase *)mwindow->cwindow->gui)||
80 (masterwindow == (BC_WindowBase *)mwindow->gui->mbuttons))
83 // mwindow/cwindow update
85 double current_position = mwindow->edl->local_session->get_selectionstart(1);
89 new_position += current_position;
92 new_position = current_position - new_position;
97 new_position = mwindow->edl->align_to_frame(new_position, 1);
98 new_position -= mwindow->edl->session->get_frame_offset() / mwindow->edl->session->frame_rate;;
101 if (current_position != new_position)
103 mwindow->edl->local_session->set_selectionstart(new_position);
104 mwindow->edl->local_session->set_selectionend(new_position);
105 mwindow->gui->lock_window();
106 mwindow->find_cursor();
107 mwindow->gui->update(1, 1, 1, 1, 1, 1, 0);
108 mwindow->gui->unlock_window();
109 mwindow->cwindow->update(1, 0, 0, 0, 0);
112 if ((masterwindow == (BC_WindowBase *)mwindow->vwindow->gui) &&
113 mwindow->vwindow->get_edl())
116 VWindow *vwindow = mwindow->vwindow;
117 double current_position = vwindow->get_edl()->local_session->get_selectionstart(1);
121 new_position += current_position;
124 new_position = current_position - new_position;
129 if (new_position > vwindow->get_edl()->tracks->total_length())
130 new_position = vwindow->get_edl()->tracks->total_length();
131 if (new_position < 0)
133 new_position = vwindow->get_edl()->align_to_frame(new_position, 1);
134 if (current_position != new_position)
136 vwindow->get_edl()->local_session->set_selectionstart(new_position);
137 vwindow->get_edl()->local_session->set_selectionend(new_position);
138 vwindow->gui->lock_window();
139 vwindow->update_position(CHANGE_NONE, 0, 1);
140 vwindow->gui->unlock_window();
149 ManualGotoWindow::ManualGotoWindow(MWindow *mwindow, ManualGoto *thread)
150 : BC_Window(PROGRAM_NAME ": Goto position",
151 mwindow->gui->get_abs_cursor_x(1) - 250 / 2,
152 mwindow->gui->get_abs_cursor_y(1) - 80 / 2,
161 this->mwindow = mwindow;
162 this->thread = thread;
165 ManualGotoWindow::~ManualGotoWindow()
169 void ManualGotoWindow::reset_data(double position)
173 mwindow->gui->get_abs_cursor_x(1) - 250 / 2,
174 mwindow->gui->get_abs_cursor_y(1) - 80 / 2);
175 set_entered_position_sec(position);
176 signtitle->update("=");
182 double ManualGotoWindow::get_entered_position_sec()
184 int64_t hh = atoi(boxhours->get_text());
185 int64_t mm = atoi(boxminutes->get_text());
186 int64_t ss = atoi(boxseconds->get_text());
187 int64_t ms = atoi(boxmsec->get_text());
189 double seconds = ((((hh * 60) + mm) * 60) + ss) + (1.0 * ms) / 1000;
193 void ManualGotoWindow::set_entered_position_sec(double position)
195 // Lifted from units.C
196 int hour, minute, second, thousandths;
198 position = fabs(position);
199 hour = (int)(position / 3600);
200 minute = (int)(position / 60 - hour * 60);
201 second = (int)position - (int64_t)hour * 3600 - (int64_t)minute * 60;
202 thousandths = (int)(position * 1000) % 1000;
204 boxhours->reshape_update(hour);
205 boxminutes->reshape_update(minute);
206 boxseconds->reshape_update(second);
207 boxmsec->reshape_update(thousandths);
210 int ManualGotoWindow::activate()
212 boxhours->reshape_update(-1);
213 boxminutes->reshape_update(-1);
214 boxseconds->reshape_update(-1);
215 boxmsec->reshape_update(-1);
216 int result = BC_Window::activate();
217 boxminutes->deactivate();
218 boxseconds->deactivate();
219 boxmsec->deactivate();
220 boxhours->activate();
223 void ManualGotoWindow::create_objects()
230 add_subwindow(title = new BC_Title(x1 - 2, y, _("hour min sec msec"), SMALLFONT));
231 y += title->get_h() + 3;
233 add_subwindow(signtitle = new BC_Title(x1 - 17, y, "=", LARGEFONT));
234 add_subwindow(boxhours = new ManualGotoNumber(this, x1, y, 16, 0, 9, 1));
235 x1 += boxhours->get_w() + 4;
236 add_subwindow(boxminutes = new ManualGotoNumber(this, x1, y, 26, 0, 59, 2));
237 x1 += boxminutes->get_w() + 4;
238 add_subwindow(boxseconds = new ManualGotoNumber(this, x1, y, 26, 0, 59, 2));
239 x1 += boxseconds->get_w() + 4;
240 add_subwindow(boxmsec = new ManualGotoNumber(this, x1, y, 34, 0, 999, 3));
241 y += boxhours->get_h() + 10;
243 add_subwindow(new BC_OKButton(this));
244 add_subwindow(new BC_CancelButton(this));
251 ManualGotoNumber::ManualGotoNumber(ManualGotoWindow *window, int x, int y, int w, int min_num, int max_num, int chars)
252 : BC_TextBox(x, y, w, 1, "0")
254 this->window = window;
255 this->min_num = min_num;
256 this->max_num = max_num;
260 int ManualGotoNumber::handle_event()
265 int ManualGotoNumber::deactivate()
268 return BC_TextBox::deactivate();
271 int ManualGotoNumber::activate()
273 int retval = BC_TextBox::activate();
274 select_whole_text(1);
279 void ManualGotoNumber::reshape_update(int64_t number)
281 char format_text[10];
282 char text[BCTEXTLEN];
284 number = atoll(get_text());
285 if (number > max_num) number = max_num;
286 if (number < min_num) number = min_num;
287 sprintf(format_text, "%%0%dlli", chars);
288 sprintf(text, format_text, number);
290 select_whole_text(-1);
293 int ManualGotoNumber::keypress_event()
295 int in_textlen = strlen(get_text());
296 int key = get_keypress();
300 window->signtitle->update("+");
305 window->signtitle->update("-");
310 window->signtitle->update("=");
315 if ((key >= '0' && key <='9') ||
316 (key == ESC) || (key == RETURN) ||
317 (key == TAB) || (key == LEFTTAB) ||
319 (key == LEFT) || (key == RIGHT) ||
320 (key == UP) || (key == DOWN) ||
321 (key == PGUP) || (key == PGDN) ||
322 (key == END) || (key == HOME) ||
323 (key == BACKSPACE) || (key == DELETE) ||
324 (ctrl_down() && (key == 'v' || key == 'V' || key == 'c' || key == 'C' || key == 'x' || key == 'X')))
327 if (in_textlen >= chars && key >= '0' && key <= '9' && !select_whole_text(0))
330 if (!ok_key) return 1;
333 // treat dot as tab - for use from numerical keypad
340 int result = BC_TextBox::keypress_event();
341 int out_textlen = strlen(get_text());
342 // automatic cycle when we enter two numbers
343 if (key != TAB && out_textlen == chars && get_ibeam_letter() == chars)
357 // c-file-style: "linux"