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