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