bd tweaks, add png browse to titler, ladspa path fix, colorpicker tweaks
[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         client->send_configure_change();
603 }
604
605 void  TitleWindow::next_font()
606 {
607         int current_font = font->get_number();
608         current_font++;
609         if( current_font >= fonts.total ) current_font = 0;
610
611         if( current_font < 0 || current_font >= fonts.total ) return;
612
613         for( int i=0; i<fonts.total; ++i ) {
614                 fonts.values[i]->set_selected(i == current_font);
615         }
616
617         font->update(fonts.values[current_font]->get_text());
618         strcpy(client->config.font, fonts.values[current_font]->get_text());
619         client->send_configure_change();
620 }
621
622 int TitleWindow::insert_ibeam(const char *txt, int adv)
623 {
624         int ibeam = cur_ibeam;
625         client->insert_text(txt, ibeam);
626         if( (ibeam += adv) >= client->config.wlen)
627                 ibeam = client->config.wlen;
628         text->wset_selection(-1, -1, ibeam);
629         text->update(client->config.wtext);
630         client->send_configure_change();
631         return 1;
632 }
633
634 void TitleWindow::update_color()
635 {
636 //printf("TitleWindow::update_color %x\n", client->config.color);
637         set_color(client->config.color);
638         draw_box(color_x, color_y, COLOR_W, COLOR_H);
639         flash(color_x, color_y, COLOR_W, COLOR_H);
640         set_color(client->config.outline_color);
641         draw_box(outline_color_x, outline_color_y, COLOR_W, COLOR_H);
642         set_color(BLACK);
643         draw_rectangle(color_x, color_y, COLOR_W, COLOR_H);
644         draw_rectangle(outline_color_x, outline_color_y, COLOR_W, COLOR_H);
645         flash(outline_color_x, outline_color_y, COLOR_W, COLOR_H);
646 }
647
648 void TitleWindow::update_justification()
649 {
650         left->update(client->config.hjustification == JUSTIFY_LEFT);
651         center->update(client->config.hjustification == JUSTIFY_CENTER);
652         right->update(client->config.hjustification == JUSTIFY_RIGHT);
653         top->update(client->config.vjustification == JUSTIFY_TOP);
654         mid->update(client->config.vjustification == JUSTIFY_MID);
655         bottom->update(client->config.vjustification == JUSTIFY_BOTTOM);
656 }
657
658 void TitleWindow::update()
659 {
660         title_x->update((int64_t)client->config.title_x);
661         title_y->update((int64_t)client->config.title_y);
662         title_w->update((int64_t)client->config.title_w);
663         title_h->update((int64_t)client->config.title_h);
664         italic->update(client->config.style & BC_FONT_ITALIC);
665         bold->update(client->config.style & BC_FONT_BOLD);
666         size->update(client->config.size);
667         motion->update(TitleMain::motion_to_text(client->config.motion_strategy));
668         loop->update(client->config.loop);
669         dropshadow->update((int64_t)client->config.dropshadow);
670         fade_in->update((float)client->config.fade_in);
671         fade_out->update((float)client->config.fade_out);
672         font->update(client->config.font);
673         text->update(&client->config.wtext[0]);
674         speed->update(client->config.pixels_per_second);
675         outline->update((int64_t)client->config.outline_size);
676 #ifdef USE_STOKER
677         stroker->update((int64_t)client->config.stroke_width);
678 #endif
679         timecode->update(client->config.timecode);
680         timecode_format->update(client->config.timecode_format);
681         background->update(client->config.background);
682         background_path->update(client->config.background_path);
683         loop_playback->update((int64_t)client->config.loop_playback);
684
685         char string[BCTEXTLEN];
686         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
687                 if( timeunit_formats[i] == client->config.timecode_format ) {
688                         timecode_format->set_text(
689                                 Units::print_time_format(timeunit_formats[i], string));
690                         break;
691                 }
692         }
693         update_justification();
694         update_color();
695 }
696
697
698 TitleFontTumble::TitleFontTumble(TitleMain *client, TitleWindow *window, int x, int y)
699  : BC_Tumbler(x, y)
700 {
701         this->client = client;
702         this->window = window;
703 }
704 int TitleFontTumble::handle_up_event()
705 {
706         window->previous_font();
707         return 1;
708 }
709
710 int TitleFontTumble::handle_down_event()
711 {
712         window->next_font();
713         return 1;
714 }
715
716
717
718 TitleSizeTumble::TitleSizeTumble(TitleMain *client, TitleWindow *window, int x, int y)
719  : BC_Tumbler(x, y)
720 {
721         this->client = client;
722         this->window = window;
723 }
724
725 int TitleSizeTumble::handle_up_event()
726 {
727         int current_index = -1;
728         int current_difference = -1;
729         for( int i=0; i<window->sizes.size(); ++i ) {
730                 int size = atoi(window->sizes.get(i)->get_text());
731                 if( current_index < 0 ||
732                         abs(size - client->config.size) < current_difference ) {
733                         current_index = i;
734                         current_difference = abs(size - client->config.size);
735                 }
736         }
737
738         current_index++;
739         if( current_index >= window->sizes.size() ) current_index = 0;
740
741
742         client->config.size = atoi(window->sizes.get(current_index)->get_text());
743         window->size->update(client->config.size);
744         client->send_configure_change();
745         return 1;
746 }
747
748 int TitleSizeTumble::handle_down_event()
749 {
750         int current_index = -1;
751         int current_difference = -1;
752         for( int i=0; i<window->sizes.size(); ++i ) {
753                 int size = atoi(window->sizes.get(i)->get_text());
754                 if( current_index < 0 ||
755                         abs(size - client->config.size) < current_difference ) {
756                         current_index = i;
757                         current_difference = abs(size - client->config.size);
758                 }
759         }
760
761         current_index--;
762         if( current_index < 0 ) current_index = window->sizes.size() - 1;
763
764
765         client->config.size = atoi(window->sizes.get(current_index)->get_text());
766         window->size->update(client->config.size);
767         client->send_configure_change();
768         return 1;
769 }
770
771 TitleBold::TitleBold(TitleMain *client, TitleWindow *window, int x, int y)
772  : BC_CheckBox(x, y, client->config.style & BC_FONT_BOLD, _("Bold"))
773 {
774         this->client = client;
775         this->window = window;
776 }
777
778 int TitleBold::handle_event()
779 {
780         client->config.style =
781                 (client->config.style & ~BC_FONT_BOLD) |
782                         (get_value() ? BC_FONT_BOLD : 0);
783         client->send_configure_change();
784         return 1;
785 }
786
787 TitleItalic::TitleItalic(TitleMain *client, TitleWindow *window, int x, int y)
788  : BC_CheckBox(x, y, client->config.style & BC_FONT_ITALIC, _("Italic"))
789 {
790         this->client = client;
791         this->window = window;
792 }
793 int TitleItalic::handle_event()
794 {
795         client->config.style =
796                 (client->config.style & ~BC_FONT_ITALIC) |
797                         (get_value() ? BC_FONT_ITALIC : 0);
798         client->send_configure_change();
799         return 1;
800 }
801
802
803
804 TitleSize::TitleSize(TitleMain *client, TitleWindow *window, int x, int y, char *text)
805  : BC_PopupTextBox(window,
806                 &window->sizes,
807                 text,
808                 x,
809                 y,
810                 64,
811                 300)
812 {
813         this->client = client;
814         this->window = window;
815 }
816 TitleSize::~TitleSize()
817 {
818 }
819 int TitleSize::handle_event()
820 {
821         client->config.size = atol(get_text());
822 //printf("TitleSize::handle_event 1 %s\n", get_text());
823         client->send_configure_change();
824         return 1;
825 }
826 void TitleSize::update(int size)
827 {
828         char string[BCTEXTLEN];
829         sprintf(string, "%d", size);
830         BC_PopupTextBox::update(string);
831 }
832
833 TitlePitch::
834 TitlePitch(TitleMain *client, TitleWindow *window, int x, int y, int *value)
835  : BC_TumbleTextBox(window, *value, 0, INT_MAX, x, y, 64)
836 {
837         this->client = client;
838         this->window = window;
839         this->value = value;
840 }
841
842 TitlePitch::
843 ~TitlePitch()
844 {
845 }
846
847 int TitlePitch::handle_event()
848 {
849         *value = atol(get_text());
850         client->send_configure_change();
851         return 1;
852 }
853
854 TitleColorButton::TitleColorButton(TitleMain *client, TitleWindow *window, int x, int y)
855  : BC_GenericButton(x, y, _("Color..."))
856 {
857         this->client = client;
858         this->window = window;
859 }
860 int TitleColorButton::handle_event()
861 {
862         window->color_thread->start_window(client->config.color,
863                 client->config.alpha);
864         return 1;
865 }
866 TitleOutlineColorButton::TitleOutlineColorButton(TitleMain *client, TitleWindow *window, int x, int y)
867  : BC_GenericButton(x, y, _("Outline color..."))
868 {
869         this->client = client;
870         this->window = window;
871 }
872 int TitleOutlineColorButton::handle_event()
873 {
874         window->outline_color_thread->start_window(client->config.outline_color,
875                 client->config.outline_alpha);
876         return 1;
877 }
878
879
880 TitleMotion::TitleMotion(TitleMain *client, TitleWindow *window, int x, int y)
881  : BC_PopupTextBox(window, &window->paths,
882                 client->motion_to_text(client->config.motion_strategy),
883                 x, y, 120, 100)
884 {
885         this->client = client;
886         this->window = window;
887 }
888 int TitleMotion::handle_event()
889 {
890         client->config.motion_strategy = client->text_to_motion(get_text());
891         client->send_configure_change();
892         return 1;
893 }
894
895 TitleLoop::TitleLoop(TitleMain *client, int x, int y)
896  : BC_CheckBox(x, y, client->config.loop, _("Loop"))
897 {
898         this->client = client;
899 }
900 int TitleLoop::handle_event()
901 {
902         client->config.loop = get_value();
903         client->send_configure_change();
904         return 1;
905 }
906 TitleTimecode::TitleTimecode(TitleMain *client, int x, int y)
907  : BC_CheckBox(x, y, client->config.timecode, _("Stamp timecode"))
908 {
909         this->client = client;
910 }
911 int TitleTimecode::handle_event()
912 {
913         client->config.timecode = get_value();
914         client->send_configure_change();
915         return 1;
916 }
917
918 TitleTimecodeFormat::TitleTimecodeFormat(TitleMain *client, int x, int y, const char *text)
919  : BC_PopupMenu(x, y, 100, text, 1)
920 {
921         this->client = client;
922 }
923
924 int TitleTimecodeFormat::handle_event()
925 {
926         client->config.timecode_format = Units::text_to_format(get_text());
927         client->send_configure_change();
928         return 1;
929 }
930
931 void TitleTimecodeFormat::create_objects()
932 {
933         char string[BCTEXTLEN];
934         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
935                 add_item(new BC_MenuItem(
936                         Units::print_time_format(timeunit_formats[i], string)));
937         }
938 }
939
940
941 int TitleTimecodeFormat::update(int timecode_format)
942 {
943         char string[BCTEXTLEN];
944         for( int i=0; i<lengthof(timeunit_formats); ++i ) {
945                 if( timeunit_formats[i] == timecode_format ) {
946                         set_text(Units::print_time_format(timeunit_formats[i], string));
947                         break;
948                 }
949         }
950         return 0;
951 }
952
953 TitleFade::TitleFade(TitleMain *client, TitleWindow *window,
954         double *value, int x, int y)
955  : BC_TextBox(x, y, 80, 1, (float)*value)
956 {
957         this->client = client;
958         this->window = window;
959         this->value = value;
960         set_precision(2);
961 }
962
963 int TitleFade::handle_event()
964 {
965         *value = atof(get_text());
966         client->send_configure_change();
967         return 1;
968 }
969
970 TitleFont::TitleFont(TitleMain *client, TitleWindow *window, int x, int y)
971  : BC_PopupTextBox(window, &window->fonts, client->config.font,
972                 x, y, 200, 500, LISTBOX_ICON_LIST)
973 {
974         this->client = client;
975         this->window = window;
976 }
977 int TitleFont::handle_event()
978 {
979         strcpy(client->config.font, get_text());
980         client->send_configure_change();
981         return 1;
982 }
983
984 TitleText::TitleText(TitleMain *client, TitleWindow *window,
985         int x, int y, int w, int h)
986  : BC_ScrollTextBox(window, x, y, w,
987                 BC_TextBox::pixels_to_rows(window, MEDIUMFONT, h),
988                 client->config.wtext, 8192)
989 {
990         this->client = client;
991         this->window = window;
992 //printf("TitleText::TitleText %s\n", client->config.text);
993 }
994
995 int TitleText::button_press_event()
996 {
997         if( get_buttonpress() == 3 ) {
998                 window->cur_ibeam = get_ibeam_letter();
999                 window->cur_popup->activate_menu();
1000                 return 1;
1001         }
1002         return BC_ScrollTextBox::button_press_event();
1003 }
1004
1005 int TitleText::handle_event()
1006 {
1007         window->fonts_popup->deactivate();
1008         int len =  sizeof(client->config.wtext) / sizeof(wchar_t);
1009         wcsncpy(client->config.wtext, get_wtext(), len);
1010         client->config.wtext[len-1] = 0;
1011         client->config.wlen = wcslen(client->config.wtext);
1012         client->send_configure_change();
1013         return 1;
1014 }
1015
1016
1017 TitleDropShadow::TitleDropShadow(TitleMain *client, TitleWindow *window, int x, int y)
1018  : BC_TumbleTextBox(window, (int64_t)client->config.dropshadow,
1019         (int64_t)-1000, (int64_t)1000, x, y, 70)
1020 {
1021         this->client = client;
1022         this->window = window;
1023 }
1024 int TitleDropShadow::handle_event()
1025 {
1026         client->config.dropshadow = atol(get_text());
1027         client->send_configure_change();
1028         return 1;
1029 }
1030
1031
1032 TitleOutline::TitleOutline(TitleMain *client, TitleWindow *window, int x, int y)
1033  : BC_TumbleTextBox(window, (int64_t)client->config.outline_size,
1034         (int64_t)0, (int64_t)1000, x, y, 70)
1035 {
1036         this->client = client;
1037         this->window = window;
1038 }
1039 int TitleOutline::handle_event()
1040 {
1041         client->config.outline_size = atol(get_text());
1042         client->send_configure_change();
1043         return 1;
1044 }
1045
1046 TitleStroker::TitleStroker(TitleMain *client, TitleWindow *window, int x, int y)
1047  : BC_TumbleTextBox(window, (int64_t)client->config.stroke_width,
1048         (int64_t)0, (int64_t)1000, x, y, 70)
1049 {
1050         this->client = client;
1051         this->window = window;
1052 }
1053 int TitleStroker::handle_event()
1054 {
1055         client->config.stroke_width = atol(get_text());
1056         if( client->config.stroke_width > 1 )
1057                 client->config.style |= BC_FONT_OUTLINE;
1058         else
1059                 client->config.style &= ~BC_FONT_OUTLINE;
1060         client->send_configure_change();
1061         return 1;
1062 }
1063
1064
1065 TitleX::TitleX(TitleMain *client, TitleWindow *window, int x, int y)
1066  : BC_TumbleTextBox(window, (int64_t)client->config.title_x,
1067         (int64_t)-32767, (int64_t)32767, x, y, 50)
1068 {
1069         this->client = client;
1070         this->window = window;
1071 }
1072 int TitleX::handle_event()
1073 {
1074         client->config.title_x = atol(get_text());
1075         client->send_configure_change();
1076         return 1;
1077 }
1078
1079 TitleY::TitleY(TitleMain *client, TitleWindow *window, int x, int y)
1080  : BC_TumbleTextBox(window, (int64_t)client->config.title_y,
1081         (int64_t)-32767, (int64_t)32767, x, y, 50)
1082 {
1083         this->client = client;
1084         this->window = window;
1085 }
1086 int TitleY::handle_event()
1087 {
1088         client->config.title_y = atol(get_text());
1089         client->send_configure_change();
1090         return 1;
1091 }
1092
1093 TitleW::TitleW(TitleMain *client, TitleWindow *window, int x, int y)
1094  : BC_TumbleTextBox(window, (int64_t)client->config.title_w,
1095         (int64_t)0, (int64_t)32767, x, y, 50)
1096 {
1097         this->client = client;
1098         this->window = window;
1099 }
1100 int TitleW::handle_event()
1101 {
1102         client->config.title_w = atol(get_text());
1103         client->send_configure_change();
1104         return 1;
1105 }
1106
1107 TitleH::TitleH(TitleMain *client, TitleWindow *window, int x, int y)
1108  : BC_TumbleTextBox(window, (int64_t)client->config.title_h,
1109         (int64_t)0, (int64_t)32767, x, y, 50)
1110 {
1111         this->client = client;
1112         this->window = window;
1113 }
1114 int TitleH::handle_event()
1115 {
1116         client->config.title_h = atol(get_text());
1117         client->send_configure_change();
1118         return 1;
1119 }
1120
1121 TitleSpeed::TitleSpeed(TitleMain *client, TitleWindow *window, int x, int y)
1122  : BC_TumbleTextBox(window, (float)client->config.pixels_per_second,
1123         (float)0, (float)1000, x, y, 100)
1124 {
1125         this->client = client;
1126         set_precision(2);
1127         set_increment(10);
1128 }
1129
1130
1131 int TitleSpeed::handle_event()
1132 {
1133         client->config.pixels_per_second = atof(get_text());
1134         client->send_configure_change();
1135         return 1;
1136 }
1137
1138
1139 TitleLeft::TitleLeft(TitleMain *client, TitleWindow *window, int x, int y)
1140  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_LEFT, _("Left"))
1141 {
1142         this->client = client;
1143         this->window = window;
1144 }
1145 int TitleLeft::handle_event()
1146 {
1147         client->config.hjustification = JUSTIFY_LEFT;
1148         window->update_justification();
1149         client->send_configure_change();
1150         return 1;
1151 }
1152
1153 TitleCenter::TitleCenter(TitleMain *client, TitleWindow *window, int x, int y)
1154  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_CENTER, _("Center"))
1155 {
1156         this->client = client;
1157         this->window = window;
1158 }
1159 int TitleCenter::handle_event()
1160 {
1161         client->config.hjustification = JUSTIFY_CENTER;
1162         window->update_justification();
1163         client->send_configure_change();
1164         return 1;
1165 }
1166
1167 TitleRight::TitleRight(TitleMain *client, TitleWindow *window, int x, int y)
1168  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_RIGHT, _("Right"))
1169 {
1170         this->client = client;
1171         this->window = window;
1172 }
1173 int TitleRight::handle_event()
1174 {
1175         client->config.hjustification = JUSTIFY_RIGHT;
1176         window->update_justification();
1177         client->send_configure_change();
1178         return 1;
1179 }
1180
1181
1182
1183 TitleTop::TitleTop(TitleMain *client, TitleWindow *window, int x, int y)
1184  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_TOP, _("Top"))
1185 {
1186         this->client = client;
1187         this->window = window;
1188 }
1189 int TitleTop::handle_event()
1190 {
1191         client->config.vjustification = JUSTIFY_TOP;
1192         window->update_justification();
1193         client->send_configure_change();
1194         return 1;
1195 }
1196
1197 TitleMid::TitleMid(TitleMain *client, TitleWindow *window, int x, int y)
1198  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_MID, _("Mid"))
1199 {
1200         this->client = client;
1201         this->window = window;
1202 }
1203 int TitleMid::handle_event()
1204 {
1205         client->config.vjustification = JUSTIFY_MID;
1206         window->update_justification();
1207         client->send_configure_change();
1208         return 1;
1209 }
1210
1211 TitleBottom::TitleBottom(TitleMain *client, TitleWindow *window, int x, int y)
1212  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_BOTTOM, _("Bottom"))
1213 {
1214         this->client = client;
1215         this->window = window;
1216 }
1217 int TitleBottom::handle_event()
1218 {
1219         client->config.vjustification = JUSTIFY_BOTTOM;
1220         window->update_justification();
1221         client->send_configure_change();
1222         return 1;
1223 }
1224
1225
1226
1227 TitleColorThread::TitleColorThread(TitleMain *client, TitleWindow *window, int is_outline)
1228  : ColorThread(1, _("Text Color"))
1229 {
1230         this->client = client;
1231         this->window = window;
1232         this->is_outline = is_outline;
1233 }
1234
1235 int TitleColorThread::handle_new_color(int output, int alpha)
1236 {
1237         if( is_outline ) {
1238                 client->config.outline_color = output;
1239                 client->config.outline_alpha = alpha;
1240         }
1241         else {
1242                 client->config.color = output;
1243                 client->config.alpha = alpha;
1244         }
1245
1246         window->lock_window("TitleColorThread::handle_new_color");
1247         window->update_color();
1248         window->flush();
1249         window->unlock_window();
1250
1251         client->send_configure_change();
1252         return 1;
1253 }
1254
1255 TitleDrag::TitleDrag(TitleMain *client, TitleWindow *window, int x, int y)
1256  : BC_CheckBox(x, y, client->config.drag, _("Drag"))
1257 {
1258         this->client = client;
1259         this->window = window;
1260 }
1261
1262 int TitleDrag::handle_event()
1263 {
1264         int value = get_value();
1265         client->config.drag = value;
1266         if( value )
1267                 window->grab(client->server->mwindow->cwindow->gui);
1268         else
1269                 window->ungrab(client->server->mwindow->cwindow->gui);
1270         client->send_configure_change();
1271         return 1;
1272 }
1273
1274 TitleBackground::TitleBackground(TitleMain *client, TitleWindow *window, int x, int y)
1275  : BC_CheckBox(x, y, client->config.background, _("Background:"))
1276 {
1277         this->client = client;
1278         this->window = window;
1279 }
1280
1281 int TitleBackground::handle_event()
1282 {
1283         client->config.background = get_value();
1284         client->send_configure_change();
1285         return 1;
1286 }
1287
1288 TitleBackgroundPath::TitleBackgroundPath(TitleMain *client, TitleWindow *window, int x, int y)
1289  : BC_TextBox(x, y, 240, 1, client->config.background_path)
1290 {
1291         this->client = client;
1292         this->window = window;
1293 }
1294
1295 int TitleBackgroundPath::handle_event()
1296 {
1297         strncpy(client->config.background_path, get_text(), sizeof(client->config.background_path));
1298         client->send_configure_change();
1299         return 1;
1300 }
1301
1302 TitleLoopPlayback::TitleLoopPlayback(TitleMain *client, int x, int y)
1303  : BC_CheckBox(x, y, client->config.loop_playback, _("Loop playback"))
1304 {
1305         this->client = client;
1306 }
1307 int TitleLoopPlayback::handle_event()
1308 {
1309         client->config.loop_playback = get_value();
1310         client->send_configure_change();
1311         return 1;
1312 }
1313
1314
1315 TitleCurPopup::TitleCurPopup(TitleMain *client, TitleWindow *window)
1316  : BC_PopupMenu(0, 0, 0, "", 0)
1317 {
1318         this->client = client;
1319         this->window = window;
1320 }
1321 int TitleCurPopup::handle_event()
1322 {
1323         return 1;
1324 }
1325 void TitleCurPopup::create_objects()
1326 {
1327         TitleCurItem *cur_item;
1328         TitleCurSubMenu *sub_menu;
1329         add_item(cur_item = new TitleCurItem(this, _("nudge")));
1330         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1331         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("nudge dx,dy")));
1332         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/nudge")));
1333         add_item(cur_item = new TitleCurItem(this, _("color")));
1334         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1335         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("color #")));
1336         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("color ")));
1337         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/color")));
1338         add_item(cur_item = new TitleCurItem(this, _("alpha")));
1339         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1340         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("alpha ")));
1341         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("alpha 0.")));
1342         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("alpha .5")));
1343         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("alpha 1.")));
1344         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/alpha")));
1345         add_item(cur_item = new TitleCurItem(this, _("font")));
1346         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1347         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("font name")));
1348         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("font ")));
1349         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/font")));
1350         add_item(cur_item = new TitleCurItem(this, _("size")));
1351         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1352         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("size +")));
1353         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("size -")));
1354         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("size ")));
1355         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/size")));
1356         add_item(cur_item = new TitleCurItem(this, _("bold")));
1357         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1358         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("bold 1")));
1359         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("bold 0")));
1360         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/bold")));
1361         add_item(cur_item = new TitleCurItem(this, _("italic")));
1362         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1363         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("italic 1")));
1364         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("italic 0")));
1365         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/italic")));
1366         add_item(cur_item = new TitleCurItem(this, _("caps")));
1367         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1368         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("caps 1")));
1369         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("caps 0")));
1370         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("caps -1")));
1371         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/caps")));
1372         add_item(cur_item = new TitleCurItem(this, _("ul")));
1373         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1374         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("ul 1")));
1375         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("ul 0")));
1376         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/ul")));
1377         add_item(cur_item = new TitleCurItem(this, _("blink")));
1378         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1379         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("blink 1")));
1380         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("blink -1")));
1381         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("blink ")));
1382         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("blink 0")));
1383         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/blink")));
1384         add_item(cur_item = new TitleCurItem(this, _("fixed")));
1385         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1386         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("fixed ")));
1387         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("fixed 20")));
1388         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("fixed 10")));
1389         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("fixed 0")));
1390         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/fixed")));
1391         add_item(cur_item = new TitleCurItem(this, _("sup")));
1392         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1393         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("sup 1")));
1394         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("sup 0")));
1395         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("sup -1")));
1396         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("/sup")));
1397         add_item(cur_item = new TitleCurItem(this, _("png")));
1398         cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
1399         sub_menu->add_submenuitem(new TitleCurSubMenuItem(sub_menu,_("png file")));
1400 }
1401
1402 TitleCurItem::TitleCurItem(TitleCurPopup *popup, const char *text)
1403  : BC_MenuItem(text)
1404 {
1405         this->popup = popup;
1406 }
1407 int TitleCurItem::handle_event()
1408 {
1409         return 1;
1410 }
1411
1412 TitleCurSubMenu::TitleCurSubMenu(TitleCurItem *cur_item)
1413 {
1414         this->cur_item = cur_item;
1415 }
1416 TitleCurSubMenu::~TitleCurSubMenu()
1417 {
1418 }
1419
1420 TitleCurSubMenuItem::TitleCurSubMenuItem(TitleCurSubMenu *submenu, const char *text)
1421  : BC_MenuItem(text)
1422 {
1423         this->submenu = submenu;
1424 }
1425 TitleCurSubMenuItem::~TitleCurSubMenuItem()
1426 {
1427 }
1428 int TitleCurSubMenuItem::handle_event()
1429 {
1430         TitleCurPopup *popup = submenu->cur_item->popup;
1431         TitleWindow *window = popup->window;
1432         const char *item_text = get_text();
1433         if( !strcmp(item_text, _("font name")) ) {
1434                 int px, py;
1435                 window->get_pop_cursor_xy(px ,py);
1436                 window->fonts_popup->activate(px, py, 300,200);
1437                 return 1;
1438         }
1439         if( !strcmp(item_text, _("color #")) ) {
1440                 window->color_popup->activate();
1441                 return 1;
1442         }
1443         if( !strcmp(item_text, _("png file")) ) {
1444                 window->png_popup->activate();
1445                 return 1;
1446         }
1447         char txt[BCSTRLEN];
1448         sprintf(txt, "<%s>", item_text);
1449         int adv = strlen(txt);
1450         if( adv > 1 && (txt[1] != '/' && strcmp(txt,_("font"))) ) --adv;
1451         return window->insert_ibeam(txt,adv);
1452 }
1453
1454 TitleFontsPopup::TitleFontsPopup(TitleMain *client, TitleWindow *window)
1455  : BC_ListBox(-1, -1, 1, 1, LISTBOX_ICON_LIST,
1456         &window->fonts, 0, 0, 1, 0, 1)
1457 {
1458         this->client = client;
1459         this->window = window;
1460         set_use_button(0);
1461 }
1462 TitleFontsPopup::~TitleFontsPopup()
1463 {
1464 }
1465
1466 int TitleFontsPopup::handle_event()
1467 {
1468         deactivate();
1469         BC_ListBoxItem *item = get_selection(0, 0);
1470         if( !item ) return 1;
1471         const char *item_text = item->get_text();
1472         char txt[BCTEXTLEN];  sprintf(txt, "<font %s>",item_text);
1473         return window->insert_ibeam(txt, strlen(txt));
1474 }
1475
1476 TitleColorPopup::TitleColorPopup(TitleMain *client, TitleWindow *window)
1477  : ColorThread(0, _("Text Color"))
1478 {
1479         this->client = client;
1480         this->window = window;
1481         this->color_value = client->config.color;
1482 }
1483 TitleColorPopup::~TitleColorPopup()
1484 {
1485 }
1486 int TitleColorPopup::handle_new_color(int output, int alpha)
1487 {
1488         color_value = output;
1489         return 1;
1490 }
1491 int TitleColorPopup::activate()
1492 {
1493         start_window(client->config.color, 255, 1);
1494         return 1;
1495 }
1496 void TitleColorPopup::handle_done_event(int result)
1497 {
1498         if( result ) return;
1499         char txt[BCSTRLEN];  sprintf(txt, "<color #%06x>",color_value);
1500         window->insert_ibeam(txt, strlen(txt));
1501 }
1502
1503 TitlePngPopup::TitlePngPopup(TitleMain *client, TitleWindow *window)
1504  : BC_DialogThread()
1505 {
1506         this->client = client;
1507         this->window = window;
1508 }
1509
1510 TitlePngPopup::~TitlePngPopup()
1511 {
1512         close_window();
1513 }
1514
1515 void TitlePngPopup::handle_done_event(int result)
1516 {
1517         if( result ) return;
1518         BrowseButtonWindow *gui = (BrowseButtonWindow *)get_gui();
1519         const char *path = gui->get_submitted_path();
1520         char txt[BCSTRLEN];  sprintf(txt, "<png %s>",path);
1521         window->insert_ibeam(txt, strlen(txt));
1522 }
1523
1524 BC_Window *TitlePngPopup::new_gui()
1525 {
1526         BC_DisplayInfo display_info;
1527         int x = display_info.get_abs_cursor_x();
1528         int y = display_info.get_abs_cursor_y();
1529
1530         BC_Window *gui = new BrowseButtonWindow(client->server->mwindow->theme,
1531                 x-25, y-100, window, "", _("Png file"), _("Png path"), 0);
1532         gui->create_objects();
1533         return gui;
1534 }
1535
1536 int TitlePngPopup::activate()
1537 {
1538         BC_DialogThread::start();
1539         return 1;
1540 }
1541