• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files

hvirtual/plugins/titler/titlewindow.C

Go to the documentation of this file.
00001 #include "bcdisplayinfo.h"
00002 #include "titlewindow.h"
00003 
00004 #include <string.h>
00005 #include <libintl.h>
00006 #define _(String) gettext(String)
00007 #define gettext_noop(String) String
00008 #define N_(String) gettext_noop (String)
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 PLUGIN_THREAD_OBJECT(TitleMain, TitleThread, TitleWindow)
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 TitleWindow::TitleWindow(TitleMain *client, int x, int y)
00030  : BC_Window(client->gui_string, 
00031         x,
00032         y,
00033         client->window_w, 
00034         client->window_h, 
00035         100, 
00036         100, 
00037         1, 
00038         0,
00039         1)
00040 { 
00041         this->client = client; 
00042 }
00043 
00044 TitleWindow::~TitleWindow()
00045 {
00046         sizes.remove_all_objects();
00047         encodings.remove_all_objects();
00048         timecodeformats.remove_all_objects();
00049         delete timecodeformat;
00050         delete color_thread;
00051 #ifdef USE_OUTLINE
00052         delete color_stroke_thread;
00053 #endif
00054         delete title_x;
00055         delete title_y;
00056 }
00057 
00058 int TitleWindow::create_objects()
00059 {
00060         int x = 10, y = 10;
00061         timecodeformats.append(new BC_ListBoxItem(TIME_SECONDS__STR));
00062         timecodeformats.append(new BC_ListBoxItem(TIME_HMS__STR));              
00063         timecodeformats.append(new BC_ListBoxItem(TIME_HMS2__STR));                     
00064         timecodeformats.append(new BC_ListBoxItem(TIME_HMS3__STR));             
00065         timecodeformats.append(new BC_ListBoxItem(TIME_HMSF__STR));             
00066         //      timecodeformats.append(new BC_ListBoxItem(TIME_SAMPLES__STR));          
00067         //      timecodeformats.append(new BC_ListBoxItem(TIME_SAMPLES_HEX__STR));      
00068         timecodeformats.append(new BC_ListBoxItem(TIME_FRAMES__STR));           
00069         //      timecodeformats.append(new BC_ListBoxItem(TIME_FEET_FRAMES__STR));      
00070         
00071         encodings.append(new BC_ListBoxItem("ISO8859-1"));
00072         encodings.append(new BC_ListBoxItem("ISO8859-2"));
00073         encodings.append(new BC_ListBoxItem("ISO8859-3"));
00074         encodings.append(new BC_ListBoxItem("ISO8859-4"));
00075         encodings.append(new BC_ListBoxItem("ISO8859-5"));
00076         encodings.append(new BC_ListBoxItem("ISO8859-6"));
00077         encodings.append(new BC_ListBoxItem("ISO8859-7"));
00078         encodings.append(new BC_ListBoxItem("ISO8859-8"));
00079         encodings.append(new BC_ListBoxItem("ISO8859-9"));
00080         encodings.append(new BC_ListBoxItem("ISO8859-10"));
00081         encodings.append(new BC_ListBoxItem("ISO8859-11"));
00082         encodings.append(new BC_ListBoxItem("ISO8859-12"));
00083         encodings.append(new BC_ListBoxItem("ISO8859-13"));
00084         encodings.append(new BC_ListBoxItem("ISO8859-14"));
00085         encodings.append(new BC_ListBoxItem("ISO8859-15"));
00086         encodings.append(new BC_ListBoxItem("KOI8"));
00087 
00088 
00089 
00090         sizes.append(new BC_ListBoxItem("8"));
00091         sizes.append(new BC_ListBoxItem("9"));
00092         sizes.append(new BC_ListBoxItem("10"));
00093         sizes.append(new BC_ListBoxItem("11"));
00094         sizes.append(new BC_ListBoxItem("12"));
00095         sizes.append(new BC_ListBoxItem("13"));
00096         sizes.append(new BC_ListBoxItem("14"));
00097         sizes.append(new BC_ListBoxItem("16"));
00098         sizes.append(new BC_ListBoxItem("18"));
00099         sizes.append(new BC_ListBoxItem("20"));
00100         sizes.append(new BC_ListBoxItem("22"));
00101         sizes.append(new BC_ListBoxItem("24"));
00102         sizes.append(new BC_ListBoxItem("26"));
00103         sizes.append(new BC_ListBoxItem("28"));
00104         sizes.append(new BC_ListBoxItem("32"));
00105         sizes.append(new BC_ListBoxItem("36"));
00106         sizes.append(new BC_ListBoxItem("40"));
00107         sizes.append(new BC_ListBoxItem("48"));
00108         sizes.append(new BC_ListBoxItem("56"));
00109         sizes.append(new BC_ListBoxItem("64"));
00110         sizes.append(new BC_ListBoxItem("72"));
00111         sizes.append(new BC_ListBoxItem("100"));
00112         sizes.append(new BC_ListBoxItem("128"));
00113 
00114         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(NO_MOTION)));
00115         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(BOTTOM_TO_TOP)));
00116         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(TOP_TO_BOTTOM)));
00117         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(RIGHT_TO_LEFT)));
00118         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(LEFT_TO_RIGHT)));
00119 
00120 
00121 
00122 // Construct font list
00123         for(int i = 0; i < client->fonts->total; i++)
00124         {
00125                 int exists = 0;
00126                 for(int j = 0; j < fonts.total; j++)
00127                 {
00128                         if(!strcasecmp(fonts.values[j]->get_text(), 
00129                                 client->fonts->values[i]->fixed_title)) 
00130                         {
00131                                 exists = 1;
00132                                 break;
00133                         }
00134                 }
00135 
00136                 if(!exists) fonts.append(new 
00137                         BC_ListBoxItem(client->fonts->values[i]->fixed_title));
00138         }
00139 
00140 // Sort font list
00141         int done = 0;
00142         while(!done)
00143         {
00144                 done = 1;
00145                 for(int i = 0; i < fonts.total - 1; i++)
00146                 {
00147                         if(strcmp(fonts.values[i]->get_text(), fonts.values[i + 1]->get_text()) > 0)
00148                         {
00149                                 BC_ListBoxItem *temp = fonts.values[i + 1];
00150                                 fonts.values[i + 1] = fonts.values[i];
00151                                 fonts.values[i] = temp;
00152                                 done = 0;
00153                         }
00154                 }
00155         }       
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168         add_tool(font_title = new BC_Title(x, y, _("Font:")));
00169         font = new TitleFont(client, this, x, y + 20);
00170         font->create_objects();
00171         x += 230;
00172         add_subwindow(font_tumbler = new TitleFontTumble(client, this, x, y + 20));
00173         x += 30;
00174         char string[BCTEXTLEN];
00175         add_tool(size_title = new BC_Title(x, y, _("Size:")));
00176         sprintf(string, "%d", client->config.size);
00177         size = new TitleSize(client, this, x, y + 20, string);
00178         size->create_objects();
00179         x += 140;
00180 
00181         add_tool(style_title = new BC_Title(x, y, _("Style:")));
00182         add_tool(italic = new TitleItalic(client, this, x, y + 20));
00183         add_tool(bold = new TitleBold(client, this, x, y + 50));
00184 #ifdef USE_OUTLINE
00185         add_tool(stroke = new TitleStroke(client, this, x, y + 80));
00186 #endif
00187         x += 90;
00188         add_tool(justify_title = new BC_Title(x, y, _("Justify:")));
00189         add_tool(left = new TitleLeft(client, this, x, y + 20));
00190         add_tool(center = new TitleCenter(client, this, x, y + 50));
00191         add_tool(right = new TitleRight(client, this, x, y + 80));
00192 
00193         x += 80;
00194         add_tool(top = new TitleTop(client, this, x, y + 20));
00195         add_tool(mid = new TitleMid(client, this, x, y + 50));
00196         add_tool(bottom= new TitleBottom(client, this, x, y + 80));
00197         
00198 
00199 
00200         y += 50;
00201         x = 10;
00202 
00203         add_tool(x_title = new BC_Title(x, y, _("X:")));
00204         title_x = new TitleX(client, this, x, y + 20);
00205         title_x->create_objects();
00206         x += 90;
00207 
00208         add_tool(y_title = new BC_Title(x, y, _("Y:")));
00209         title_y = new TitleY(client, this, x, y + 20);
00210         title_y->create_objects();
00211         x += 90;
00212 
00213         add_tool(motion_title = new BC_Title(x, y, _("Motion type:")));
00214 
00215         motion = new TitleMotion(client, this, x, y + 20);
00216         motion->create_objects();
00217         x += 150;
00218         
00219         add_tool(loop = new TitleLoop(client, x, y + 20));
00220         x += 100;
00221         
00222         x = 10;
00223         y += 50;
00224 
00225         add_tool(dropshadow_title = new BC_Title(x, y, _("Drop shadow:")));
00226         dropshadow = new TitleDropShadow(client, this, x, y + 20);
00227         dropshadow->create_objects();
00228         x += 100;
00229 
00230         add_tool(fadein_title = new BC_Title(x, y, _("Fade in (sec):")));
00231         add_tool(fade_in = new TitleFade(client, this, &client->config.fade_in, x, y + 20));
00232         x += 100;
00233 
00234         add_tool(fadeout_title = new BC_Title(x, y, _("Fade out (sec):")));
00235         add_tool(fade_out = new TitleFade(client, this, &client->config.fade_out, x, y + 20));
00236         x += 110;
00237 
00238         add_tool(speed_title = new BC_Title(x, y, _("Speed:")));
00239         speed = new TitleSpeed(client, this, x, y + 20);
00240         speed->create_objects();
00241         x += 110;
00242 
00243         add_tool(color_button = new TitleColorButton(client, this, x, y + 20));
00244         x += color_button->get_w();
00245         color_x = x;
00246         color_y = y + 20;
00247         color_thread = new TitleColorThread(client, this);
00248 
00249         x = 10;
00250         y += 50;
00251         add_tool(encoding_title = new BC_Title(x, y + 3, _("Encoding:")));
00252         encoding = new TitleEncoding(client, this, x, y + 20);
00253         encoding->create_objects();
00254 
00255 #ifdef USE_OUTLINE
00256         x += 160;
00257         add_tool(strokewidth_title = new BC_Title(x, y, _("Outline width:")));
00258         stroke_width = new TitleStrokeW(client, 
00259                 this, 
00260                 x, 
00261                 y + 20);
00262         stroke_width->create_objects();
00263 
00264         x += 210;
00265         add_tool(color_stroke_button = new TitleColorStrokeButton(client, 
00266                 this, 
00267                 x, 
00268                 y + 20));
00269         color_stroke_x = color_x;
00270         color_stroke_y = y + 20;
00271         color_stroke_thread = new TitleColorStrokeThread(client, this);
00272 #endif
00273 
00274 
00275         x = 10;
00276         y += 50;
00277 
00278         add_tool(text_title = new BC_Title(x, y + 3, _("Text:")));
00279 
00280         x += 100;
00281         add_tool(timecode = new TitleTimecode(client, x, y));
00282 
00283 
00284         x += timecode->get_w() + 5;
00285         BC_SubWindow *thisw;
00286         add_tool(thisw = new BC_Title(x, y+4, _("Format:")));
00287         x += thisw->get_w() + 5;
00288         timecodeformat = new TitleTimecodeFormat(client, this, x, y);
00289         timecodeformat->create_objects();
00290 
00291         x = 10;
00292         y += 30;
00293         text = new TitleText(client, 
00294                 this, 
00295                 x, 
00296                 y, 
00297                 get_w() - x - 10, 
00298                 get_h() - y - 20 - 10);
00299         text->create_objects();
00300 
00301         update_color();
00302 
00303         show_window();
00304         flush();
00305         return 0;
00306 }
00307 
00308 int TitleWindow::resize_event(int w, int h)
00309 {
00310         client->window_w = w;
00311         client->window_h = h;
00312 
00313         clear_box(0, 0, w, h);
00314         font_title->reposition_window(font_title->get_x(), font_title->get_y());
00315         font->reposition_window(font->get_x(), font->get_y());
00316         font_tumbler->reposition_window(font_tumbler->get_x(), font_tumbler->get_y());
00317         x_title->reposition_window(x_title->get_x(), x_title->get_y());
00318         title_x->reposition_window(title_x->get_x(), title_x->get_y());
00319         y_title->reposition_window(y_title->get_x(), y_title->get_y());
00320         title_y->reposition_window(title_y->get_x(), title_y->get_y());
00321         style_title->reposition_window(style_title->get_x(), style_title->get_y());
00322         italic->reposition_window(italic->get_x(), italic->get_y());
00323         bold->reposition_window(bold->get_x(), bold->get_y());
00324 #ifdef USE_OUTLINE
00325         stroke->reposition_window(stroke->get_x(), stroke->get_y());
00326 #endif
00327         size_title->reposition_window(size_title->get_x(), size_title->get_y());
00328         size->reposition_window(size->get_x(), size->get_y());
00329         encoding_title->reposition_window(encoding_title->get_x(), encoding_title->get_y());
00330         encoding->reposition_window(encoding->get_x(), encoding->get_y());
00331         color_button->reposition_window(color_button->get_x(), color_button->get_y());
00332 #ifdef USE_OUTLINE
00333         color_stroke_button->reposition_window(color_stroke_button->get_x(), color_stroke_button->get_y());
00334 #endif
00335         motion_title->reposition_window(motion_title->get_x(), motion_title->get_y());
00336         motion->reposition_window(motion->get_x(), motion->get_y());
00337         loop->reposition_window(loop->get_x(), loop->get_y());
00338         dropshadow_title->reposition_window(dropshadow_title->get_x(), dropshadow_title->get_y());
00339         dropshadow->reposition_window(dropshadow->get_x(), dropshadow->get_y());
00340         fadein_title->reposition_window(fadein_title->get_x(), fadein_title->get_y());
00341         fade_in->reposition_window(fade_in->get_x(), fade_in->get_y());
00342         fadeout_title->reposition_window(fadeout_title->get_x(), fadeout_title->get_y());
00343         fade_out->reposition_window(fade_out->get_x(), fade_out->get_y());
00344         text_title->reposition_window(text_title->get_x(), text_title->get_y());
00345 #ifdef USE_OUTLINE
00346         stroke_width->reposition_window(stroke_width->get_x(), stroke_width->get_y());
00347         strokewidth_title->reposition_window(strokewidth_title->get_x(), strokewidth_title->get_y());
00348 #endif
00349         timecode->reposition_window(timecode->get_x(), timecode->get_y());
00350 
00351         text->reposition_window(text->get_x(), 
00352                 text->get_y(), 
00353                 w - text->get_x() - 10,
00354                 BC_TextBox::pixels_to_rows(this, MEDIUMFONT, h - text->get_y() - 10));
00355 
00356 
00357 
00358         justify_title->reposition_window(justify_title->get_x(), justify_title->get_y());
00359         left->reposition_window(left->get_x(), left->get_y());
00360         center->reposition_window(center->get_x(), center->get_y());
00361         right->reposition_window(right->get_x(), right->get_y());
00362         top->reposition_window(top->get_x(), top->get_y());
00363         mid->reposition_window(mid->get_x(), mid->get_y());
00364         bottom->reposition_window(bottom->get_x(), bottom->get_y());
00365         speed_title->reposition_window(speed_title->get_x(), speed_title->get_y());
00366         speed->reposition_window(speed->get_x(), speed->get_y());
00367         update_color();
00368         flash();
00369 
00370         return 1;
00371 }
00372 
00373 
00374 void TitleWindow::previous_font()
00375 {
00376         int current_font = font->get_number();
00377         current_font--;
00378         if(current_font < 0) current_font = fonts.total - 1;
00379 
00380         if(current_font < 0 || current_font >= fonts.total) return;
00381 
00382         for(int i = 0; i < fonts.total; i++)
00383         {
00384                 fonts.values[i]->set_selected(i == current_font);
00385         }
00386 
00387         font->update(fonts.values[current_font]->get_text());
00388         strcpy(client->config.font, fonts.values[current_font]->get_text());
00389         client->send_configure_change();
00390 }
00391 
00392 void  TitleWindow::next_font()
00393 {
00394         int current_font = font->get_number();
00395         current_font++;
00396         if(current_font >= fonts.total) current_font = 0;
00397 
00398         if(current_font < 0 || current_font >= fonts.total) return;
00399 
00400         for(int i = 0; i < fonts.total; i++)
00401         {
00402                 fonts.values[i]->set_selected(i == current_font);
00403         }
00404 
00405         font->update(fonts.values[current_font]->get_text());
00406         strcpy(client->config.font, fonts.values[current_font]->get_text());
00407         client->send_configure_change();
00408 }
00409 
00410 
00411 int TitleWindow::close_event()
00412 {
00413 // Set result to 1 to indicate a client side close
00414         set_done(1);
00415         return 1;
00416 }
00417 
00418 void TitleWindow::update_color()
00419 {
00420 //printf("TitleWindow::update_color %x\n", client->config.color);
00421         set_color(client->config.color);
00422         draw_box(color_x, color_y, 100, 30);
00423         flash(color_x, color_y, 100, 30);
00424 #ifdef USE_OUTLINE
00425         set_color(client->config.color_stroke);
00426         draw_box(color_stroke_x, color_stroke_y, 100, 30);
00427         flash(color_stroke_x, color_stroke_y, 100, 30);
00428 #endif
00429 }
00430 
00431 void TitleWindow::update_justification()
00432 {
00433         left->update(client->config.hjustification == JUSTIFY_LEFT);
00434         center->update(client->config.hjustification == JUSTIFY_CENTER);
00435         right->update(client->config.hjustification == JUSTIFY_RIGHT);
00436         top->update(client->config.vjustification == JUSTIFY_TOP);
00437         mid->update(client->config.vjustification == JUSTIFY_MID);
00438         bottom->update(client->config.vjustification == JUSTIFY_BOTTOM);
00439 }
00440 
00441 void TitleWindow::update()
00442 {
00443         title_x->update((int64_t)client->config.x);
00444         title_y->update((int64_t)client->config.y);
00445         italic->update(client->config.style & FONT_ITALIC);
00446         bold->update(client->config.style & FONT_BOLD);
00447 #ifdef USE_OUTLINE
00448         stroke->update(client->config.style & FONT_OUTLINE);
00449 #endif
00450         size->update(client->config.size);
00451         encoding->update(client->config.encoding);
00452         timecode->update(client->config.timecode);
00453         timecodeformat->update(client->config.timecodeformat);
00454         motion->update(TitleMain::motion_to_text(client->config.motion_strategy));
00455         loop->update(client->config.loop);
00456         dropshadow->update((float)client->config.dropshadow);
00457         fade_in->update((float)client->config.fade_in);
00458         fade_out->update((float)client->config.fade_out);
00459 #ifdef USE_OUTLINE
00460         stroke_width->update((float)client->config.stroke_width);
00461 #endif
00462         font->update(client->config.font);
00463         text->update(client->config.text);
00464         speed->update(client->config.pixels_per_second);
00465         update_justification();
00466         update_color();
00467 }
00468 
00469 
00470 TitleFontTumble::TitleFontTumble(TitleMain *client, TitleWindow *window, int x, int y)
00471  : BC_Tumbler(x, y)
00472 {
00473         this->client = client;
00474         this->window = window;
00475 }
00476 int TitleFontTumble::handle_up_event()
00477 {
00478         window->previous_font();
00479         return 1;
00480 }
00481 
00482 int TitleFontTumble::handle_down_event()
00483 {
00484         window->next_font();
00485         return 1;
00486 }
00487 
00488 TitleBold::TitleBold(TitleMain *client, TitleWindow *window, int x, int y)
00489  : BC_CheckBox(x, y, client->config.style & FONT_BOLD, _("Bold"))
00490 {
00491         this->client = client;
00492         this->window = window;
00493 }
00494 
00495 int TitleBold::handle_event()
00496 {
00497         client->config.style = (client->config.style & ~FONT_BOLD) | (get_value() ? FONT_BOLD : 0);
00498         client->send_configure_change();
00499         return 1;
00500 }
00501 
00502 TitleItalic::TitleItalic(TitleMain *client, TitleWindow *window, int x, int y)
00503  : BC_CheckBox(x, y, client->config.style & FONT_ITALIC, _("Italic"))
00504 {
00505         this->client = client;
00506         this->window = window;
00507 }
00508 int TitleItalic::handle_event()
00509 {
00510         client->config.style = (client->config.style & ~FONT_ITALIC) | (get_value() ? FONT_ITALIC : 0);
00511         client->send_configure_change();
00512         return 1;
00513 }
00514 
00515 TitleStroke::TitleStroke(TitleMain *client, TitleWindow *window, int x, int y)
00516  : BC_CheckBox(x, y, client->config.style & FONT_OUTLINE, _("Outline"))
00517 {
00518         this->client = client;
00519         this->window = window;
00520 }
00521 
00522 int TitleStroke::handle_event()
00523 {
00524         client->config.style = 
00525                 (client->config.style & ~FONT_OUTLINE) | 
00526                 (get_value() ? FONT_OUTLINE : 0);
00527         client->send_configure_change();
00528         return 1;
00529 }
00530 
00531 
00532 
00533 TitleSize::TitleSize(TitleMain *client, TitleWindow *window, int x, int y, char *text)
00534  : BC_PopupTextBox(window, 
00535                 &window->sizes,
00536                 text,
00537                 x, 
00538                 y, 
00539                 100,
00540                 300)
00541 {
00542         this->client = client;
00543         this->window = window;
00544 }
00545 TitleSize::~TitleSize()
00546 {
00547 }
00548 int TitleSize::handle_event()
00549 {
00550         client->config.size = atol(get_text());
00551 //printf("TitleSize::handle_event 1 %s\n", get_text());
00552         client->send_configure_change();
00553         return 1;
00554 }
00555 void TitleSize::update(int size)
00556 {
00557         char string[BCTEXTLEN];
00558         sprintf(string, "%d", size);
00559         BC_PopupTextBox::update(string);
00560 }
00561 TitleEncoding::TitleEncoding(TitleMain *client, TitleWindow *window, int x, int y)
00562  : BC_PopupTextBox(window, 
00563                 &window->encodings,
00564                 client->config.encoding,
00565                 x, 
00566                 y, 
00567                 100,
00568                 300)
00569 {
00570         this->client = client;
00571         this->window = window;
00572 }
00573 
00574 TitleEncoding::~TitleEncoding()
00575 {
00576 }
00577 int TitleEncoding::handle_event()
00578 {
00579         strcpy(client->config.encoding, get_text());
00580         client->send_configure_change();
00581