add BC_SCALE env var for hi def monitors, cleanup theme data
[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, 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(5), y2+margin, _("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         wchar_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(wchar_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         text->update(client->config.wtext ? &client->config.wtext[0] : L"");
586         speed->update(client->config.pixels_per_second);
587         outline->update((int64_t)client->config.outline_size);
588 #ifdef USE_STROKER
589         stroker->update((int64_t)client->config.stroke_width);
590 #endif
591         timecode->update(client->config.timecode);
592         timecode_format->update(client->config.timecode_format);
593         background->update(client->config.background);
594         background_path->update(client->config.background_path);
595         loop_playback->update((int64_t)client->config.loop_playback);
596
597         char string[BCTEXTLEN];
598         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
599                 if( timeunit_formats[i] == client->config.timecode_format ) {
600                         timecode_format->set_text(
601                                 Units::print_time_format(timeunit_formats[i], string));
602                         break;
603                 }
604         }
605         update_justification();
606         update_stats();
607         update_color();
608 }
609
610
611 TitleFontTumble::TitleFontTumble(TitleMain *client, TitleWindow *window, int x, int y)
612  : BC_Tumbler(x, y)
613 {
614         this->client = client;
615         this->window = window;
616 }
617 int TitleFontTumble::handle_up_event()
618 {
619         window->previous_font();
620         return 1;
621 }
622
623 int TitleFontTumble::handle_down_event()
624 {
625         window->next_font();
626         return 1;
627 }
628
629
630 TitleSizeTumble::TitleSizeTumble(TitleMain *client, TitleWindow *window, int x, int y)
631  : BC_Tumbler(x, y)
632 {
633         this->client = client;
634         this->window = window;
635 }
636
637 int TitleSizeTumble::handle_up_event()
638 {
639         int current_index = -1;
640         int current_difference = -1;
641         for( int i=0; i<window->sizes.size(); ++i ) {
642                 int size = atoi(window->sizes.get(i)->get_text());
643                 if( current_index < 0 ||
644                         abs(size - client->config.size) < current_difference ) {
645                         current_index = i;
646                         current_difference = abs(size - client->config.size);
647                 }
648         }
649
650         current_index++;
651         if( current_index >= window->sizes.size() ) current_index = 0;
652
653
654         client->config.size = atoi(window->sizes.get(current_index)->get_text());
655         window->size->update(client->config.size);
656         window->send_configure_change();
657         return 1;
658 }
659
660 int TitleSizeTumble::handle_down_event()
661 {
662         int current_index = -1;
663         int current_difference = -1;
664         for( int i=0; i<window->sizes.size(); ++i ) {
665                 int size = atoi(window->sizes.get(i)->get_text());
666                 if( current_index < 0 ||
667                         abs(size - client->config.size) < current_difference ) {
668                         current_index = i;
669                         current_difference = abs(size - client->config.size);
670                 }
671         }
672
673         current_index--;
674         if( current_index < 0 ) current_index = window->sizes.size() - 1;
675
676
677         client->config.size = atoi(window->sizes.get(current_index)->get_text());
678         window->size->update(client->config.size);
679         window->send_configure_change();
680         return 1;
681 }
682
683 TitleAlias::TitleAlias(TitleMain *client, TitleWindow *window, int x, int y)
684  : BC_CheckBox(x, y, client->config.style & FONT_ALIAS, _("Smooth"))
685 {
686         this->client = client;
687         this->window = window;
688 }
689
690 int TitleAlias::handle_event()
691 {
692         client->config.style =
693                 (client->config.style & ~FONT_ALIAS) |
694                         (get_value() ? FONT_ALIAS : 0);
695         window->send_configure_change();
696         return 1;
697 }
698
699 TitleBold::TitleBold(TitleMain *client, TitleWindow *window, int x, int y)
700  : BC_CheckBox(x, y, client->config.style & BC_FONT_BOLD, _("Bold"))
701 {
702         this->client = client;
703         this->window = window;
704 }
705
706 int TitleBold::handle_event()
707 {
708         client->config.style =
709                 (client->config.style & ~BC_FONT_BOLD) |
710                         (get_value() ? BC_FONT_BOLD : 0);
711         window->send_configure_change();
712         return 1;
713 }
714
715 TitleItalic::TitleItalic(TitleMain *client, TitleWindow *window, int x, int y)
716  : BC_CheckBox(x, y, client->config.style & BC_FONT_ITALIC, _("Italic"))
717 {
718         this->client = client;
719         this->window = window;
720 }
721 int TitleItalic::handle_event()
722 {
723         client->config.style =
724                 (client->config.style & ~BC_FONT_ITALIC) |
725                         (get_value() ? BC_FONT_ITALIC : 0);
726         window->send_configure_change();
727         return 1;
728 }
729
730
731
732 TitleSize::TitleSize(TitleMain *client, TitleWindow *window, int x, int y, char *text)
733  : BC_PopupTextBox(window, &window->sizes, text, x, y, xS(64), yS(300))
734 {
735         this->client = client;
736         this->window = window;
737 }
738 TitleSize::~TitleSize()
739 {
740 }
741 int TitleSize::handle_event()
742 {
743         client->config.size = atol(get_text());
744 //printf("TitleSize::handle_event 1 %s\n", get_text());
745         window->send_configure_change();
746         return 1;
747 }
748 void TitleSize::update(int size)
749 {
750         char string[BCTEXTLEN];
751         sprintf(string, "%d", size);
752         BC_PopupTextBox::update(string);
753 }
754
755 TitlePitch::
756 TitlePitch(TitleMain *client, TitleWindow *window, int x, int y, int *value)
757  : BC_TumbleTextBox(window, *value, 0, INT_MAX, x, y, xS(64))
758 {
759         this->client = client;
760         this->window = window;
761         this->value = value;
762 }
763
764 TitlePitch::
765 ~TitlePitch()
766 {
767 }
768
769 int TitlePitch::handle_event()
770 {
771         *value = atol(get_text());
772         window->send_configure_change();
773         return 1;
774 }
775
776 TitleColorButton::TitleColorButton(TitleMain *client, TitleWindow *window, int x, int y)
777  : ColorCircleButton(_("Text Color"), x, y, COLOR_W, COLOR_H,
778                 client->config.color, client->config.alpha, 1)
779 {
780         this->client = client;
781         this->window = window;
782 }
783 int TitleColorButton::handle_new_color(int output, int alpha)
784 {
785         client->config.color = output;
786         client->config.alpha = alpha;
787         window->send_configure_change();
788         return 1;
789 }
790 void TitleColorButton::handle_done_event(int result)
791 {
792         if( result ) {
793                 handle_new_color(orig_color, orig_alpha);
794                 window->lock_window("TitleColorButton::handle_done_event");
795                 update_gui(orig_color);
796                 window->unlock_window();
797         }
798 }
799
800 TitleOutlineColorButton::TitleOutlineColorButton(TitleMain *client, TitleWindow *window, int x, int y)
801  : ColorCircleButton(_("Outline Color"), x, y, COLOR_W, COLOR_H,
802                 client->config.outline_color, client->config.outline_alpha, 1)
803 {
804         this->client = client;
805         this->window = window;
806 }
807 int TitleOutlineColorButton::handle_new_color(int output, int alpha)
808 {
809         client->config.outline_color = output;
810         client->config.outline_alpha = alpha;
811         window->send_configure_change();
812         return 1;
813 }
814 void TitleOutlineColorButton::handle_done_event(int result)
815 {
816         if( result ) {
817                 handle_new_color(orig_color, orig_alpha);
818                 window->lock_window("TitleColorButton::handle_done_event");
819                 update_gui(orig_color);
820                 window->unlock_window();
821         }
822 }
823
824
825 TitleMotion::TitleMotion(TitleMain *client, TitleWindow *window, int x, int y)
826  : BC_PopupTextBox(window, &window->paths,
827                 client->motion_to_text(client->config.motion_strategy),
828                 x, y, xS(120), yS(100))
829 {
830         this->client = client;
831         this->window = window;
832 }
833 int TitleMotion::handle_event()
834 {
835         client->config.motion_strategy = client->text_to_motion(get_text());
836         window->send_configure_change();
837         return 1;
838 }
839
840 TitleLoop::TitleLoop(TitleMain *client, TitleWindow *window, int x, int y)
841  : BC_CheckBox(x, y, client->config.loop, _("Loop"))
842 {
843         this->client = client;
844         this->window = window;
845 }
846 int TitleLoop::handle_event()
847 {
848         client->config.loop = get_value();
849         window->send_configure_change();
850         return 1;
851 }
852 TitleTimecode::TitleTimecode(TitleMain *client, TitleWindow *window, int x, int y)
853  : BC_CheckBox(x, y, client->config.timecode, _("Stamp timecode"))
854 {
855         this->client = client;
856         this->window = window;
857 }
858 int TitleTimecode::handle_event()
859 {
860         client->config.timecode = get_value();
861         client->send_configure_change();
862         return 1;
863 }
864
865 TitleTimecodeFormat::TitleTimecodeFormat(TitleMain *client, TitleWindow *window,
866                 int x, int y, int tw, const char *text)
867  : BC_PopupMenu(x, y, BC_PopupMenu::calculate_w(tw)+xS(10), text, 1)
868 {
869         this->client = client;
870         this->window = window;
871 }
872
873 int TitleTimecodeFormat::handle_event()
874 {
875         client->config.timecode_format = Units::text_to_format(get_text());
876         window->send_configure_change();
877         return 1;
878 }
879
880 void TitleTimecodeFormat::create_objects()
881 {
882         char string[BCTEXTLEN];
883         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
884                 add_item(new BC_MenuItem(
885                         Units::print_time_format(timeunit_formats[i], string)));
886         }
887 }
888
889
890 int TitleTimecodeFormat::update(int timecode_format)
891 {
892         char string[BCTEXTLEN];
893         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
894                 if( timeunit_formats[i] == timecode_format ) {
895                         set_text(Units::print_time_format(timeunit_formats[i], string));
896                         break;
897                 }
898         }
899         return 0;
900 }
901
902 TitleFade::TitleFade(TitleMain *client, TitleWindow *window,
903         double *value, int x, int y)
904  : BC_TextBox(x, y, xS(80), 1, (float)*value)
905 {
906         this->client = client;
907         this->window = window;
908         this->value = value;
909         set_precision(2);
910 }
911
912 int TitleFade::handle_event()
913 {
914         *value = atof(get_text());
915         window->send_configure_change();
916         return 1;
917 }
918
919 void TitleWindow::check_style(const char *font_name, int update)
920 {
921         BC_FontEntry *font_nrm = TitleMain::get_font(font_name, 0);
922         BC_FontEntry *font_itl = TitleMain::get_font(font_name, BC_FONT_ITALIC);
923         BC_FontEntry *font_bld = TitleMain::get_font(font_name, BC_FONT_BOLD);
924         BC_FontEntry *font_bit = TitleMain::get_font(font_name, BC_FONT_ITALIC | BC_FONT_BOLD);
925         int has_norm = font_nrm != 0 ? 1 : 0;
926         int has_ital = font_itl != 0 || font_bit != 0 ? 1 : 0;
927         int has_bold = font_bld != 0 || font_bit != 0 ? 1 : 0;
928         if( bold->get_value() ) {
929                 if( !has_bold ) bold->update(0);
930         }
931         else {
932                 if( !has_norm && has_bold ) bold->update(1);
933         }
934         if( italic->get_value() ) {
935                 if( !has_ital ) italic->update(0);
936         }
937         else {
938                 if( !has_norm && has_ital ) italic->update(1);
939         }
940         if( has_norm && has_bold ) bold->enable();   else bold->disable();
941         if( has_norm && has_ital ) italic->enable(); else italic->disable();
942         if( update ) {
943                 int style = stroker && atof(stroker->get_text()) ? BC_FONT_OUTLINE : 0;
944                 if( bold->get_value() ) style |= BC_FONT_BOLD;
945                 if( italic->get_value() ) style |= BC_FONT_ITALIC;
946                 if( alias->get_value() ) style |= FONT_ALIAS;
947                 client->config.style = style;
948         }
949 }
950
951 TitleFont::TitleFont(TitleMain *client, TitleWindow *window, int x, int y)
952  : BC_PopupTextBox(window, &window->fonts, client->config.font,
953                 x, y, xS(340), yS(300), LISTBOX_ICON_LIST)
954 {
955         this->client = client;
956         this->window = window;
957 }
958 int TitleFont::handle_event()
959 {
960         strcpy(client->config.font, get_text());
961         window->check_style(client->config.font, 1);
962         window->send_configure_change();
963         return 1;
964 }
965
966 TitleText::TitleText(TitleMain *client, TitleWindow *window,
967         int x, int y, int w, int h)
968  : BC_ScrollTextBox(window, x, y, w,
969                 BC_TextBox::pixels_to_rows(window, MEDIUMFONT, h),
970                 client->config.wtext, 0)
971 {
972         this->client = client;
973         this->window = window;
974 //printf("TitleText::TitleText %s\n", client->config.text);
975 }
976
977 int TitleText::button_press_event()
978 {
979         if( get_buttonpress() == 3 ) {
980                 window->cur_ibeam = get_ibeam_letter();
981                 window->cur_popup->activate_menu();
982                 return 1;
983         }
984         return BC_ScrollTextBox::button_press_event();
985 }
986
987 int TitleText::handle_event()
988 {
989         window->fonts_popup->deactivate();
990         const wchar_t *wtext = get_wtext();
991         long wlen = wcslen(wtext);
992         client->config.demand(wlen);
993         wcsncpy(client->config.wtext, wtext, client->config.wsize);
994         client->config.wlen = wlen;
995         window->update_stats();
996         window->send_configure_change();
997         return 1;
998 }
999 TitleTextChars::TitleTextChars(int x, int y, int w)
1000  : BC_Title(x, y, "", MEDIUMFONT, -1, 0, w)
1001 {
1002 }
1003 TitleTextChars::~TitleTextChars()
1004 {
1005 }
1006 int TitleTextChars::update(int n)
1007 {
1008         char text[BCSTRLEN];
1009         sprintf(text, _("chars: %d  "),n);
1010         return BC_Title::update(text, 0);
1011 }
1012
1013
1014 TitleDropShadow::TitleDropShadow(TitleMain *client, TitleWindow *window, int x, int y)
1015  : BC_TumbleTextBox(window, client->config.dropshadow,
1016                 -1000, 1000, x, y, xS(70))
1017 {
1018         this->client = client;
1019         this->window = window;
1020 }
1021 int TitleDropShadow::handle_event()
1022 {
1023         client->config.dropshadow = atol(get_text());
1024         window->send_configure_change();
1025         return 1;
1026 }
1027
1028
1029 TitleOutline::TitleOutline(TitleMain *client, TitleWindow *window, int x, int y)
1030  : BC_TumbleTextBox(window, client->config.outline_size,
1031                 0.f, 1000.f, x, y, xS(70))
1032 {
1033         this->client = client;
1034         this->window = window;
1035         set_precision(1);
1036 }
1037 int TitleOutline::handle_event()
1038 {
1039         client->config.outline_size = atof(get_text());
1040         window->send_configure_change();
1041         return 1;
1042 }
1043
1044
1045 TitleStroker::TitleStroker(TitleMain *client, TitleWindow *window, int x, int y)
1046  : BC_TumbleTextBox(window, client->config.stroke_width,
1047                 0.f, 1000.f, x, y, xS(70))
1048 {
1049         this->client = client;
1050         this->window = window;
1051         set_precision(1);
1052 }
1053 int TitleStroker::handle_event()
1054 {
1055         client->config.stroke_width = atof(get_text());
1056         if( client->config.stroke_width )
1057                 client->config.style |= BC_FONT_OUTLINE;
1058         else
1059                 client->config.style &= ~BC_FONT_OUTLINE;
1060         window->send_configure_change();
1061         return 1;
1062 }
1063
1064
1065 TitleX::TitleX(TitleMain *client, TitleWindow *window, int x, int y)
1066  : BC_TumbleTextBox(window, client->config.title_x,
1067                 -32767.f, 32767.f, x, y, xS(50))
1068 {
1069         this->client = client;
1070         this->window = window;
1071         set_precision(1);
1072 }
1073 int TitleX::handle_event()
1074 {
1075         client->config.title_x = atof(get_text());
1076         window->update_drag();
1077         return 1;
1078 }
1079
1080 TitleY::TitleY(TitleMain *client, TitleWindow *window, int x, int y)
1081  : BC_TumbleTextBox(window, client->config.title_y,
1082                 -32767.f, 32767.f, x, y, xS(50))
1083 {
1084         this->client = client;
1085         this->window = window;
1086         set_precision(1);
1087 }
1088 int TitleY::handle_event()
1089 {
1090         client->config.title_y = atof(get_text());
1091         window->update_drag();
1092         return 1;
1093 }
1094
1095 TitleW::TitleW(TitleMain *client, TitleWindow *window, int x, int y)
1096  : BC_TumbleTextBox(window, client->config.title_w,
1097                 0, 32767, x, y, xS(50))
1098 {
1099         this->client = client;
1100         this->window = window;
1101 }
1102 int TitleW::handle_event()
1103 {
1104         client->config.title_w = atol(get_text());
1105         window->update_drag();
1106         return 1;
1107 }
1108
1109 TitleH::TitleH(TitleMain *client, TitleWindow *window, int x, int y)
1110  : BC_TumbleTextBox(window, client->config.title_h,
1111                 0, 32767, x, y, xS(50))
1112 {
1113         this->client = client;
1114         this->window = window;
1115 }
1116 int TitleH::handle_event()
1117 {
1118         client->config.title_h = atol(get_text());
1119         window->update_drag();
1120         return 1;
1121 }
1122
1123 TitleSpeed::TitleSpeed(TitleMain *client, TitleWindow *window, int x, int y)
1124  : BC_TumbleTextBox(window, client->config.pixels_per_second,
1125                 0.f, 1000.f, x, y, xS(100))
1126 {
1127         this->client = client;
1128         this->window = window;
1129         set_precision(2);
1130         set_increment(10);
1131 }
1132
1133
1134 int TitleSpeed::handle_event()
1135 {
1136         client->config.pixels_per_second = atof(get_text());
1137         window->send_configure_change();
1138         return 1;
1139 }
1140
1141
1142 TitleLeft::TitleLeft(TitleMain *client, TitleWindow *window, int x, int y)
1143  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_LEFT, _("Left"))
1144 {
1145         this->client = client;
1146         this->window = window;
1147 }
1148 int TitleLeft::handle_event()
1149 {
1150         client->config.hjustification = JUSTIFY_LEFT;
1151         window->update_justification();
1152         window->send_configure_change();
1153         return 1;
1154 }
1155
1156 TitleCenter::TitleCenter(TitleMain *client, TitleWindow *window, int x, int y)
1157  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_CENTER, _("Center"))
1158 {
1159         this->client = client;
1160         this->window = window;
1161 }
1162 int TitleCenter::handle_event()
1163 {
1164         client->config.hjustification = JUSTIFY_CENTER;
1165         window->update_justification();
1166         window->send_configure_change();
1167         return 1;
1168 }
1169
1170 TitleRight::TitleRight(TitleMain *client, TitleWindow *window, int x, int y)
1171  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_RIGHT, _("Right"))
1172 {
1173         this->client = client;
1174         this->window = window;
1175 }
1176 int TitleRight::handle_event()
1177 {
1178         client->config.hjustification = JUSTIFY_RIGHT;
1179         window->update_justification();
1180         window->send_configure_change();
1181         return 1;
1182 }
1183
1184
1185
1186 TitleTop::TitleTop(TitleMain *client, TitleWindow *window, int x, int y)
1187  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_TOP, _("Top"))
1188 {
1189         this->client = client;
1190         this->window = window;
1191 }
1192 int TitleTop::handle_event()
1193 {
1194         client->config.vjustification = JUSTIFY_TOP;
1195         window->update_justification();
1196         window->send_configure_change();
1197         return 1;
1198 }
1199
1200 TitleMid::TitleMid(TitleMain *client, TitleWindow *window, int x, int y)
1201  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_MID, _("Mid"))
1202 {
1203         this->client = client;
1204         this->window = window;
1205 }
1206 int TitleMid::handle_event()
1207 {
1208         client->config.vjustification = JUSTIFY_MID;
1209         window->update_justification();
1210         window->send_configure_change();
1211         return 1;
1212 }
1213
1214 TitleBottom::TitleBottom(TitleMain *client, TitleWindow *window, int x, int y)
1215  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_BOTTOM, _("Bottom"))
1216 {
1217         this->client = client;
1218         this->window = window;
1219 }
1220 int TitleBottom::handle_event()
1221 {
1222         client->config.vjustification = JUSTIFY_BOTTOM;
1223         window->update_justification();
1224         window->send_configure_change();
1225         return 1;
1226 }
1227
1228 TitleDrag::TitleDrag(TitleMain *client, TitleWindow *window, int x, int y)
1229  : DragCheckBox(client->server->mwindow, x, y, _("Drag"), &client->config.drag,
1230                 client->config.title_x, client->config.title_y,
1231                 client->config.title_w, client->config.title_h)
1232 {
1233         this->client = client;
1234         this->window = window;
1235 }
1236
1237 Track *TitleDrag::get_drag_track()
1238 {
1239         return !client->server->plugin ? 0 :
1240                 client->server->plugin->track;
1241 }
1242 int64_t TitleDrag::get_drag_position()
1243 {
1244         return client->get_source_position();
1245 }
1246
1247 void TitleDrag::update_gui()
1248 {
1249         client->config.drag = get_value();
1250         client->config.title_x = drag_x;
1251         client->config.title_y = drag_y;
1252         client->config.title_w = drag_w+0.5;
1253         client->config.title_h = drag_h+0.5;
1254         window->title_x->update((float)client->config.title_x);
1255         window->title_y->update((float)client->config.title_y);
1256         window->title_w->update((int64_t)client->config.title_w);
1257         window->title_h->update((int64_t)client->config.title_h);
1258         window->send_configure_change();
1259 }
1260
1261 int TitleDrag::handle_event()
1262 {
1263         int ret = DragCheckBox::handle_event();
1264         window->send_configure_change();
1265         return ret;
1266 }
1267
1268 TitleBackground::TitleBackground(TitleMain *client, TitleWindow *window, int x, int y)
1269  : BC_CheckBox(x, y, client->config.background, _("Background:"))
1270 {
1271         this->client = client;
1272         this->window = window;
1273 }
1274
1275 int TitleBackground::handle_event()
1276 {
1277         client->config.background = get_value();
1278         window->send_configure_change();
1279         return 1;
1280 }
1281
1282 TitleBackgroundPath::TitleBackgroundPath(TitleMain *client, TitleWindow *window, int x, int y)
1283  : BC_TextBox(x, y, xS(240), 1, client->config.background_path)
1284 {
1285         this->client = client;
1286         this->window = window;
1287 }
1288
1289 int TitleBackgroundPath::handle_event()
1290 {
1291         strncpy(client->config.background_path, get_text(), sizeof(client->config.background_path));
1292         window->send_configure_change();
1293         return 1;
1294 }
1295
1296 TitleLoopPlayback::TitleLoopPlayback(TitleMain *client, TitleWindow *window, int x, int y)
1297  : BC_CheckBox(x, y, client->config.loop_playback, _("Loop playback"))
1298 {
1299         this->client = client;
1300         this->window = window;
1301 }
1302 int TitleLoopPlayback::handle_event()
1303 {
1304         client->config.loop_playback = get_value();
1305         window->send_configure_change();
1306         return 1;
1307 }
1308
1309
1310 TitleCurPopup::TitleCurPopup(TitleMain *client, TitleWindow *window)
1311  : BC_PopupMenu(0, 0, 0, "", 0)
1312 {
1313         this->client = client;
1314         this->window = window;
1315 }
1316 int TitleCurPopup::handle_event()
1317 {
1318         return 1;
1319 }
1320
1321 void TitleCurSubMenu::add_subitemx(int popup_type, va_list ap, const char *fmt)
1322 {
1323         char item[BCSTRLEN];
1324         vsnprintf(item, sizeof(item)-1, fmt, ap);
1325         item[sizeof(item)-1] = 0;
1326         add_submenuitem(new TitleCurSubMenuItem(this, item, popup_type));
1327 }
1328
1329 void TitleCurPopup::create_objects()
1330 {
1331         TitleCurItem *cur_item;
1332         TitleCurSubMenu *sub_menu;
1333         char *item;
1334         add_item(cur_item = new TitleCurItem(this, item = _(KW_NUDGE)));
1335         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1336         sub_menu->add_subitem("%s dx,dy",item);
1337         sub_menu->add_subitem("/%s",item);
1338         add_item(cur_item = new TitleCurItem(this, item = _(KW_COLOR)));
1339         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1340         sub_menu->add_subitem(POPUP_COLOR,"%s %s",item,_("#"));
1341         sub_menu->add_subitem("%s ",item);
1342         sub_menu->add_subitem("/%s",item);
1343         add_item(cur_item = new TitleCurItem(this, item = _(KW_ALPHA)));
1344         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1345         sub_menu->add_subitem("%s ",item);
1346         sub_menu->add_subitem("%s 0.",item);
1347         sub_menu->add_subitem("%s .5",item);
1348         sub_menu->add_subitem("%s 1.",item);
1349         sub_menu->add_subitem("/%s",item);
1350         add_item(cur_item = new TitleCurItem(this, item = _(KW_FONT)));
1351         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1352         sub_menu->add_subitem(POPUP_FONT,"%s %s",item, _("name"));
1353         sub_menu->add_subitem(POPUP_OFFSET, "%s ",item);
1354         sub_menu->add_subitem("/%s",item);
1355         add_item(cur_item = new TitleCurItem(this, item = _(KW_SIZE)));
1356         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1357         sub_menu->add_subitem("%s +",item);
1358         sub_menu->add_subitem("%s -",item);
1359         sub_menu->add_subitem("%s ",item);
1360         sub_menu->add_subitem("/%s",item);
1361         add_item(cur_item = new TitleCurItem(this, item = _(KW_BOLD)));
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_ITALIC)));
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",item);
1371         add_item(cur_item = new TitleCurItem(this, item = _(KW_CAPS)));
1372         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1373         sub_menu->add_subitem("%s 1",item);
1374         sub_menu->add_subitem("%s 0",item);
1375         sub_menu->add_subitem("%s -1",item);
1376         sub_menu->add_subitem("/%s",item);
1377         add_item(cur_item = new TitleCurItem(this, item = _(KW_UL)));
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 0",item);
1381         sub_menu->add_subitem("/%s",item);
1382         add_item(cur_item = new TitleCurItem(this, item = _(KW_BLINK)));
1383         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1384         sub_menu->add_subitem("%s 1",item);
1385         sub_menu->add_subitem("%s -1",item);
1386         sub_menu->add_subitem("%s ",item);
1387         sub_menu->add_subitem("%s 0",item);
1388         sub_menu->add_subitem("/%s",item);
1389         add_item(cur_item = new TitleCurItem(this, item = _(KW_FIXED)));
1390         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1391         sub_menu->add_subitem("%s ",item);
1392         sub_menu->add_subitem("%s 20",item);
1393         sub_menu->add_subitem("%s 10",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_ALIAS)));
1397         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1398         sub_menu->add_subitem("%s 1",item);
1399         sub_menu->add_subitem("%s 0",item);
1400         sub_menu->add_subitem("/%s",item);
1401         add_item(cur_item = new TitleCurItem(this, item = _(KW_SUP)));
1402         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1403         sub_menu->add_subitem("%s 1",item);
1404         sub_menu->add_subitem("%s 0",item);
1405         sub_menu->add_subitem("%s -1",item);
1406         sub_menu->add_subitem("/%s",item);
1407         add_item(cur_item = new TitleCurItem(this, item = _(KW_PNG)));
1408         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1409         sub_menu->add_subitem(POPUP_PNG,"%s %s", item, _("file"));
1410 }
1411
1412 TitleCurItem::TitleCurItem(TitleCurPopup *popup, const char *text)
1413  : BC_MenuItem(text)
1414 {
1415         this->popup = popup;
1416 }
1417 int TitleCurItem::handle_event()
1418 {
1419         return 1;
1420 }
1421
1422 TitleCurSubMenu::TitleCurSubMenu(TitleCurItem *cur_item)
1423 {
1424         this->cur_item = cur_item;
1425 }
1426 TitleCurSubMenu::~TitleCurSubMenu()
1427 {
1428 }
1429
1430 TitleCurSubMenuItem::TitleCurSubMenuItem(TitleCurSubMenu *submenu, const char *text, int popup_type)
1431  : BC_MenuItem(text)
1432 {
1433         this->submenu = submenu;
1434         this->popup_type = popup_type;
1435 }
1436 TitleCurSubMenuItem::~TitleCurSubMenuItem()
1437 {
1438 }
1439 int TitleCurSubMenuItem::handle_event()
1440 {
1441         TitleCurPopup *popup = submenu->cur_item->popup;
1442         TitleWindow *window = popup->window;
1443         const char *item_text = get_text();
1444         int ofs = *item_text == '/' ? 0 : -1;
1445         switch( popup_type ) {
1446         case POPUP_FONT: {
1447                 int px, py;
1448                 window->get_pop_cursor(px ,py);
1449                 window->fonts_popup->activate(px, py, xS(300),yS(200));
1450                 return 1; }
1451         case POPUP_COLOR: {
1452                 window->color_popup->activate();
1453                 return 1; }
1454         case POPUP_PNG: {
1455                 window->png_popup->activate();
1456                 return 1; }
1457         case POPUP_OFFSET:
1458                 ofs = -1;
1459                 break;
1460         }
1461         char txt[BCSTRLEN];
1462         sprintf(txt, "<%s>", item_text);
1463         return window->insert_ibeam(txt, ofs);
1464 }
1465
1466 TitleFontsPopup::TitleFontsPopup(TitleMain *client, TitleWindow *window)
1467  : BC_ListBox(-1, -1, 1, 1, LISTBOX_ICON_LIST,
1468         &window->fonts, 0, 0, 1, 0, 1)
1469 {
1470         this->client = client;
1471         this->window = window;
1472         set_use_button(0);
1473         set_show_query(1);
1474 }
1475 TitleFontsPopup::~TitleFontsPopup()
1476 {
1477 }
1478 int TitleFontsPopup::keypress_event()
1479 {
1480         switch( get_keypress() ) {
1481         case ESC:
1482         case DELETE:
1483                 deactivate();
1484                 return 1;
1485         default:
1486                 break;
1487         }
1488         return BC_ListBox::keypress_event();
1489 }
1490
1491 int TitleFontsPopup::handle_event()
1492 {
1493         deactivate();
1494         BC_ListBoxItem *item = get_selection(0, 0);
1495         if( !item ) return 1;
1496         const char *item_text = item->get_text();
1497         char txt[BCTEXTLEN];  sprintf(txt, "<%s %s>", _(KW_FONT), item_text);
1498         return window->insert_ibeam(txt);
1499 }
1500
1501 TitleColorPopup::TitleColorPopup(TitleMain *client, TitleWindow *window)
1502  : ColorPicker(0, _("Color"))
1503 {
1504         this->client = client;
1505         this->window = window;
1506         this->color_value = client->config.color;
1507 }
1508 TitleColorPopup::~TitleColorPopup()
1509 {
1510 }
1511 int TitleColorPopup::handle_new_color(int output, int alpha)
1512 {
1513         color_value = output;
1514         return 1;
1515 }
1516 int TitleColorPopup::activate()
1517 {
1518         start_window(client->config.color, 255, 1);
1519         return 1;
1520 }
1521 void TitleColorPopup::handle_done_event(int result)
1522 {
1523         if( !result ) {
1524                 char txt[BCSTRLEN];  sprintf(txt, "<%s #%06x>", _(KW_COLOR), color_value);
1525                 window->lock_window("TitleColorPopup::handle_done_event");
1526                 window->insert_ibeam(txt);
1527                 window->unlock_window();
1528         }
1529 }
1530
1531 TitlePngPopup::TitlePngPopup(TitleMain *client, TitleWindow *window)
1532  : BC_DialogThread()
1533 {
1534         this->client = client;
1535         this->window = window;
1536 }
1537
1538 TitlePngPopup::~TitlePngPopup()
1539 {
1540         close_window();
1541 }
1542
1543 void TitlePngPopup::handle_done_event(int result)
1544 {
1545         if( result ) return;
1546         BrowseButtonWindow *gui = (BrowseButtonWindow *)get_gui();
1547         const char *path = gui->get_submitted_path();
1548         char txt[BCSTRLEN];  sprintf(txt, "<%s %s>", _(KW_PNG), path);
1549         window->lock_window("TitlePngPopup::handle_done_event");
1550         window->insert_ibeam(txt);
1551         window->unlock_window();
1552 }
1553
1554 BC_Window *TitlePngPopup::new_gui()
1555 {
1556         MWindow *mwindow = client->server->mwindow;
1557         int x, y;  mwindow->gui->get_abs_cursor(x, y);
1558
1559         BC_Window *gui = new BrowseButtonWindow(mwindow->theme,
1560                 x-xS(25), y-yS(100), window, "", _("Png file"), _("Png path"), 0);
1561         gui->create_objects();
1562         return gui;
1563 }
1564
1565 int TitlePngPopup::activate()
1566 {
1567         BC_DialogThread::start();
1568         return 1;
1569 }
1570