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