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