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