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