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