remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / plugins / titler / titlewindow.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 "bcsignals.h"
24 #include "cstrdup.h"
25 #include "language.h"
26 #include "theme.h"
27 #include "titlewindow.h"
28 #include "bcfontentry.h"
29
30 #include <wchar.h>
31
32 static const int timeunit_formats[] =
33 {
34         TIME_HMS,
35         TIME_SECONDS,
36         TIME_HMSF,
37         TIME_SAMPLES,
38         TIME_SAMPLES_HEX,
39         TIME_FRAMES,
40         TIME_FEET_FRAMES
41 };
42
43 TitleWindow::TitleWindow(TitleMain *client)
44  : PluginClientWindow(client,
45         client->config.window_w,
46         client->config.window_h,
47         100,
48         100,
49         1)
50 {
51 //printf("TitleWindow::TitleWindow %d %d %d\n", __LINE__, client->config.window_w, client->config.window_h);
52         this->client = client;
53         font_tumbler = 0;
54         justify_title = 0;
55         style_title = 0;
56         size_title = 0;
57         title_y = 0;
58         bottom = 0;
59         size = 0;
60         loop = 0;
61         title_x = 0;
62         dropshadow = 0;
63         motion = 0;
64         dropshadow_title = 0;
65         text = 0;
66         timecode = 0;
67         fade_in = 0;
68         encoding_title = 0;
69         x_title = 0;
70         bold = 0;
71         color_y = 0;
72         speed = 0;
73         center = 0;
74         italic = 0;
75         text_title = 0;
76         motion_title = 0;
77         fadeout_title = 0;
78         font_title = 0;
79         fadein_title = 0;
80         fade_out = 0;
81         color_button = 0;
82         left = 0;
83         speed_title = 0;
84         top = 0;
85         font = 0;
86         right = 0;
87         color_x = 0;
88         color_y = 0;
89         y_title = 0;
90         color_thread = 0;
91         mid = 0;
92         encoding_title = 0;
93         encoding = 0;
94 }
95
96 TitleWindow::~TitleWindow()
97 {
98         for(int j = 0; j < fonts.size(); j++)
99         {
100 // delete the pixmaps but not the vframes since they're static
101                 delete fonts.get(j)->get_icon();
102         }
103
104         sizes.remove_all_objects();
105         delete timecode_format;
106         delete color_thread;
107 #ifdef USE_OUTLINE
108         delete color_stroke_thread;
109 #endif
110         delete title_x;
111         delete title_y;
112 }
113
114 void TitleWindow::create_objects()
115 {
116         int x = 10, y = 10;
117         int margin = client->get_theme()->widget_border;
118         char string[BCTEXTLEN];
119
120 #define COLOR_W 50
121 #define COLOR_H 30
122         client->build_previews(this);
123
124         encodings.append(new BC_ListBoxItem("ISO8859-1"));
125         encodings.append(new BC_ListBoxItem("ISO8859-2"));
126         encodings.append(new BC_ListBoxItem("ISO8859-3"));
127         encodings.append(new BC_ListBoxItem("ISO8859-4"));
128         encodings.append(new BC_ListBoxItem("ISO8859-5"));
129         encodings.append(new BC_ListBoxItem("ISO8859-6"));
130         encodings.append(new BC_ListBoxItem("ISO8859-7"));
131         encodings.append(new BC_ListBoxItem("ISO8859-8"));
132         encodings.append(new BC_ListBoxItem("ISO8859-9"));
133         encodings.append(new BC_ListBoxItem("ISO8859-10"));
134         encodings.append(new BC_ListBoxItem("ISO8859-11"));
135         encodings.append(new BC_ListBoxItem("ISO8859-12"));
136         encodings.append(new BC_ListBoxItem("ISO8859-13"));
137         encodings.append(new BC_ListBoxItem("ISO8859-14"));
138         encodings.append(new BC_ListBoxItem("ISO8859-15"));
139         encodings.append(new BC_ListBoxItem("KOI8"));
140         encodings.append(new BC_ListBoxItem("UTF-8"));
141
142
143         sizes.append(new BC_ListBoxItem("8"));
144         sizes.append(new BC_ListBoxItem("9"));
145         sizes.append(new BC_ListBoxItem("10"));
146         sizes.append(new BC_ListBoxItem("11"));
147         sizes.append(new BC_ListBoxItem("12"));
148         sizes.append(new BC_ListBoxItem("13"));
149         sizes.append(new BC_ListBoxItem("14"));
150         sizes.append(new BC_ListBoxItem("16"));
151         sizes.append(new BC_ListBoxItem("18"));
152         sizes.append(new BC_ListBoxItem("20"));
153         sizes.append(new BC_ListBoxItem("22"));
154         sizes.append(new BC_ListBoxItem("24"));
155         sizes.append(new BC_ListBoxItem("26"));
156         sizes.append(new BC_ListBoxItem("28"));
157         sizes.append(new BC_ListBoxItem("32"));
158         sizes.append(new BC_ListBoxItem("36"));
159         sizes.append(new BC_ListBoxItem("40"));
160         sizes.append(new BC_ListBoxItem("48"));
161         sizes.append(new BC_ListBoxItem("56"));
162         sizes.append(new BC_ListBoxItem("64"));
163         sizes.append(new BC_ListBoxItem("72"));
164         sizes.append(new BC_ListBoxItem("100"));
165         sizes.append(new BC_ListBoxItem("128"));
166         sizes.append(new BC_ListBoxItem("256"));
167         sizes.append(new BC_ListBoxItem("512"));
168         sizes.append(new BC_ListBoxItem("1024"));
169
170         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(NO_MOTION)));
171         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(BOTTOM_TO_TOP)));
172         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(TOP_TO_BOTTOM)));
173         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(RIGHT_TO_LEFT)));
174         paths.append(new BC_ListBoxItem(TitleMain::motion_to_text(LEFT_TO_RIGHT)));
175
176
177
178 // Construct font list
179         ArrayList<BC_FontEntry*> *fontlist = get_resources()->fontlist;
180
181         for(int i = 0; i < fontlist->size(); i++) {
182                 int exists = 0;
183                 for(int j = 0; j < fonts.size(); j++) {
184                         if(!strcasecmp(fonts.get(j)->get_text(),
185                                 fontlist->get(i)->displayname)) {
186                                 exists = 1;
187                                 break;
188                         }
189                 }
190
191                 BC_ListBoxItem *item = 0;
192                 if(!exists) {
193                         fonts.append(item = new
194                                 BC_ListBoxItem(fontlist->get(i)->displayname));
195                         if(!strcmp(client->config.font, item->get_text()))
196                                 item->set_selected(1);
197                         if(fontlist->values[i]->image)
198                         {
199                                 VFrame *vframe = fontlist->get(i)->image;
200                                 BC_Pixmap *icon = new BC_Pixmap(this, vframe, PIXMAP_ALPHA);
201                                 item->set_icon(icon);
202                                 item->set_icon_vframe(vframe);
203                         }
204                 }
205         }
206
207 // Sort font list
208         int done = 0;
209         while(!done) {
210                 done = 1;
211                 for(int i = 0; i < fonts.size() - 1; i++) {
212                         if(strcmp(fonts.values[i]->get_text(),
213                                 fonts.values[i + 1]->get_text()) > 0) {
214                                 BC_ListBoxItem *temp = fonts.values[i + 1];
215                                 fonts.values[i + 1] = fonts.values[i];
216                                 fonts.values[i] = temp;
217                                 done = 0;
218                         }
219                 }
220         }
221
222         add_tool(font_title = new BC_Title(x, y, _("Font:")));
223         font = new TitleFont(client, this, x, y + font_title->get_h());
224         font->create_objects();
225         x += font->get_w();
226         add_subwindow(font_tumbler = new TitleFontTumble(client, this, x, y+10));
227         x += font_tumbler->get_w() + margin;
228
229         int x1 = x, y1 = y;
230         add_tool(size_title = new BC_Title(x1, y1+10, _("Size:")));
231         sprintf(string, "%d", client->config.size);
232         x1 += size_title->get_w() + margin;
233         size = new TitleSize(client, this, x1, y1+10, string);
234         size->create_objects();
235         int x2 = x1 + size->get_w(), y2 = y1 + size->get_h() + margin;
236         add_subwindow(size_tumbler = new TitleSizeTumble(client, this, x2, y1+10));
237
238         add_tool(pitch_title = new BC_Title(x-5, y2+10, _("Pitch:")));
239         pitch = new TitlePitch(client, this, x1, y2+10, &client->config.line_pitch);
240         pitch->create_objects();
241         x = x2 + size_tumbler->get_w() + margin;
242         int y3 = pitch->get_y() + pitch->get_h();
243
244         add_tool(style_title = new BC_Title(x, y, _("Style:")));
245         add_tool(italic = new TitleItalic(client, this, x, y + 20));
246         int w1 = italic->get_w();
247         add_tool(bold = new TitleBold(client, this, x, y + 50));
248         if( bold->get_w() > w1 ) w1 = bold->get_w();
249 #ifdef USE_OUTLINE
250         add_tool(stroke = new TitleStroke(client, this, x, y + 80));
251         if( stroke->get_w() > w1 ) w1 = stroke->get_w();
252 #endif
253         x += w1 + 10;
254         add_tool(justify_title = new BC_Title(x, y, _("Justify:")));
255         add_tool(left = new TitleLeft(client, this, x, y + 20));
256         w1 = left->get_w();
257         add_tool(center = new TitleCenter(client, this, x, y + 50));
258         if( center->get_w() > w1 ) w1 = center->get_w();
259         add_tool(right = new TitleRight(client, this, x, y + 80));
260         if( right->get_w() > w1 ) w1 = right->get_w();
261
262         x += w1 + 10;
263         add_tool(top = new TitleTop(client, this, x, y + 20));
264         add_tool(mid = new TitleMid(client, this, x, y + 50));
265         add_tool(bottom= new TitleBottom(client, this, x, y + 80));
266
267         x = 10;
268         y = y3;
269
270         add_tool(x_title = new BC_Title(x, y, _("X:")));
271         title_x = new TitleX(client, this, x, y + 20);
272         title_x->create_objects();
273         x += 90;
274
275         add_tool(y_title = new BC_Title(x, y, _("Y:")));
276         title_y = new TitleY(client, this, x, y + 20);
277         title_y->create_objects();
278         x += 90;
279
280         add_tool(motion_title = new BC_Title(x, y, _("Motion type:")));
281
282         motion = new TitleMotion(client, this, x, y + 20);
283         motion->create_objects();
284         x += 150;
285
286         add_tool(loop = new TitleLoop(client, x, y + 20));
287
288         x = 10;
289         y += 50;
290
291         add_tool(dropshadow_title = new BC_Title(x, y, _("Drop shadow:")));
292         w1 = dropshadow_title->get_w();
293         dropshadow = new TitleDropShadow(client, this, x, y + 20);
294         dropshadow->create_objects();
295         if( dropshadow->get_w() > w1 ) w1 = dropshadow->get_w();
296         x += w1 + 10;
297
298         add_tool(fadein_title = new BC_Title(x, y, _("Fade in (sec):")));
299         w1 = fadein_title->get_w();
300         add_tool(fade_in = new TitleFade(client, this, &client->config.fade_in, x, y + 20));
301         if( fade_in->get_w() > w1 ) w1 = fade_in->get_w();
302         x += w1 + 10;
303
304         add_tool(fadeout_title = new BC_Title(x, y, _("Fade out (sec):")));
305         w1 = fadeout_title->get_w();
306         add_tool(fade_out = new TitleFade(client, this, &client->config.fade_out, x, y + 20));
307         if( fade_out->get_w() > w1 ) w1 = fade_out->get_w();
308         x += w1 + 10;
309
310         add_tool(speed_title = new BC_Title(x, y, _("Speed:")));
311         w1 = speed_title->get_w();
312         speed = new TitleSpeed(client, this, x, y + 20);
313         speed->create_objects();
314         if( speed->get_w() > w1 ) w1 = speed->get_w();
315         x += w1 + 10;
316
317         color_x = x;
318         color_y = y + 16;
319         x += COLOR_W + 5;
320         add_tool(color_button = new TitleColorButton(client, this, x, y + 16, 0));
321         x += color_button->get_w() + 5;
322         color_thread = new TitleColorThread(client, this, 0);
323
324         x = color_x;
325         y += 50;
326
327         outline_color_x = x;
328         outline_color_y = y + 20;
329         x += COLOR_W + 5;
330         add_tool(outline_color_button = new TitleColorButton(client, this, x, y + 20, 1));
331         x += outline_color_button->get_w();
332         outline_color_thread = new TitleColorThread(client, this, 1);
333
334         x = 10;
335 //      y += 50;
336
337         add_tool(outline_title = new BC_Title(x, y, _("Outline:")));
338         outline = new TitleOutline(client, this, x, y + outline_title->get_h() + margin);
339         outline->create_objects();
340         x += outline->get_w() + margin;
341
342 #ifndef X_HAVE_UTF8_STRING
343         add_tool(encoding_title = new BC_Title(x, y + 3, _("Encoding:")));
344         encoding = new TitleEncoding(client, this, x, y + encoding_title->get_h() + margin);
345         encoding->create_objects();
346         x += 100;
347 #endif
348
349         y += outline_title->get_h() + margin;
350         add_tool(timecode = new TitleTimecode(client, x, y));
351         x += timecode->get_w() + margin;
352
353         add_tool(timecode_format = new TitleTimecodeFormat(client, x, y,
354                 Units::print_time_format(client->config.timecode_format, string)));
355         timecode_format->create_objects();
356         x = 10;
357         y += timecode_format->get_h() + margin;
358
359         add_tool(text_title = new BC_Title(x, y + 3, _("Text:")));
360         y += text_title->get_h() + margin;
361         text = new TitleText(client, this, x, y, get_w() - x - 10, get_h() - y - 50);
362         text->create_objects();
363         update();
364
365         show_window(1);
366 }
367
368 int TitleWindow::resize_event(int w, int h)
369 {
370         client->config.window_w = w;
371         client->config.window_h = h;
372
373         clear_box(0, 0, w, h);
374         font_title->reposition_window(font_title->get_x(), font_title->get_y());
375         font->reposition_window(font->get_x(), font->get_y());
376         font_tumbler->reposition_window(font_tumbler->get_x(), font_tumbler->get_y());
377         x_title->reposition_window(x_title->get_x(), x_title->get_y());
378         title_x->reposition_window(title_x->get_x(), title_x->get_y());
379         y_title->reposition_window(y_title->get_x(), y_title->get_y());
380         title_y->reposition_window(title_y->get_x(), title_y->get_y());
381         style_title->reposition_window(style_title->get_x(), style_title->get_y());
382         italic->reposition_window(italic->get_x(), italic->get_y());
383         bold->reposition_window(bold->get_x(), bold->get_y());
384 #ifdef USE_OUTLINE
385         stroke->reposition_window(stroke->get_x(), stroke->get_y());
386 #endif
387         size_title->reposition_window(size_title->get_x(), size_title->get_y());
388         size->reposition_window(size->get_x(), size->get_y());
389         size_tumbler->reposition_window(size_tumbler->get_x(), size_tumbler->get_y());
390         pitch_title->reposition_window(pitch_title->get_x(), pitch_title->get_y());
391         pitch->reposition_window(pitch->get_x(), pitch->get_y());
392
393 #ifndef X_HAVE_UTF8_STRING
394         encoding->reposition_window(encoding->get_x(), encoding->get_y());
395 #endif
396
397         color_button->reposition_window(color_button->get_x(), color_button->get_y());
398 #ifdef USE_OUTLINE
399         color_stroke_button->reposition_window(color_stroke_button->get_x(), color_stroke_button->get_y());
400 #endif
401         outline_color_button->reposition_window(outline_color_button->get_x(), outline_color_button->get_y());
402         motion_title->reposition_window(motion_title->get_x(), motion_title->get_y());
403         motion->reposition_window(motion->get_x(), motion->get_y());
404         loop->reposition_window(loop->get_x(), loop->get_y());
405         dropshadow_title->reposition_window(dropshadow_title->get_x(), dropshadow_title->get_y());
406         dropshadow->reposition_window(dropshadow->get_x(), dropshadow->get_y());
407         fadein_title->reposition_window(fadein_title->get_x(), fadein_title->get_y());
408         fade_in->reposition_window(fade_in->get_x(), fade_in->get_y());
409         fadeout_title->reposition_window(fadeout_title->get_x(), fadeout_title->get_y());
410         fade_out->reposition_window(fade_out->get_x(), fade_out->get_y());
411         text_title->reposition_window(text_title->get_x(), text_title->get_y());
412 #ifdef USE_OUTLINE
413         stroke_width->reposition_window(stroke_width->get_x(), stroke_width->get_y());
414         strokewidth_title->reposition_window(strokewidth_title->get_x(), strokewidth_title->get_y());
415 #endif
416         timecode->reposition_window(timecode->get_x(), timecode->get_y());
417
418         text->reposition_window(text->get_x(),
419                 text->get_y(),
420                 w - text->get_x() - 10,
421                 BC_TextBox::pixels_to_rows(this, MEDIUMFONT, h - text->get_y() - 10));
422
423
424
425         justify_title->reposition_window(justify_title->get_x(), justify_title->get_y());
426         left->reposition_window(left->get_x(), left->get_y());
427         center->reposition_window(center->get_x(), center->get_y());
428         right->reposition_window(right->get_x(), right->get_y());
429         top->reposition_window(top->get_x(), top->get_y());
430         mid->reposition_window(mid->get_x(), mid->get_y());
431         bottom->reposition_window(bottom->get_x(), bottom->get_y());
432         speed_title->reposition_window(speed_title->get_x(), speed_title->get_y());
433         speed->reposition_window(speed->get_x(), speed->get_y());
434         update_color();
435         flash();
436
437         return 1;
438 }
439
440
441 void TitleWindow::previous_font()
442 {
443         int current_font = font->get_number();
444         current_font--;
445         if(current_font < 0) current_font = fonts.total - 1;
446
447         if(current_font < 0 || current_font >= fonts.total) return;
448
449         for(int i = 0; i < fonts.total; i++)
450         {
451                 fonts.values[i]->set_selected(i == current_font);
452         }
453
454         font->update(fonts.values[current_font]->get_text());
455         strcpy(client->config.font, fonts.values[current_font]->get_text());
456         client->send_configure_change();
457 }
458
459 void  TitleWindow::next_font()
460 {
461         int current_font = font->get_number();
462         current_font++;
463         if(current_font >= fonts.total) current_font = 0;
464
465         if(current_font < 0 || current_font >= fonts.total) return;
466
467         for(int i = 0; i < fonts.total; i++)
468         {
469                 fonts.values[i]->set_selected(i == current_font);
470         }
471
472         font->update(fonts.values[current_font]->get_text());
473         strcpy(client->config.font, fonts.values[current_font]->get_text());
474         client->send_configure_change();
475 }
476
477
478
479 void TitleWindow::update_color()
480 {
481 //printf("TitleWindow::update_color %x\n", client->config.color);
482         set_color(client->config.color);
483         draw_box(color_x, color_y, COLOR_W, COLOR_H);
484         flash(color_x, color_y, COLOR_W, COLOR_H);
485         set_color(client->config.outline_color);
486         draw_box(outline_color_x, outline_color_y, COLOR_W, COLOR_H);
487         set_color(BLACK);
488         draw_rectangle(color_x, color_y, COLOR_W, COLOR_H);
489         draw_rectangle(outline_color_x, outline_color_y, COLOR_W, COLOR_H);
490         flash(outline_color_x, outline_color_y, COLOR_W, COLOR_H);
491 }
492
493 void TitleWindow::update_justification()
494 {
495         left->update(client->config.hjustification == JUSTIFY_LEFT);
496         center->update(client->config.hjustification == JUSTIFY_CENTER);
497         right->update(client->config.hjustification == JUSTIFY_RIGHT);
498         top->update(client->config.vjustification == JUSTIFY_TOP);
499         mid->update(client->config.vjustification == JUSTIFY_MID);
500         bottom->update(client->config.vjustification == JUSTIFY_BOTTOM);
501 }
502
503 void TitleWindow::update()
504 {
505         title_x->update((int64_t)client->config.x);
506         title_y->update((int64_t)client->config.y);
507         italic->update(client->config.style & BC_FONT_ITALIC);
508         bold->update(client->config.style & BC_FONT_BOLD);
509 #ifdef USE_OUTLINE
510         stroke->update(client->config.style & BC_FONT_OUTLINE);
511 #endif
512         size->update(client->config.size);
513 #ifndef X_HAVE_UTF8_STRING
514         encoding->update(client->config.encoding);
515 #endif
516         motion->update(TitleMain::motion_to_text(client->config.motion_strategy));
517         loop->update(client->config.loop);
518         dropshadow->update((float)client->config.dropshadow);
519         fade_in->update((float)client->config.fade_in);
520         fade_out->update((float)client->config.fade_out);
521 #ifdef USE_OUTLINE
522         stroke_width->update((float)client->config.stroke_width);
523 #endif
524         font->update(client->config.font);
525         text->update(&client->config.wtext[0]);
526         speed->update(client->config.pixels_per_second);
527         outline->update((int64_t)client->config.outline_size);
528         timecode->update(client->config.timecode);
529         timecode_format->update(client->config.timecode_format);
530
531         char string[BCTEXTLEN];
532         for(int i = 0; i < lengthof(timeunit_formats); i++) {
533                 if(timeunit_formats[i] == client->config.timecode_format)
534                 {
535                         timecode_format->set_text(
536                                 Units::print_time_format(timeunit_formats[i], string));
537                         break;
538                 }
539         }
540         update_justification();
541         update_color();
542 }
543
544
545 TitleFontTumble::TitleFontTumble(TitleMain *client, TitleWindow *window, int x, int y)
546  : BC_Tumbler(x, y)
547 {
548         this->client = client;
549         this->window = window;
550 }
551 int TitleFontTumble::handle_up_event()
552 {
553         window->previous_font();
554         return 1;
555 }
556
557 int TitleFontTumble::handle_down_event()
558 {
559         window->next_font();
560         return 1;
561 }
562
563
564
565 TitleSizeTumble::TitleSizeTumble(TitleMain *client, TitleWindow *window, int x, int y)
566  : BC_Tumbler(x, y)
567 {
568         this->client = client;
569         this->window = window;
570 }
571
572 int TitleSizeTumble::handle_up_event()
573 {
574         int current_index = -1;
575         int current_difference = -1;
576         for(int i = 0; i < window->sizes.size(); i++)
577         {
578                 int size = atoi(window->sizes.get(i)->get_text());
579                 if(current_index < 0 ||
580                         abs(size - client->config.size) < current_difference)
581                 {
582                         current_index = i;
583                         current_difference = abs(size - client->config.size);
584                 }
585         }
586
587         current_index++;
588         if(current_index >= window->sizes.size()) current_index = 0;
589
590
591         client->config.size = atoi(window->sizes.get(current_index)->get_text());
592         window->size->update(client->config.size);
593         client->send_configure_change();
594         return 1;
595 }
596
597 int TitleSizeTumble::handle_down_event()
598 {
599         int current_index = -1;
600         int current_difference = -1;
601         for(int i = 0; i < window->sizes.size(); i++)
602         {
603                 int size = atoi(window->sizes.get(i)->get_text());
604                 if(current_index < 0 ||
605                         abs(size - client->config.size) < current_difference)
606                 {
607                         current_index = i;
608                         current_difference = abs(size - client->config.size);
609                 }
610         }
611
612         current_index--;
613         if(current_index < 0) current_index = window->sizes.size() - 1;
614
615
616         client->config.size = atoi(window->sizes.get(current_index)->get_text());
617         window->size->update(client->config.size);
618         client->send_configure_change();
619         return 1;
620 }
621
622 TitleBold::TitleBold(TitleMain *client, TitleWindow *window, int x, int y)
623  : BC_CheckBox(x, y, client->config.style & BC_FONT_BOLD, _("Bold"))
624 {
625         this->client = client;
626         this->window = window;
627 }
628
629 int TitleBold::handle_event()
630 {
631         client->config.style =
632                 (client->config.style & ~BC_FONT_BOLD) |
633                         (get_value() ? BC_FONT_BOLD : 0);
634         client->send_configure_change();
635         return 1;
636 }
637
638 TitleItalic::TitleItalic(TitleMain *client, TitleWindow *window, int x, int y)
639  : BC_CheckBox(x, y, client->config.style & BC_FONT_ITALIC, _("Italic"))
640 {
641         this->client = client;
642         this->window = window;
643 }
644 int TitleItalic::handle_event()
645 {
646         client->config.style =
647                 (client->config.style & ~BC_FONT_ITALIC) |
648                         (get_value() ? BC_FONT_ITALIC : 0);
649         client->send_configure_change();
650         return 1;
651 }
652
653
654
655 TitleSize::TitleSize(TitleMain *client, TitleWindow *window, int x, int y, char *text)
656  : BC_PopupTextBox(window,
657                 &window->sizes,
658                 text,
659                 x,
660                 y,
661                 64,
662                 300)
663 {
664         this->client = client;
665         this->window = window;
666 }
667 TitleSize::~TitleSize()
668 {
669 }
670 int TitleSize::handle_event()
671 {
672         client->config.size = atol(get_text());
673 //printf("TitleSize::handle_event 1 %s\n", get_text());
674         client->send_configure_change();
675         return 1;
676 }
677 void TitleSize::update(int size)
678 {
679         char string[BCTEXTLEN];
680         sprintf(string, "%d", size);
681         BC_PopupTextBox::update(string);
682 }
683
684 TitlePitch::
685 TitlePitch(TitleMain *client, TitleWindow *window, int x, int y, int *value)
686  : BC_TumbleTextBox(window, *value, 0, INT_MAX, x, y, 64)
687
688 {
689         this->client = client;
690         this->window = window;
691         this->value = value;
692 }
693
694 TitlePitch::
695 ~TitlePitch()
696 {
697 }
698
699 int TitlePitch::handle_event()
700 {
701         *value = atof(get_text());
702         client->send_configure_change();
703         return 1;
704 }
705
706 TitleColorButton::TitleColorButton(TitleMain *client,
707         TitleWindow *window,
708         int x,
709         int y,
710         int is_outline)
711  : BC_GenericButton(x, y, is_outline ? _("Outline color...") : _("Color..."))
712 {
713         this->client = client;
714         this->window = window;
715         this->is_outline = is_outline;
716 }
717 int TitleColorButton::handle_event()
718 {
719         if(is_outline)
720                 window->outline_color_thread->start_window(client->config.outline_color,
721                         client->config.outline_alpha);
722         else
723                 window->color_thread->start_window(client->config.color,
724                         client->config.alpha);
725         return 1;
726 }
727
728 TitleMotion::TitleMotion(TitleMain *client, TitleWindow *window, int x, int y)
729  : BC_PopupTextBox(window,
730                 &window->paths,
731                 client->motion_to_text(client->config.motion_strategy),
732                 x,
733                 y,
734                 120,
735                 100)
736 {
737         this->client = client;
738         this->window = window;
739 }
740 int TitleMotion::handle_event()
741 {
742         client->config.motion_strategy = client->text_to_motion(get_text());
743         client->send_configure_change();
744         return 1;
745 }
746
747 TitleLoop::TitleLoop(TitleMain *client, int x, int y)
748  : BC_CheckBox(x, y, client->config.loop, _("Loop"))
749 {
750         this->client = client;
751 }
752 int TitleLoop::handle_event()
753 {
754         client->config.loop = get_value();
755         client->send_configure_change();
756         return 1;
757 }
758 TitleTimecode::TitleTimecode(TitleMain *client, int x, int y)
759  : BC_CheckBox(x, y, client->config.timecode, _("Stamp timecode"))
760 {
761         this->client = client;
762 }
763 int TitleTimecode::handle_event()
764 {
765         client->config.timecode = get_value();
766         client->send_configure_change();
767         return 1;
768 }
769
770 TitleTimecodeFormat::TitleTimecodeFormat(TitleMain *client, int x, int y, const char *text)
771  : BC_PopupMenu(x, y, 100, text, 1)
772 {
773         this->client = client;
774 }
775
776 int TitleTimecodeFormat::handle_event()
777 {
778         client->config.timecode_format = Units::text_to_format(get_text());
779         client->send_configure_change();
780         return 1;
781 }
782
783 void TitleTimecodeFormat::create_objects()
784 {
785         char string[BCTEXTLEN];
786         for(int i = 0; i < lengthof(timeunit_formats); i++) {
787                 add_item(new BC_MenuItem(
788                         Units::print_time_format(timeunit_formats[i], string)));
789         }
790 }
791
792
793 int TitleTimecodeFormat::update(int timecode_format)
794 {
795         char string[BCTEXTLEN];
796         for(int i = 0; i < lengthof(timeunit_formats); i++) {
797                 if(timeunit_formats[i] == timecode_format)
798                 {
799                         set_text(Units::print_time_format(timeunit_formats[i], string));
800                         break;
801                 }
802         }
803         return 0;
804 }
805
806 TitleFade::TitleFade(TitleMain *client,
807         TitleWindow *window,
808         double *value,
809         int x,
810         int y)
811  : BC_TextBox(x, y, 90, 1, (float)*value)
812 {
813         this->client = client;
814         this->window = window;
815         this->value = value;
816 }
817
818 int TitleFade::handle_event()
819 {
820         *value = atof(get_text());
821         client->send_configure_change();
822         return 1;
823 }
824
825 TitleFont::TitleFont(TitleMain *client, TitleWindow *window, int x, int y)
826  : BC_PopupTextBox(window,
827                 &window->fonts,
828                 client->config.font,
829                 x,
830                 y,
831                 200,
832                 500,
833                 LISTBOX_ICON_LIST)
834 {
835         this->client = client;
836         this->window = window;
837 }
838 int TitleFont::handle_event()
839 {
840         strcpy(client->config.font, get_text());
841         client->send_configure_change();
842         return 1;
843 }
844
845 TitleText::TitleText(TitleMain *client,
846         TitleWindow *window, int x, int y, int w, int h)
847  : BC_ScrollTextBox(window, x, y, w,
848                 BC_TextBox::pixels_to_rows(window, MEDIUMFONT, h),
849                 client->config.wtext, 8192)
850 {
851         this->client = client;
852         this->window = window;
853 //printf("TitleText::TitleText %s\n", client->config.text);
854 }
855
856 int TitleText::handle_event()
857 {
858         int len =  sizeof(client->config.wtext) / sizeof(wchar_t);
859         wcsncpy(client->config.wtext, get_wtext(), len);
860         client->config.wtext[len-1] = 0;
861         client->config.wlen = wcslen(client->config.wtext);
862         client->send_configure_change();
863         return 1;
864 }
865
866
867 TitleDropShadow::TitleDropShadow(TitleMain *client, TitleWindow *window, int x, int y)
868  : BC_TumbleTextBox(window,
869         (int64_t)client->config.dropshadow,
870         (int64_t)-1000,
871         (int64_t)1000,
872         x,
873         y,
874         70)
875 {
876         this->client = client;
877         this->window = window;
878 }
879 int TitleDropShadow::handle_event()
880 {
881         client->config.dropshadow = atol(get_text());
882         client->send_configure_change();
883         return 1;
884 }
885
886
887 TitleOutline::TitleOutline(TitleMain *client, TitleWindow *window, int x, int y)
888  : BC_TumbleTextBox(window,
889         (int64_t)client->config.outline_size,
890         (int64_t)0,
891         (int64_t)1000,
892         x,
893         y,
894         70)
895 {
896         this->client = client;
897         this->window = window;
898 }
899 int TitleOutline::handle_event()
900 {
901         client->config.outline_size = atol(get_text());
902         client->send_configure_change();
903         return 1;
904 }
905
906
907 TitleX::TitleX(TitleMain *client, TitleWindow *window, int x, int y)
908  : BC_TumbleTextBox(window,
909         (int64_t)client->config.x,
910         (int64_t)-2048,
911         (int64_t)2048,
912         x,
913         y,
914         60)
915 {
916         this->client = client;
917         this->window = window;
918 }
919 int TitleX::handle_event()
920 {
921         client->config.x = atol(get_text());
922         client->send_configure_change();
923         return 1;
924 }
925
926 TitleY::TitleY(TitleMain *client, TitleWindow *window, int x, int y)
927  : BC_TumbleTextBox(window,
928         (int64_t)client->config.y,
929         (int64_t)-2048,
930         (int64_t)2048,
931         x,
932         y,
933         60)
934 {
935         this->client = client;
936         this->window = window;
937 }
938 int TitleY::handle_event()
939 {
940         client->config.y = atol(get_text());
941         client->send_configure_change();
942         return 1;
943 }
944
945 TitleStrokeW::TitleStrokeW(TitleMain *client,
946         TitleWindow *window,
947         int x,
948         int y)
949  : BC_TumbleTextBox(window,
950         (float)client->config.stroke_width,
951         (float)-2048,
952         (float)2048,
953         x,
954         y,
955         60)
956 {
957         this->client = client;
958         this->window = window;
959 }
960 int TitleStrokeW::handle_event()
961 {
962         client->config.stroke_width = atof(get_text());
963         client->send_configure_change();
964         return 1;
965 }
966
967
968 TitleSpeed::TitleSpeed(TitleMain *client, TitleWindow *window, int x, int y)
969  : BC_TumbleTextBox(window,
970         (float)client->config.pixels_per_second,
971         (float)0,
972         (float)1000,
973         x,
974         y,
975         70)
976 {
977         this->client = client;
978 }
979
980
981 int TitleSpeed::handle_event()
982 {
983         client->config.pixels_per_second = atof(get_text());
984         client->send_configure_change();
985         return 1;
986 }
987
988
989
990
991
992
993
994 TitleLeft::TitleLeft(TitleMain *client, TitleWindow *window, int x, int y)
995  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_LEFT, _("Left"))
996 {
997         this->client = client;
998         this->window = window;
999 }
1000 int TitleLeft::handle_event()
1001 {
1002         client->config.hjustification = JUSTIFY_LEFT;
1003         window->update_justification();
1004         client->send_configure_change();
1005         return 1;
1006 }
1007
1008 TitleCenter::TitleCenter(TitleMain *client, TitleWindow *window, int x, int y)
1009  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_CENTER, _("Center"))
1010 {
1011         this->client = client;
1012         this->window = window;
1013 }
1014 int TitleCenter::handle_event()
1015 {
1016         client->config.hjustification = JUSTIFY_CENTER;
1017         window->update_justification();
1018         client->send_configure_change();
1019         return 1;
1020 }
1021
1022 TitleRight::TitleRight(TitleMain *client, TitleWindow *window, int x, int y)
1023  : BC_Radial(x, y, client->config.hjustification == JUSTIFY_RIGHT, _("Right"))
1024 {
1025         this->client = client;
1026         this->window = window;
1027 }
1028 int TitleRight::handle_event()
1029 {
1030         client->config.hjustification = JUSTIFY_RIGHT;
1031         window->update_justification();
1032         client->send_configure_change();
1033         return 1;
1034 }
1035
1036
1037
1038 TitleTop::TitleTop(TitleMain *client, TitleWindow *window, int x, int y)
1039  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_TOP, _("Top"))
1040 {
1041         this->client = client;
1042         this->window = window;
1043 }
1044 int TitleTop::handle_event()
1045 {
1046         client->config.vjustification = JUSTIFY_TOP;
1047         window->update_justification();
1048         client->send_configure_change();
1049         return 1;
1050 }
1051
1052 TitleMid::TitleMid(TitleMain *client, TitleWindow *window, int x, int y)
1053  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_MID, _("Mid"))
1054 {
1055         this->client = client;
1056         this->window = window;
1057 }
1058 int TitleMid::handle_event()
1059 {
1060         client->config.vjustification = JUSTIFY_MID;
1061         window->update_justification();
1062         client->send_configure_change();
1063         return 1;
1064 }
1065
1066 TitleBottom::TitleBottom(TitleMain *client, TitleWindow *window, int x, int y)
1067  : BC_Radial(x, y, client->config.vjustification == JUSTIFY_BOTTOM, _("Bottom"))
1068 {
1069         this->client = client;
1070         this->window = window;
1071 }
1072 int TitleBottom::handle_event()
1073 {
1074         client->config.vjustification = JUSTIFY_BOTTOM;
1075         window->update_justification();
1076         client->send_configure_change();
1077         return 1;
1078 }
1079
1080
1081
1082 TitleColorThread::TitleColorThread(TitleMain *client, TitleWindow *window, int is_outline)
1083  : ColorThread(1)
1084 {
1085         this->client = client;
1086         this->window = window;
1087         this->is_outline = is_outline;
1088 }
1089
1090 int TitleColorThread::handle_new_color(int output, int alpha)
1091 {
1092         if(is_outline)
1093         {
1094                 client->config.outline_color = output;
1095                 client->config.outline_alpha = alpha;
1096         }
1097         else
1098         {
1099                 client->config.color = output;
1100                 client->config.alpha = alpha;
1101         }
1102
1103         window->lock_window("TitleColorThread::handle_new_color");
1104         window->update_color();
1105         window->flush();
1106         window->unlock_window();
1107
1108         client->send_configure_change();
1109
1110
1111         return 1;
1112 }
1113 TitleColorStrokeThread::TitleColorStrokeThread(TitleMain *client, TitleWindow *window)
1114  : ColorThread()
1115 {
1116         this->client = client;
1117         this->window = window;
1118 }
1119
1120 int TitleColorStrokeThread::handle_event(int output)
1121 {
1122         client->config.color_stroke = output;
1123         window->update_color();
1124         window->flush();
1125         client->send_configure_change();
1126         return 1;
1127 }