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