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