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