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