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