de6d10cbda4d64c5e6e558ec3c5f99e9d7bc95b6
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / titler / titlerwindow.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "bcdialog.h"
24 #include "bcsignals.h"
25 #include "browsebutton.h"
26 #include "clip.h"
27 #include "cstrdup.h"
28 #include "automation.h"
29 #include "cwindow.h"
30 #include "cwindowgui.h"
31 #include "dragcheckbox.h"
32 #include "edl.h"
33 #include "edlsession.h"
34 #include "keys.h"
35 #include "language.h"
36 #include "mainerror.h"
37 #include "mwindow.h"
38 #include "mwindowgui.h"
39 #include "plugin.h"
40 #include "pluginserver.h"
41 #include "theme.h"
42 #include "track.h"
43 #include "tracks.h"
44 #include "titlerwindow.h"
45 #include "bcfontentry.h"
46
47 static const int timeunit_formats[] =
48 {
49         TIME_HMS,
50         TIME_SECONDS,
51         TIME_HMSF,
52         TIME_SAMPLES,
53         TIME_SAMPLES_HEX,
54         TIME_FRAMES,
55         TIME_FEET_FRAMES
56 };
57
58 TitleWindow::TitleWindow(TitleMain *client)
59  : PluginClientWindow(client,
60         client->config.window_w, client->config.window_h,
61         xS(100), yS(100), 1)
62 {
63 //printf("TitleWindow::TitleWindow %d %d %d\n", __LINE__, client->config.window_w, client->config.window_h);
64         this->client = client;
65
66         font_title = 0;
67         font = 0;
68         font_tumbler = 0;
69         x_title = 0; title_x = 0;
70         y_title = 0; title_y = 0;
71         w_title = 0; title_w = 0;
72         h_title = 0; title_h = 0;
73         dropshadow_title = 0; dropshadow = 0;
74         outline_title = 0;    outline = 0;
75         stroker_title = 0;    stroker = 0;
76         style_title = 0;
77         italic = 0;
78         bold = 0;
79         drag = 0;
80         cur_popup = 0;
81         fonts_popup = 0;
82         png_popup = 0;
83
84         drag_dx = drag_dy = dragging = 0;
85         cur_ibeam = -1;
86
87         size_title = 0;
88         size = 0;
89         size_tumbler = 0;
90         pitch_title = 0;
91         pitch = 0;
92         encoding_title = 0;
93         encoding = 0;
94         color_button = 0;
95         outline_button = 0;
96         color_popup = 0;
97         motion_title = 0;
98         motion = 0;
99         line_pitch = 0;
100         loop = 0;
101         fadein_title = 0;
102         fade_in = 0;
103         fadeout_title = 0;
104         fade_out = 0;
105         text_title = 0;
106         text = 0;
107         text_chars = 0;
108         justify_title = 0;
109         left = 0;  center = 0;  right = 0;
110         top = 0;   mid = 0;     bottom = 0;
111         speed_title = 0;
112         speed = 0;
113         timecode = 0;
114         timecode_format = 0;
115         background = 0;
116         background_path = 0;
117         loop_playback = 0;
118         pending_config = 0;
119 }
120
121 void TitleWindow::done_event(int result)
122 {
123         color_button->close_picker();
124         outline_button->close_picker();
125         drag->drag_deactivate();
126         delete color_popup;     color_popup = 0;
127         delete png_popup;       png_popup = 0;
128
129 }
130
131 TitleWindow::~TitleWindow()
132 {
133         delete color_popup;
134         delete png_popup;
135         for( int i=0; i<fonts.size(); ++i )
136                 delete fonts[i]->get_icon();
137
138         sizes.remove_all_objects();
139         delete timecode_format;
140         delete title_x;
141         delete title_y;
142         delete title_w;
143         delete title_h;
144 }
145
146 void TitleWindow::create_objects()
147 {
148         int x = xS(10), y = yS(10);
149         int margin = client->get_theme()->widget_border;
150         char string[BCTEXTLEN];
151
152 #define COLOR_W xS(50)
153 #define COLOR_H yS(30)
154         client->build_previews(this);
155
156         sizes.append(new BC_ListBoxItem("8"));
157         sizes.append(new BC_ListBoxItem("9"));
158         sizes.append(new BC_ListBoxItem("10"));
159         sizes.append(new BC_ListBoxItem("11"));
160         sizes.append(new BC_ListBoxItem("12"));
161         sizes.append(new BC_ListBoxItem("13"));
162         sizes.append(new BC_ListBoxItem("14"));
163         sizes.append(new BC_ListBoxItem("16"));
164         sizes.append(new BC_ListBoxItem("18"));
165         sizes.append(new BC_ListBoxItem("20"));
166         sizes.append(new BC_ListBoxItem("22"));
167         sizes.append(new BC_ListBoxItem("24"));
168         sizes.append(new BC_ListBoxItem("26"));
169         sizes.append(new BC_ListBoxItem("28"));
170         sizes.append(new BC_ListBoxItem("32"));
171         sizes.append(new BC_ListBoxItem("36"));
172         sizes.append(new BC_ListBoxItem("40"));
173         sizes.append(new BC_ListBoxItem("48"));
174         sizes.append(new BC_ListBoxItem("56"));
175         sizes.append(new BC_ListBoxItem("64"));
176         sizes.append(new BC_ListBoxItem("72"));
177         sizes.append(new BC_ListBoxItem("100"));
178         sizes.append(new BC_ListBoxItem("128"));
179         sizes.append(new BC_ListBoxItem("256"));
180         sizes.append(new BC_ListBoxItem("512"));
181         sizes.append(new BC_ListBoxItem("1024"));
182
183         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(NO_MOTION)));
184         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(BOTTOM_TO_TOP)));
185         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(TOP_TO_BOTTOM)));
186         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(RIGHT_TO_LEFT)));
187         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(LEFT_TO_RIGHT)));
188
189
190
191 // Construct font list
192         ArrayList<BC_FontEntry*> *fontlist = get_resources()->fontlist;
193
194         for( int i=0; i<fontlist->size(); ++i ) {
195                 int exists = 0;
196                 for( int j=0; j<fonts.size(); ++j ) {
197                         if( !strcasecmp(fonts.get(j)->get_text(),
198                                 fontlist->get(i)->displayname) ) {
199                                 exists = 1;
200                                 break;
201                         }
202                 }
203
204                 BC_ListBoxItem *item = 0;
205                 if( !exists ) {
206                         fonts.append(item = new
207                                 BC_ListBoxItem(fontlist->get(i)->displayname));
208                         if( !strcmp(client->config.font, item->get_text()) )
209                                 item->set_selected(1);
210                         if( fontlist->values[i]->image ) {
211                                 VFrame *vframe = fontlist->get(i)->image;
212                                 BC_Pixmap *icon = new BC_Pixmap(this, vframe, PIXMAP_ALPHA);
213                                 item->set_icon(icon);
214                                 item->set_icon_vframe(vframe);
215                         }
216                 }
217         }
218
219 // Sort font list
220         int done = 0;
221         while(!done) {
222                 done = 1;
223                 for( int i=0; i<fonts.size()-1; ++i ) {
224                         if( strcmp(fonts.values[i]->get_text(),
225                                 fonts.values[i + 1]->get_text()) > 0 ) {
226                                 BC_ListBoxItem *temp = fonts.values[i + 1];
227                                 fonts.values[i + 1] = fonts.values[i];
228                                 fonts.values[i] = temp;
229                                 done = 0;
230                         }
231                 }
232         }
233
234         add_tool(font_title = new BC_Title(x, y, _("Font:")));
235         font = new TitleFont(client, this, x, y + font_title->get_h());
236         font->create_objects();
237         font->set_show_query(1);
238         x += font->get_w();
239         add_subwindow(font_tumbler = new TitleFontTumble(client, this, x, y+margin));
240         x += font_tumbler->get_w() + margin;
241
242         int x1 = x+xS(20), y1 = y;
243         add_tool(size_title = new BC_Title(x1, y1+margin, _("Size:")));
244         sprintf(string, "%.2f", client->config.size);
245         x1 += size_title->get_w() + margin;
246         size = new TitleSize(client, this, x1, y1+margin, string);
247         size->create_objects();
248         int x2 = x1 + size->get_w(), y2 = y1 + size->get_h() + margin;
249         add_subwindow(size_tumbler = new TitleSizeTumble(client, this, x2, y1+margin));
250
251         add_tool(pitch_title = new BC_Title(x-xS(16), y2+margin, _("Line Pitch:")));
252         pitch = new TitlePitch(client, this, x1, y2+margin, &client->config.line_pitch);
253         pitch->create_objects();
254
255         int x3 = x2 + size_tumbler->get_w() + xS(50);
256         int y3 = pitch->get_y() + pitch->get_h();
257
258         add_tool(style_title = new BC_Title(x=x3, y, _("Style:")));
259         add_tool(italic = new TitleItalic(client, this, x, y + yS(20)));
260         int w1 = italic->get_w();
261         add_tool(bold = new TitleBold(client, this, x, y + yS(50)));
262         if( bold->get_w() > w1 ) w1 = bold->get_w();
263
264         add_tool(drag = new TitleDrag(client, this, x, y + yS(80)));
265         drag->create_objects();
266         if( drag->get_w() > w1 ) w1 = drag->get_w();
267         if( client->config.drag && drag->drag_activate() )
268                 eprintf("drag enabled, but compositor already grabbed\n");
269
270         add_tool(alias = new TitleAlias(client, this, x, y+yS(110)));
271         if( alias->get_w() > w1 ) w1 = drag->get_w();
272
273         x += w1 + margin;
274         add_tool(justify_title = new BC_Title(x+xS(50), y, _("Justify:")));
275         add_tool(left = new TitleLeft(client, this, x, y + yS(20)));
276         w1 = left->get_w();
277         add_tool(center = new TitleCenter(client, this, x, y + yS(50)));
278         if( center->get_w() > w1 ) w1 = center->get_w();
279         add_tool(right = new TitleRight(client, this, x, y + yS(80)));
280         if( right->get_w() > w1 ) w1 = right->get_w();
281
282         x += w1 + margin;
283         add_tool(top = new TitleTop(client, this, x, y + yS(20)));
284         add_tool(mid = new TitleMid(client, this, x, y + yS(50)));
285         add_tool(bottom= new TitleBottom(client, this, x, y + yS(80)));
286
287         x = margin;
288         y = y3+yS(10);
289
290         w1 = BC_Title::calculate_w(this, _("X:"));
291         if( (x1 = BC_Title::calculate_w(this, _("Y:"))) > w1 ) w1 = x1;
292         if( (x1 = BC_Title::calculate_w(this, _("W:"))) > w1 ) w1 = x1;
293         if( (x1 = BC_Title::calculate_w(this, _("H:"))) > w1 ) w1 = x1;
294         add_tool(x_title = new BC_Title(x1=x, y, _("X:")));
295         x1 += w1;
296         title_x = new TitleX(client, this, x1, y);
297         title_x->create_objects();
298         x1 += title_x->get_w()+margin;
299         add_tool(y_title = new BC_Title(x1, y, _("Y:")));
300         x1 += w1;
301         title_y = new TitleY(client, this, x1, y);
302         title_y->create_objects();
303         x1 += title_y->get_w();
304         y1 = y + title_y->get_h();
305
306         add_tool(w_title = new BC_Title(x1=x, y1, _("W:")));
307         x1 += w1;
308         title_w = new TitleW(client, this, x1, y1);
309         title_w->create_objects();
310         x1 += title_w->get_w()+margin;
311         add_tool(h_title = new BC_Title(x1, y1, _("H:")));
312         x1 += w1;
313         title_h = new TitleH(client, this, x1, y1);
314         title_h->create_objects();
315         x1 += title_h->get_w();
316
317         x = x1+xS(2)*margin;
318         add_tool(motion_title = new BC_Title(x1=x, y, _("Motion:")));
319         x1 += motion_title->get_w()+margin;
320         motion = new TitleMotion(client, this, x1, y);
321         motion->create_objects();
322         add_tool(loop = new TitleLoop(client, this, x, y1));
323         x = margin;    y = y1 + loop->get_h()+yS(20);
324
325         add_tool(dropshadow_title = new BC_Title(x, y, _("Drop shadow:")));
326         w1 = dropshadow_title->get_w();
327         dropshadow = new TitleDropShadow(client, this, x, y + yS(20));
328         dropshadow->create_objects();
329         if( dropshadow->get_w() > w1 ) w1 = dropshadow->get_w();
330         x += w1 + margin;
331
332         add_tool(fadein_title = new BC_Title(x, y, _("Fade in (sec):")));
333         w1 = fadein_title->get_w();
334         add_tool(fade_in = new TitleFade(client, this, &client->config.fade_in, x, y + yS(20)));
335         if( fade_in->get_w() > w1 ) w1 = fade_in->get_w();
336         x += w1 + margin;
337
338         add_tool(fadeout_title = new BC_Title(x, y, _("Fade out (sec):")));
339         w1 = fadeout_title->get_w();
340         add_tool(fade_out = new TitleFade(client, this, &client->config.fade_out, x, y + yS(20)));
341         if( fade_out->get_w() > w1 ) w1 = fade_out->get_w();
342         x += w1 + margin;
343
344         add_tool(speed_title = new BC_Title(x, y, _("Speed:")));
345         w1 = speed_title->get_w();
346         y += speed_title->get_h() + yS(5);  y1 = y;
347         speed = new TitleSpeed(client, this, x, y);
348         speed->create_objects();
349         if( speed->get_w() > w1 ) w1 = speed->get_w();
350         x += w1 + margin;
351         y2 = y + speed->get_h() + yS(10);
352
353         add_tool(color_button_title = new BC_Title(x3, y1+yS(10), _("Color:")));
354         x1 = x3 + color_button_title->get_w() + xS(30);
355         add_tool(color_button = new TitleColorButton(client, this, x1, y1));
356         y1 += color_button->get_h() + yS(10);
357         add_tool(outline_button_title = new BC_Title(x3, y1+yS(10), _("Outline:")));
358         add_tool(outline_button = new TitleOutlineColorButton(client, this, x1, y1));
359
360         x = yS(10);  y = y2;
361         add_tool(outline_title = new BC_Title(x, y, _("Outline:")));
362         y1 =  y + outline_title->get_h() + margin;
363         outline = new TitleOutline(client, this, x, y1);
364         outline->create_objects();
365         x += outline->get_w() + xS(2)*margin;
366 #ifdef USE_STROKER
367         add_tool(stroker_title = new BC_Title(x, y, _("Stroker:")));
368         stroker = new TitleStroker(client, this, x, y1);
369         stroker->create_objects();
370         x += stroker->get_w() + margin;
371 #endif
372         add_tool(timecode = new TitleTimecode(client, this, x, y));
373         y += timecode->get_h() + margin;
374         int tw = 0;
375         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
376                 char text[BCSTRLEN];
377                 Units::print_time_format(timeunit_formats[i], text);
378                 int w = get_text_width(MEDIUMFONT, text);
379                 if( tw < w ) tw = w;
380         }
381         add_tool(timecode_format = new TitleTimecodeFormat(client, this, x, y, tw,
382                 Units::print_time_format(client->config.timecode_format, string)));
383         timecode_format->create_objects();
384         y += timecode_format->get_h() + margin;
385
386         x = xS(10);
387         add_tool(background = new TitleBackground(client, this, x, y));
388         x += background->get_w() + margin;
389         add_tool(background_path = new TitleBackgroundPath(client, this, x, y));
390         x += background_path->get_w() + margin;
391         add_tool(background_browse = new BrowseButton(
392                 client->server->mwindow->theme, this, background_path,
393                 x, y, "", _("background media"), _("Select background media path")));
394         x += background_browse->get_w() + xS(3)*margin;
395         add_tool(loop_playback = new TitleLoopPlayback(client, this, x, y));
396         y += loop_playback->get_h() + yS(10);
397
398         x = xS(10);
399         add_tool(text_title = new BC_Title(x, y, _("Text:")));
400         x += text_title->get_w() + xS(20);
401         int wid = BC_Title::calculate_w(this,"0")*xS(10);
402         add_tool(text_chars = new TitleTextChars(x,y,wid));
403
404         y += text_title->get_h() + margin;
405         x = margin;
406         text = new TitleText(client, this, x, y, get_w()-margin - x, get_h() - y - yS(10));
407         text->create_objects();
408
409         add_tool(cur_popup = new TitleCurPopup(client, this));
410         cur_popup->create_objects();
411         add_tool(fonts_popup = new TitleFontsPopup(client, this));
412         color_popup = new TitleColorPopup(client, this);
413         png_popup = new TitlePngPopup(client, this);
414
415         show_window(1);
416         update_gui();
417 }
418
419 int TitleWindow::resize_event(int w, int h)
420 {
421         client->config.window_w = w;
422         client->config.window_h = h;
423
424         clear_box(0, 0, w, h);
425         font_title->reposition_window(font_title->get_x(), font_title->get_y());
426         font->reposition_window(font->get_x(), font->get_y());
427         font_tumbler->reposition_window(font_tumbler->get_x(), font_tumbler->get_y());
428         x_title->reposition_window(x_title->get_x(), x_title->get_y());
429         title_x->reposition_window(title_x->get_x(), title_x->get_y());
430         y_title->reposition_window(y_title->get_x(), y_title->get_y());
431         title_y->reposition_window(title_y->get_x(), title_y->get_y());
432         w_title->reposition_window(w_title->get_x(), w_title->get_y());
433         title_w->reposition_window(title_w->get_x(), title_w->get_y());
434         h_title->reposition_window(h_title->get_x(), h_title->get_y());
435         title_h->reposition_window(title_h->get_x(), title_h->get_y());
436         style_title->reposition_window(style_title->get_x(), style_title->get_y());
437         italic->reposition_window(italic->get_x(), italic->get_y());
438         bold->reposition_window(bold->get_x(), bold->get_y());
439         drag->reposition_window(drag->get_x(), drag->get_y());
440         alias->reposition_window(alias->get_x(), alias->get_y());
441         size_title->reposition_window(size_title->get_x(), size_title->get_y());
442         size->reposition_window(size->get_x(), size->get_y());
443         size_tumbler->reposition_window(size_tumbler->get_x(), size_tumbler->get_y());
444         pitch_title->reposition_window(pitch_title->get_x(), pitch_title->get_y());
445         pitch->reposition_window(pitch->get_x(), pitch->get_y());
446
447         color_button_title->reposition_window(color_button_title->get_x(), color_button_title->get_y());
448         color_button->reposition_window(color_button->get_x(), color_button->get_y());
449         outline_button_title->reposition_window(outline_button_title->get_x(), outline_button_title->get_y());
450         outline_button->reposition_window(outline_button->get_x(), outline_button->get_y());
451         motion_title->reposition_window(motion_title->get_x(), motion_title->get_y());
452         motion->reposition_window(motion->get_x(), motion->get_y());
453         loop->reposition_window(loop->get_x(), loop->get_y());
454         dropshadow_title->reposition_window(dropshadow_title->get_x(), dropshadow_title->get_y());
455         dropshadow->reposition_window(dropshadow->get_x(), dropshadow->get_y());
456         fadein_title->reposition_window(fadein_title->get_x(), fadein_title->get_y());
457         fade_in->reposition_window(fade_in->get_x(), fade_in->get_y());
458         fadeout_title->reposition_window(fadeout_title->get_x(), fadeout_title->get_y());
459         fade_out->reposition_window(fade_out->get_x(), fade_out->get_y());
460         text_title->reposition_window(text_title->get_x(), text_title->get_y());
461         timecode->reposition_window(timecode->get_x(), timecode->get_y());
462         text->reposition_window(text->get_x(), text->get_y(), w - text->get_x() - xS(10),
463                 BC_TextBox::pixels_to_rows(this, MEDIUMFONT, h - text->get_y() - yS(10)));
464         justify_title->reposition_window(justify_title->get_x(), justify_title->get_y());
465         left->reposition_window(left->get_x(), left->get_y());
466         center->reposition_window(center->get_x(), center->get_y());
467         right->reposition_window(right->get_x(), right->get_y());
468         top->reposition_window(top->get_x(), top->get_y());
469         mid->reposition_window(mid->get_x(), mid->get_y());
470         bottom->reposition_window(bottom->get_x(), bottom->get_y());
471         speed_title->reposition_window(speed_title->get_x(), speed_title->get_y());
472         speed->reposition_window(speed->get_x(), speed->get_y());
473         update_color();
474         flash();
475
476         return 1;
477 }
478
479 void TitleWindow::update_drag()
480 {
481         drag->drag_x = client->config.title_x;
482         drag->drag_y = client->config.title_y;
483         drag->drag_w = client->config.title_w;
484         drag->drag_h = client->config.title_h;
485         send_configure_change();
486 }
487 void TitleWindow::send_configure_change()
488 {
489         client->send_configure_change();
490 }
491
492 void TitleWindow::previous_font()
493 {
494         int current_font = font->get_number();
495         if( !fonts.total ) current_font = -1;
496         else if( --current_font < 0 ) current_font = fonts.total - 1;
497         font->set_number(current_font);
498
499         if( current_font < 0 || current_font >= fonts.total ) return;
500
501         for( int i=0; i<fonts.total; ++i ) {
502                 fonts.values[i]->set_selected(i == current_font);
503         }
504
505         font->update(fonts.values[current_font]->get_text());
506         strcpy(client->config.font, fonts.values[current_font]->get_text());
507         check_style(client->config.font,1);
508         send_configure_change();
509 }
510
511 void  TitleWindow::next_font()
512 {
513         int current_font = font->get_number();
514         if( !fonts.total ) current_font = -1;
515         else if( ++current_font >= fonts.total ) current_font = 0;
516         font->set_number(current_font);
517
518         if( current_font < 0 || current_font >= fonts.total ) return;
519
520         for( int i=0; i<fonts.total; ++i ) {
521                 fonts.values[i]->set_selected(i == current_font);
522         }
523
524         font->update(fonts.values[current_font]->get_text());
525         strcpy(client->config.font, fonts.values[current_font]->get_text());
526         check_style(client->config.font,1);
527         send_configure_change();
528 }
529
530 int TitleWindow::insert_ibeam(const char *txt, int ofs)
531 {
532         int ibeam = cur_ibeam;
533         int ilen = strlen(txt)+1;
534         wchr_t wtxt[ilen];
535         int len = BC_Resources::encode(client->config.encoding, BC_Resources::wide_encoding,
536                 (char*)txt,ilen, (char *)wtxt,ilen*sizeof(wtxt[0])) / sizeof(wchr_t);
537         client->insert_text(wtxt, ibeam);
538         while( len > 0 && !wtxt[len] ) --len;
539         int adv = len+1 + ofs;
540         if( (ibeam += adv) >= client->config.wlen)
541                 ibeam = client->config.wlen;
542         text->wset_selection(-1, -1, ibeam);
543         text->update(client->config.wtext);
544         send_configure_change();
545         return 1;
546 }
547
548 void TitleWindow::update_color()
549 {
550         color_button->update_gui(client->config.color);
551         outline_button->update_gui(client->config.outline_color);
552 }
553
554 void TitleWindow::update_justification()
555 {
556         left->update(client->config.hjustification == JUSTIFY_LEFT);
557         center->update(client->config.hjustification == JUSTIFY_CENTER);
558         right->update(client->config.hjustification == JUSTIFY_RIGHT);
559         top->update(client->config.vjustification == JUSTIFY_TOP);
560         mid->update(client->config.vjustification == JUSTIFY_MID);
561         bottom->update(client->config.vjustification == JUSTIFY_BOTTOM);
562 }
563
564 void TitleWindow::update_stats()
565 {
566         text_chars->update(client->config.wlen);
567 }
568
569 void TitleWindow::update_gui()
570 {
571         title_x->update((int64_t)client->config.title_x);
572         title_y->update((int64_t)client->config.title_y);
573         title_w->update((int64_t)client->config.title_w);
574         title_h->update((int64_t)client->config.title_h);
575         drag->drag_x = client->config.title_x;
576         drag->drag_y = client->config.title_y;
577         drag->drag_w = client->config.title_w;
578         drag->drag_h = client->config.title_h;
579         italic->update(client->config.style & BC_FONT_ITALIC);
580         bold->update(client->config.style & BC_FONT_BOLD);
581         alias->update(client->config.style & FONT_ALIAS);
582         size->update(client->config.size);
583         motion->update(TitleMain::motion_to_text(client->config.motion_strategy));
584         loop->update(client->config.loop);
585         dropshadow->update((int64_t)client->config.dropshadow);
586         fade_in->update((float)client->config.fade_in);
587         fade_out->update((float)client->config.fade_out);
588         font->update(client->config.font);
589         check_style(client->config.font,0);
590         wchr_t wz[1] = { 0 };
591         text->update(client->config.wtext ? &client->config.wtext[0] : wz);
592         speed->update(client->config.pixels_per_second);
593         outline->update((int64_t)client->config.outline_size);
594 #ifdef USE_STROKER
595         stroker->update((int64_t)client->config.stroke_width);
596 #endif
597         timecode->update(client->config.timecode);
598         timecode_format->update(client->config.timecode_format);
599         background->update(client->config.background);
600         background_path->update(client->config.background_path);
601         loop_playback->update((int64_t)client->config.loop_playback);
602
603         char string[BCTEXTLEN];
604         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
605                 if( timeunit_formats[i] == client->config.timecode_format ) {
606                         timecode_format->set_text(
607                                 Units::print_time_format(timeunit_formats[i], string));
608                         break;
609                 }
610         }
611         update_justification();
612         update_stats();
613         update_color();
614 }
615
616
617 TitleFontTumble::TitleFontTumble(TitleMain *client, TitleWindow *window, int x, int y)
618  : BC_Tumbler(x, y)
619 {
620         this->client = client;
621         this->window = window;
622 }
623 int TitleFontTumble::handle_up_event()
624 {
625         window->previous_font();
626         return 1;
627 }
628
629 int TitleFontTumble::handle_down_event()
630 {
631         window->next_font();
632         return 1;
633 }
634
635
636 TitleSizeTumble::TitleSizeTumble(TitleMain *client, TitleWindow *window, int x, int y)
637  : BC_Tumbler(x, y)
638 {
639         this->client = client;
640         this->window = window;
641 }
642
643 int TitleSizeTumble::handle_up_event()
644 {
645         int current_index = -1;
646         int current_difference = -1;
647         for( int i=0; i<window->sizes.size(); ++i ) {
648                 int size = atoi(window->sizes.get(i)->get_text());
649                 if( current_index < 0 ||
650                         abs(size - client->config.size) < current_difference ) {
651                         current_index = i;
652                         current_difference = abs(size - client->config.size);
653                 }
654         }
655
656         current_index++;
657         if( current_index >= window->sizes.size() ) current_index = 0;
658
659
660         client->config.size = atoi(window->sizes.get(current_index)->get_text());
661         window->size->update(client->config.size);
662         window->send_configure_change();
663         return 1;
664 }
665
666 int TitleSizeTumble::handle_down_event()
667 {
668         int current_index = -1;
669         int current_difference = -1;
670         for( int i=0; i<window->sizes.size(); ++i ) {
671                 int size = atoi(window->sizes.get(i)->get_text());
672                 if( current_index < 0 ||
673                         abs(size - client->config.size) < current_difference ) {
674                         current_index = i;
675                         current_difference = abs(size - client->config.size);
676                 }
677         }
678
679         current_index--;
680         if( current_index < 0 ) current_index = window->sizes.size() - 1;
681
682
683         client->config.size = atoi(window->sizes.get(current_index)->get_text());
684         window->size->update(client->config.size);
685         window->send_configure_change();
686         return 1;
687 }
688
689 TitleAlias::TitleAlias(TitleMain *client, TitleWindow *window, int x, int y)
690  : BC_CheckBox(x, y, client->config.style & FONT_ALIAS, _("Smooth"))
691 {
692         this->client = client;
693         this->window = window;
694 }
695
696 int TitleAlias::handle_event()
697 {
698         client->config.style =
699                 (client->config.style & ~FONT_ALIAS) |
700                         (get_value() ? FONT_ALIAS : 0);
701         window->send_configure_change();
702         return 1;
703 }
704
705 TitleBold::TitleBold(TitleMain *client, TitleWindow *window, int x, int y)
706  : BC_CheckBox(x, y, client->config.style & BC_FONT_BOLD, _("Bold"))
707 {
708         this->client = client;
709         this->window = window;
710 }
711
712 int TitleBold::handle_event()
713 {
714         client->config.style =
715                 (client->config.style & ~BC_FONT_BOLD) |
716                         (get_value() ? BC_FONT_BOLD : 0);
717         window->send_configure_change();
718         return 1;
719 }
720
721 TitleItalic::TitleItalic(TitleMain *client, TitleWindow *window, int x, int y)
722  : BC_CheckBox(x, y, client->config.style & BC_FONT_ITALIC, _("Italic"))
723 {
724         this->client = client;
725         this->window = window;
726 }
727 int TitleItalic::handle_event()
728 {
729         client->config.style =
730                 (client->config.style & ~BC_FONT_ITALIC) |
731                         (get_value() ? BC_FONT_ITALIC : 0);
732         window->send_configure_change();
733         return 1;
734 }
735
736
737
738 TitleSize::TitleSize(TitleMain *client, TitleWindow *window, int x, int y, char *text)
739  : BC_PopupTextBox(window, &window->sizes, text, x, y, xS(64), yS(300))
740 {
741         this->client = client;
742         this->window = window;
743 }
744 TitleSize::~TitleSize()
745 {
746 }
747 int TitleSize::handle_event()
748 {
749         client->config.size = atol(get_text());
750 //printf("TitleSize::handle_event 1 %s\n", get_text());
751         window->send_configure_change();
752         return 1;
753 }
754 void TitleSize::update(int size)
755 {
756         char string[BCTEXTLEN];
757         sprintf(string, "%d", size);
758         BC_PopupTextBox::update(string);
759 }
760
761 TitlePitch::
762 TitlePitch(TitleMain *client, TitleWindow *window, int x, int y, int *value)
763  : BC_TumbleTextBox(window, *value, 0, INT_MAX, x, y, xS(64))
764 {
765         this->client = client;
766         this->window = window;
767         this->value = value;
768 }
769
770 TitlePitch::
771 ~TitlePitch()
772 {
773 }
774
775 int TitlePitch::handle_event()
776 {
777         *value = atol(get_text());
778         window->send_configure_change();
779         return 1;
780 }
781
782 TitleColorButton::TitleColorButton(TitleMain *client, TitleWindow *window, int x, int y)
783  : ColorCircleButton(_("Text Color"), x, y, COLOR_W, COLOR_H,
784                 client->config.color, client->config.alpha, 1)
785 {
786         this->client = client;
787         this->window = window;
788 }
789 int TitleColorButton::handle_new_color(int output, int alpha)
790 {
791         client->config.color = output;
792         client->config.alpha = alpha;
793         window->send_configure_change();
794         return 1;
795 }
796 void TitleColorButton::handle_done_event(int result)
797 {
798         if( result ) {
799                 handle_new_color(orig_color, orig_alpha);
800                 window->lock_window("TitleColorButton::handle_done_event");
801                 update_gui(orig_color);
802                 window->unlock_window();
803         }
804 }
805
806 TitleOutlineColorButton::TitleOutlineColorButton(TitleMain *client, TitleWindow *window, int x, int y)
807  : ColorCircleButton(_("Outline Color"), x, y, COLOR_W, COLOR_H,
808                 client->config.outline_color, client->config.outline_alpha, 1)
809 {
810         this->client = client;
811         this->window = window;
812 }
813 int TitleOutlineColorButton::handle_new_color(int output, int alpha)
814 {
815         client->config.outline_color = output;
816         client->config.outline_alpha = alpha;
817         window->send_configure_change();
818         return 1;
819 }
820 void TitleOutlineColorButton::handle_done_event(int result)
821 {
822         if( result ) {
823                 handle_new_color(orig_color, orig_alpha);
824                 window->lock_window("TitleColorButton::handle_done_event");
825                 update_gui(orig_color);
826                 window->unlock_window();
827         }
828 }
829
830
831 TitleMotion::TitleMotion(TitleMain *client, TitleWindow *window, int x, int y)
832  : BC_PopupTextBox(window, &window->paths,
833                 client->motion_to_text(client->config.motion_strategy),
834                 x, y, xS(120), yS(100))
835 {
836         this->client = client;
837         this->window = window;
838 }
839 int TitleMotion::handle_event()
840 {
841         client->config.motion_strategy = client->text_to_motion(get_text());
842         window->send_configure_change();
843         return 1;
844 }
845
846 TitleLoop::TitleLoop(TitleMain *client, TitleWindow *window, int x, int y)
847  : BC_CheckBox(x, y, client->config.loop, _("Loop"))
848 {
849         this->client = client;
850         this->window = window;
851 }
852 int TitleLoop::handle_event()
853 {
854         client->config.loop = get_value();
855         window->send_configure_change();
856         return 1;
857 }
858 TitleTimecode::TitleTimecode(TitleMain *client, TitleWindow *window, int x, int y)
859  : BC_CheckBox(x, y, client->config.timecode, _("Stamp timecode"))
860 {
861         this->client = client;
862         this->window = window;
863 }
864 int TitleTimecode::handle_event()
865 {
866         client->config.timecode = get_value();
867         client->send_configure_change();
868         return 1;
869 }
870
871 TitleTimecodeFormat::TitleTimecodeFormat(TitleMain *client, TitleWindow *window,
872                 int x, int y, int tw, const char *text)
873  : BC_PopupMenu(x, y, BC_PopupMenu::calculate_w(tw)+xS(10), text, 1)
874 {
875         this->client = client;
876         this->window = window;
877 }
878
879 int TitleTimecodeFormat::handle_event()
880 {
881         client->config.timecode_format = Units::text_to_format(get_text());
882         window->send_configure_change();
883         return 1;
884 }
885
886 void TitleTimecodeFormat::create_objects()
887 {
888         char string[BCTEXTLEN];
889         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
890                 add_item(new BC_MenuItem(
891                         Units::print_time_format(timeunit_formats[i], string)));
892         }
893 }
894
895
896 int TitleTimecodeFormat::update(int timecode_format)
897 {
898         char string[BCTEXTLEN];
899         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
900                 if( timeunit_formats[i] == timecode_format ) {
901                         set_text(Units::print_time_format(timeunit_formats[i], string));
902                         break;
903                 }
904         }
905         return 0;
906 }
907
908 TitleFade::TitleFade(TitleMain *client, TitleWindow *window,
909         double *value, int x, int y)
910  : BC_TextBox(x, y, xS(80), 1, (float)*value)
911 {
912         this->client = client;
913         this->window = window;
914         this->value = value;
915         set_precision(2);
916 }
917
918 int TitleFade::handle_event()
919 {
920         *value = atof(get_text());
921         window->send_configure_change();
922         return 1;
923 }
924
925 void TitleWindow::check_style(const char *font_name, int update)
926 {
927         BC_FontEntry *font_nrm = TitleMain::get_font(font_name, 0);
928         BC_FontEntry *font_itl = TitleMain::get_font(font_name, BC_FONT_ITALIC);
929         BC_FontEntry *font_bld = TitleMain::get_font(font_name, BC_FONT_BOLD);
930         BC_FontEntry *font_bit = TitleMain::get_font(font_name, BC_FONT_ITALIC | BC_FONT_BOLD);
931         int has_norm = font_nrm != 0 ? 1 : 0;
932         int has_ital = font_itl != 0 || font_bit != 0 ? 1 : 0;
933         int has_bold = font_bld != 0 || font_bit != 0 ? 1 : 0;
934         if( bold->get_value() ) {
935                 if( !has_bold ) bold->update(0);
936         }
937         else {
938                 if( !has_norm && has_bold ) bold->update(1);
939         }
940         if( italic->get_value() ) {
941                 if( !has_ital ) italic->update(0);
942         }
943         else {
944                 if( !has_norm && has_ital ) italic->update(1);
945         }
946         if( has_norm && has_bold ) bold->enable();   else bold->disable();
947         if( has_norm && has_ital ) italic->enable(); else italic->disable();
948         if( update ) {
949                 int style = stroker && atof(stroker->get_text()) ? BC_FONT_OUTLINE : 0;
950                 if( bold->get_value() ) style |= BC_FONT_BOLD;
951                 if( italic->get_value() ) style |= BC_FONT_ITALIC;
952                 if( alias->get_value() ) style |= FONT_ALIAS;
953                 client->config.style = style;
954         }
955 }
956
957 TitleFont::TitleFont(TitleMain *client, TitleWindow *window, int x, int y)
958  : BC_PopupTextBox(window, &window->fonts, client->config.font,
959                 x, y, xS(340), yS(300), LISTBOX_ICON_LIST)
960 {
961         this->client = client;
962         this->window = window;
963 }
964 int TitleFont::handle_event()
965 {
966         strcpy(client->config.font, get_text());
967         window->check_style(client->config.font, 1);
968         window->send_configure_change();
969         return 1;
970 }
971
972 TitleText::TitleText(TitleMain *client, TitleWindow *window,
973         int x, int y, int w, int h)
974  : BC_ScrollTextBox(window, x, y, w,
975                 BC_TextBox::pixels_to_rows(window, MEDIUMFONT, h),
976                 client->config.wtext, 0)
977 {
978         this->client = client;
979         this->window = window;
980 //printf("TitleText::TitleText %s\n", client->config.text);
981 }
982
983 int TitleText::button_press_event()
984 {
985         if( get_buttonpress() == 3 ) {
986                 window->cur_ibeam = get_ibeam_letter();
987                 window->cur_popup->activate_menu();
988                 return 1;
989         }
990         return BC_ScrollTextBox::button_press_event();
991 }
992
993 int TitleText::handle_event()
994 {
995         window->fonts_popup->deactivate();
996         const wchr_t *wtext = get_wtext();
997         long wlen = wstrlen(wtext);
998         client->config.demand(wlen);
999         wstrncpy(client->config.wtext, wtext, client->config.wsize);
1000         client->config.wlen = wlen;
1001         window->update_stats();
1002         window->send_configure_change();
1003         return 1;
1004 }
1005 TitleTextChars::TitleTextChars(int x, int y, int w)
1006  : BC_Title(x, y, "", MEDIUMFONT, -1, 0, w)
1007 {
1008 }
1009 TitleTextChars::~TitleTextChars()
1010 {
1011 }
1012 int TitleTextChars::update(int n)
1013 {
1014         char text[BCSTRLEN];
1015         sprintf(text, _("chars: %d  "),n);
1016         return BC_Title::update(text, 0);
1017 }
1018
1019
1020 TitleDropShadow::TitleDropShadow(TitleMain *client, TitleWindow *window, int x, int y)
1021  : BC_TumbleTextBox(window, client->config.dropshadow,
1022                 -1000, 1000, x, y, xS(70))
1023 {
1024         this->client = client;
1025         this->window = window;
1026 }
1027 int TitleDropShadow::handle_event()
1028 {
1029         client->config.dropshadow = atol(get_text());
1030         window->send_configure_change();
1031         return 1;
1032 }
1033
1034
1035 TitleOutline::TitleOutline(TitleMain *client, TitleWindow *window, int x, int y)
1036  : BC_TumbleTextBox(window, client->config.outline_size,
1037                 0.f, 1000.f, x, y, xS(70))
1038 {
1039         this->client = client;
1040         this->window = window;
1041         set_precision(1);
1042 }
1043 int TitleOutline::handle_event()
1044 {
1045         client->config.outline_size = atof(get_text());
1046         window->send_configure_change();
1047         return 1;
1048 }
1049
1050
1051 TitleStroker::TitleStroker(TitleMain *client, TitleWindow *window, int x, int y)
1052  : BC_TumbleTextBox(window, client->config.stroke_width,
1053                 0.f, 1000.f, x, y, xS(70))
1054 {
1055         this->client = client;
1056         this->window = window;
1057         set_precision(1);
1058 }
1059 int TitleStroker::handle_event()
1060 {
1061         client->config.stroke_width = atof(get_text());
1062         if( client->config.stroke_width )
1063                 client->config.style |= BC_FONT_OUTLINE;
1064         else
1065                 client->config.style &= ~BC_FONT_OUTLINE;
1066         window->send_configure_change();
1067         return 1;
1068 }
1069
1070
1071 TitleX::TitleX(TitleMain *client, TitleWindow *window, int x, int y)
1072  : BC_TumbleTextBox(window, client->config.title_x,
1073                 -32767.f, 32767.f, x, y, xS(50))
1074 {
1075         this->client = client;
1076         this->window = window;
1077         set_precision(1);
1078 }
1079 int TitleX::handle_event()
1080 {
1081         client->config.title_x = atof(get_text());
1082         window->update_drag();
1083         return 1;
1084 }
1085
1086 TitleY::TitleY(TitleMain *client, TitleWindow *window, int x, int y)
1087  : BC_TumbleTextBox(window, client->config.title_y,
1088                 -32767.f, 32767.f, x, y, xS(50))
1089 {
1090         this->client = client;
1091         this->window = window;
1092         set_precision(1);
1093 }
1094 int TitleY::handle_event()
1095 {
1096         client->config.title_y = atof(get_text());
1097         window->update_drag();
1098         return 1;
1099 }
1100
1101 TitleW::TitleW(TitleMain *client, TitleWindow *window, int x, int y)
1102  : BC_TumbleTextBox(window, client->config.title_w,
1103                 0, 32767, x, y, xS(50))
1104 {
1105         this->client = client;
1106         this->window = window;
1107 }
1108 int TitleW::handle_event()
1109 {
1110         client->config.title_w = atol(get_text());
1111         window->update_drag();
1112         return 1;
1113 }
1114
1115 TitleH::TitleH(TitleMain *client, TitleWindow *window, int x, int y)
1116  : BC_TumbleTextBox(window, client->config.title_h,
1117                 0, 32767, x, y, xS(50))
1118 {
1119         this->client = client;
1120         this->window = window;
1121 }
1122 int TitleH::handle_event()
1123 {
1124         client->config.title_h = atol(get_text());
1125         window->update_drag();
1126         return 1;
1127 }
1128
1129 TitleSpeed::TitleSpeed(TitleMain *client, TitleWindow *window, int x, int y)
1130  : BC_TumbleTextBox(window, client->config.pixels_per_second,
1131                 0.f, 1000.f, x, y, xS(100))
1132 {
1133         this->client = client;
1134         this->window = window;
1135         set_precision(2);
1136         set_increment(10);
1137 }
1138
1139
1140 int TitleSpeed::handle_event()
1141 {
1142         client->config.pixels_per_second = atof(get_text());
1143         window->send_configure_change();
1144         return 1;
1145 }
1146
1147
1148 TitleLeft::TitleLeft(TitleMain *client, TitleWindow *window, int x, int y)
1149  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_LEFT, _("Left"))
1150 {
1151         this->client = client;
1152         this->window = window;
1153 }
1154 int TitleLeft::handle_event()
1155 {
1156         client->config.hjustification = JUSTIFY_LEFT;
1157         window->update_justification();
1158         window->send_configure_change();
1159         return 1;
1160 }
1161
1162 TitleCenter::TitleCenter(TitleMain *client, TitleWindow *window, int x, int y)
1163  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_CENTER, _("Center"))
1164 {
1165         this->client = client;
1166         this->window = window;
1167 }
1168 int TitleCenter::handle_event()
1169 {
1170         client->config.hjustification = JUSTIFY_CENTER;
1171         window->update_justification();
1172         window->send_configure_change();
1173         return 1;
1174 }
1175
1176 TitleRight::TitleRight(TitleMain *client, TitleWindow *window, int x, int y)
1177  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_RIGHT, _("Right"))
1178 {
1179         this->client = client;
1180         this->window = window;
1181 }
1182 int TitleRight::handle_event()
1183 {
1184         client->config.hjustification = JUSTIFY_RIGHT;
1185         window->update_justification();
1186         window->send_configure_change();
1187         return 1;
1188 }
1189
1190
1191
1192 TitleTop::TitleTop(TitleMain *client, TitleWindow *window, int x, int y)
1193  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_TOP, _("Top"))
1194 {
1195         this->client = client;
1196         this->window = window;
1197 }
1198 int TitleTop::handle_event()
1199 {
1200         client->config.vjustification = JUSTIFY_TOP;
1201         window->update_justification();
1202         window->send_configure_change();
1203         return 1;
1204 }
1205
1206 TitleMid::TitleMid(TitleMain *client, TitleWindow *window, int x, int y)
1207  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_MID, _("Mid"))
1208 {
1209         this->client = client;
1210         this->window = window;
1211 }
1212 int TitleMid::handle_event()
1213 {
1214         client->config.vjustification = JUSTIFY_MID;
1215         window->update_justification();
1216         window->send_configure_change();
1217         return 1;
1218 }
1219
1220 TitleBottom::TitleBottom(TitleMain *client, TitleWindow *window, int x, int y)
1221  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_BOTTOM, _("Bottom"))
1222 {
1223         this->client = client;
1224         this->window = window;
1225 }
1226 int TitleBottom::handle_event()
1227 {
1228         client->config.vjustification = JUSTIFY_BOTTOM;
1229         window->update_justification();
1230         window->send_configure_change();
1231         return 1;
1232 }
1233
1234 TitleDrag::TitleDrag(TitleMain *client, TitleWindow *window, int x, int y)
1235  : DragCheckBox(client->server->mwindow, x, y, _("Drag"), &client->config.drag,
1236                 client->config.title_x, client->config.title_y,
1237                 client->config.title_w, client->config.title_h)
1238 {
1239         this->client = client;
1240         this->window = window;
1241 }
1242
1243 Track *TitleDrag::get_drag_track()
1244 {
1245         PluginServer *server = client->server;
1246         int plugin_id = server->plugin_id;
1247         Plugin *plugin = server->edl->tracks->plugin_exists(plugin_id);
1248         return !plugin ? 0 : plugin->track;
1249 }
1250 int64_t TitleDrag::get_drag_position()
1251 {
1252         return client->get_source_position();
1253 }
1254
1255 void TitleDrag::update_gui()
1256 {
1257         client->config.drag = get_value();
1258         client->config.title_x = drag_x;
1259         client->config.title_y = drag_y;
1260         client->config.title_w = drag_w+0.5;
1261         client->config.title_h = drag_h+0.5;
1262         window->title_x->update((float)client->config.title_x);
1263         window->title_y->update((float)client->config.title_y);
1264         window->title_w->update((int64_t)client->config.title_w);
1265         window->title_h->update((int64_t)client->config.title_h);
1266         window->send_configure_change();
1267 }
1268
1269 int TitleDrag::handle_event()
1270 {
1271         int ret = DragCheckBox::handle_event();
1272         window->send_configure_change();
1273         return ret;
1274 }
1275
1276 TitleBackground::TitleBackground(TitleMain *client, TitleWindow *window, int x, int y)
1277  : BC_CheckBox(x, y, client->config.background, _("Background:"))
1278 {
1279         this->client = client;
1280         this->window = window;
1281 }
1282
1283 int TitleBackground::handle_event()
1284 {
1285         client->config.background = get_value();
1286         window->send_configure_change();
1287         return 1;
1288 }
1289
1290 TitleBackgroundPath::TitleBackgroundPath(TitleMain *client, TitleWindow *window, int x, int y)
1291  : BC_TextBox(x, y, xS(240), 1, client->config.background_path)
1292 {
1293         this->client = client;
1294         this->window = window;
1295 }
1296
1297 int TitleBackgroundPath::handle_event()
1298 {
1299         strncpy(client->config.background_path, get_text(), sizeof(client->config.background_path));
1300         window->send_configure_change();
1301         return 1;
1302 }
1303
1304 TitleLoopPlayback::TitleLoopPlayback(TitleMain *client, TitleWindow *window, int x, int y)
1305  : BC_CheckBox(x, y, client->config.loop_playback, _("Loop playback"))
1306 {
1307         this->client = client;
1308         this->window = window;
1309 }
1310 int TitleLoopPlayback::handle_event()
1311 {
1312         client->config.loop_playback = get_value();
1313         window->send_configure_change();
1314         return 1;
1315 }
1316
1317
1318 TitleCurPopup::TitleCurPopup(TitleMain *client, TitleWindow *window)
1319  : BC_PopupMenu(0, 0, 0, "", 0)
1320 {
1321         this->client = client;
1322         this->window = window;
1323 }
1324 int TitleCurPopup::handle_event()
1325 {
1326         return 1;
1327 }
1328
1329 void TitleCurSubMenu::add_subitemx(int popup_type, va_list ap, const char *fmt)
1330 {
1331         char item[BCSTRLEN];
1332         vsnprintf(item, sizeof(item)-1, fmt, ap);
1333         item[sizeof(item)-1] = 0;
1334         add_submenuitem(new TitleCurSubMenuItem(this, item, popup_type));
1335 }
1336
1337 void TitleCurPopup::create_objects()
1338 {
1339         TitleCurItem *cur_item;
1340         TitleCurSubMenu *sub_menu;
1341         char *item;
1342         add_item(cur_item = new TitleCurItem(this, item = _(KW_NUDGE)));
1343         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1344         sub_menu->add_subitem("%s dx,dy",item);
1345         sub_menu->add_subitem("/%s",item);
1346         add_item(cur_item = new TitleCurItem(this, item = _(KW_COLOR)));
1347         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1348         sub_menu->add_subitem(POPUP_COLOR,"%s %s",item,_("#"));
1349         sub_menu->add_subitem("%s ",item);
1350         sub_menu->add_subitem("/%s",item);
1351         add_item(cur_item = new TitleCurItem(this, item = _(KW_ALPHA)));
1352         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1353         sub_menu->add_subitem("%s ",item);
1354         sub_menu->add_subitem("%s 0.",item);
1355         sub_menu->add_subitem("%s .5",item);
1356         sub_menu->add_subitem("%s 1.",item);
1357         sub_menu->add_subitem("/%s",item);
1358         add_item(cur_item = new TitleCurItem(this, item = _(KW_FONT)));
1359         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1360         sub_menu->add_subitem(POPUP_FONT,"%s %s",item, _("name"));
1361         sub_menu->add_subitem(POPUP_OFFSET, "%s ",item);
1362         sub_menu->add_subitem("/%s",item);
1363         add_item(cur_item = new TitleCurItem(this, item = _(KW_SIZE)));
1364         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1365         sub_menu->add_subitem("%s +",item);
1366         sub_menu->add_subitem("%s -",item);
1367         sub_menu->add_subitem("%s ",item);
1368         sub_menu->add_subitem("/%s",item);
1369         add_item(cur_item = new TitleCurItem(this, item = _(KW_BOLD)));
1370         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1371         sub_menu->add_subitem("%s 1",item);
1372         sub_menu->add_subitem("%s 0",item);
1373         sub_menu->add_subitem("/%s",item);
1374         add_item(cur_item = new TitleCurItem(this, item = _(KW_ITALIC)));
1375         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1376         sub_menu->add_subitem("%s 1",item);
1377         sub_menu->add_subitem("%s 0",item);
1378         sub_menu->add_subitem("/%s",item);
1379         add_item(cur_item = new TitleCurItem(this, item = _(KW_CAPS)));
1380         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1381         sub_menu->add_subitem("%s 1",item);
1382         sub_menu->add_subitem("%s 0",item);
1383         sub_menu->add_subitem("%s -1",item);
1384         sub_menu->add_subitem("/%s",item);
1385         add_item(cur_item = new TitleCurItem(this, item = _(KW_UL)));
1386         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1387         sub_menu->add_subitem("%s 1",item);
1388         sub_menu->add_subitem("%s 0",item);
1389         sub_menu->add_subitem("/%s",item);
1390         add_item(cur_item = new TitleCurItem(this, item = _(KW_BLINK)));
1391         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1392         sub_menu->add_subitem("%s 1",item);
1393         sub_menu->add_subitem("%s -1",item);
1394         sub_menu->add_subitem("%s ",item);
1395         sub_menu->add_subitem("%s 0",item);
1396         sub_menu->add_subitem("/%s",item);
1397         add_item(cur_item = new TitleCurItem(this, item = _(KW_FIXED)));
1398         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1399         sub_menu->add_subitem("%s ",item);
1400         sub_menu->add_subitem("%s 20",item);
1401         sub_menu->add_subitem("%s 10",item);
1402         sub_menu->add_subitem("%s 0",item);
1403         sub_menu->add_subitem("/%s",item);
1404         add_item(cur_item = new TitleCurItem(this, item = _(KW_ALIAS)));
1405         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1406         sub_menu->add_subitem("%s 1",item);
1407         sub_menu->add_subitem("%s 0",item);
1408         sub_menu->add_subitem("/%s",item);
1409         add_item(cur_item = new TitleCurItem(this, item = _(KW_SUP)));
1410         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1411         sub_menu->add_subitem("%s 1",item);
1412         sub_menu->add_subitem("%s 0",item);
1413         sub_menu->add_subitem("%s -1",item);
1414         sub_menu->add_subitem("/%s",item);
1415         add_item(cur_item = new TitleCurItem(this, item = _(KW_PNG)));
1416         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1417         sub_menu->add_subitem(POPUP_PNG,"%s %s", item, _("file"));
1418 }
1419
1420 TitleCurItem::TitleCurItem(TitleCurPopup *popup, const char *text)
1421  : BC_MenuItem(text)
1422 {
1423         this->popup = popup;
1424 }
1425 int TitleCurItem::handle_event()
1426 {
1427         return 1;
1428 }
1429
1430 TitleCurSubMenu::TitleCurSubMenu(TitleCurItem *cur_item)
1431 {
1432         this->cur_item = cur_item;
1433 }
1434 TitleCurSubMenu::~TitleCurSubMenu()
1435 {
1436 }
1437
1438 TitleCurSubMenuItem::TitleCurSubMenuItem(TitleCurSubMenu *submenu, const char *text, int popup_type)
1439  : BC_MenuItem(text)
1440 {
1441         this->submenu = submenu;
1442         this->popup_type = popup_type;
1443 }
1444 TitleCurSubMenuItem::~TitleCurSubMenuItem()
1445 {
1446 }
1447 int TitleCurSubMenuItem::handle_event()
1448 {
1449         TitleCurPopup *popup = submenu->cur_item->popup;
1450         TitleWindow *window = popup->window;
1451         const char *item_text = get_text();
1452         int ofs = *item_text == '/' ? 0 : -1;
1453         switch( popup_type ) {
1454         case POPUP_FONT: {
1455                 int px, py;
1456                 window->get_pop_cursor(px ,py);
1457                 window->fonts_popup->activate(px, py, xS(300),yS(200));
1458                 return 1; }
1459         case POPUP_COLOR: {
1460                 window->color_popup->activate();
1461                 return 1; }
1462         case POPUP_PNG: {
1463                 window->png_popup->activate();
1464                 return 1; }
1465         case POPUP_OFFSET:
1466                 ofs = -1;
1467                 break;
1468         }
1469         char txt[BCSTRLEN];
1470         sprintf(txt, "<%s>", item_text);
1471         return window->insert_ibeam(txt, ofs);
1472 }
1473
1474 TitleFontsPopup::TitleFontsPopup(TitleMain *client, TitleWindow *window)
1475  : BC_ListBox(-1, -1, 1, 1, LISTBOX_ICON_LIST,
1476         &window->fonts, 0, 0, 1, 0, 1)
1477 {
1478         this->client = client;
1479         this->window = window;
1480         set_use_button(0);
1481         set_show_query(1);
1482 }
1483 TitleFontsPopup::~TitleFontsPopup()
1484 {
1485 }
1486 int TitleFontsPopup::keypress_event()
1487 {
1488         switch( get_keypress() ) {
1489         case ESC:
1490         case DELETE:
1491                 deactivate();
1492                 return 1;
1493         default:
1494                 break;
1495         }
1496         return BC_ListBox::keypress_event();
1497 }
1498
1499 int TitleFontsPopup::handle_event()
1500 {
1501         deactivate();
1502         BC_ListBoxItem *item = get_selection(0, 0);
1503         if( !item ) return 1;
1504         const char *item_text = item->get_text();
1505         char txt[BCTEXTLEN];  sprintf(txt, "<%s %s>", _(KW_FONT), item_text);
1506         return window->insert_ibeam(txt);
1507 }
1508
1509 TitleColorPopup::TitleColorPopup(TitleMain *client, TitleWindow *window)
1510  : ColorPicker(0, _("Color"))
1511 {
1512         this->client = client;
1513         this->window = window;
1514         this->color_value = client->config.color;
1515 }
1516 TitleColorPopup::~TitleColorPopup()
1517 {
1518 }
1519 int TitleColorPopup::handle_new_color(int output, int alpha)
1520 {
1521         color_value = output;
1522         return 1;
1523 }
1524 int TitleColorPopup::activate()
1525 {
1526         start_window(client->config.color, 255, 1);
1527         return 1;
1528 }
1529 void TitleColorPopup::handle_done_event(int result)
1530 {
1531         if( !result ) {
1532                 char txt[BCSTRLEN];  sprintf(txt, "<%s #%06x>", _(KW_COLOR), color_value);
1533                 window->lock_window("TitleColorPopup::handle_done_event");
1534                 window->insert_ibeam(txt);
1535                 window->unlock_window();
1536         }
1537 }
1538
1539 TitlePngPopup::TitlePngPopup(TitleMain *client, TitleWindow *window)
1540  : BC_DialogThread()
1541 {
1542         this->client = client;
1543         this->window = window;
1544 }
1545
1546 TitlePngPopup::~TitlePngPopup()
1547 {
1548         close_window();
1549 }
1550
1551 void TitlePngPopup::handle_done_event(int result)
1552 {
1553         if( result ) return;
1554         BrowseButtonWindow *gui = (BrowseButtonWindow *)get_gui();
1555         const char *path = gui->get_submitted_path();
1556         char txt[BCTEXTLEN];  sprintf(txt, "<%s %s>", _(KW_PNG), path);
1557         window->lock_window("TitlePngPopup::handle_done_event");
1558         window->insert_ibeam(txt);
1559         window->unlock_window();
1560 }
1561
1562 BC_Window *TitlePngPopup::new_gui()
1563 {
1564         MWindow *mwindow = client->server->mwindow;
1565         int x, y;  mwindow->gui->get_abs_cursor(x, y);
1566
1567         BC_Window *gui = new BrowseButtonWindow(mwindow->theme,
1568                 x-xS(25), y-yS(100), window, "", _("Png file"), _("Png path"), 0);
1569         gui->create_objects();
1570         return gui;
1571 }
1572
1573 int TitlePngPopup::activate()
1574 {
1575         BC_DialogThread::start();
1576         return 1;
1577 }
1578