d44140607b00556445ca58ebc54aac3933502b4d
[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-16 - strlen(text->get_text());
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 len =  sizeof(client->config.wtext) / sizeof(wchar_t);
1068         wcsncpy(client->config.wtext, get_wtext(), len);
1069         client->config.wtext[len-1] = 0;
1070         client->config.wlen = wcslen(client->config.wtext);
1071         window->update_stats();
1072         client->send_configure_change();
1073         return 1;
1074 }
1075 TitleTextChars::TitleTextChars(int x, int y, int w)
1076  : BC_Title(x, y, "", MEDIUMFONT, -1, 0, w)
1077 {
1078 }
1079 TitleTextChars::~TitleTextChars()
1080 {
1081 }
1082 int TitleTextChars::update(int n)
1083 {
1084         char text[BCSTRLEN];
1085         sprintf(text, _("chars: %d  "),n);
1086         return BC_Title::update(text, 0);
1087 }
1088
1089 TitleTextBfrSz::TitleTextBfrSz(int x, int y, int w)
1090  : BC_Title(x, y, "", MEDIUMFONT, -1, 0, w)
1091 {
1092 }
1093 TitleTextBfrSz::~TitleTextBfrSz()
1094 {
1095 }
1096 int TitleTextBfrSz::update(int n)
1097 {
1098         char text[BCSTRLEN];
1099         sprintf(text, _("bfrsz: %d  "),n);
1100         return BC_Title::update(text, 0);
1101 }
1102
1103
1104 TitleDropShadow::TitleDropShadow(TitleMain *client, TitleWindow *window, int x, int y)
1105  : BC_TumbleTextBox(window, (int64_t)client->config.dropshadow,
1106         (int64_t)-1000, (int64_t)1000, x, y, 70)
1107 {
1108         this->client = client;
1109         this->window = window;
1110 }
1111 int TitleDropShadow::handle_event()
1112 {
1113         client->config.dropshadow = atol(get_text());
1114         client->send_configure_change();
1115         return 1;
1116 }
1117
1118
1119 TitleOutline::TitleOutline(TitleMain *client, TitleWindow *window, int x, int y)
1120  : BC_TumbleTextBox(window, (int64_t)client->config.outline_size,
1121         (int64_t)0, (int64_t)1000, x, y, 70)
1122 {
1123         this->client = client;
1124         this->window = window;
1125 }
1126 int TitleOutline::handle_event()
1127 {
1128         client->config.outline_size = atol(get_text());
1129         client->send_configure_change();
1130         return 1;
1131 }
1132
1133
1134 TitleStroker::TitleStroker(TitleMain *client, TitleWindow *window, int x, int y)
1135  : BC_TumbleTextBox(window, (int64_t)client->config.stroke_width,
1136         (int64_t)0, (int64_t)1000, x, y, 70)
1137 {
1138         this->client = client;
1139         this->window = window;
1140 }
1141 int TitleStroker::handle_event()
1142 {
1143         client->config.stroke_width = atof(get_text());
1144         if( client->config.stroke_width )
1145                 client->config.style |= BC_FONT_OUTLINE;
1146         else
1147                 client->config.style &= ~BC_FONT_OUTLINE;
1148         client->send_configure_change();
1149         return 1;
1150 }
1151
1152
1153 TitleX::TitleX(TitleMain *client, TitleWindow *window, int x, int y)
1154  : BC_TumbleTextBox(window, (int64_t)client->config.title_x,
1155         (int64_t)-32767, (int64_t)32767, x, y, 50)
1156 {
1157         this->client = client;
1158         this->window = window;
1159 }
1160 int TitleX::handle_event()
1161 {
1162         client->config.title_x = atol(get_text());
1163         client->send_configure_change();
1164         return 1;
1165 }
1166
1167 TitleY::TitleY(TitleMain *client, TitleWindow *window, int x, int y)
1168  : BC_TumbleTextBox(window, (int64_t)client->config.title_y,
1169         (int64_t)-32767, (int64_t)32767, x, y, 50)
1170 {
1171         this->client = client;
1172         this->window = window;
1173 }
1174 int TitleY::handle_event()
1175 {
1176         client->config.title_y = atol(get_text());
1177         client->send_configure_change();
1178         return 1;
1179 }
1180
1181 TitleW::TitleW(TitleMain *client, TitleWindow *window, int x, int y)
1182  : BC_TumbleTextBox(window, (int64_t)client->config.title_w,
1183         (int64_t)0, (int64_t)32767, x, y, 50)
1184 {
1185         this->client = client;
1186         this->window = window;
1187 }
1188 int TitleW::handle_event()
1189 {
1190         client->config.title_w = atol(get_text());
1191         client->send_configure_change();
1192         return 1;
1193 }
1194
1195 TitleH::TitleH(TitleMain *client, TitleWindow *window, int x, int y)
1196  : BC_TumbleTextBox(window, (int64_t)client->config.title_h,
1197         (int64_t)0, (int64_t)32767, x, y, 50)
1198 {
1199         this->client = client;
1200         this->window = window;
1201 }
1202 int TitleH::handle_event()
1203 {
1204         client->config.title_h = atol(get_text());
1205         client->send_configure_change();
1206         return 1;
1207 }
1208
1209 TitleSpeed::TitleSpeed(TitleMain *client, TitleWindow *window, int x, int y)
1210  : BC_TumbleTextBox(window, (float)client->config.pixels_per_second,
1211         (float)0, (float)1000, x, y, 100)
1212 {
1213         this->client = client;
1214         set_precision(2);
1215         set_increment(10);
1216 }
1217
1218
1219 int TitleSpeed::handle_event()
1220 {
1221         client->config.pixels_per_second = atof(get_text());
1222         client->send_configure_change();
1223         return 1;
1224 }
1225
1226
1227 TitleLeft::TitleLeft(TitleMain *client, TitleWindow *window, int x, int y)
1228  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_LEFT, _("Left"))
1229 {
1230         this->client = client;
1231         this->window = window;
1232 }
1233 int TitleLeft::handle_event()
1234 {
1235         client->config.hjustification = JUSTIFY_LEFT;
1236         window->update_justification();
1237         client->send_configure_change();
1238         return 1;
1239 }
1240
1241 TitleCenter::TitleCenter(TitleMain *client, TitleWindow *window, int x, int y)
1242  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_CENTER, _("Center"))
1243 {
1244         this->client = client;
1245         this->window = window;
1246 }
1247 int TitleCenter::handle_event()
1248 {
1249         client->config.hjustification = JUSTIFY_CENTER;
1250         window->update_justification();
1251         client->send_configure_change();
1252         return 1;
1253 }
1254
1255 TitleRight::TitleRight(TitleMain *client, TitleWindow *window, int x, int y)
1256  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_RIGHT, _("Right"))
1257 {
1258         this->client = client;
1259         this->window = window;
1260 }
1261 int TitleRight::handle_event()
1262 {
1263         client->config.hjustification = JUSTIFY_RIGHT;
1264         window->update_justification();
1265         client->send_configure_change();
1266         return 1;
1267 }
1268
1269
1270
1271 TitleTop::TitleTop(TitleMain *client, TitleWindow *window, int x, int y)
1272  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_TOP, _("Top"))
1273 {
1274         this->client = client;
1275         this->window = window;
1276 }
1277 int TitleTop::handle_event()
1278 {
1279         client->config.vjustification = JUSTIFY_TOP;
1280         window->update_justification();
1281         client->send_configure_change();
1282         return 1;
1283 }
1284
1285 TitleMid::TitleMid(TitleMain *client, TitleWindow *window, int x, int y)
1286  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_MID, _("Mid"))
1287 {
1288         this->client = client;
1289         this->window = window;
1290 }
1291 int TitleMid::handle_event()
1292 {
1293         client->config.vjustification = JUSTIFY_MID;
1294         window->update_justification();
1295         client->send_configure_change();
1296         return 1;
1297 }
1298
1299 TitleBottom::TitleBottom(TitleMain *client, TitleWindow *window, int x, int y)
1300  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_BOTTOM, _("Bottom"))
1301 {
1302         this->client = client;
1303         this->window = window;
1304 }
1305 int TitleBottom::handle_event()
1306 {
1307         client->config.vjustification = JUSTIFY_BOTTOM;
1308         window->update_justification();
1309         client->send_configure_change();
1310         return 1;
1311 }
1312
1313
1314
1315 TitleColorThread::TitleColorThread(TitleMain *client, TitleWindow *window, int is_outline)
1316  : ColorPicker(1, is_outline? _("Outline Color") : _("Text Color"))
1317 {
1318         this->client = client;
1319         this->window = window;
1320         this->is_outline = is_outline;
1321 }
1322
1323 int TitleColorThread::handle_new_color(int output, int alpha)
1324 {
1325         if( is_outline ) {
1326                 client->config.outline_color = output;
1327                 client->config.outline_alpha = alpha;
1328         }
1329         else {
1330                 client->config.color = output;
1331                 client->config.alpha = alpha;
1332         }
1333
1334         window->lock_window("TitleColorThread::handle_new_color");
1335         window->update_color();
1336         window->flush();
1337         window->unlock_window();
1338
1339         client->send_configure_change();
1340         return 1;
1341 }
1342
1343 TitleDrag::TitleDrag(TitleMain *client, TitleWindow *window, int x, int y)
1344  : BC_CheckBox(x, y, client->config.drag, _("Drag"))
1345 {
1346         this->client = client;
1347         this->window = window;
1348 }
1349
1350 int TitleDrag::handle_event()
1351 {
1352         int value = get_value();
1353         client->config.drag = value;
1354         if( value )
1355                 window->grab(client->server->mwindow->cwindow->gui);
1356         else
1357                 window->ungrab(client->server->mwindow->cwindow->gui);
1358         client->send_configure_change();
1359         return 1;
1360 }
1361
1362 TitleBackground::TitleBackground(TitleMain *client, TitleWindow *window, int x, int y)
1363  : BC_CheckBox(x, y, client->config.background, _("Background:"))
1364 {
1365         this->client = client;
1366         this->window = window;
1367 }
1368
1369 int TitleBackground::handle_event()
1370 {
1371         client->config.background = get_value();
1372         client->send_configure_change();
1373         return 1;
1374 }
1375
1376 TitleBackgroundPath::TitleBackgroundPath(TitleMain *client, TitleWindow *window, int x, int y)
1377  : BC_TextBox(x, y, 240, 1, client->config.background_path)
1378 {
1379         this->client = client;
1380         this->window = window;
1381 }
1382
1383 int TitleBackgroundPath::handle_event()
1384 {
1385         strncpy(client->config.background_path, get_text(), sizeof(client->config.background_path));
1386         client->send_configure_change();
1387         return 1;
1388 }
1389
1390 TitleLoopPlayback::TitleLoopPlayback(TitleMain *client, int x, int y)
1391  : BC_CheckBox(x, y, client->config.loop_playback, _("Loop playback"))
1392 {
1393         this->client = client;
1394 }
1395 int TitleLoopPlayback::handle_event()
1396 {
1397         client->config.loop_playback = get_value();
1398         client->send_configure_change();
1399         return 1;
1400 }
1401
1402
1403 TitleCurPopup::TitleCurPopup(TitleMain *client, TitleWindow *window)
1404  : BC_PopupMenu(0, 0, 0, "", 0)
1405 {
1406         this->client = client;
1407         this->window = window;
1408 }
1409 int TitleCurPopup::handle_event()
1410 {
1411         return 1;
1412 }
1413
1414 void TitleCurSubMenu::add_subitem(int popup_type, va_list ap, const char *fmt)
1415 {
1416         char item[BCSTRLEN];
1417         vsnprintf(item, sizeof(item)-1, fmt, ap);
1418         item[sizeof(item)-1] = 0;
1419         add_submenuitem(new TitleCurSubMenuItem(this, item, popup_type));
1420 }
1421
1422 void TitleCurPopup::create_objects()
1423 {
1424         TitleCurItem *cur_item;
1425         TitleCurSubMenu *sub_menu;
1426         char *item;
1427         add_item(cur_item = new TitleCurItem(this, item = KW_NUDGE));
1428         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1429         sub_menu->add_subitem("%s dx,dy",item);
1430         sub_menu->add_subitem("/%s",item);
1431         add_item(cur_item = new TitleCurItem(this, item = KW_COLOR));
1432         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1433         sub_menu->add_subitem(POPUP_COLOR,"%s %s",item,_("#"));
1434         sub_menu->add_subitem("%s ",item);
1435         sub_menu->add_subitem("/%s",item);
1436         add_item(cur_item = new TitleCurItem(this, item = KW_ALPHA));
1437         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1438         sub_menu->add_subitem("%s ",item);
1439         sub_menu->add_subitem("%s 0.",item);
1440         sub_menu->add_subitem("%s .5",item);
1441         sub_menu->add_subitem("%s 1.",item);
1442         sub_menu->add_subitem("/%s",item);
1443         add_item(cur_item = new TitleCurItem(this, item = KW_FONT));
1444         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1445         sub_menu->add_subitem(POPUP_FONT,"%s %s",item, _("name"));
1446         sub_menu->add_subitem(POPUP_OFFSET, "%s ",item);
1447         sub_menu->add_subitem("/%s",item);
1448         add_item(cur_item = new TitleCurItem(this, item = KW_SIZE));
1449         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1450         sub_menu->add_subitem("%s +",item);
1451         sub_menu->add_subitem("%s -",item);
1452         sub_menu->add_subitem("%s ",item);
1453         sub_menu->add_subitem("/%s",item);
1454         add_item(cur_item = new TitleCurItem(this, item = KW_BOLD));
1455         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1456         sub_menu->add_subitem("%s 1",item);
1457         sub_menu->add_subitem("%s 0",item);
1458         sub_menu->add_subitem("/%s",item);
1459         add_item(cur_item = new TitleCurItem(this, item = KW_ITALIC));
1460         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1461         sub_menu->add_subitem("%s 1",item);
1462         sub_menu->add_subitem("%s 0",item);
1463         sub_menu->add_subitem("/%s",item);
1464         add_item(cur_item = new TitleCurItem(this, item = KW_CAPS));
1465         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1466         sub_menu->add_subitem("%s 1",item);
1467         sub_menu->add_subitem("%s 0",item);
1468         sub_menu->add_subitem("%s -1",item);
1469         sub_menu->add_subitem("/%s",item);
1470         add_item(cur_item = new TitleCurItem(this, item = KW_UL));
1471         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1472         sub_menu->add_subitem("%s 1",item);
1473         sub_menu->add_subitem("%s 0",item);
1474         sub_menu->add_subitem("/%s",item);
1475         add_item(cur_item = new TitleCurItem(this, item = KW_BLINK));
1476         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1477         sub_menu->add_subitem("%s 1",item);
1478         sub_menu->add_subitem("%s -1",item);
1479         sub_menu->add_subitem("%s ",item);
1480         sub_menu->add_subitem("%s 0",item);
1481         sub_menu->add_subitem("/%s",item);
1482         add_item(cur_item = new TitleCurItem(this, item = KW_FIXED));
1483         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1484         sub_menu->add_subitem("%s ",item);
1485         sub_menu->add_subitem("%s 20",item);
1486         sub_menu->add_subitem("%s 10",item);
1487         sub_menu->add_subitem("%s 0",item);
1488         sub_menu->add_subitem("/%s",item);
1489         add_item(cur_item = new TitleCurItem(this, item = KW_SUP));
1490         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1491         sub_menu->add_subitem("%s 1",item);
1492         sub_menu->add_subitem("%s 0",item);
1493         sub_menu->add_subitem("%s -1",item);
1494         sub_menu->add_subitem("/%s",item);
1495         add_item(cur_item = new TitleCurItem(this, item = KW_PNG));
1496         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1497         sub_menu->add_subitem(POPUP_PNG,"%s %s", item, _("file"));
1498 }
1499
1500 TitleCurItem::TitleCurItem(TitleCurPopup *popup, const char *text)
1501  : BC_MenuItem(text)
1502 {
1503         this->popup = popup;
1504 }
1505 int TitleCurItem::handle_event()
1506 {
1507         return 1;
1508 }
1509
1510 TitleCurSubMenu::TitleCurSubMenu(TitleCurItem *cur_item)
1511 {
1512         this->cur_item = cur_item;
1513 }
1514 TitleCurSubMenu::~TitleCurSubMenu()
1515 {
1516 }
1517
1518 TitleCurSubMenuItem::TitleCurSubMenuItem(TitleCurSubMenu *submenu, const char *text, int popup_type)
1519  : BC_MenuItem(text)
1520 {
1521         this->submenu = submenu;
1522         this->popup_type = popup_type;
1523 }
1524 TitleCurSubMenuItem::~TitleCurSubMenuItem()
1525 {
1526 }
1527 int TitleCurSubMenuItem::handle_event()
1528 {
1529         TitleCurPopup *popup = submenu->cur_item->popup;
1530         TitleWindow *window = popup->window;
1531         const char *item_text = get_text();
1532         int ofs = *item_text == '/' ? 0 : -1;
1533         switch( popup_type ) {
1534         case POPUP_FONT: {
1535                 int px, py;
1536                 window->get_pop_cursor_xy(px ,py);
1537                 window->fonts_popup->activate(px, py, 300,200);
1538                 return 1; }
1539         case POPUP_COLOR: {
1540                 window->color_popup->activate();
1541                 return 1; }
1542         case POPUP_PNG: {
1543                 window->png_popup->activate();
1544                 return 1; }
1545         case POPUP_OFFSET:
1546                 ofs = -1;
1547                 break;
1548         }
1549         char txt[BCSTRLEN];
1550         sprintf(txt, "<%s>", item_text);
1551         return window->insert_ibeam(txt, ofs);
1552 }
1553
1554 TitleFontsPopup::TitleFontsPopup(TitleMain *client, TitleWindow *window)
1555  : BC_ListBox(-1, -1, 1, 1, LISTBOX_ICON_LIST,
1556         &window->fonts, 0, 0, 1, 0, 1)
1557 {
1558         this->client = client;
1559         this->window = window;
1560         set_use_button(0);
1561         set_show_query(1);
1562 }
1563 TitleFontsPopup::~TitleFontsPopup()
1564 {
1565 }
1566 int TitleFontsPopup::keypress_event()
1567 {
1568         switch( get_keypress() ) {
1569         case ESC:
1570         case DELETE:
1571                 deactivate();
1572                 return 1;
1573         default:
1574                 break;
1575         }
1576         return BC_ListBox::keypress_event();
1577 }
1578
1579 int TitleFontsPopup::handle_event()
1580 {
1581         deactivate();
1582         BC_ListBoxItem *item = get_selection(0, 0);
1583         if( !item ) return 1;
1584         const char *item_text = item->get_text();
1585         char txt[BCTEXTLEN];  sprintf(txt, "<%s %s>", KW_FONT, item_text);
1586         return window->insert_ibeam(txt);
1587 }
1588
1589 TitleColorPopup::TitleColorPopup(TitleMain *client, TitleWindow *window)
1590  : ColorPicker(0, _("Color"))
1591 {
1592         this->client = client;
1593         this->window = window;
1594         this->color_value = client->config.color;
1595 }
1596 TitleColorPopup::~TitleColorPopup()
1597 {
1598 }
1599 int TitleColorPopup::handle_new_color(int output, int alpha)
1600 {
1601         color_value = output;
1602         return 1;
1603 }
1604 int TitleColorPopup::activate()
1605 {
1606         start_window(client->config.color, 255, 1);
1607         return 1;
1608 }
1609 void TitleColorPopup::handle_done_event(int result)
1610 {
1611         if( result ) return;
1612         char txt[BCSTRLEN];  sprintf(txt, "<%s #%06x>", KW_COLOR, color_value);
1613         window->insert_ibeam(txt);
1614 }
1615
1616 TitlePngPopup::TitlePngPopup(TitleMain *client, TitleWindow *window)
1617  : BC_DialogThread()
1618 {
1619         this->client = client;
1620         this->window = window;
1621 }
1622
1623 TitlePngPopup::~TitlePngPopup()
1624 {
1625         close_window();
1626 }
1627
1628 void TitlePngPopup::handle_done_event(int result)
1629 {
1630         if( result ) return;
1631         BrowseButtonWindow *gui = (BrowseButtonWindow *)get_gui();
1632         const char *path = gui->get_submitted_path();
1633         char txt[BCSTRLEN];  sprintf(txt, "<%s %s>", KW_PNG, path);
1634         window->insert_ibeam(txt);
1635 }
1636
1637 BC_Window *TitlePngPopup::new_gui()
1638 {
1639         BC_DisplayInfo display_info;
1640         int x = display_info.get_abs_cursor_x();
1641         int y = display_info.get_abs_cursor_y();
1642
1643         BC_Window *gui = new BrowseButtonWindow(client->server->mwindow->theme,
1644                 x-25, y-100, window, "", _("Png file"), _("Png path"), 0);
1645         gui->create_objects();
1646         return gui;
1647 }
1648
1649 int TitlePngPopup::activate()
1650 {
1651         BC_DialogThread::start();
1652         return 1;
1653 }
1654