00001 #include "awindow.h"
00002 #include "awindowgui.h"
00003 #include "manualgoto.h"
00004 #include "edl.h"
00005 #include "fonts.h"
00006 #include "language.h"
00007 #include "localsession.h"
00008 #include "mainsession.h"
00009 #include "mwindow.h"
00010 #include "mwindowgui.h"
00011 #include "vwindow.h"
00012 #include "vwindowgui.h"
00013 #include "keys.h"
00014 #include "maincursor.h"
00015 #include "cwindow.h"
00016 #include "mwindowgui.h"
00017 #include "edlsession.h"
00018 #include "tracks.h"
00019
00020 ManualGoto::ManualGoto(MWindow *mwindow, BC_WindowBase *masterwindow)
00021 : Thread()
00022 {
00023 this->mwindow = mwindow;
00024 this->masterwindow = masterwindow;
00025 gotowindow = 0;
00026 done = 0;
00027 }
00028
00029 ManualGoto::~ManualGoto()
00030 {
00031 done = 1;
00032 gotowindow->set_done(1);
00033 Thread::join();
00034 if (gotowindow)
00035 delete gotowindow;
00036 }
00037
00038 void ManualGoto::open_window()
00039 {
00040
00041 double position;
00042 if ((masterwindow == (BC_WindowBase *)mwindow->cwindow->gui)||
00043 (masterwindow == (BC_WindowBase *)mwindow->gui->mbuttons))
00044 {
00045
00046 position = mwindow->edl->local_session->get_selectionstart(1);
00047 position += mwindow->edl->session->get_frame_offset() /
00048 mwindow->edl->session->frame_rate;;
00049 }
00050 else
00051 if (mwindow->vwindow->get_edl())
00052 position = mwindow->vwindow->get_edl()->local_session->get_selectionstart(1);
00053 else
00054 return;
00055 if (!gotowindow)
00056 {
00057 gotowindow = new ManualGotoWindow(mwindow, this);
00058 gotowindow->create_objects();
00059 gotowindow->reset_data(position);
00060 Thread::start();
00061 } else
00062 gotowindow->reset_data(position);
00063 }
00064
00065 void ManualGoto::run()
00066 {
00067 int result = 1;
00068 while (!done)
00069 {
00070 result = gotowindow->run_window();
00071 gotowindow->lock_window();
00072 gotowindow->hide_window();
00073 gotowindow->unlock_window();
00074
00075 if (!done && result == 0)
00076 {
00077 double new_position = gotowindow->get_entered_position_sec();
00078 char modifier = gotowindow->signtitle->get_text()[0];
00079 if ((masterwindow == (BC_WindowBase *)mwindow->cwindow->gui)||
00080 (masterwindow == (BC_WindowBase *)mwindow->gui->mbuttons))
00081
00082 {
00083
00084
00085 double current_position = mwindow->edl->local_session->get_selectionstart(1);
00086 switch (modifier)
00087 {
00088 case '+':
00089 new_position += current_position;
00090 break;
00091 case '-':
00092 new_position = current_position - new_position;
00093 break;
00094 default:
00095 break;
00096 }
00097 new_position = mwindow->edl->align_to_frame(new_position, 1);
00098 new_position -= mwindow->edl->session->get_frame_offset() / mwindow->edl->session->frame_rate;;
00099 if (new_position < 0)
00100 new_position = 0;
00101 if (current_position != new_position)
00102 {
00103 mwindow->edl->local_session->set_selectionstart(new_position);
00104 mwindow->edl->local_session->set_selectionend(new_position);
00105 mwindow->gui->lock_window();
00106 mwindow->find_cursor();
00107 mwindow->gui->update(1, 1, 1, 1, 1, 1, 0);
00108 mwindow->gui->unlock_window();
00109 mwindow->cwindow->update(1, 0, 0, 0, 0);
00110 }
00111 } else
00112 if ((masterwindow == (BC_WindowBase *)mwindow->vwindow->gui) &&
00113 mwindow->vwindow->get_edl())
00114 {
00115
00116 VWindow *vwindow = mwindow->vwindow;
00117 double current_position = vwindow->get_edl()->local_session->get_selectionstart(1);
00118 switch (modifier)
00119 {
00120 case '+':
00121 new_position += current_position;
00122 break;
00123 case '-':
00124 new_position = current_position - new_position;
00125 break;
00126 default:
00127 break;
00128 }
00129 if (new_position > vwindow->get_edl()->tracks->total_length())
00130 new_position = vwindow->get_edl()->tracks->total_length();
00131 if (new_position < 0)
00132 new_position = 0;
00133 new_position = vwindow->get_edl()->align_to_frame(new_position, 1);
00134 if (current_position != new_position)
00135 {
00136 vwindow->get_edl()->local_session->set_selectionstart(new_position);
00137 vwindow->get_edl()->local_session->set_selectionend(new_position);
00138 vwindow->gui->lock_window();
00139 vwindow->update_position(CHANGE_NONE, 0, 1);
00140 vwindow->gui->unlock_window();
00141 }
00142 }
00143 }
00144 }
00145 }
00146
00147
00148
00149 ManualGotoWindow::ManualGotoWindow(MWindow *mwindow, ManualGoto *thread)
00150 : BC_Window(PROGRAM_NAME ": Goto position",
00151 mwindow->gui->get_abs_cursor_x(1) - 250 / 2,
00152 mwindow->gui->get_abs_cursor_y(1) - 80 / 2,
00153 250,
00154 80,
00155 250,
00156 80,
00157 0,
00158 0,
00159 1)
00160 {
00161 this->mwindow = mwindow;
00162 this->thread = thread;
00163 }
00164
00165 ManualGotoWindow::~ManualGotoWindow()
00166 {
00167 }
00168
00169 void ManualGotoWindow::reset_data(double position)
00170 {
00171 lock_window();
00172 reposition_window(
00173 mwindow->gui->get_abs_cursor_x(1) - 250 / 2,
00174 mwindow->gui->get_abs_cursor_y(1) - 80 / 2);
00175 set_entered_position_sec(position);
00176 signtitle->update("=");
00177 activate();
00178 show_window();
00179 unlock_window();
00180 }
00181
00182 double ManualGotoWindow::get_entered_position_sec()
00183 {
00184 int64_t hh = atoi(boxhours->get_text());
00185 int64_t mm = atoi(boxminutes->get_text());
00186 int64_t ss = atoi(boxseconds->get_text());
00187 int64_t ms = atoi(boxmsec->get_text());
00188
00189 double seconds = ((((hh * 60) + mm) * 60) + ss) + (1.0 * ms) / 1000;
00190 return seconds;
00191 }
00192
00193 void ManualGotoWindow::set_entered_position_sec(double position)
00194 {
00195
00196 int hour, minute, second, thousandths;
00197
00198 position = fabs(position);
00199 hour = (int)(position / 3600);
00200 minute = (int)(position / 60 - hour * 60);
00201 second = (int)position - (int64_t)hour * 3600 - (int64_t)minute * 60;
00202 thousandths = (int)(position * 1000) % 1000;
00203
00204 boxhours->reshape_update(hour);
00205 boxminutes->reshape_update(minute);
00206 boxseconds->reshape_update(second);
00207 boxmsec->reshape_update(thousandths);
00208 }
00209
00210 int ManualGotoWindow::activate()
00211 {
00212 boxhours->reshape_update(-1);
00213 boxminutes->reshape_update(-1);
00214 boxseconds->reshape_update(-1);
00215 boxmsec->reshape_update(-1);
00216 int result = BC_Window::activate();
00217 boxminutes->deactivate();
00218 boxseconds->deactivate();
00219 boxmsec->deactivate();
00220 boxhours->activate();
00221 return result;
00222 }
00223 void ManualGotoWindow::create_objects()
00224 {
00225 int x = 76, y = 5;
00226 int x1 = x;
00227 int boxwidth = 26;
00228
00229 BC_Title *title;
00230 add_subwindow(title = new BC_Title(x1 - 2, y, _("hour min sec msec"), SMALLFONT));
00231 y += title->get_h() + 3;
00232
00233 add_subwindow(signtitle = new BC_Title(x1 - 17, y, "=", LARGEFONT));
00234 add_subwindow(boxhours = new ManualGotoNumber(this, x1, y, 16, 0, 9, 1));
00235 x1 += boxhours->get_w() + 4;
00236 add_subwindow(boxminutes = new ManualGotoNumber(this, x1, y, 26, 0, 59, 2));
00237 x1 += boxminutes->get_w() + 4;
00238 add_subwindow(boxseconds = new ManualGotoNumber(this, x1, y, 26, 0, 59, 2));
00239 x1 += boxseconds->get_w() + 4;
00240 add_subwindow(boxmsec = new ManualGotoNumber(this, x1, y, 34, 0, 999, 3));
00241 y += boxhours->get_h() + 10;
00242
00243 add_subwindow(new BC_OKButton(this));
00244 add_subwindow(new BC_CancelButton(this));
00245 }
00246
00247
00248
00249
00250
00251 ManualGotoNumber::ManualGotoNumber(ManualGotoWindow *window, int x, int y, int w, int min_num, int max_num, int chars)
00252 : BC_TextBox(x, y, w, 1, "0")
00253 {
00254 this->window = window;
00255 this->min_num = min_num;
00256 this->max_num = max_num;
00257 this->chars = chars;
00258 }
00259
00260 int ManualGotoNumber::handle_event()
00261 {
00262 return 1;
00263 }
00264
00265 int ManualGotoNumber::deactivate()
00266 {
00267 reshape_update(-1);
00268 return BC_TextBox::deactivate();
00269 }
00270
00271 int ManualGotoNumber::activate()
00272 {
00273 int retval = BC_TextBox::activate();
00274 select_whole_text(1);
00275 return retval;
00276 }
00277
00278
00279 void ManualGotoNumber::reshape_update(int64_t number)
00280 {
00281 char format_text[10];
00282 char text[BCTEXTLEN];
00283 if (number < 0)
00284 number = atoll(get_text());
00285 if (number > max_num) number = max_num;
00286 if (number < min_num) number = min_num;
00287 sprintf(format_text, "%%0%dlli", chars);
00288 sprintf(text, format_text, number);
00289 update(text);
00290 select_whole_text(-1);
00291 }
00292
00293 int ManualGotoNumber::keypress_event()
00294 {
00295 int in_textlen = strlen(get_text());
00296 int key = get_keypress();
00297
00298 if (key == '+')
00299 {
00300 window->signtitle->update("+");
00301 return 1;
00302 }
00303 if (key == '-')
00304 {
00305 window->signtitle->update("-");
00306 return 1;
00307 }
00308 if (key == '=')
00309 {
00310 window->signtitle->update("=");
00311 return 1;
00312 }
00313
00314 int ok_key = 0;
00315 if ((key >= '0' && key <='9') ||
00316 (key == ESC) || (key == RETURN) ||
00317 (key == TAB) || (key == LEFTTAB) ||
00318 (key == '.') ||
00319 (key == LEFT) || (key == RIGHT) ||
00320 (key == UP) || (key == DOWN) ||
00321 (key == PGUP) || (key == PGDN) ||
00322 (key == END) || (key == HOME) ||
00323 (key == BACKSPACE) || (key == DELETE) ||
00324 (ctrl_down() && (key == 'v' || key == 'V' || key == 'c' || key == 'C' || key == 'x' || key == 'X')))
00325 ok_key = 1;
00326
00327 if (in_textlen >= chars && key >= '0' && key <= '9' && !select_whole_text(0))
00328 ok_key = 0;
00329
00330 if (!ok_key) return 1;
00331
00332
00333
00334 if (key == '.')
00335 {
00336 cycle_textboxes(1);
00337 return 1;
00338 };
00339
00340 int result = BC_TextBox::keypress_event();
00341 int out_textlen = strlen(get_text());
00342
00343 if (key != TAB && out_textlen == chars && get_ibeam_letter() == chars)
00344 cycle_textboxes(1);
00345 return result;
00346 }
00347
00348
00349
00350
00351
00352
00353