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