4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
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"
24 #include "bcsignals.h"
25 #include "browsebutton.h"
28 #include "automation.h"
30 #include "cwindowgui.h"
31 #include "dragcheckbox.h"
33 #include "edlsession.h"
36 #include "mainerror.h"
38 #include "mwindowgui.h"
40 #include "pluginserver.h"
44 #include "titlerwindow.h"
45 #include "bcfontentry.h"
47 #define DEFAULT_TIMECODEFORMAT TIME_HMSF
49 static const int timeunit_formats[] =
60 TitleWindow::TitleWindow(TitleMain *client)
61 : PluginClientWindow(client,
62 client->config.window_w, client->config.window_h,
65 //printf("TitleWindow::TitleWindow %d %d %d\n", __LINE__, client->config.window_w, client->config.window_h);
66 this->client = client;
71 x_title = 0; title_x = 0;
72 y_title = 0; title_y = 0;
73 w_title = 0; title_w = 0;
74 h_title = 0; title_h = 0;
75 dropshadow_title = 0; dropshadow = 0;
76 outline_title = 0; outline = 0;
77 stroker_title = 0; stroker = 0;
86 drag_dx = drag_dy = dragging = 0;
111 left = 0; center = 0; right = 0;
112 top = 0; mid = 0; bottom = 0;
123 void TitleWindow::done_event(int result)
125 color_button->close_picker();
126 outline_button->close_picker();
127 drag->drag_deactivate();
128 delete color_popup; color_popup = 0;
129 delete png_popup; png_popup = 0;
133 TitleWindow::~TitleWindow()
137 for( int i=0; i<fonts.size(); ++i )
138 delete fonts[i]->get_icon();
140 sizes.remove_all_objects();
141 delete timecode_format;
148 void TitleWindow::create_objects()
150 int x = xS(10), y = yS(10);
151 int margin = client->get_theme()->widget_border;
152 char string[BCTEXTLEN];
154 #define COLOR_W xS(50)
155 #define COLOR_H yS(30)
156 client->build_previews(this);
158 sizes.append(new BC_ListBoxItem("8"));
159 sizes.append(new BC_ListBoxItem("9"));
160 sizes.append(new BC_ListBoxItem("10"));
161 sizes.append(new BC_ListBoxItem("11"));
162 sizes.append(new BC_ListBoxItem("12"));
163 sizes.append(new BC_ListBoxItem("13"));
164 sizes.append(new BC_ListBoxItem("14"));
165 sizes.append(new BC_ListBoxItem("16"));
166 sizes.append(new BC_ListBoxItem("18"));
167 sizes.append(new BC_ListBoxItem("20"));
168 sizes.append(new BC_ListBoxItem("22"));
169 sizes.append(new BC_ListBoxItem("24"));
170 sizes.append(new BC_ListBoxItem("26"));
171 sizes.append(new BC_ListBoxItem("28"));
172 sizes.append(new BC_ListBoxItem("32"));
173 sizes.append(new BC_ListBoxItem("36"));
174 sizes.append(new BC_ListBoxItem("40"));
175 sizes.append(new BC_ListBoxItem("48"));
176 sizes.append(new BC_ListBoxItem("56"));
177 sizes.append(new BC_ListBoxItem("64"));
178 sizes.append(new BC_ListBoxItem("72"));
179 sizes.append(new BC_ListBoxItem("100"));
180 sizes.append(new BC_ListBoxItem("128"));
181 sizes.append(new BC_ListBoxItem("256"));
182 sizes.append(new BC_ListBoxItem("512"));
183 sizes.append(new BC_ListBoxItem("1024"));
185 paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(NO_MOTION)));
186 paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(BOTTOM_TO_TOP)));
187 paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(TOP_TO_BOTTOM)));
188 paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(RIGHT_TO_LEFT)));
189 paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(LEFT_TO_RIGHT)));
193 // Construct font list
194 ArrayList<BC_FontEntry*> *fontlist = get_resources()->fontlist;
196 for( int i=0; i<fontlist->size(); ++i ) {
198 for( int j=0; j<fonts.size(); ++j ) {
199 if( !strcasecmp(fonts.get(j)->get_text(),
200 fontlist->get(i)->displayname) ) {
206 BC_ListBoxItem *item = 0;
208 fonts.append(item = new
209 BC_ListBoxItem(fontlist->get(i)->displayname));
210 if( !strcmp(client->config.font, item->get_text()) )
211 item->set_selected(1);
212 if( fontlist->values[i]->image ) {
213 VFrame *vframe = fontlist->get(i)->image;
214 BC_Pixmap *icon = new BC_Pixmap(this, vframe, PIXMAP_ALPHA);
215 item->set_icon(icon);
216 item->set_icon_vframe(vframe);
225 for( int i=0; i<fonts.size()-1; ++i ) {
226 if( strcmp(fonts.values[i]->get_text(),
227 fonts.values[i + 1]->get_text()) > 0 ) {
228 BC_ListBoxItem *temp = fonts.values[i + 1];
229 fonts.values[i + 1] = fonts.values[i];
230 fonts.values[i] = temp;
236 add_tool(font_title = new BC_Title(x, y, _("Font:")));
237 font = new TitleFont(client, this, x, y + font_title->get_h());
238 font->create_objects();
239 font->set_show_query(1);
241 add_subwindow(font_tumbler = new TitleFontTumble(client, this, x, y+margin));
242 x += font_tumbler->get_w() + margin;
244 int x1 = x+xS(20), y1 = y;
245 add_tool(size_title = new BC_Title(x1, y1+margin, _("Size:")));
246 sprintf(string, "%.2f", client->config.size);
247 x1 += size_title->get_w() + margin;
248 size = new TitleSize(client, this, x1, y1+margin, string);
249 size->create_objects();
250 int x2 = x1 + size->get_w(), y2 = y1 + size->get_h() + margin;
251 add_subwindow(size_tumbler = new TitleSizeTumble(client, this, x2, y1+margin));
253 add_tool(pitch_title = new BC_Title(x-xS(16), y2+margin, _("Line Pitch:")));
254 pitch = new TitlePitch(client, this, x1, y2+margin, &client->config.line_pitch);
255 pitch->create_objects();
257 int x3 = x2 + size_tumbler->get_w() + xS(50);
258 int y3 = pitch->get_y() + pitch->get_h();
260 add_tool(style_title = new BC_Title(x=x3, y, _("Style:")));
261 add_tool(italic = new TitleItalic(client, this, x, y + yS(20)));
262 int w1 = italic->get_w();
263 add_tool(bold = new TitleBold(client, this, x, y + yS(50)));
264 if( bold->get_w() > w1 ) w1 = bold->get_w();
266 if( client->drag && drag->drag_activate() ) {
267 eprintf("drag enabled, but compositor already grabbed\n");
270 add_tool(drag = new TitleDrag(client, this, x, y + yS(80)));
271 drag->create_objects();
272 if( drag->get_w() > w1 ) w1 = drag->get_w();
274 add_tool(alias = new TitleAlias(client, this, x, y+yS(110)));
275 if( alias->get_w() > w1 ) w1 = drag->get_w();
278 add_tool(justify_title = new BC_Title(x+xS(50), y, _("Justify:")));
279 add_tool(left = new TitleLeft(client, this, x, y + yS(20)));
281 add_tool(center = new TitleCenter(client, this, x, y + yS(50)));
282 if( center->get_w() > w1 ) w1 = center->get_w();
283 add_tool(right = new TitleRight(client, this, x, y + yS(80)));
284 if( right->get_w() > w1 ) w1 = right->get_w();
287 add_tool(top = new TitleTop(client, this, x, y + yS(20)));
288 add_tool(mid = new TitleMid(client, this, x, y + yS(50)));
289 add_tool(bottom= new TitleBottom(client, this, x, y + yS(80)));
294 w1 = BC_Title::calculate_w(this, _("X:"));
295 if( (x1 = BC_Title::calculate_w(this, _("Y:"))) > w1 ) w1 = x1;
296 if( (x1 = BC_Title::calculate_w(this, _("W:"))) > w1 ) w1 = x1;
297 if( (x1 = BC_Title::calculate_w(this, _("H:"))) > w1 ) w1 = x1;
298 add_tool(x_title = new BC_Title(x1=x, y, _("X:")));
300 title_x = new TitleX(client, this, x1, y);
301 title_x->create_objects();
302 x1 += title_x->get_w()+margin;
303 add_tool(y_title = new BC_Title(x1, y, _("Y:")));
305 title_y = new TitleY(client, this, x1, y);
306 title_y->create_objects();
307 x1 += title_y->get_w();
308 y1 = y + title_y->get_h();
310 add_tool(w_title = new BC_Title(x1=x, y1, _("W:")));
312 title_w = new TitleW(client, this, x1, y1);
313 title_w->create_objects();
314 x1 += title_w->get_w()+margin;
315 add_tool(h_title = new BC_Title(x1, y1, _("H:")));
317 title_h = new TitleH(client, this, x1, y1);
318 title_h->create_objects();
319 x1 += title_h->get_w();
322 add_tool(motion_title = new BC_Title(x1=x, y, _("Motion:")));
323 x1 += motion_title->get_w()+margin;
324 motion = new TitleMotion(client, this, x1, y);
325 motion->create_objects();
326 add_tool(loop = new TitleLoop(client, this, x, y1));
327 x = margin; y = y1 + loop->get_h()+yS(20);
329 add_tool(dropshadow_title = new BC_Title(x, y, _("Drop shadow:")));
330 w1 = dropshadow_title->get_w();
331 dropshadow = new TitleDropShadow(client, this, x, y + yS(20));
332 dropshadow->create_objects();
333 if( dropshadow->get_w() > w1 ) w1 = dropshadow->get_w();
336 add_tool(fadein_title = new BC_Title(x, y, _("Fade in (sec):")));
337 w1 = fadein_title->get_w();
338 add_tool(fade_in = new TitleFade(client, this, &client->config.fade_in, x, y + yS(20)));
339 if( fade_in->get_w() > w1 ) w1 = fade_in->get_w();
342 add_tool(fadeout_title = new BC_Title(x, y, _("Fade out (sec):")));
343 w1 = fadeout_title->get_w();
344 add_tool(fade_out = new TitleFade(client, this, &client->config.fade_out, x, y + yS(20)));
345 if( fade_out->get_w() > w1 ) w1 = fade_out->get_w();
348 add_tool(speed_title = new BC_Title(x, y, _("Speed:")));
349 w1 = speed_title->get_w();
350 y += speed_title->get_h() + yS(5); y1 = y;
351 speed = new TitleSpeed(client, this, x, y);
352 speed->create_objects();
353 if( speed->get_w() > w1 ) w1 = speed->get_w();
355 y2 = y + speed->get_h() + yS(10);
357 add_tool(color_button_title = new BC_Title(x3, y1+yS(10), _("Color:")));
358 x1 = x3 + color_button_title->get_w() + xS(30);
359 add_tool(color_button = new TitleColorButton(client, this, x1, y1));
360 y1 += color_button->get_h() + yS(10);
361 add_tool(outline_button_title = new BC_Title(x3, y1+yS(10), _("Outline:")));
362 add_tool(outline_button = new TitleOutlineColorButton(client, this, x1, y1));
365 add_tool(outline_title = new BC_Title(x, y, _("Outline:")));
366 y1 = y + outline_title->get_h() + margin;
367 outline = new TitleOutline(client, this, x, y1);
368 outline->create_objects();
369 x += outline->get_w() + xS(2)*margin;
371 add_tool(stroker_title = new BC_Title(x, y, _("Stroker:")));
372 stroker = new TitleStroker(client, this, x, y1);
373 stroker->create_objects();
374 x += stroker->get_w() + margin;
378 add_tool(reset_button = new TitleResetButton(client, this, x3, y1+yS(30)));
379 reset_button->create_objects();
382 add_tool(timecode = new TitleTimecode(client, this, x, y));
383 y += timecode->get_h() + margin;
385 for( int i=0; i<lengthof(timeunit_formats); ++i ) {
387 Units::print_time_format(timeunit_formats[i], text);
388 int w = get_text_width(MEDIUMFONT, text);
391 add_tool(timecode_format = new TitleTimecodeFormat(client, this, x, y, tw,
392 Units::print_time_format(client->config.timecode_format, string)));
393 timecode_format->create_objects();
394 y += timecode_format->get_h() + margin;
397 add_tool(background = new TitleBackground(client, this, x, y));
398 x += background->get_w() + margin;
399 add_tool(background_path = new TitleBackgroundPath(client, this, x, y));
400 x += background_path->get_w() + margin;
401 add_tool(background_browse = new BrowseButton(
402 client->server->mwindow->theme, this, background_path,
403 x, y, "", _("background media"), _("Select background media path")));
404 x += background_browse->get_w() + xS(3)*margin;
405 add_tool(loop_playback = new TitleLoopPlayback(client, this, x, y));
406 y += loop_playback->get_h() + yS(10);
409 add_tool(text_title = new BC_Title(x, y, _("Text:")));
410 x += text_title->get_w() + xS(20);
411 int wid = BC_Title::calculate_w(this,"0")*xS(10);
412 add_tool(text_chars = new TitleTextChars(x,y,wid));
414 y += text_title->get_h() + margin;
416 text = new TitleText(client, this, x, y, get_w()-margin - x, get_h() - y - yS(10));
417 text->create_objects();
419 add_tool(cur_popup = new TitleCurPopup(client, this));
420 cur_popup->create_objects();
421 add_tool(fonts_popup = new TitleFontsPopup(client, this));
422 color_popup = new TitleColorPopup(client, this);
423 png_popup = new TitlePngPopup(client, this);
429 int TitleWindow::resize_event(int w, int h)
431 client->config.window_w = w;
432 client->config.window_h = h;
434 clear_box(0, 0, w, h);
435 font_title->reposition_window(font_title->get_x(), font_title->get_y());
436 font->reposition_window(font->get_x(), font->get_y());
437 font_tumbler->reposition_window(font_tumbler->get_x(), font_tumbler->get_y());
438 x_title->reposition_window(x_title->get_x(), x_title->get_y());
439 title_x->reposition_window(title_x->get_x(), title_x->get_y());
440 y_title->reposition_window(y_title->get_x(), y_title->get_y());
441 title_y->reposition_window(title_y->get_x(), title_y->get_y());
442 w_title->reposition_window(w_title->get_x(), w_title->get_y());
443 title_w->reposition_window(title_w->get_x(), title_w->get_y());
444 h_title->reposition_window(h_title->get_x(), h_title->get_y());
445 title_h->reposition_window(title_h->get_x(), title_h->get_y());
446 style_title->reposition_window(style_title->get_x(), style_title->get_y());
447 italic->reposition_window(italic->get_x(), italic->get_y());
448 bold->reposition_window(bold->get_x(), bold->get_y());
449 drag->reposition_window(drag->get_x(), drag->get_y());
450 alias->reposition_window(alias->get_x(), alias->get_y());
451 size_title->reposition_window(size_title->get_x(), size_title->get_y());
452 size->reposition_window(size->get_x(), size->get_y());
453 size_tumbler->reposition_window(size_tumbler->get_x(), size_tumbler->get_y());
454 pitch_title->reposition_window(pitch_title->get_x(), pitch_title->get_y());
455 pitch->reposition_window(pitch->get_x(), pitch->get_y());
457 reset_button->reposition_window(reset_button->get_x(), reset_button->get_y());
458 color_button_title->reposition_window(color_button_title->get_x(), color_button_title->get_y());
459 color_button->reposition_window(color_button->get_x(), color_button->get_y());
460 outline_button_title->reposition_window(outline_button_title->get_x(), outline_button_title->get_y());
461 outline_button->reposition_window(outline_button->get_x(), outline_button->get_y());
462 motion_title->reposition_window(motion_title->get_x(), motion_title->get_y());
463 motion->reposition_window(motion->get_x(), motion->get_y());
464 loop->reposition_window(loop->get_x(), loop->get_y());
465 dropshadow_title->reposition_window(dropshadow_title->get_x(), dropshadow_title->get_y());
466 dropshadow->reposition_window(dropshadow->get_x(), dropshadow->get_y());
467 fadein_title->reposition_window(fadein_title->get_x(), fadein_title->get_y());
468 fade_in->reposition_window(fade_in->get_x(), fade_in->get_y());
469 fadeout_title->reposition_window(fadeout_title->get_x(), fadeout_title->get_y());
470 fade_out->reposition_window(fade_out->get_x(), fade_out->get_y());
471 text_title->reposition_window(text_title->get_x(), text_title->get_y());
472 timecode->reposition_window(timecode->get_x(), timecode->get_y());
473 text->reposition_window(text->get_x(), text->get_y(), w - text->get_x() - xS(10),
474 BC_TextBox::pixels_to_rows(this, MEDIUMFONT, h - text->get_y() - yS(10)));
475 justify_title->reposition_window(justify_title->get_x(), justify_title->get_y());
476 left->reposition_window(left->get_x(), left->get_y());
477 center->reposition_window(center->get_x(), center->get_y());
478 right->reposition_window(right->get_x(), right->get_y());
479 top->reposition_window(top->get_x(), top->get_y());
480 mid->reposition_window(mid->get_x(), mid->get_y());
481 bottom->reposition_window(bottom->get_x(), bottom->get_y());
482 speed_title->reposition_window(speed_title->get_x(), speed_title->get_y());
483 speed->reposition_window(speed->get_x(), speed->get_y());
490 void TitleWindow::update_drag()
492 drag->drag_x = client->config.title_x;
493 drag->drag_y = client->config.title_y;
494 drag->drag_w = client->config.title_w;
495 drag->drag_h = client->config.title_h;
496 send_configure_change();
498 void TitleWindow::send_configure_change()
500 client->send_configure_change();
503 void TitleWindow::previous_font()
505 int current_font = font->get_number();
506 if( !fonts.total ) current_font = -1;
507 else if( --current_font < 0 ) current_font = fonts.total - 1;
508 font->set_number(current_font);
510 if( current_font < 0 || current_font >= fonts.total ) return;
512 for( int i=0; i<fonts.total; ++i ) {
513 fonts.values[i]->set_selected(i == current_font);
516 font->update(fonts.values[current_font]->get_text());
517 strcpy(client->config.font, fonts.values[current_font]->get_text());
518 check_style(client->config.font,1);
519 send_configure_change();
522 void TitleWindow::next_font()
524 int current_font = font->get_number();
525 if( !fonts.total ) current_font = -1;
526 else if( ++current_font >= fonts.total ) current_font = 0;
527 font->set_number(current_font);
529 if( current_font < 0 || current_font >= fonts.total ) return;
531 for( int i=0; i<fonts.total; ++i ) {
532 fonts.values[i]->set_selected(i == current_font);
535 font->update(fonts.values[current_font]->get_text());
536 strcpy(client->config.font, fonts.values[current_font]->get_text());
537 check_style(client->config.font,1);
538 send_configure_change();
541 int TitleWindow::insert_ibeam(const char *txt, int ofs)
543 int ibeam = cur_ibeam;
544 int ilen = strlen(txt)+1;
546 int len = BC_Resources::encode(client->config.encoding, BC_Resources::wide_encoding,
547 (char*)txt,ilen, (char *)wtxt,ilen*sizeof(wtxt[0])) / sizeof(wchr_t);
548 client->insert_text(wtxt, ibeam);
549 while( len > 0 && !wtxt[len] ) --len;
550 int adv = len+1 + ofs;
551 if( (ibeam += adv) >= client->config.wlen)
552 ibeam = client->config.wlen;
553 text->wset_selection(-1, -1, ibeam);
554 text->update(client->config.wtext);
555 send_configure_change();
559 void TitleWindow::update_color()
561 color_button->update_gui(client->config.color);
562 outline_button->update_gui(client->config.outline_color);
565 void TitleWindow::update_justification()
567 left->update(client->config.hjustification == JUSTIFY_LEFT);
568 center->update(client->config.hjustification == JUSTIFY_CENTER);
569 right->update(client->config.hjustification == JUSTIFY_RIGHT);
570 top->update(client->config.vjustification == JUSTIFY_TOP);
571 mid->update(client->config.vjustification == JUSTIFY_MID);
572 bottom->update(client->config.vjustification == JUSTIFY_BOTTOM);
575 void TitleWindow::update_stats()
577 text_chars->update(client->config.wlen);
580 void TitleWindow::update_gui()
582 title_x->update((int64_t)client->config.title_x);
583 title_y->update((int64_t)client->config.title_y);
584 title_w->update((int64_t)client->config.title_w);
585 title_h->update((int64_t)client->config.title_h);
586 drag->drag_x = client->config.title_x;
587 drag->drag_y = client->config.title_y;
588 drag->drag_w = client->config.title_w;
589 drag->drag_h = client->config.title_h;
590 italic->update(client->config.style & BC_FONT_ITALIC);
591 bold->update(client->config.style & BC_FONT_BOLD);
592 alias->update(client->config.style & FONT_ALIAS);
593 size->update(client->config.size);
594 pitch->update((int64_t)client->config.line_pitch);
595 motion->update(TitleMain::motion_to_text(client->config.motion_strategy));
596 loop->update(client->config.loop);
597 dropshadow->update((int64_t)client->config.dropshadow);
598 fade_in->update((float)client->config.fade_in);
599 fade_out->update((float)client->config.fade_out);
600 font->update(client->config.font);
601 check_style(client->config.font,0);
602 wchr_t wz[1] = { 0 };
603 text->update(client->config.wtext ? &client->config.wtext[0] : wz);
604 speed->update(client->config.pixels_per_second);
605 outline->update((int64_t)client->config.outline_size);
607 stroker->update((int64_t)client->config.stroke_width);
609 timecode->update(client->config.timecode);
610 timecode_format->update(client->config.timecode_format);
611 background->update(client->config.background);
612 background_path->update(client->config.background_path);
613 loop_playback->update((int64_t)client->config.loop_playback);
615 char string[BCTEXTLEN];
616 for( int i=0; i<lengthof(timeunit_formats); ++i ) {
617 if( timeunit_formats[i] == client->config.timecode_format ) {
618 timecode_format->set_text(
619 Units::print_time_format(timeunit_formats[i], string));
623 update_justification();
629 TitleFontTumble::TitleFontTumble(TitleMain *client, TitleWindow *window, int x, int y)
632 this->client = client;
633 this->window = window;
635 int TitleFontTumble::handle_up_event()
637 window->previous_font();
641 int TitleFontTumble::handle_down_event()
648 TitleSizeTumble::TitleSizeTumble(TitleMain *client, TitleWindow *window, int x, int y)
651 this->client = client;
652 this->window = window;
655 int TitleSizeTumble::handle_up_event()
657 int current_index = -1;
658 int current_difference = -1;
659 for( int i=0; i<window->sizes.size(); ++i ) {
660 int size = atoi(window->sizes.get(i)->get_text());
661 if( current_index < 0 ||
662 abs(size - client->config.size) < current_difference ) {
664 current_difference = abs(size - client->config.size);
669 if( current_index >= window->sizes.size() ) current_index = 0;
672 client->config.size = atoi(window->sizes.get(current_index)->get_text());
673 window->size->update(client->config.size);
674 window->send_configure_change();
678 int TitleSizeTumble::handle_down_event()
680 int current_index = -1;
681 int current_difference = -1;
682 for( int i=0; i<window->sizes.size(); ++i ) {
683 int size = atoi(window->sizes.get(i)->get_text());
684 if( current_index < 0 ||
685 abs(size - client->config.size) < current_difference ) {
687 current_difference = abs(size - client->config.size);
692 if( current_index < 0 ) current_index = window->sizes.size() - 1;
695 client->config.size = atoi(window->sizes.get(current_index)->get_text());
696 window->size->update(client->config.size);
697 window->send_configure_change();
701 TitleAlias::TitleAlias(TitleMain *client, TitleWindow *window, int x, int y)
702 : BC_CheckBox(x, y, client->config.style & FONT_ALIAS, _("Smooth"))
704 this->client = client;
705 this->window = window;
708 int TitleAlias::handle_event()
710 client->config.style =
711 (client->config.style & ~FONT_ALIAS) |
712 (get_value() ? FONT_ALIAS : 0);
713 window->send_configure_change();
717 TitleBold::TitleBold(TitleMain *client, TitleWindow *window, int x, int y)
718 : BC_CheckBox(x, y, client->config.style & BC_FONT_BOLD, _("Bold"))
720 this->client = client;
721 this->window = window;
724 int TitleBold::handle_event()
726 client->config.style =
727 (client->config.style & ~BC_FONT_BOLD) |
728 (get_value() ? BC_FONT_BOLD : 0);
729 window->send_configure_change();
733 TitleItalic::TitleItalic(TitleMain *client, TitleWindow *window, int x, int y)
734 : BC_CheckBox(x, y, client->config.style & BC_FONT_ITALIC, _("Italic"))
736 this->client = client;
737 this->window = window;
739 int TitleItalic::handle_event()
741 client->config.style =
742 (client->config.style & ~BC_FONT_ITALIC) |
743 (get_value() ? BC_FONT_ITALIC : 0);
744 window->send_configure_change();
750 TitleSize::TitleSize(TitleMain *client, TitleWindow *window, int x, int y, char *text)
751 : BC_PopupTextBox(window, &window->sizes, text, x, y, xS(64), yS(300))
753 this->client = client;
754 this->window = window;
756 TitleSize::~TitleSize()
759 int TitleSize::handle_event()
761 client->config.size = atol(get_text());
762 //printf("TitleSize::handle_event 1 %s\n", get_text());
763 window->send_configure_change();
766 void TitleSize::update(int size)
768 char string[BCTEXTLEN];
769 sprintf(string, "%d", size);
770 BC_PopupTextBox::update(string);
774 TitlePitch(TitleMain *client, TitleWindow *window, int x, int y, int *value)
775 : BC_TumbleTextBox(window, *value, 0, INT_MAX, x, y, xS(64))
777 this->client = client;
778 this->window = window;
787 int TitlePitch::handle_event()
789 *value = atol(get_text());
790 window->send_configure_change();
796 TitleResetButton::TitleResetButton(TitleMain *client, TitleWindow *window, int x, int y)
797 : BC_GenericButton (x, y, _("Reset"))
799 this->client = client;
800 this->window = window;
801 set_tooltip("Reset to default values");
809 int TitleResetButton::handle_event()
811 strcpy(client->config.font, "fixed");
812 client->config.title_x = 0;
813 client->config.title_y = 0;
814 client->config.title_w = 0;
815 client->config.title_h = 0;
816 client->config.hjustification = JUSTIFY_CENTER;
817 client->config.vjustification = JUSTIFY_MID;
818 client->config.style = FONT_ALIAS;
819 client->config.motion_strategy = NO_MOTION;
820 client->config.timecode_format = DEFAULT_TIMECODEFORMAT;
821 client->config.loop = 0;
822 client->config.dropshadow = 0;
823 client->config.fade_in = 0;
824 client->config.fade_out = 0;
825 client->config.pixels_per_second = 100;
826 client->config.outline_size = 0;
827 client->config.outline_color = RED;
828 client->config.outline_alpha = 0xff;
829 client->config.color_stroke = 0xff0000;
830 client->config.size = 48;
831 client->config.line_pitch = 0;
832 client->config.color = WHITE;
833 client->config.alpha = 0xff;
834 client->config.timecode = 0;
835 client->config.background = 0;
836 strcpy(client->config.background_path, "");
838 client->config.stroke_width = 0;
840 client->config.loop_playback = 0;
841 client->config.wlen = 0;
843 client->config.wtext[0] = wz;
844 window->send_configure_change();
845 window->update_gui();
850 TitleColorButton::TitleColorButton(TitleMain *client, TitleWindow *window, int x, int y)
851 : ColorCircleButton(_("Text Color"), x, y, COLOR_W, COLOR_H,
852 client->config.color, client->config.alpha, 1)
854 this->client = client;
855 this->window = window;
857 int TitleColorButton::handle_new_color(int output, int alpha)
859 client->config.color = output;
860 client->config.alpha = alpha;
861 window->send_configure_change();
864 void TitleColorButton::handle_done_event(int result)
867 handle_new_color(orig_color, orig_alpha);
868 window->lock_window("TitleColorButton::handle_done_event");
869 update_gui(orig_color);
870 window->unlock_window();
874 TitleOutlineColorButton::TitleOutlineColorButton(TitleMain *client, TitleWindow *window, int x, int y)
875 : ColorCircleButton(_("Outline Color"), x, y, COLOR_W, COLOR_H,
876 client->config.outline_color, client->config.outline_alpha, 1)
878 this->client = client;
879 this->window = window;
881 int TitleOutlineColorButton::handle_new_color(int output, int alpha)
883 client->config.outline_color = output;
884 client->config.outline_alpha = alpha;
885 window->send_configure_change();
888 void TitleOutlineColorButton::handle_done_event(int result)
891 handle_new_color(orig_color, orig_alpha);
892 window->lock_window("TitleColorButton::handle_done_event");
893 update_gui(orig_color);
894 window->unlock_window();
899 TitleMotion::TitleMotion(TitleMain *client, TitleWindow *window, int x, int y)
900 : BC_PopupTextBox(window, &window->paths,
901 client->motion_to_text(client->config.motion_strategy),
902 x, y, xS(120), yS(100))
904 this->client = client;
905 this->window = window;
907 int TitleMotion::handle_event()
909 client->config.motion_strategy = client->text_to_motion(get_text());
910 window->send_configure_change();
914 TitleLoop::TitleLoop(TitleMain *client, TitleWindow *window, int x, int y)
915 : BC_CheckBox(x, y, client->config.loop, _("Loop"))
917 this->client = client;
918 this->window = window;
920 int TitleLoop::handle_event()
922 client->config.loop = get_value();
923 window->send_configure_change();
926 TitleTimecode::TitleTimecode(TitleMain *client, TitleWindow *window, int x, int y)
927 : BC_CheckBox(x, y, client->config.timecode, _("Stamp timecode"))
929 this->client = client;
930 this->window = window;
932 int TitleTimecode::handle_event()
934 client->config.timecode = get_value();
935 client->send_configure_change();
939 TitleTimecodeFormat::TitleTimecodeFormat(TitleMain *client, TitleWindow *window,
940 int x, int y, int tw, const char *text)
941 : BC_PopupMenu(x, y, BC_PopupMenu::calculate_w(tw)+xS(10), text, 1)
943 this->client = client;
944 this->window = window;
947 int TitleTimecodeFormat::handle_event()
949 client->config.timecode_format = Units::text_to_format(get_text());
950 window->send_configure_change();
954 void TitleTimecodeFormat::create_objects()
956 char string[BCTEXTLEN];
957 for( int i=0; i<lengthof(timeunit_formats); ++i ) {
958 add_item(new BC_MenuItem(
959 Units::print_time_format(timeunit_formats[i], string)));
964 int TitleTimecodeFormat::update(int timecode_format)
966 char string[BCTEXTLEN];
967 for( int i=0; i<lengthof(timeunit_formats); ++i ) {
968 if( timeunit_formats[i] == timecode_format ) {
969 set_text(Units::print_time_format(timeunit_formats[i], string));
976 TitleFade::TitleFade(TitleMain *client, TitleWindow *window,
977 double *value, int x, int y)
978 : BC_TextBox(x, y, xS(80), 1, (float)*value)
980 this->client = client;
981 this->window = window;
986 int TitleFade::handle_event()
988 *value = atof(get_text());
989 window->send_configure_change();
993 void TitleWindow::check_style(const char *font_name, int update)
995 BC_FontEntry *font_nrm = TitleMain::get_font(font_name, 0);
996 BC_FontEntry *font_itl = TitleMain::get_font(font_name, BC_FONT_ITALIC);
997 BC_FontEntry *font_bld = TitleMain::get_font(font_name, BC_FONT_BOLD);
998 BC_FontEntry *font_bit = TitleMain::get_font(font_name, BC_FONT_ITALIC | BC_FONT_BOLD);
999 int has_norm = font_nrm != 0 ? 1 : 0;
1000 int has_ital = font_itl != 0 || font_bit != 0 ? 1 : 0;
1001 int has_bold = font_bld != 0 || font_bit != 0 ? 1 : 0;
1002 if( bold->get_value() ) {
1003 if( !has_bold ) bold->update(0);
1006 if( !has_norm && has_bold ) bold->update(1);
1008 if( italic->get_value() ) {
1009 if( !has_ital ) italic->update(0);
1012 if( !has_norm && has_ital ) italic->update(1);
1014 if( has_norm && has_bold ) bold->enable(); else bold->disable();
1015 if( has_norm && has_ital ) italic->enable(); else italic->disable();
1017 int style = stroker && atof(stroker->get_text()) ? BC_FONT_OUTLINE : 0;
1018 if( bold->get_value() ) style |= BC_FONT_BOLD;
1019 if( italic->get_value() ) style |= BC_FONT_ITALIC;
1020 if( alias->get_value() ) style |= FONT_ALIAS;
1021 client->config.style = style;
1025 TitleFont::TitleFont(TitleMain *client, TitleWindow *window, int x, int y)
1026 : BC_PopupTextBox(window, &window->fonts, client->config.font,
1027 x, y, xS(340), yS(300), LISTBOX_ICON_LIST)
1029 this->client = client;
1030 this->window = window;
1032 int TitleFont::handle_event()
1034 strcpy(client->config.font, get_text());
1035 window->check_style(client->config.font, 1);
1036 window->send_configure_change();
1040 TitleText::TitleText(TitleMain *client, TitleWindow *window,
1041 int x, int y, int w, int h)
1042 : BC_ScrollTextBox(window, x, y, w,
1043 BC_TextBox::pixels_to_rows(window, MEDIUMFONT, h),
1044 client->config.wtext, 0)
1046 this->client = client;
1047 this->window = window;
1048 //printf("TitleText::TitleText %s\n", client->config.text);
1051 int TitleText::button_press_event()
1053 if( get_buttonpress() == 3 ) {
1054 window->cur_ibeam = get_ibeam_letter();
1055 window->cur_popup->activate_menu();
1058 return BC_ScrollTextBox::button_press_event();
1061 int TitleText::handle_event()
1063 window->fonts_popup->deactivate();
1064 const wchr_t *wtext = get_wtext();
1065 long wlen = wstrlen(wtext);
1066 client->config.demand(wlen);
1067 wstrncpy(client->config.wtext, wtext, client->config.wsize);
1068 client->config.wlen = wlen;
1069 window->update_stats();
1070 window->send_configure_change();
1073 TitleTextChars::TitleTextChars(int x, int y, int w)
1074 : BC_Title(x, y, "", MEDIUMFONT, -1, 0, w)
1077 TitleTextChars::~TitleTextChars()
1080 int TitleTextChars::update(int n)
1082 char text[BCSTRLEN];
1083 sprintf(text, _("chars: %d "),n);
1084 return BC_Title::update(text, 0);
1088 TitleDropShadow::TitleDropShadow(TitleMain *client, TitleWindow *window, int x, int y)
1089 : BC_TumbleTextBox(window, client->config.dropshadow,
1090 -1000, 1000, x, y, xS(70))
1092 this->client = client;
1093 this->window = window;
1095 int TitleDropShadow::handle_event()
1097 client->config.dropshadow = atol(get_text());
1098 window->send_configure_change();
1103 TitleOutline::TitleOutline(TitleMain *client, TitleWindow *window, int x, int y)
1104 : BC_TumbleTextBox(window, client->config.outline_size,
1105 0.f, 1000.f, x, y, xS(70))
1107 this->client = client;
1108 this->window = window;
1111 int TitleOutline::handle_event()
1113 client->config.outline_size = atof(get_text());
1114 window->send_configure_change();
1119 TitleStroker::TitleStroker(TitleMain *client, TitleWindow *window, int x, int y)
1120 : BC_TumbleTextBox(window, client->config.stroke_width,
1121 0.f, 1000.f, x, y, xS(70))
1123 this->client = client;
1124 this->window = window;
1127 int TitleStroker::handle_event()
1129 client->config.stroke_width = atof(get_text());
1130 if( client->config.stroke_width )
1131 client->config.style |= BC_FONT_OUTLINE;
1133 client->config.style &= ~BC_FONT_OUTLINE;
1134 window->send_configure_change();
1139 TitleX::TitleX(TitleMain *client, TitleWindow *window, int x, int y)
1140 : BC_TumbleTextBox(window, client->config.title_x,
1141 -32767.f, 32767.f, x, y, xS(50))
1143 this->client = client;
1144 this->window = window;
1147 int TitleX::handle_event()
1149 client->config.title_x = atof(get_text());
1150 window->update_drag();
1154 TitleY::TitleY(TitleMain *client, TitleWindow *window, int x, int y)
1155 : BC_TumbleTextBox(window, client->config.title_y,
1156 -32767.f, 32767.f, x, y, xS(50))
1158 this->client = client;
1159 this->window = window;
1162 int TitleY::handle_event()
1164 client->config.title_y = atof(get_text());
1165 window->update_drag();
1169 TitleW::TitleW(TitleMain *client, TitleWindow *window, int x, int y)
1170 : BC_TumbleTextBox(window, client->config.title_w,
1171 0, 32767, x, y, xS(50))
1173 this->client = client;
1174 this->window = window;
1176 int TitleW::handle_event()
1178 client->config.title_w = atol(get_text());
1179 window->update_drag();
1183 TitleH::TitleH(TitleMain *client, TitleWindow *window, int x, int y)
1184 : BC_TumbleTextBox(window, client->config.title_h,
1185 0, 32767, x, y, xS(50))
1187 this->client = client;
1188 this->window = window;
1190 int TitleH::handle_event()
1192 client->config.title_h = atol(get_text());
1193 window->update_drag();
1197 TitleSpeed::TitleSpeed(TitleMain *client, TitleWindow *window, int x, int y)
1198 : BC_TumbleTextBox(window, client->config.pixels_per_second,
1199 0.f, 1000.f, x, y, xS(100))
1201 this->client = client;
1202 this->window = window;
1208 int TitleSpeed::handle_event()
1210 client->config.pixels_per_second = atof(get_text());
1211 window->send_configure_change();
1216 TitleLeft::TitleLeft(TitleMain *client, TitleWindow *window, int x, int y)
1217 : BC_Radial(x, y, client->config.hjustification == JUSTIFY_LEFT, _("Left"))
1219 this->client = client;
1220 this->window = window;
1222 int TitleLeft::handle_event()
1224 client->config.hjustification = JUSTIFY_LEFT;
1225 window->update_justification();
1226 window->send_configure_change();
1230 TitleCenter::TitleCenter(TitleMain *client, TitleWindow *window, int x, int y)
1231 : BC_Radial(x, y, client->config.hjustification == JUSTIFY_CENTER, _("Center"))
1233 this->client = client;
1234 this->window = window;
1236 int TitleCenter::handle_event()
1238 client->config.hjustification = JUSTIFY_CENTER;
1239 window->update_justification();
1240 window->send_configure_change();
1244 TitleRight::TitleRight(TitleMain *client, TitleWindow *window, int x, int y)
1245 : BC_Radial(x, y, client->config.hjustification == JUSTIFY_RIGHT, _("Right"))
1247 this->client = client;
1248 this->window = window;
1250 int TitleRight::handle_event()
1252 client->config.hjustification = JUSTIFY_RIGHT;
1253 window->update_justification();
1254 window->send_configure_change();
1260 TitleTop::TitleTop(TitleMain *client, TitleWindow *window, int x, int y)
1261 : BC_Radial(x, y, client->config.vjustification == JUSTIFY_TOP, _("Top"))
1263 this->client = client;
1264 this->window = window;
1266 int TitleTop::handle_event()
1268 client->config.vjustification = JUSTIFY_TOP;
1269 window->update_justification();
1270 window->send_configure_change();
1274 TitleMid::TitleMid(TitleMain *client, TitleWindow *window, int x, int y)
1275 : BC_Radial(x, y, client->config.vjustification == JUSTIFY_MID, _("Mid"))
1277 this->client = client;
1278 this->window = window;
1280 int TitleMid::handle_event()
1282 client->config.vjustification = JUSTIFY_MID;
1283 window->update_justification();
1284 window->send_configure_change();
1288 TitleBottom::TitleBottom(TitleMain *client, TitleWindow *window, int x, int y)
1289 : BC_Radial(x, y, client->config.vjustification == JUSTIFY_BOTTOM, _("Bottom"))
1291 this->client = client;
1292 this->window = window;
1294 int TitleBottom::handle_event()
1296 client->config.vjustification = JUSTIFY_BOTTOM;
1297 window->update_justification();
1298 window->send_configure_change();
1302 TitleDrag::TitleDrag(TitleMain *client, TitleWindow *window, int x, int y)
1303 : DragCheckBox(client->server->mwindow, x, y, _("Drag"), &client->drag,
1304 client->config.title_x, client->config.title_y,
1305 client->config.title_w, client->config.title_h)
1307 this->client = client;
1308 this->window = window;
1311 Track *TitleDrag::get_drag_track()
1313 PluginServer *server = client->server;
1314 int plugin_id = server->plugin_id;
1315 Plugin *plugin = server->edl->tracks->plugin_exists(plugin_id);
1316 return !plugin ? 0 : plugin->track;
1318 int64_t TitleDrag::get_drag_position()
1320 return client->get_source_position();
1323 void TitleDrag::update_gui()
1325 client->drag = get_value();
1326 client->config.title_x = drag_x;
1327 client->config.title_y = drag_y;
1328 client->config.title_w = drag_w+0.5;
1329 client->config.title_h = drag_h+0.5;
1330 window->title_x->update((float)client->config.title_x);
1331 window->title_y->update((float)client->config.title_y);
1332 window->title_w->update((int64_t)client->config.title_w);
1333 window->title_h->update((int64_t)client->config.title_h);
1334 window->send_configure_change();
1337 int TitleDrag::handle_event()
1339 int ret = DragCheckBox::handle_event();
1340 client->drag = get_value();
1341 window->send_configure_change();
1345 TitleBackground::TitleBackground(TitleMain *client, TitleWindow *window, int x, int y)
1346 : BC_CheckBox(x, y, client->config.background, _("Background:"))
1348 this->client = client;
1349 this->window = window;
1352 int TitleBackground::handle_event()
1354 client->config.background = get_value();
1355 window->send_configure_change();
1359 TitleBackgroundPath::TitleBackgroundPath(TitleMain *client, TitleWindow *window, int x, int y)
1360 : BC_TextBox(x, y, xS(240), 1, client->config.background_path)
1362 this->client = client;
1363 this->window = window;
1366 int TitleBackgroundPath::handle_event()
1368 strncpy(client->config.background_path, get_text(), sizeof(client->config.background_path));
1369 window->send_configure_change();
1373 TitleLoopPlayback::TitleLoopPlayback(TitleMain *client, TitleWindow *window, int x, int y)
1374 : BC_CheckBox(x, y, client->config.loop_playback, _("Loop playback"))
1376 this->client = client;
1377 this->window = window;
1379 int TitleLoopPlayback::handle_event()
1381 client->config.loop_playback = get_value();
1382 window->send_configure_change();
1387 TitleCurPopup::TitleCurPopup(TitleMain *client, TitleWindow *window)
1388 : BC_PopupMenu(0, 0, 0, "", 0)
1390 this->client = client;
1391 this->window = window;
1393 int TitleCurPopup::handle_event()
1398 void TitleCurSubMenu::add_subitemx(int popup_type, va_list ap, const char *fmt)
1400 char item[BCSTRLEN];
1401 vsnprintf(item, sizeof(item)-1, fmt, ap);
1402 item[sizeof(item)-1] = 0;
1403 add_submenuitem(new TitleCurSubMenuItem(this, item, popup_type));
1406 void TitleCurPopup::create_objects()
1408 TitleCurItem *cur_item;
1409 TitleCurSubMenu *sub_menu;
1411 add_item(cur_item = new TitleCurItem(this, item = _(KW_NUDGE)));
1412 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1413 sub_menu->add_subitem("%s dx,dy",item);
1414 sub_menu->add_subitem("/%s",item);
1415 add_item(cur_item = new TitleCurItem(this, item = _(KW_COLOR)));
1416 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1417 sub_menu->add_subitem(POPUP_COLOR,"%s %s",item,_("#"));
1418 sub_menu->add_subitem("%s ",item);
1419 sub_menu->add_subitem("/%s",item);
1420 add_item(cur_item = new TitleCurItem(this, item = _(KW_ALPHA)));
1421 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1422 sub_menu->add_subitem("%s ",item);
1423 sub_menu->add_subitem("%s 0.",item);
1424 sub_menu->add_subitem("%s .5",item);
1425 sub_menu->add_subitem("%s 1.",item);
1426 sub_menu->add_subitem("/%s",item);
1427 add_item(cur_item = new TitleCurItem(this, item = _(KW_FONT)));
1428 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1429 sub_menu->add_subitem(POPUP_FONT,"%s %s",item, _("name"));
1430 sub_menu->add_subitem(POPUP_OFFSET, "%s ",item);
1431 sub_menu->add_subitem("/%s",item);
1432 add_item(cur_item = new TitleCurItem(this, item = _(KW_SIZE)));
1433 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1434 sub_menu->add_subitem("%s +",item);
1435 sub_menu->add_subitem("%s -",item);
1436 sub_menu->add_subitem("%s ",item);
1437 sub_menu->add_subitem("/%s",item);
1438 add_item(cur_item = new TitleCurItem(this, item = _(KW_BOLD)));
1439 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1440 sub_menu->add_subitem("%s 1",item);
1441 sub_menu->add_subitem("%s 0",item);
1442 sub_menu->add_subitem("/%s",item);
1443 add_item(cur_item = new TitleCurItem(this, item = _(KW_ITALIC)));
1444 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1445 sub_menu->add_subitem("%s 1",item);
1446 sub_menu->add_subitem("%s 0",item);
1447 sub_menu->add_subitem("/%s",item);
1448 add_item(cur_item = new TitleCurItem(this, item = _(KW_CAPS)));
1449 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1450 sub_menu->add_subitem("%s 1",item);
1451 sub_menu->add_subitem("%s 0",item);
1452 sub_menu->add_subitem("%s -1",item);
1453 sub_menu->add_subitem("/%s",item);
1454 add_item(cur_item = new TitleCurItem(this, item = _(KW_UL)));
1455 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1456 sub_menu->add_subitem("%s 1",item);
1457 sub_menu->add_subitem("%s 0",item);
1458 sub_menu->add_subitem("/%s",item);
1459 add_item(cur_item = new TitleCurItem(this, item = _(KW_BLINK)));
1460 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1461 sub_menu->add_subitem("%s 1",item);
1462 sub_menu->add_subitem("%s -1",item);
1463 sub_menu->add_subitem("%s ",item);
1464 sub_menu->add_subitem("%s 0",item);
1465 sub_menu->add_subitem("/%s",item);
1466 add_item(cur_item = new TitleCurItem(this, item = _(KW_FIXED)));
1467 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1468 sub_menu->add_subitem("%s ",item);
1469 sub_menu->add_subitem("%s 20",item);
1470 sub_menu->add_subitem("%s 10",item);
1471 sub_menu->add_subitem("%s 0",item);
1472 sub_menu->add_subitem("/%s",item);
1473 add_item(cur_item = new TitleCurItem(this, item = _(KW_ALIAS)));
1474 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1475 sub_menu->add_subitem("%s 1",item);
1476 sub_menu->add_subitem("%s 0",item);
1477 sub_menu->add_subitem("/%s",item);
1478 add_item(cur_item = new TitleCurItem(this, item = _(KW_SUP)));
1479 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1480 sub_menu->add_subitem("%s 1",item);
1481 sub_menu->add_subitem("%s 0",item);
1482 sub_menu->add_subitem("%s -1",item);
1483 sub_menu->add_subitem("/%s",item);
1484 add_item(cur_item = new TitleCurItem(this, item = _(KW_PNG)));
1485 cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1486 sub_menu->add_subitem(POPUP_PNG,"%s %s", item, _("file"));
1489 TitleCurItem::TitleCurItem(TitleCurPopup *popup, const char *text)
1492 this->popup = popup;
1494 int TitleCurItem::handle_event()
1499 TitleCurSubMenu::TitleCurSubMenu(TitleCurItem *cur_item)
1501 this->cur_item = cur_item;
1503 TitleCurSubMenu::~TitleCurSubMenu()
1507 TitleCurSubMenuItem::TitleCurSubMenuItem(TitleCurSubMenu *submenu, const char *text, int popup_type)
1510 this->submenu = submenu;
1511 this->popup_type = popup_type;
1513 TitleCurSubMenuItem::~TitleCurSubMenuItem()
1517 // from https://stackoverflow.com/questions/779875/what-function-is-to-replace-a-substring-from-a-string-in-c
1518 void strreplace(char *src, char *str, char *rep)
1520 char *p = strstr(src, str);
1523 int len = strlen(src)+strlen(rep)-strlen(str);
1527 strncpy(r, src, p-src);
1529 strncat(r, rep, strlen(rep));
1530 strncat(r, p+strlen(str), p+strlen(str)-src+strlen(src));
1532 strreplace(p+strlen(rep), str, rep);
1538 int TitleCurSubMenuItem::handle_event()
1540 TitleCurPopup *popup = submenu->cur_item->popup;
1541 TitleWindow *window = popup->window;
1542 char *item_text = N_(get_text());
1544 if (strstr(item_text, _(KW_NUDGE))) {
1545 strreplace(item_text, _(KW_NUDGE), (char*)N_(KW_NUDGE));
1547 else if (strstr(item_text, _(KW_COLOR))) {
1548 strreplace(item_text, _(KW_COLOR), (char*)N_(KW_COLOR));
1550 else if (strstr(item_text, _(KW_ALPHA))) {
1551 strreplace(item_text, _(KW_ALPHA), (char*)N_(KW_ALPHA));
1553 else if (strstr(item_text, _(KW_FONT))) {
1554 strreplace(item_text, _(KW_FONT), (char*)N_(KW_FONT));
1556 else if (strstr(item_text, _(KW_SIZE))) {
1557 strreplace(item_text, _(KW_SIZE), (char*)N_(KW_SIZE));
1559 else if (strstr(item_text, _(KW_BOLD))) {
1560 strreplace(item_text, _(KW_BOLD), (char*)N_(KW_BOLD));
1562 else if (strstr(item_text, _(KW_ITALIC))) {
1563 strreplace(item_text, _(KW_ITALIC), (char*)N_(KW_ITALIC));
1565 else if (strstr(item_text, _(KW_CAPS))) {
1566 strreplace(item_text, _(KW_CAPS), (char*)N_(KW_CAPS));
1568 else if (strstr(item_text, _(KW_UL))) {
1569 strreplace(item_text, _(KW_UL), (char*)N_(KW_UL));
1571 else if (strstr(item_text, _(KW_BLINK))) {
1572 strreplace(item_text, _(KW_BLINK), (char*)N_(KW_BLINK));
1574 else if (strstr(item_text, _(KW_FIXED))) {
1575 strreplace(item_text, _(KW_FIXED), (char*)N_(KW_FIXED));
1577 else if (strstr(item_text, _(KW_ALIAS))) {
1578 strreplace(item_text, _(KW_ALIAS), (char*)N_(KW_ALIAS));
1580 else if (strstr(item_text, _(KW_SUP))) {
1581 strreplace(item_text, _(KW_SUP), (char*)N_(KW_SUP));
1585 int ofs = *item_text == '/' ? 0 : -1;
1586 switch( popup_type ) {
1589 window->get_pop_cursor(px ,py);
1590 window->fonts_popup->activate(px, py, xS(300),yS(200));
1593 window->color_popup->activate();
1596 window->png_popup->activate();
1603 sprintf(txt, "<%s>", N_(item_text));
1604 //printf("Item text: %s \n", N_(item_text));
1606 if (strstr(item_text, N_(KW_NUDGE))) {
1607 strreplace(item_text, (char*)N_(KW_NUDGE), _(KW_NUDGE));
1609 else if (strstr(item_text, N_(KW_COLOR))) {
1610 strreplace(item_text, (char*)N_(KW_COLOR), _(KW_COLOR));
1612 else if (strstr(item_text, N_(KW_ALPHA))) {
1613 strreplace(item_text, (char*)N_(KW_ALPHA), _(KW_ALPHA));
1615 else if (strstr(item_text, N_(KW_FONT))) {
1616 strreplace(item_text, (char*)N_(KW_FONT), _(KW_FONT));
1618 else if (strstr(item_text, N_(KW_SIZE))) {
1619 strreplace(item_text, (char*)N_(KW_SIZE), _(KW_SIZE));
1621 else if (strstr(item_text, N_(KW_BOLD))) {
1622 strreplace(item_text, (char*)N_(KW_BOLD), _(KW_BOLD));
1624 else if (strstr(item_text, N_(KW_ITALIC))) {
1625 strreplace(item_text, (char*)N_(KW_ITALIC), _(KW_ITALIC));
1627 else if (strstr(item_text, N_(KW_CAPS))) {
1628 strreplace(item_text, (char*)N_(KW_CAPS), _(KW_CAPS));
1630 else if (strstr(item_text, N_(KW_UL))) {
1631 strreplace(item_text, (char*)N_(KW_UL), _(KW_UL));
1633 else if (strstr(item_text, N_(KW_BLINK))) {
1634 strreplace(item_text, (char*)N_(KW_BLINK), _(KW_BLINK));
1636 else if (strstr(item_text, N_(KW_FIXED))) {
1637 strreplace(item_text, (char*)N_(KW_FIXED), _(KW_FIXED));
1639 else if (strstr(item_text, N_(KW_ALIAS))) {
1640 strreplace(item_text, (char*)N_(KW_ALIAS), _(KW_ALIAS));
1642 else if (strstr(item_text, N_(KW_SUP))) {
1643 strreplace(item_text, (char*)N_(KW_SUP), _(KW_SUP));
1647 return window->insert_ibeam(N_(txt), ofs);
1650 TitleFontsPopup::TitleFontsPopup(TitleMain *client, TitleWindow *window)
1651 : BC_ListBox(-1, -1, 1, 1, LISTBOX_ICON_LIST,
1652 &window->fonts, 0, 0, 1, 0, 1)
1654 this->client = client;
1655 this->window = window;
1659 TitleFontsPopup::~TitleFontsPopup()
1662 int TitleFontsPopup::keypress_event()
1664 switch( get_keypress() ) {
1672 return BC_ListBox::keypress_event();
1675 int TitleFontsPopup::handle_event()
1678 BC_ListBoxItem *item = get_selection(0, 0);
1679 if( !item ) return 1;
1680 const char *item_text = item->get_text();
1681 char txt[BCTEXTLEN]; sprintf(txt, "<%s %s>", N_(KW_FONT), item_text);
1682 return window->insert_ibeam(txt);
1685 TitleColorPopup::TitleColorPopup(TitleMain *client, TitleWindow *window)
1686 : ColorPicker(0, _("Color"))
1688 this->client = client;
1689 this->window = window;
1690 this->color_value = client->config.color;
1692 TitleColorPopup::~TitleColorPopup()
1695 int TitleColorPopup::handle_new_color(int output, int alpha)
1697 color_value = output;
1700 int TitleColorPopup::activate()
1702 start_window(client->config.color, 255, 1);
1705 void TitleColorPopup::handle_done_event(int result)
1708 char txt[BCSTRLEN]; sprintf(txt, "<%s #%06x>", _(KW_COLOR), color_value);
1709 window->lock_window("TitleColorPopup::handle_done_event");
1710 window->insert_ibeam(txt);
1711 window->unlock_window();
1715 TitlePngPopup::TitlePngPopup(TitleMain *client, TitleWindow *window)
1718 this->client = client;
1719 this->window = window;
1722 TitlePngPopup::~TitlePngPopup()
1727 void TitlePngPopup::handle_done_event(int result)
1729 if( result ) return;
1730 BrowseButtonWindow *gui = (BrowseButtonWindow *)get_gui();
1731 const char *path = gui->get_submitted_path();
1732 char txt[BCTEXTLEN]; sprintf(txt, "<%s %s>", _(KW_PNG), path);
1733 window->lock_window("TitlePngPopup::handle_done_event");
1734 window->insert_ibeam(txt);
1735 window->unlock_window();
1738 BC_Window *TitlePngPopup::new_gui()
1740 MWindow *mwindow = client->server->mwindow;
1741 int x, y; mwindow->gui->get_abs_cursor(x, y);
1743 BC_Window *gui = new BrowseButtonWindow(mwindow->theme,
1744 x-xS(25), y-yS(100), window, "", _("Png file"), _("Png path"), 0);
1745 gui->create_objects();
1749 int TitlePngPopup::activate()
1751 BC_DialogThread::start();