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