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