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