fc4fc8f87ab5515bcd922baf00d63577699be7ed
[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 }
143
144 void TitleWindow::create_objects()
145 {
146         int x = xS(10), y = yS(10);
147         int margin = client->get_theme()->widget_border;
148         char string[BCTEXTLEN];
149
150 #define COLOR_W xS(50)
151 #define COLOR_H yS(30)
152         client->build_previews(this);
153
154         sizes.append(new BC_ListBoxItem("8"));
155         sizes.append(new BC_ListBoxItem("9"));
156         sizes.append(new BC_ListBoxItem("10"));
157         sizes.append(new BC_ListBoxItem("11"));
158         sizes.append(new BC_ListBoxItem("12"));
159         sizes.append(new BC_ListBoxItem("13"));
160         sizes.append(new BC_ListBoxItem("14"));
161         sizes.append(new BC_ListBoxItem("16"));
162         sizes.append(new BC_ListBoxItem("18"));
163         sizes.append(new BC_ListBoxItem("20"));
164         sizes.append(new BC_ListBoxItem("22"));
165         sizes.append(new BC_ListBoxItem("24"));
166         sizes.append(new BC_ListBoxItem("26"));
167         sizes.append(new BC_ListBoxItem("28"));
168         sizes.append(new BC_ListBoxItem("32"));
169         sizes.append(new BC_ListBoxItem("36"));
170         sizes.append(new BC_ListBoxItem("40"));
171         sizes.append(new BC_ListBoxItem("48"));
172         sizes.append(new BC_ListBoxItem("56"));
173         sizes.append(new BC_ListBoxItem("64"));
174         sizes.append(new BC_ListBoxItem("72"));
175         sizes.append(new BC_ListBoxItem("100"));
176         sizes.append(new BC_ListBoxItem("128"));
177         sizes.append(new BC_ListBoxItem("256"));
178         sizes.append(new BC_ListBoxItem("512"));
179         sizes.append(new BC_ListBoxItem("1024"));
180
181         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(NO_MOTION)));
182         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(BOTTOM_TO_TOP)));
183         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(TOP_TO_BOTTOM)));
184         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(RIGHT_TO_LEFT)));
185         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(LEFT_TO_RIGHT)));
186
187
188
189 // Construct font list
190         ArrayList<BC_FontEntry*> *fontlist = get_resources()->fontlist;
191
192         for( int i=0; i<fontlist->size(); ++i ) {
193                 int exists = 0;
194                 for( int j=0; j<fonts.size(); ++j ) {
195                         if( !strcasecmp(fonts.get(j)->get_text(),
196                                 fontlist->get(i)->displayname) ) {
197                                 exists = 1;
198                                 break;
199                         }
200                 }
201
202                 BC_ListBoxItem *item = 0;
203                 if( !exists ) {
204                         fonts.append(item = new
205                                 BC_ListBoxItem(fontlist->get(i)->displayname));
206                         if( !strcmp(client->config.font, item->get_text()) )
207                                 item->set_selected(1);
208                         if( fontlist->values[i]->image ) {
209                                 VFrame *vframe = fontlist->get(i)->image;
210                                 BC_Pixmap *icon = new BC_Pixmap(this, vframe, PIXMAP_ALPHA);
211                                 item->set_icon(icon);
212                                 item->set_icon_vframe(vframe);
213                         }
214                 }
215         }
216
217 // Sort font list
218         int done = 0;
219         while(!done) {
220                 done = 1;
221                 for( int i=0; i<fonts.size()-1; ++i ) {
222                         if( strcmp(fonts.values[i]->get_text(),
223                                 fonts.values[i + 1]->get_text()) > 0 ) {
224                                 BC_ListBoxItem *temp = fonts.values[i + 1];
225                                 fonts.values[i + 1] = fonts.values[i];
226                                 fonts.values[i] = temp;
227                                 done = 0;
228                         }
229                 }
230         }
231
232         add_tool(font_title = new BC_Title(x, y, _("Font:")));
233         font = new TitleFont(client, this, x, y + font_title->get_h());
234         font->create_objects();
235         font->set_show_query(1);
236         x += font->get_w();
237         add_subwindow(font_tumbler = new TitleFontTumble(client, this, x, y+margin));
238         x += font_tumbler->get_w() + margin;
239
240         int x1 = x+xS(20), y1 = y;
241         add_tool(size_title = new BC_Title(x1, y1+margin, _("Size:")));
242         sprintf(string, "%.2f", client->config.size);
243         x1 += size_title->get_w() + margin;
244         size = new TitleSize(client, this, x1, y1+margin, string);
245         size->create_objects();
246         int x2 = x1 + size->get_w(), y2 = y1 + size->get_h() + margin;
247         add_subwindow(size_tumbler = new TitleSizeTumble(client, this, x2, y1+margin));
248
249         add_tool(pitch_title = new BC_Title(x-xS(16), y2+margin, _("Line Pitch:")));
250         pitch = new TitlePitch(client, this, x1, y2+margin, &client->config.line_pitch);
251         pitch->create_objects();
252
253         int x3 = x2 + size_tumbler->get_w() + xS(50);
254         int y3 = pitch->get_y() + pitch->get_h();
255
256         add_tool(style_title = new BC_Title(x=x3, y, _("Style:")));
257         add_tool(italic = new TitleItalic(client, this, x, y + yS(20)));
258         int w1 = italic->get_w();
259         add_tool(bold = new TitleBold(client, this, x, y + yS(50)));
260         if( bold->get_w() > w1 ) w1 = bold->get_w();
261
262         add_tool(drag = new TitleDrag(client, this, x, y + yS(80)));
263         drag->create_objects();
264         if( drag->get_w() > w1 ) w1 = drag->get_w();
265         if( client->config.drag ) {
266                 if( drag->drag_activate() )
267                         eprintf("drag enabled, but compositor already grabbed\n");
268         }
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         italic->update(client->config.style & BC_FONT_ITALIC);
576         bold->update(client->config.style & BC_FONT_BOLD);
577         alias->update(client->config.style & FONT_ALIAS);
578         size->update(client->config.size);
579         motion->update(TitleMain::motion_to_text(client->config.motion_strategy));
580         loop->update(client->config.loop);
581         dropshadow->update((int64_t)client->config.dropshadow);
582         fade_in->update((float)client->config.fade_in);
583         fade_out->update((float)client->config.fade_out);
584         font->update(client->config.font);
585         check_style(client->config.font,0);
586         wchr_t wz[1] = { 0 };
587         text->update(client->config.wtext ? &client->config.wtext[0] : wz);
588         speed->update(client->config.pixels_per_second);
589         outline->update((int64_t)client->config.outline_size);
590 #ifdef USE_STROKER
591         stroker->update((int64_t)client->config.stroke_width);
592 #endif
593         timecode->update(client->config.timecode);
594         timecode_format->update(client->config.timecode_format);
595         background->update(client->config.background);
596         background_path->update(client->config.background_path);
597         loop_playback->update((int64_t)client->config.loop_playback);
598
599         char string[BCTEXTLEN];
600         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
601                 if( timeunit_formats[i] == client->config.timecode_format ) {
602                         timecode_format->set_text(
603                                 Units::print_time_format(timeunit_formats[i], string));
604                         break;
605                 }
606         }
607         update_justification();
608         update_stats();
609         update_color();
610 }
611
612
613 TitleFontTumble::TitleFontTumble(TitleMain *client, TitleWindow *window, int x, int y)
614  : BC_Tumbler(x, y)
615 {
616         this->client = client;
617         this->window = window;
618 }
619 int TitleFontTumble::handle_up_event()
620 {
621         window->previous_font();
622         return 1;
623 }
624
625 int TitleFontTumble::handle_down_event()
626 {
627         window->next_font();
628         return 1;
629 }
630
631
632 TitleSizeTumble::TitleSizeTumble(TitleMain *client, TitleWindow *window, int x, int y)
633  : BC_Tumbler(x, y)
634 {
635         this->client = client;
636         this->window = window;
637 }
638
639 int TitleSizeTumble::handle_up_event()
640 {
641         int current_index = -1;
642         int current_difference = -1;
643         for( int i=0; i<window->sizes.size(); ++i ) {
644                 int size = atoi(window->sizes.get(i)->get_text());
645                 if( current_index < 0 ||
646                         abs(size - client->config.size) < current_difference ) {
647                         current_index = i;
648                         current_difference = abs(size - client->config.size);
649                 }
650         }
651
652         current_index++;
653         if( current_index >= window->sizes.size() ) current_index = 0;
654
655
656         client->config.size = atoi(window->sizes.get(current_index)->get_text());
657         window->size->update(client->config.size);
658         window->send_configure_change();
659         return 1;
660 }
661
662 int TitleSizeTumble::handle_down_event()
663 {
664         int current_index = -1;
665         int current_difference = -1;
666         for( int i=0; i<window->sizes.size(); ++i ) {
667                 int size = atoi(window->sizes.get(i)->get_text());
668                 if( current_index < 0 ||
669                         abs(size - client->config.size) < current_difference ) {
670                         current_index = i;
671                         current_difference = abs(size - client->config.size);
672                 }
673         }
674
675         current_index--;
676         if( current_index < 0 ) current_index = window->sizes.size() - 1;
677
678
679         client->config.size = atoi(window->sizes.get(current_index)->get_text());
680         window->size->update(client->config.size);
681         window->send_configure_change();
682         return 1;
683 }
684
685 TitleAlias::TitleAlias(TitleMain *client, TitleWindow *window, int x, int y)
686  : BC_CheckBox(x, y, client->config.style & FONT_ALIAS, _("Smooth"))
687 {
688         this->client = client;
689         this->window = window;
690 }
691
692 int TitleAlias::handle_event()
693 {
694         client->config.style =
695                 (client->config.style & ~FONT_ALIAS) |
696                         (get_value() ? FONT_ALIAS : 0);
697         window->send_configure_change();
698         return 1;
699 }
700
701 TitleBold::TitleBold(TitleMain *client, TitleWindow *window, int x, int y)
702  : BC_CheckBox(x, y, client->config.style & BC_FONT_BOLD, _("Bold"))
703 {
704         this->client = client;
705         this->window = window;
706 }
707
708 int TitleBold::handle_event()
709 {
710         client->config.style =
711                 (client->config.style & ~BC_FONT_BOLD) |
712                         (get_value() ? BC_FONT_BOLD : 0);
713         window->send_configure_change();
714         return 1;
715 }
716
717 TitleItalic::TitleItalic(TitleMain *client, TitleWindow *window, int x, int y)
718  : BC_CheckBox(x, y, client->config.style & BC_FONT_ITALIC, _("Italic"))
719 {
720         this->client = client;
721         this->window = window;
722 }
723 int TitleItalic::handle_event()
724 {
725         client->config.style =
726                 (client->config.style & ~BC_FONT_ITALIC) |
727                         (get_value() ? BC_FONT_ITALIC : 0);
728         window->send_configure_change();
729         return 1;
730 }
731
732
733
734 TitleSize::TitleSize(TitleMain *client, TitleWindow *window, int x, int y, char *text)
735  : BC_PopupTextBox(window, &window->sizes, text, x, y, xS(64), yS(300))
736 {
737         this->client = client;
738         this->window = window;
739 }
740 TitleSize::~TitleSize()
741 {
742 }
743 int TitleSize::handle_event()
744 {
745         client->config.size = atol(get_text());
746 //printf("TitleSize::handle_event 1 %s\n", get_text());
747         window->send_configure_change();
748         return 1;
749 }
750 void TitleSize::update(int size)
751 {
752         char string[BCTEXTLEN];
753         sprintf(string, "%d", size);
754         BC_PopupTextBox::update(string);
755 }
756
757 TitlePitch::
758 TitlePitch(TitleMain *client, TitleWindow *window, int x, int y, int *value)
759  : BC_TumbleTextBox(window, *value, 0, INT_MAX, x, y, xS(64))
760 {
761         this->client = client;
762         this->window = window;
763         this->value = value;
764 }
765
766 TitlePitch::
767 ~TitlePitch()
768 {
769 }
770
771 int TitlePitch::handle_event()
772 {
773         *value = atol(get_text());
774         window->send_configure_change();
775         return 1;
776 }
777
778 TitleColorButton::TitleColorButton(TitleMain *client, TitleWindow *window, int x, int y)
779  : ColorCircleButton(_("Text Color"), x, y, COLOR_W, COLOR_H,
780                 client->config.color, client->config.alpha, 1)
781 {
782         this->client = client;
783         this->window = window;
784 }
785 int TitleColorButton::handle_new_color(int output, int alpha)
786 {
787         client->config.color = output;
788         client->config.alpha = alpha;
789         window->send_configure_change();
790         return 1;
791 }
792 void TitleColorButton::handle_done_event(int result)
793 {
794         if( result ) {
795                 handle_new_color(orig_color, orig_alpha);
796                 window->lock_window("TitleColorButton::handle_done_event");
797                 update_gui(orig_color);
798                 window->unlock_window();
799         }
800 }
801
802 TitleOutlineColorButton::TitleOutlineColorButton(TitleMain *client, TitleWindow *window, int x, int y)
803  : ColorCircleButton(_("Outline Color"), x, y, COLOR_W, COLOR_H,
804                 client->config.outline_color, client->config.outline_alpha, 1)
805 {
806         this->client = client;
807         this->window = window;
808 }
809 int TitleOutlineColorButton::handle_new_color(int output, int alpha)
810 {
811         client->config.outline_color = output;
812         client->config.outline_alpha = alpha;
813         window->send_configure_change();
814         return 1;
815 }
816 void TitleOutlineColorButton::handle_done_event(int result)
817 {
818         if( result ) {
819                 handle_new_color(orig_color, orig_alpha);
820                 window->lock_window("TitleColorButton::handle_done_event");
821                 update_gui(orig_color);
822                 window->unlock_window();
823         }
824 }
825
826
827 TitleMotion::TitleMotion(TitleMain *client, TitleWindow *window, int x, int y)
828  : BC_PopupTextBox(window, &window->paths,
829                 client->motion_to_text(client->config.motion_strategy),
830                 x, y, xS(120), yS(100))
831 {
832         this->client = client;
833         this->window = window;
834 }
835 int TitleMotion::handle_event()
836 {
837         client->config.motion_strategy = client->text_to_motion(get_text());
838         window->send_configure_change();
839         return 1;
840 }
841
842 TitleLoop::TitleLoop(TitleMain *client, TitleWindow *window, int x, int y)
843  : BC_CheckBox(x, y, client->config.loop, _("Loop"))
844 {
845         this->client = client;
846         this->window = window;
847 }
848 int TitleLoop::handle_event()
849 {
850         client->config.loop = get_value();
851         window->send_configure_change();
852         return 1;
853 }
854 TitleTimecode::TitleTimecode(TitleMain *client, TitleWindow *window, int x, int y)
855  : BC_CheckBox(x, y, client->config.timecode, _("Stamp timecode"))
856 {
857         this->client = client;
858         this->window = window;
859 }
860 int TitleTimecode::handle_event()
861 {
862         client->config.timecode = get_value();
863         client->send_configure_change();
864         return 1;
865 }
866
867 TitleTimecodeFormat::TitleTimecodeFormat(TitleMain *client, TitleWindow *window,
868                 int x, int y, int tw, const char *text)
869  : BC_PopupMenu(x, y, BC_PopupMenu::calculate_w(tw)+xS(10), text, 1)
870 {
871         this->client = client;
872         this->window = window;
873 }
874
875 int TitleTimecodeFormat::handle_event()
876 {
877         client->config.timecode_format = Units::text_to_format(get_text());
878         window->send_configure_change();
879         return 1;
880 }
881
882 void TitleTimecodeFormat::create_objects()
883 {
884         char string[BCTEXTLEN];
885         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
886                 add_item(new BC_MenuItem(
887                         Units::print_time_format(timeunit_formats[i], string)));
888         }
889 }
890
891
892 int TitleTimecodeFormat::update(int timecode_format)
893 {
894         char string[BCTEXTLEN];
895         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
896                 if( timeunit_formats[i] == timecode_format ) {
897                         set_text(Units::print_time_format(timeunit_formats[i], string));
898                         break;
899                 }
900         }
901         return 0;
902 }
903
904 TitleFade::TitleFade(TitleMain *client, TitleWindow *window,
905         double *value, int x, int y)
906  : BC_TextBox(x, y, xS(80), 1, (float)*value)
907 {
908         this->client = client;
909         this->window = window;
910         this->value = value;
911         set_precision(2);
912 }
913
914 int TitleFade::handle_event()
915 {
916         *value = atof(get_text());
917         window->send_configure_change();
918         return 1;
919 }
920
921 void TitleWindow::check_style(const char *font_name, int update)
922 {
923         BC_FontEntry *font_nrm = TitleMain::get_font(font_name, 0);
924         BC_FontEntry *font_itl = TitleMain::get_font(font_name, BC_FONT_ITALIC);
925         BC_FontEntry *font_bld = TitleMain::get_font(font_name, BC_FONT_BOLD);
926         BC_FontEntry *font_bit = TitleMain::get_font(font_name, BC_FONT_ITALIC | BC_FONT_BOLD);
927         int has_norm = font_nrm != 0 ? 1 : 0;
928         int has_ital = font_itl != 0 || font_bit != 0 ? 1 : 0;
929         int has_bold = font_bld != 0 || font_bit != 0 ? 1 : 0;
930         if( bold->get_value() ) {
931                 if( !has_bold ) bold->update(0);
932         }
933         else {
934                 if( !has_norm && has_bold ) bold->update(1);
935         }
936         if( italic->get_value() ) {
937                 if( !has_ital ) italic->update(0);
938         }
939         else {
940                 if( !has_norm && has_ital ) italic->update(1);
941         }
942         if( has_norm && has_bold ) bold->enable();   else bold->disable();
943         if( has_norm && has_ital ) italic->enable(); else italic->disable();
944         if( update ) {
945                 int style = stroker && atof(stroker->get_text()) ? BC_FONT_OUTLINE : 0;
946                 if( bold->get_value() ) style |= BC_FONT_BOLD;
947                 if( italic->get_value() ) style |= BC_FONT_ITALIC;
948                 if( alias->get_value() ) style |= FONT_ALIAS;
949                 client->config.style = style;
950         }
951 }
952
953 TitleFont::TitleFont(TitleMain *client, TitleWindow *window, int x, int y)
954  : BC_PopupTextBox(window, &window->fonts, client->config.font,
955                 x, y, xS(340), yS(300), LISTBOX_ICON_LIST)
956 {
957         this->client = client;
958         this->window = window;
959 }
960 int TitleFont::handle_event()
961 {
962         strcpy(client->config.font, get_text());
963         window->check_style(client->config.font, 1);
964         window->send_configure_change();
965         return 1;
966 }
967
968 TitleText::TitleText(TitleMain *client, TitleWindow *window,
969         int x, int y, int w, int h)
970  : BC_ScrollTextBox(window, x, y, w,
971                 BC_TextBox::pixels_to_rows(window, MEDIUMFONT, h),
972                 client->config.wtext, 0)
973 {
974         this->client = client;
975         this->window = window;
976 //printf("TitleText::TitleText %s\n", client->config.text);
977 }
978
979 int TitleText::button_press_event()
980 {
981         if( get_buttonpress() == 3 ) {
982                 window->cur_ibeam = get_ibeam_letter();
983                 window->cur_popup->activate_menu();
984                 return 1;
985         }
986         return BC_ScrollTextBox::button_press_event();
987 }
988
989 int TitleText::handle_event()
990 {
991         window->fonts_popup->deactivate();
992         const wchr_t *wtext = get_wtext();
993         long wlen = wstrlen(wtext);
994         client->config.demand(wlen);
995         wstrncpy(client->config.wtext, wtext, client->config.wsize);
996         client->config.wlen = wlen;
997         window->update_stats();
998         window->send_configure_change();
999         return 1;
1000 }
1001 TitleTextChars::TitleTextChars(int x, int y, int w)
1002  : BC_Title(x, y, "", MEDIUMFONT, -1, 0, w)
1003 {
1004 }
1005 TitleTextChars::~TitleTextChars()
1006 {
1007 }
1008 int TitleTextChars::update(int n)
1009 {
1010         char text[BCSTRLEN];
1011         sprintf(text, _("chars: %d  "),n);
1012         return BC_Title::update(text, 0);
1013 }
1014
1015
1016 TitleDropShadow::TitleDropShadow(TitleMain *client, TitleWindow *window, int x, int y)
1017  : BC_TumbleTextBox(window, client->config.dropshadow,
1018                 -1000, 1000, x, y, xS(70))
1019 {
1020         this->client = client;
1021         this->window = window;
1022 }
1023 int TitleDropShadow::handle_event()
1024 {
1025         client->config.dropshadow = atol(get_text());
1026         window->send_configure_change();
1027         return 1;
1028 }
1029
1030
1031 TitleOutline::TitleOutline(TitleMain *client, TitleWindow *window, int x, int y)
1032  : BC_TumbleTextBox(window, client->config.outline_size,
1033                 0.f, 1000.f, x, y, xS(70))
1034 {
1035         this->client = client;
1036         this->window = window;
1037         set_precision(1);
1038 }
1039 int TitleOutline::handle_event()
1040 {
1041         client->config.outline_size = atof(get_text());
1042         window->send_configure_change();
1043         return 1;
1044 }
1045
1046
1047 TitleStroker::TitleStroker(TitleMain *client, TitleWindow *window, int x, int y)
1048  : BC_TumbleTextBox(window, client->config.stroke_width,
1049                 0.f, 1000.f, x, y, xS(70))
1050 {
1051         this->client = client;
1052         this->window = window;
1053         set_precision(1);
1054 }
1055 int TitleStroker::handle_event()
1056 {
1057         client->config.stroke_width = atof(get_text());
1058         if( client->config.stroke_width )
1059                 client->config.style |= BC_FONT_OUTLINE;
1060         else
1061                 client->config.style &= ~BC_FONT_OUTLINE;
1062         window->send_configure_change();
1063         return 1;
1064 }
1065
1066
1067 TitleX::TitleX(TitleMain *client, TitleWindow *window, int x, int y)
1068  : BC_TumbleTextBox(window, client->config.title_x,
1069                 -32767.f, 32767.f, x, y, xS(50))
1070 {
1071         this->client = client;
1072         this->window = window;
1073         set_precision(1);
1074 }
1075 int TitleX::handle_event()
1076 {
1077         client->config.title_x = atof(get_text());
1078         window->update_drag();
1079         return 1;
1080 }
1081
1082 TitleY::TitleY(TitleMain *client, TitleWindow *window, int x, int y)
1083  : BC_TumbleTextBox(window, client->config.title_y,
1084                 -32767.f, 32767.f, x, y, xS(50))
1085 {
1086         this->client = client;
1087         this->window = window;
1088         set_precision(1);
1089 }
1090 int TitleY::handle_event()
1091 {
1092         client->config.title_y = atof(get_text());
1093         window->update_drag();
1094         return 1;
1095 }
1096
1097 TitleW::TitleW(TitleMain *client, TitleWindow *window, int x, int y)
1098  : BC_TumbleTextBox(window, client->config.title_w,
1099                 0, 32767, x, y, xS(50))
1100 {
1101         this->client = client;
1102         this->window = window;
1103 }
1104 int TitleW::handle_event()
1105 {
1106         client->config.title_w = atol(get_text());
1107         window->update_drag();
1108         return 1;
1109 }
1110
1111 TitleH::TitleH(TitleMain *client, TitleWindow *window, int x, int y)
1112  : BC_TumbleTextBox(window, client->config.title_h,
1113                 0, 32767, x, y, xS(50))
1114 {
1115         this->client = client;
1116         this->window = window;
1117 }
1118 int TitleH::handle_event()
1119 {
1120         client->config.title_h = atol(get_text());
1121         window->update_drag();
1122         return 1;
1123 }
1124
1125 TitleSpeed::TitleSpeed(TitleMain *client, TitleWindow *window, int x, int y)
1126  : BC_TumbleTextBox(window, client->config.pixels_per_second,
1127                 0.f, 1000.f, x, y, xS(100))
1128 {
1129         this->client = client;
1130         this->window = window;
1131         set_precision(2);
1132         set_increment(10);
1133 }
1134
1135
1136 int TitleSpeed::handle_event()
1137 {
1138         client->config.pixels_per_second = atof(get_text());
1139         window->send_configure_change();
1140         return 1;
1141 }
1142
1143
1144 TitleLeft::TitleLeft(TitleMain *client, TitleWindow *window, int x, int y)
1145  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_LEFT, _("Left"))
1146 {
1147         this->client = client;
1148         this->window = window;
1149 }
1150 int TitleLeft::handle_event()
1151 {
1152         client->config.hjustification = JUSTIFY_LEFT;
1153         window->update_justification();
1154         window->send_configure_change();
1155         return 1;
1156 }
1157
1158 TitleCenter::TitleCenter(TitleMain *client, TitleWindow *window, int x, int y)
1159  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_CENTER, _("Center"))
1160 {
1161         this->client = client;
1162         this->window = window;
1163 }
1164 int TitleCenter::handle_event()
1165 {
1166         client->config.hjustification = JUSTIFY_CENTER;
1167         window->update_justification();
1168         window->send_configure_change();
1169         return 1;
1170 }
1171
1172 TitleRight::TitleRight(TitleMain *client, TitleWindow *window, int x, int y)
1173  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_RIGHT, _("Right"))
1174 {
1175         this->client = client;
1176         this->window = window;
1177 }
1178 int TitleRight::handle_event()
1179 {
1180         client->config.hjustification = JUSTIFY_RIGHT;
1181         window->update_justification();
1182         window->send_configure_change();
1183         return 1;
1184 }
1185
1186
1187
1188 TitleTop::TitleTop(TitleMain *client, TitleWindow *window, int x, int y)
1189  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_TOP, _("Top"))
1190 {
1191         this->client = client;
1192         this->window = window;
1193 }
1194 int TitleTop::handle_event()
1195 {
1196         client->config.vjustification = JUSTIFY_TOP;
1197         window->update_justification();
1198         window->send_configure_change();
1199         return 1;
1200 }
1201
1202 TitleMid::TitleMid(TitleMain *client, TitleWindow *window, int x, int y)
1203  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_MID, _("Mid"))
1204 {
1205         this->client = client;
1206         this->window = window;
1207 }
1208 int TitleMid::handle_event()
1209 {
1210         client->config.vjustification = JUSTIFY_MID;
1211         window->update_justification();
1212         window->send_configure_change();
1213         return 1;
1214 }
1215
1216 TitleBottom::TitleBottom(TitleMain *client, TitleWindow *window, int x, int y)
1217  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_BOTTOM, _("Bottom"))
1218 {
1219         this->client = client;
1220         this->window = window;
1221 }
1222 int TitleBottom::handle_event()
1223 {
1224         client->config.vjustification = JUSTIFY_BOTTOM;
1225         window->update_justification();
1226         window->send_configure_change();
1227         return 1;
1228 }
1229
1230 TitleDrag::TitleDrag(TitleMain *client, TitleWindow *window, int x, int y)
1231  : DragCheckBox(client->server->mwindow, x, y, _("Drag"), &client->config.drag,
1232                 client->config.title_x, client->config.title_y,
1233                 client->config.title_w, client->config.title_h)
1234 {
1235         this->client = client;
1236         this->window = window;
1237 }
1238
1239 Track *TitleDrag::get_drag_track()
1240 {
1241         PluginServer *server = client->server;
1242         int plugin_id = server->plugin_id;
1243         Plugin *plugin = server->edl->tracks->plugin_exists(plugin_id);
1244         return !plugin ? 0 : plugin->track;
1245 }
1246 int64_t TitleDrag::get_drag_position()
1247 {
1248         return client->get_source_position();
1249 }
1250
1251 void TitleDrag::update_gui()
1252 {
1253         client->config.drag = get_value();
1254         client->config.title_x = drag_x;
1255         client->config.title_y = drag_y;
1256         client->config.title_w = drag_w+0.5;
1257         client->config.title_h = drag_h+0.5;
1258         window->title_x->update((float)client->config.title_x);
1259         window->title_y->update((float)client->config.title_y);
1260         window->title_w->update((int64_t)client->config.title_w);
1261         window->title_h->update((int64_t)client->config.title_h);
1262         window->send_configure_change();
1263 }
1264
1265 int TitleDrag::handle_event()
1266 {
1267         int ret = DragCheckBox::handle_event();
1268         window->send_configure_change();
1269         return ret;
1270 }
1271
1272 TitleBackground::TitleBackground(TitleMain *client, TitleWindow *window, int x, int y)
1273  : BC_CheckBox(x, y, client->config.background, _("Background:"))
1274 {
1275         this->client = client;
1276         this->window = window;
1277 }
1278
1279 int TitleBackground::handle_event()
1280 {
1281         client->config.background = get_value();
1282         window->send_configure_change();
1283         return 1;
1284 }
1285
1286 TitleBackgroundPath::TitleBackgroundPath(TitleMain *client, TitleWindow *window, int x, int y)
1287  : BC_TextBox(x, y, xS(240), 1, client->config.background_path)
1288 {
1289         this->client = client;
1290         this->window = window;
1291 }
1292
1293 int TitleBackgroundPath::handle_event()
1294 {
1295         strncpy(client->config.background_path, get_text(), sizeof(client->config.background_path));
1296         window->send_configure_change();
1297         return 1;
1298 }
1299
1300 TitleLoopPlayback::TitleLoopPlayback(TitleMain *client, TitleWindow *window, int x, int y)
1301  : BC_CheckBox(x, y, client->config.loop_playback, _("Loop playback"))
1302 {
1303         this->client = client;
1304         this->window = window;
1305 }
1306 int TitleLoopPlayback::handle_event()
1307 {
1308         client->config.loop_playback = get_value();
1309         window->send_configure_change();
1310         return 1;
1311 }
1312
1313
1314 TitleCurPopup::TitleCurPopup(TitleMain *client, TitleWindow *window)
1315  : BC_PopupMenu(0, 0, 0, "", 0)
1316 {
1317         this->client = client;
1318         this->window = window;
1319 }
1320 int TitleCurPopup::handle_event()
1321 {
1322         return 1;
1323 }
1324
1325 void TitleCurSubMenu::add_subitemx(int popup_type, va_list ap, const char *fmt)
1326 {
1327         char item[BCSTRLEN];
1328         vsnprintf(item, sizeof(item)-1, fmt, ap);
1329         item[sizeof(item)-1] = 0;
1330         add_submenuitem(new TitleCurSubMenuItem(this, item, popup_type));
1331 }
1332
1333 void TitleCurPopup::create_objects()
1334 {
1335         TitleCurItem *cur_item;
1336         TitleCurSubMenu *sub_menu;
1337         char *item;
1338         add_item(cur_item = new TitleCurItem(this, item = _(KW_NUDGE)));
1339         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1340         sub_menu->add_subitem("%s dx,dy",item);
1341         sub_menu->add_subitem("/%s",item);
1342         add_item(cur_item = new TitleCurItem(this, item = _(KW_COLOR)));
1343         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1344         sub_menu->add_subitem(POPUP_COLOR,"%s %s",item,_("#"));
1345         sub_menu->add_subitem("%s ",item);
1346         sub_menu->add_subitem("/%s",item);
1347         add_item(cur_item = new TitleCurItem(this, item = _(KW_ALPHA)));
1348         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1349         sub_menu->add_subitem("%s ",item);
1350         sub_menu->add_subitem("%s 0.",item);
1351         sub_menu->add_subitem("%s .5",item);
1352         sub_menu->add_subitem("%s 1.",item);
1353         sub_menu->add_subitem("/%s",item);
1354         add_item(cur_item = new TitleCurItem(this, item = _(KW_FONT)));
1355         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1356         sub_menu->add_subitem(POPUP_FONT,"%s %s",item, _("name"));
1357         sub_menu->add_subitem(POPUP_OFFSET, "%s ",item);
1358         sub_menu->add_subitem("/%s",item);
1359         add_item(cur_item = new TitleCurItem(this, item = _(KW_SIZE)));
1360         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1361         sub_menu->add_subitem("%s +",item);
1362         sub_menu->add_subitem("%s -",item);
1363         sub_menu->add_subitem("%s ",item);
1364         sub_menu->add_subitem("/%s",item);
1365         add_item(cur_item = new TitleCurItem(this, item = _(KW_BOLD)));
1366         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1367         sub_menu->add_subitem("%s 1",item);
1368         sub_menu->add_subitem("%s 0",item);
1369         sub_menu->add_subitem("/%s",item);
1370         add_item(cur_item = new TitleCurItem(this, item = _(KW_ITALIC)));
1371         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1372         sub_menu->add_subitem("%s 1",item);
1373         sub_menu->add_subitem("%s 0",item);
1374         sub_menu->add_subitem("/%s",item);
1375         add_item(cur_item = new TitleCurItem(this, item = _(KW_CAPS)));
1376         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1377         sub_menu->add_subitem("%s 1",item);
1378         sub_menu->add_subitem("%s 0",item);
1379         sub_menu->add_subitem("%s -1",item);
1380         sub_menu->add_subitem("/%s",item);
1381         add_item(cur_item = new TitleCurItem(this, item = _(KW_UL)));
1382         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1383         sub_menu->add_subitem("%s 1",item);
1384         sub_menu->add_subitem("%s 0",item);
1385         sub_menu->add_subitem("/%s",item);
1386         add_item(cur_item = new TitleCurItem(this, item = _(KW_BLINK)));
1387         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1388         sub_menu->add_subitem("%s 1",item);
1389         sub_menu->add_subitem("%s -1",item);
1390         sub_menu->add_subitem("%s ",item);
1391         sub_menu->add_subitem("%s 0",item);
1392         sub_menu->add_subitem("/%s",item);
1393         add_item(cur_item = new TitleCurItem(this, item = _(KW_FIXED)));
1394         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1395         sub_menu->add_subitem("%s ",item);
1396         sub_menu->add_subitem("%s 20",item);
1397         sub_menu->add_subitem("%s 10",item);
1398         sub_menu->add_subitem("%s 0",item);
1399         sub_menu->add_subitem("/%s",item);
1400         add_item(cur_item = new TitleCurItem(this, item = _(KW_ALIAS)));
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_SUP)));
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 -1",item);
1410         sub_menu->add_subitem("/%s",item);
1411         add_item(cur_item = new TitleCurItem(this, item = _(KW_PNG)));
1412         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1413         sub_menu->add_subitem(POPUP_PNG,"%s %s", item, _("file"));
1414 }
1415
1416 TitleCurItem::TitleCurItem(TitleCurPopup *popup, const char *text)
1417  : BC_MenuItem(text)
1418 {
1419         this->popup = popup;
1420 }
1421 int TitleCurItem::handle_event()
1422 {
1423         return 1;
1424 }
1425
1426 TitleCurSubMenu::TitleCurSubMenu(TitleCurItem *cur_item)
1427 {
1428         this->cur_item = cur_item;
1429 }
1430 TitleCurSubMenu::~TitleCurSubMenu()
1431 {
1432 }
1433
1434 TitleCurSubMenuItem::TitleCurSubMenuItem(TitleCurSubMenu *submenu, const char *text, int popup_type)
1435  : BC_MenuItem(text)
1436 {
1437         this->submenu = submenu;
1438         this->popup_type = popup_type;
1439 }
1440 TitleCurSubMenuItem::~TitleCurSubMenuItem()
1441 {
1442 }
1443 int TitleCurSubMenuItem::handle_event()
1444 {
1445         TitleCurPopup *popup = submenu->cur_item->popup;
1446         TitleWindow *window = popup->window;
1447         const char *item_text = get_text();
1448         int ofs = *item_text == '/' ? 0 : -1;
1449         switch( popup_type ) {
1450         case POPUP_FONT: {
1451                 int px, py;
1452                 window->get_pop_cursor(px ,py);
1453                 window->fonts_popup->activate(px, py, xS(300),yS(200));
1454                 return 1; }
1455         case POPUP_COLOR: {
1456                 window->color_popup->activate();
1457                 return 1; }
1458         case POPUP_PNG: {
1459                 window->png_popup->activate();
1460                 return 1; }
1461         case POPUP_OFFSET:
1462                 ofs = -1;
1463                 break;
1464         }
1465         char txt[BCSTRLEN];
1466         sprintf(txt, "<%s>", item_text);
1467         return window->insert_ibeam(txt, ofs);
1468 }
1469
1470 TitleFontsPopup::TitleFontsPopup(TitleMain *client, TitleWindow *window)
1471  : BC_ListBox(-1, -1, 1, 1, LISTBOX_ICON_LIST,
1472         &window->fonts, 0, 0, 1, 0, 1)
1473 {
1474         this->client = client;
1475         this->window = window;
1476         set_use_button(0);
1477         set_show_query(1);
1478 }
1479 TitleFontsPopup::~TitleFontsPopup()
1480 {
1481 }
1482 int TitleFontsPopup::keypress_event()
1483 {
1484         switch( get_keypress() ) {
1485         case ESC:
1486         case DELETE:
1487                 deactivate();
1488                 return 1;
1489         default:
1490                 break;
1491         }
1492         return BC_ListBox::keypress_event();
1493 }
1494
1495 int TitleFontsPopup::handle_event()
1496 {
1497         deactivate();
1498         BC_ListBoxItem *item = get_selection(0, 0);
1499         if( !item ) return 1;
1500         const char *item_text = item->get_text();
1501         char txt[BCTEXTLEN];  sprintf(txt, "<%s %s>", _(KW_FONT), item_text);
1502         return window->insert_ibeam(txt);
1503 }
1504
1505 TitleColorPopup::TitleColorPopup(TitleMain *client, TitleWindow *window)
1506  : ColorPicker(0, _("Color"))
1507 {
1508         this->client = client;
1509         this->window = window;
1510         this->color_value = client->config.color;
1511 }
1512 TitleColorPopup::~TitleColorPopup()
1513 {
1514 }
1515 int TitleColorPopup::handle_new_color(int output, int alpha)
1516 {
1517         color_value = output;
1518         return 1;
1519 }
1520 int TitleColorPopup::activate()
1521 {
1522         start_window(client->config.color, 255, 1);
1523         return 1;
1524 }
1525 void TitleColorPopup::handle_done_event(int result)
1526 {
1527         if( !result ) {
1528                 char txt[BCSTRLEN];  sprintf(txt, "<%s #%06x>", _(KW_COLOR), color_value);
1529                 window->lock_window("TitleColorPopup::handle_done_event");
1530                 window->insert_ibeam(txt);
1531                 window->unlock_window();
1532         }
1533 }
1534
1535 TitlePngPopup::TitlePngPopup(TitleMain *client, TitleWindow *window)
1536  : BC_DialogThread()
1537 {
1538         this->client = client;
1539         this->window = window;
1540 }
1541
1542 TitlePngPopup::~TitlePngPopup()
1543 {
1544         close_window();
1545 }
1546
1547 void TitlePngPopup::handle_done_event(int result)
1548 {
1549         if( result ) return;
1550         BrowseButtonWindow *gui = (BrowseButtonWindow *)get_gui();
1551         const char *path = gui->get_submitted_path();
1552         char txt[BCTEXTLEN];  sprintf(txt, "<%s %s>", _(KW_PNG), path);
1553         window->lock_window("TitlePngPopup::handle_done_event");
1554         window->insert_ibeam(txt);
1555         window->unlock_window();
1556 }
1557
1558 BC_Window *TitlePngPopup::new_gui()
1559 {
1560         MWindow *mwindow = client->server->mwindow;
1561         int x, y;  mwindow->gui->get_abs_cursor(x, y);
1562
1563         BC_Window *gui = new BrowseButtonWindow(mwindow->theme,
1564                 x-xS(25), y-yS(100), window, "", _("Png file"), _("Png path"), 0);
1565         gui->create_objects();
1566         return gui;
1567 }
1568
1569 int TitlePngPopup::activate()
1570 {
1571         BC_DialogThread::start();
1572         return 1;
1573 }
1574