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