~akirad/cinecutie/trunk

« back to all changes in this revision

Viewing changes to cinecutie/cwindowtool.C

  • Committer: Paolo Rampino
  • Date: 2010-02-17 19:46:21 UTC
  • Revision ID: git-v1:c39ff77ffa6ae08441c12e7d7f54e3897ddde7f1
Initial Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * CINELERRA
 
4
 * Copyright (C) 2008 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 "automation.h"
 
23
#include "clip.h"
 
24
#include "condition.h"
 
25
#include "cpanel.h"
 
26
#include "cplayback.h"
 
27
#include "cwindow.h"
 
28
#include "cwindowgui.h"
 
29
#include "cwindowtool.h"
 
30
#include "edl.h"
 
31
#include "edlsession.h"
 
32
#include "floatauto.h"
 
33
#include "floatautos.h"
 
34
#include "keys.h"
 
35
#include "language.h"
 
36
#include "localsession.h"
 
37
#include "mainsession.h"
 
38
#include "maskauto.h"
 
39
#include "maskautos.h"
 
40
#include "mutex.h"
 
41
#include "mwindow.h"
 
42
#include "mwindowgui.h"
 
43
#include "theme.h"
 
44
#include "track.h"
 
45
#include "trackcanvas.h"
 
46
#include "transportque.h"
 
47
 
 
48
 
 
49
CWindowTool::CWindowTool(MWindow *mwindow, CWindowGUI *gui)
 
50
 : Thread()
 
51
{
 
52
        this->mwindow = mwindow;
 
53
        this->gui = gui;
 
54
        tool_gui = 0;
 
55
        done = 0;
 
56
        current_tool = CWINDOW_NONE;
 
57
        set_synchronous(1);
 
58
        input_lock = new Condition(0, "CWindowTool::input_lock");
 
59
        output_lock = new Condition(1, "CWindowTool::output_lock");
 
60
        tool_gui_lock = new Mutex("CWindowTool::tool_gui_lock");
 
61
}
 
62
 
 
63
CWindowTool::~CWindowTool()
 
64
{
 
65
        done = 1;
 
66
        stop_tool();
 
67
        input_lock->unlock();
 
68
        Thread::join();
 
69
        delete input_lock;
 
70
        delete output_lock;
 
71
        delete tool_gui_lock;
 
72
}
 
73
 
 
74
void CWindowTool::start_tool(int operation)
 
75
{
 
76
        CWindowToolGUI *new_gui = 0;
 
77
        int result = 0;
 
78
 
 
79
//printf("CWindowTool::start_tool 1\n");
 
80
        if(current_tool != operation)
 
81
        {
 
82
                current_tool = operation;
 
83
                switch(operation)
 
84
                {
 
85
                        case CWINDOW_EYEDROP:
 
86
                                new_gui = new CWindowEyedropGUI(mwindow, this);
 
87
                                break;
 
88
                        case CWINDOW_CROP:
 
89
                                new_gui = new CWindowCropGUI(mwindow, this);
 
90
                                break;
 
91
                        case CWINDOW_CAMERA:
 
92
                                new_gui = new CWindowCameraGUI(mwindow, this);
 
93
                                break;
 
94
                        case CWINDOW_PROJECTOR:
 
95
                                new_gui = new CWindowProjectorGUI(mwindow, this);
 
96
                                break;
 
97
                        case CWINDOW_MASK:
 
98
                                new_gui = new CWindowMaskGUI(mwindow, this);
 
99
                                break;
 
100
                        default:
 
101
                                result = 1;
 
102
                                stop_tool();
 
103
                                break;
 
104
                }
 
105
 
 
106
//printf("CWindowTool::start_tool 1\n");
 
107
 
 
108
 
 
109
                if(!result)
 
110
                {
 
111
                        stop_tool();
 
112
// Wait for previous tool GUI to finish
 
113
                        output_lock->lock("CWindowTool::start_tool");
 
114
                        this->tool_gui = new_gui;
 
115
                        tool_gui->create_objects();
 
116
                        
 
117
                        if(mwindow->edl->session->tool_window &&
 
118
                                mwindow->session->show_cwindow) tool_gui->show_window();
 
119
                        tool_gui->flush();
 
120
                        
 
121
                        
 
122
// Signal thread to run next tool GUI
 
123
                        input_lock->unlock();
 
124
                }
 
125
//printf("CWindowTool::start_tool 1\n");
 
126
        }
 
127
        else
 
128
        if(tool_gui) 
 
129
        {
 
130
                tool_gui->lock_window("CWindowTool::start_tool");
 
131
                tool_gui->update();
 
132
                tool_gui->unlock_window();
 
133
        }
 
134
 
 
135
//printf("CWindowTool::start_tool 2\n");
 
136
 
 
137
}
 
138
 
 
139
 
 
140
void CWindowTool::stop_tool()
 
141
{
 
142
        if(tool_gui)
 
143
        {
 
144
                tool_gui->lock_window("CWindowTool::stop_tool");
 
145
                tool_gui->set_done(0);
 
146
                tool_gui->unlock_window();
 
147
        }
 
148
}
 
149
 
 
150
void CWindowTool::show_tool()
 
151
{
 
152
        if(tool_gui && mwindow->edl->session->tool_window)
 
153
        {
 
154
                tool_gui->lock_window("CWindowTool::show_tool");
 
155
                tool_gui->show_window();
 
156
                tool_gui->unlock_window();
 
157
        }
 
158
}
 
159
 
 
160
void CWindowTool::hide_tool()
 
161
{
 
162
        if(tool_gui && mwindow->edl->session->tool_window)
 
163
        {
 
164
                tool_gui->lock_window("CWindowTool::show_tool");
 
165
                tool_gui->hide_window();
 
166
                tool_gui->unlock_window();
 
167
        }
 
168
}
 
169
 
 
170
 
 
171
void CWindowTool::run()
 
172
{
 
173
        while(!done)
 
174
        {
 
175
                input_lock->lock("CWindowTool::run");
 
176
                if(!done)
 
177
                {
 
178
                        tool_gui->run_window();
 
179
                        tool_gui_lock->lock("CWindowTool::run");
 
180
                        delete tool_gui;
 
181
                        tool_gui = 0;
 
182
                        tool_gui_lock->unlock();
 
183
                }
 
184
                output_lock->unlock();
 
185
        }
 
186
}
 
187
 
 
188
void CWindowTool::update_show_window()
 
189
{
 
190
        if(tool_gui)
 
191
        {
 
192
                tool_gui->lock_window("CWindowTool::update_show_window");
 
193
 
 
194
                if(mwindow->edl->session->tool_window) 
 
195
                {
 
196
                        tool_gui->update();
 
197
                        tool_gui->show_window();
 
198
                }
 
199
                else
 
200
                        tool_gui->hide_window();
 
201
                tool_gui->flush();
 
202
 
 
203
                tool_gui->unlock_window();
 
204
        }
 
205
}
 
206
 
 
207
void CWindowTool::update_values()
 
208
{
 
209
        tool_gui_lock->lock("CWindowTool::update_values");
 
210
        if(tool_gui)
 
211
        {
 
212
                tool_gui->lock_window("CWindowTool::update_values");
 
213
                tool_gui->update();
 
214
                tool_gui->flush();
 
215
                tool_gui->unlock_window();
 
216
        }
 
217
        tool_gui_lock->unlock();
 
218
}
 
219
 
 
220
 
 
221
 
 
222
 
 
223
 
 
224
 
 
225
 
 
226
CWindowToolGUI::CWindowToolGUI(MWindow *mwindow, 
 
227
        CWindowTool *thread, 
 
228
        char *title,
 
229
        int w, 
 
230
        int h)
 
231
 : BC_Window(title,
 
232
        mwindow->session->ctool_x,
 
233
        mwindow->session->ctool_y,
 
234
        w,
 
235
        h,
 
236
        w,
 
237
        h,
 
238
        0,
 
239
        0,
 
240
        1)
 
241
{
 
242
        this->mwindow = mwindow;
 
243
        this->thread = thread;
 
244
        current_operation = 0;
 
245
}
 
246
 
 
247
CWindowToolGUI::~CWindowToolGUI()
 
248
{
 
249
}
 
250
 
 
251
int CWindowToolGUI::close_event()
 
252
{
 
253
        hide_window();
 
254
        flush();
 
255
        mwindow->edl->session->tool_window = 0;
 
256
        unlock_window();
 
257
 
 
258
 
 
259
 
 
260
        thread->gui->lock_window("CWindowToolGUI::close_event");
 
261
        thread->gui->composite_panel->set_operation(mwindow->edl->session->cwindow_operation);
 
262
        thread->gui->flush();
 
263
        thread->gui->unlock_window();
 
264
 
 
265
        lock_window("CWindowToolGUI::close_event");
 
266
        return 1;
 
267
}
 
268
 
 
269
int CWindowToolGUI::keypress_event()
 
270
{
 
271
        if(get_keypress() == 'w' || get_keypress() == 'W')
 
272
                return close_event();
 
273
        return 0;
 
274
}
 
275
 
 
276
int CWindowToolGUI::translation_event()
 
277
{
 
278
        mwindow->session->ctool_x = get_x();
 
279
        mwindow->session->ctool_y = get_y();
 
280
        return 0;
 
281
}
 
282
 
 
283
 
 
284
 
 
285
 
 
286
 
 
287
 
 
288
CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, float value, int log_increment = 0)
 
289
 : BC_TumbleTextBox(gui, 
 
290
                (float)value,
 
291
                (float)-65536,
 
292
                (float)65536,
 
293
                x, 
 
294
                y, 
 
295
                100)
 
296
{
 
297
        this->gui = gui;
 
298
        set_log_floatincrement(log_increment);
 
299
}
 
300
 
 
301
CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, int value)
 
302
 : BC_TumbleTextBox(gui, 
 
303
                (int64_t)value,
 
304
                (int64_t)-65536,
 
305
                (int64_t)65536,
 
306
                x, 
 
307
                y, 
 
308
                100)
 
309
{
 
310
        this->gui = gui;
 
311
}
 
312
int CWindowCoord::handle_event()
 
313
{
 
314
        gui->event_caller = this;
 
315
        gui->handle_event();
 
316
        return 1;
 
317
}
 
318
 
 
319
 
 
320
CWindowCropOK::CWindowCropOK(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
 
321
 : BC_GenericButton(x, y, _("Do it"))
 
322
{
 
323
        this->mwindow = mwindow;
 
324
        this->gui = gui;
 
325
}
 
326
int CWindowCropOK::handle_event()
 
327
{
 
328
        mwindow->crop_video();
 
329
        return 1;
 
330
}
 
331
 
 
332
 
 
333
int CWindowCropOK::keypress_event()
 
334
{
 
335
        if(get_keypress() == 0xd) 
 
336
        {
 
337
                handle_event();
 
338
                return 1;
 
339
        }
 
340
        return 0;
 
341
}
 
342
 
 
343
 
 
344
 
 
345
 
 
346
 
 
347
 
 
348
 
 
349
CWindowCropGUI::CWindowCropGUI(MWindow *mwindow, CWindowTool *thread)
 
350
 : CWindowToolGUI(mwindow, 
 
351
        thread,
 
352
        PROGRAM_NAME ": Crop",
 
353
        330,
 
354
        100)
 
355
{
 
356
}
 
357
 
 
358
 
 
359
CWindowCropGUI::~CWindowCropGUI()
 
360
{
 
361
}
 
362
 
 
363
void CWindowCropGUI::create_objects()
 
364
{
 
365
        int x = 10, y = 10;
 
366
        BC_TumbleTextBox *textbox;
 
367
        BC_Title *title;
 
368
 
 
369
        int column1 = 0;
 
370
        int pad = MAX(BC_TextBox::calculate_h(this, MEDIUMFONT, 1, 1), 
 
371
                BC_Title::calculate_h(this, "X")) + 5;
 
372
        add_subwindow(title = new BC_Title(x, y, _("X1:")));
 
373
        column1 = MAX(column1, title->get_w());
 
374
        y += pad;
 
375
        add_subwindow(title = new BC_Title(x, y, _("W:")));
 
376
        column1 = MAX(column1, title->get_w());
 
377
        y += pad;
 
378
        add_subwindow(new CWindowCropOK(mwindow, thread->tool_gui, x, y));
 
379
 
 
380
        x += column1 + 5;
 
381
        y = 10;
 
382
        x1 = new CWindowCoord(thread->tool_gui, x, y, mwindow->edl->session->crop_x1);
 
383
        x1->create_objects();
 
384
        y += pad;
 
385
        width = new CWindowCoord(thread->tool_gui, 
 
386
                x, 
 
387
                y, 
 
388
                mwindow->edl->session->crop_x2 - 
 
389
                        mwindow->edl->session->crop_x1);
 
390
        width->create_objects();
 
391
 
 
392
 
 
393
        x += x1->get_w() + 10;
 
394
        y = 10;
 
395
        int column2 = 0;
 
396
        add_subwindow(title = new BC_Title(x, y, _("Y1:")));
 
397
        column2 = MAX(column2, title->get_w());
 
398
        y += pad;
 
399
        add_subwindow(title = new BC_Title(x, y, _("H:")));
 
400
        column2 = MAX(column2, title->get_w());
 
401
        y += pad;
 
402
 
 
403
        y = 10;
 
404
        x += column2 + 5;
 
405
        y1 = new CWindowCoord(thread->tool_gui, x, y, mwindow->edl->session->crop_y1);
 
406
        y1->create_objects();
 
407
        y += pad;
 
408
        height = new CWindowCoord(thread->tool_gui, 
 
409
                x, 
 
410
                y, 
 
411
                mwindow->edl->session->crop_y2 - 
 
412
                        mwindow->edl->session->crop_y1);
 
413
        height->create_objects();
 
414
}
 
415
 
 
416
void CWindowCropGUI::handle_event()
 
417
{
 
418
        int new_x1, new_y1;
 
419
        new_x1 = atol(x1->get_text());
 
420
        new_y1 = atol(y1->get_text());
 
421
        if(new_x1 != mwindow->edl->session->crop_x1)
 
422
        {
 
423
                mwindow->edl->session->crop_x2 = new_x1 +
 
424
                        mwindow->edl->session->crop_x2 - 
 
425
                        mwindow->edl->session->crop_x1;
 
426
                mwindow->edl->session->crop_x1 = new_x1;
 
427
        }
 
428
        if(new_y1 != mwindow->edl->session->crop_y1)
 
429
        {
 
430
                mwindow->edl->session->crop_y2 = new_y1 +
 
431
                        mwindow->edl->session->crop_y2 -
 
432
                        mwindow->edl->session->crop_y1;
 
433
                mwindow->edl->session->crop_y1 = atol(y1->get_text());
 
434
        }
 
435
        mwindow->edl->session->crop_x2 = atol(width->get_text()) + 
 
436
                mwindow->edl->session->crop_x1;
 
437
        mwindow->edl->session->crop_y2 = atol(height->get_text()) + 
 
438
                mwindow->edl->session->crop_y1;
 
439
        update();
 
440
        mwindow->cwindow->gui->lock_window("CWindowCropGUI::handle_event");
 
441
        mwindow->cwindow->gui->canvas->draw_refresh();
 
442
        mwindow->cwindow->gui->unlock_window();
 
443
}
 
444
 
 
445
void CWindowCropGUI::update()
 
446
{
 
447
        x1->update((int64_t)mwindow->edl->session->crop_x1);
 
448
        y1->update((int64_t)mwindow->edl->session->crop_y1);
 
449
        width->update((int64_t)mwindow->edl->session->crop_x2 - 
 
450
                mwindow->edl->session->crop_x1);
 
451
        height->update((int64_t)mwindow->edl->session->crop_y2 - 
 
452
                mwindow->edl->session->crop_y1);
 
453
}
 
454
 
 
455
 
 
456
 
 
457
 
 
458
 
 
459
 
 
460
CWindowEyedropGUI::CWindowEyedropGUI(MWindow *mwindow, CWindowTool *thread)
 
461
 : CWindowToolGUI(mwindow, 
 
462
        thread,
 
463
        PROGRAM_NAME ": Color",
 
464
        150,
 
465
        150)
 
466
{
 
467
}
 
468
 
 
469
CWindowEyedropGUI::~CWindowEyedropGUI()
 
470
{
 
471
}
 
472
 
 
473
void CWindowEyedropGUI::create_objects()
 
474
{
 
475
        int x = 10;
 
476
        int y = 10;
 
477
        int x2 = 70;
 
478
        BC_Title *title1, *title2, *title3;
 
479
        add_subwindow(title1 = new BC_Title(x, y, "Red:"));
 
480
        y += title1->get_h() + 5;
 
481
        add_subwindow(title2 = new BC_Title(x, y, "Green:"));
 
482
        y += title2->get_h() + 5;
 
483
        add_subwindow(title3 = new BC_Title(x, y, "Blue:"));
 
484
 
 
485
 
 
486
        add_subwindow(red = new BC_Title(x2, title1->get_y(), "0"));
 
487
        add_subwindow(green = new BC_Title(x2, title2->get_y(), "0"));
 
488
        add_subwindow(blue = new BC_Title(x2, title3->get_y(), "0"));
 
489
 
 
490
        y = blue->get_y() + blue->get_h() + 5;
 
491
        add_subwindow(sample = new BC_SubWindow(x, y, 50, 50));
 
492
        update();       
 
493
}
 
494
 
 
495
void CWindowEyedropGUI::update()
 
496
{
 
497
        red->update(mwindow->edl->local_session->red);
 
498
        green->update(mwindow->edl->local_session->green);
 
499
        blue->update(mwindow->edl->local_session->blue);
 
500
 
 
501
        int red = (int)(CLIP(mwindow->edl->local_session->red, 0, 1) * 0xff);
 
502
        int green = (int)(CLIP(mwindow->edl->local_session->green, 0, 1) * 0xff);
 
503
        int blue = (int)(CLIP(mwindow->edl->local_session->blue, 0, 1) * 0xff);
 
504
        sample->set_color((red << 16) | (green << 8) | blue);
 
505
        sample->draw_box(0, 0, sample->get_w(), sample->get_h());
 
506
        sample->set_color(BLACK);
 
507
        sample->draw_rectangle(0, 0, sample->get_w(), sample->get_h());
 
508
        sample->flash();
 
509
}
 
510
 
 
511
 
 
512
 
 
513
 
 
514
 
 
515
 
 
516
 
 
517
 
 
518
 
 
519
CWindowCameraGUI::CWindowCameraGUI(MWindow *mwindow, CWindowTool *thread)
 
520
 : CWindowToolGUI(mwindow, 
 
521
        thread,
 
522
        PROGRAM_NAME ": Camera",
 
523
        170,
 
524
        170)
 
525
{
 
526
}
 
527
CWindowCameraGUI::~CWindowCameraGUI()
 
528
{
 
529
}
 
530
 
 
531
void CWindowCameraGUI::create_objects()
 
532
{
 
533
        int x = 10, y = 10, x1;
 
534
        Track *track = mwindow->cwindow->calculate_affected_track();
 
535
        FloatAuto *x_auto = 0;
 
536
        FloatAuto *y_auto = 0;
 
537
        FloatAuto *z_auto = 0;
 
538
        BC_Title *title;
 
539
        BC_Button *button;
 
540
 
 
541
        if(track)
 
542
        {
 
543
                mwindow->cwindow->calculate_affected_autos(&x_auto,
 
544
                        &y_auto,
 
545
                        &z_auto,
 
546
                        track,
 
547
                        1,
 
548
                        0,
 
549
                        0,
 
550
                        0);
 
551
        }
 
552
 
 
553
        add_subwindow(title = new BC_Title(x, y, _("X:")));
 
554
        x += title->get_w();
 
555
        this->x = new CWindowCoord(this, 
 
556
                x, 
 
557
                y, 
 
558
                x_auto ? x_auto->value : (float)0);
 
559
        this->x->create_objects();
 
560
        y += 30;
 
561
        x = 10;
 
562
        add_subwindow(title = new BC_Title(x, y, _("Y:")));
 
563
        x += title->get_w();
 
564
        this->y = new CWindowCoord(this, 
 
565
                x, 
 
566
                y, 
 
567
                y_auto ? y_auto->value : (float)0);
 
568
        this->y->create_objects();
 
569
        y += 30;
 
570
        x = 10;
 
571
        add_subwindow(title = new BC_Title(x, y, _("Z:")));
 
572
        x += title->get_w();
 
573
        this->z = new CWindowCoord(this, 
 
574
                x, 
 
575
                y, 
 
576
                z_auto ? z_auto->value : (float)1,
 
577
                1);
 
578
        this->z->create_objects();
 
579
        this->z->set_boundaries((float).0001, (float)256.0);
 
580
 
 
581
        y += 30;
 
582
        x1 = 10;
 
583
        add_subwindow(button = new CWindowCameraLeft(mwindow, this, x1, y));
 
584
        x1 += button->get_w();
 
585
        add_subwindow(button = new CWindowCameraCenter(mwindow, this, x1, y));
 
586
        x1 += button->get_w();
 
587
        add_subwindow(button = new CWindowCameraRight(mwindow, this, x1, y));
 
588
 
 
589
        y += button->get_h();
 
590
        x1 = 10;
 
591
        add_subwindow(button = new CWindowCameraTop(mwindow, this, x1, y));
 
592
        x1 += button->get_w();
 
593
        add_subwindow(button = new CWindowCameraMiddle(mwindow, this, x1, y));
 
594
        x1 += button->get_w();
 
595
        add_subwindow(button = new CWindowCameraBottom(mwindow, this, x1, y));
 
596
 
 
597
}
 
598
 
 
599
void CWindowCameraGUI::update_preview()
 
600
{
 
601
        mwindow->restart_brender();
 
602
        mwindow->sync_parameters(CHANGE_PARAMS);
 
603
 
 
604
        mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
 
605
                        CHANGE_NONE,
 
606
                        mwindow->edl,
 
607
                        1);
 
608
        mwindow->cwindow->gui->lock_window("CWindowCameraGUI::update_preview");
 
609
        mwindow->cwindow->gui->canvas->draw_refresh();
 
610
        mwindow->cwindow->gui->unlock_window();
 
611
}
 
612
 
 
613
 
 
614
void CWindowCameraGUI::handle_event()
 
615
{
 
616
        FloatAuto *x_auto = 0;
 
617
        FloatAuto *y_auto = 0;
 
618
        FloatAuto *z_auto = 0;
 
619
        Track *track = mwindow->cwindow->calculate_affected_track();
 
620
        if(track)
 
621
        {
 
622
                if(event_caller == x)
 
623
                {
 
624
                        x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
 
625
                                track->automation->autos[AUTOMATION_CAMERA_X],
 
626
                                1);
 
627
                        if(x_auto)
 
628
                        {
 
629
                                x_auto->value = atof(x->get_text());
 
630
                                update_preview();
 
631
                        }
 
632
                }
 
633
                else
 
634
                if(event_caller == y)
 
635
                {
 
636
                        y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
 
637
                                track->automation->autos[AUTOMATION_CAMERA_Y],
 
638
                                1);
 
639
                        if(y_auto)
 
640
                        {
 
641
                                y_auto->value = atof(y->get_text());
 
642
                                update_preview();
 
643
                        }
 
644
                }
 
645
                else
 
646
                if(event_caller == z)
 
647
                {
 
648
                        z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
 
649
                                track->automation->autos[AUTOMATION_CAMERA_Z],
 
650
                                1);
 
651
                        if(z_auto)
 
652
                        {
 
653
                                float zoom = atof(z->get_text());
 
654
                                if(zoom > 10) zoom = 10; 
 
655
                                else
 
656
                                if(zoom < 0) zoom = 0;
 
657
        // Doesn't allow user to enter from scratch
 
658
        //              if(zoom != atof(z->get_text())) 
 
659
        //                      z->update(zoom);
 
660
 
 
661
                                z_auto->value = zoom;
 
662
                                mwindow->gui->lock_window("CWindowCameraGUI::handle_event");
 
663
                                mwindow->gui->canvas->draw_overlays();
 
664
                                mwindow->gui->canvas->flash();
 
665
                                mwindow->gui->unlock_window();
 
666
                                update_preview();
 
667
                        }
 
668
                }
 
669
        }
 
670
}
 
671
 
 
672
void CWindowCameraGUI::update()
 
673
{
 
674
        FloatAuto *x_auto = 0;
 
675
        FloatAuto *y_auto = 0;
 
676
        FloatAuto *z_auto = 0;
 
677
        Track *track = mwindow->cwindow->calculate_affected_track();
 
678
 
 
679
        if(track)
 
680
        {
 
681
                mwindow->cwindow->calculate_affected_autos(&x_auto,
 
682
                        &y_auto,
 
683
                        &z_auto,
 
684
                        track,
 
685
                        1,
 
686
                        0,
 
687
                        0,
 
688
                        0);
 
689
        }
 
690
 
 
691
        if(x_auto)
 
692
                x->update(x_auto->value);
 
693
        if(y_auto)
 
694
                y->update(y_auto->value);
 
695
        if(z_auto)
 
696
                z->update(z_auto->value);
 
697
}
 
698
 
 
699
// BezierAuto* CWindowCameraGUI::get_keyframe()
 
700
// {
 
701
//      BezierAuto *keyframe = 0;
 
702
//      Track *track = mwindow->cwindow->calculate_affected_track();
 
703
//      if(track)
 
704
//              keyframe = (BezierAuto*)mwindow->cwindow->calculate_affected_auto(
 
705
//                      track->automation->autos[AUTOMATION_CAMERA]);
 
706
//      return keyframe;
 
707
// }
 
708
 
 
709
 
 
710
 
 
711
CWindowCameraLeft::CWindowCameraLeft(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
 
712
 : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
 
713
{
 
714
        this->gui = gui;
 
715
        this->mwindow = mwindow;
 
716
        set_tooltip(_("Left justify"));
 
717
}
 
718
int CWindowCameraLeft::handle_event()
 
719
{
 
720
        FloatAuto *x_auto = 0;
 
721
        FloatAuto *z_auto = 0;
 
722
        Track *track = mwindow->cwindow->calculate_affected_track();
 
723
        if(track)
 
724
        {
 
725
                mwindow->cwindow->calculate_affected_autos(&x_auto,
 
726
                        0,
 
727
                        &z_auto,
 
728
                        track,
 
729
                        1,
 
730
                        1,
 
731
                        0,
 
732
                        0);
 
733
        }
 
734
 
 
735
        if(x_auto && z_auto)
 
736
        {
 
737
                int w = 0, h = 0;
 
738
                track->get_source_dimensions(
 
739
                        mwindow->edl->local_session->get_selectionstart(1),
 
740
                        w,
 
741
                        h);
 
742
 
 
743
                if(w && h)
 
744
                {
 
745
                        x_auto->value = 
 
746
                                (double)track->track_w / z_auto->value / 2 - 
 
747
                                (double)w / 2;
 
748
                        gui->update();
 
749
                        gui->update_preview();
 
750
                }
 
751
        }
 
752
 
 
753
        return 1;
 
754
}
 
755
 
 
756
 
 
757
CWindowCameraCenter::CWindowCameraCenter(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
 
758
 : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
 
759
{
 
760
        this->gui = gui;
 
761
        this->mwindow = mwindow;
 
762
        set_tooltip(_("Center horizontal"));
 
763
}
 
764
int CWindowCameraCenter::handle_event()
 
765
{
 
766
        FloatAuto *x_auto = 0;
 
767
        Track *track = mwindow->cwindow->calculate_affected_track();
 
768
        if(track)
 
769
                x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
 
770
                        track->automation->autos[AUTOMATION_CAMERA_X],
 
771
                        1);
 
772
 
 
773
        if(x_auto)
 
774
        {
 
775
                x_auto->value = 0;
 
776
                gui->update();
 
777
                gui->update_preview();
 
778
        }
 
779
 
 
780
        return 1;
 
781
}
 
782
 
 
783
 
 
784
CWindowCameraRight::CWindowCameraRight(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
 
785
 : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
 
786
{
 
787
        this->gui = gui;
 
788
        this->mwindow = mwindow;
 
789
        set_tooltip(_("Right justify"));
 
790
}
 
791
int CWindowCameraRight::handle_event()
 
792
{
 
793
        FloatAuto *x_auto = 0;
 
794
        FloatAuto *z_auto = 0;
 
795
        Track *track = mwindow->cwindow->calculate_affected_track();
 
796
        if(track)
 
797
        {
 
798
                mwindow->cwindow->calculate_affected_autos(&x_auto,
 
799
                        0,
 
800
                        &z_auto,
 
801
                        track,
 
802
                        1,
 
803
                        1,
 
804
                        0,
 
805
                        0);
 
806
        }
 
807
 
 
808
        if(x_auto && z_auto)
 
809
        {
 
810
                int w = 0, h = 0;
 
811
                track->get_source_dimensions(
 
812
                        mwindow->edl->local_session->get_selectionstart(1),
 
813
                        w,
 
814
                        h);
 
815
 
 
816
                if(w && h)
 
817
                {
 
818
                        x_auto->value = -((double)track->track_w / z_auto->value / 2 - 
 
819
                                (double)w / 2);
 
820
                        gui->update();
 
821
                        gui->update_preview();
 
822
                }
 
823
        }
 
824
 
 
825
        return 1;
 
826
}
 
827
 
 
828
 
 
829
CWindowCameraTop::CWindowCameraTop(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
 
830
 : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
 
831
{
 
832
        this->gui = gui;
 
833
        this->mwindow = mwindow;
 
834
        set_tooltip(_("Top justify"));
 
835
}
 
836
int CWindowCameraTop::handle_event()
 
837
{
 
838
        FloatAuto *y_auto = 0;
 
839
        FloatAuto *z_auto = 0;
 
840
        Track *track = mwindow->cwindow->calculate_affected_track();
 
841
        if(track)
 
842
        {
 
843
                mwindow->cwindow->calculate_affected_autos(0,
 
844
                        &y_auto,
 
845
                        &z_auto,
 
846
                        track,
 
847
                        1,
 
848
                        0,
 
849
                        1,
 
850
                        0);
 
851
        }
 
852
 
 
853
        if(y_auto && z_auto)
 
854
        {
 
855
                int w = 0, h = 0;
 
856
                track->get_source_dimensions(
 
857
                        mwindow->edl->local_session->get_selectionstart(1),
 
858
                        w,
 
859
                        h);
 
860
 
 
861
                if(w && h)
 
862
                {
 
863
                        y_auto->value = (double)track->track_h / z_auto->value / 2 - 
 
864
                                (double)h / 2;
 
865
                        gui->update();
 
866
                        gui->update_preview();
 
867
                }
 
868
        }
 
869
 
 
870
        return 1;
 
871
}
 
872
 
 
873
 
 
874
CWindowCameraMiddle::CWindowCameraMiddle(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
 
875
 : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
 
876
{
 
877
        this->gui = gui;
 
878
        this->mwindow = mwindow;
 
879
        set_tooltip(_("Center vertical"));
 
880
}
 
881
int CWindowCameraMiddle::handle_event()
 
882
{
 
883
        FloatAuto *y_auto = 0;
 
884
        Track *track = mwindow->cwindow->calculate_affected_track();
 
885
        if(track)
 
886
                y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
 
887
                        track->automation->autos[AUTOMATION_CAMERA_Y], 1);
 
888
 
 
889
        if(y_auto)
 
890
        {
 
891
                y_auto->value = 0;
 
892
                gui->update();
 
893
                gui->update_preview();
 
894
        }
 
895
 
 
896
        return 1;
 
897
}
 
898
 
 
899
 
 
900
CWindowCameraBottom::CWindowCameraBottom(MWindow *mwindow, CWindowCameraGUI *gui, int x, int y)
 
901
 : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
 
902
{
 
903
        this->gui = gui;
 
904
        this->mwindow = mwindow;
 
905
        set_tooltip(_("Bottom justify"));
 
906
}
 
907
int CWindowCameraBottom::handle_event()
 
908
{
 
909
        FloatAuto *y_auto = 0;
 
910
        FloatAuto *z_auto = 0;
 
911
        Track *track = mwindow->cwindow->calculate_affected_track();
 
912
        if(track)
 
913
        {
 
914
                mwindow->cwindow->calculate_affected_autos(0,
 
915
                        &y_auto,
 
916
                        &z_auto,
 
917
                        track,
 
918
                        1,
 
919
                        0,
 
920
                        1,
 
921
                        0);
 
922
        }
 
923
 
 
924
        if(y_auto && z_auto)
 
925
        {
 
926
                int w = 0, h = 0;
 
927
                track->get_source_dimensions(
 
928
                        mwindow->edl->local_session->get_selectionstart(1),
 
929
                        w,
 
930
                        h);
 
931
 
 
932
                if(w && h)
 
933
                {
 
934
                        y_auto->value = -((double)track->track_h / z_auto->value / 2 - 
 
935
                                (double)h / 2);
 
936
                        gui->update();
 
937
                        gui->update_preview();
 
938
                }
 
939
        }
 
940
 
 
941
        return 1;
 
942
}
 
943
 
 
944
 
 
945
 
 
946
 
 
947
 
 
948
 
 
949
 
 
950
 
 
951
 
 
952
 
 
953
 
 
954
 
 
955
 
 
956
 
 
957
 
 
958
 
 
959
 
 
960
CWindowProjectorGUI::CWindowProjectorGUI(MWindow *mwindow, CWindowTool *thread)
 
961
 : CWindowToolGUI(mwindow, 
 
962
        thread,
 
963
        PROGRAM_NAME ": Projector",
 
964
        170,
 
965
        170)
 
966
{
 
967
}
 
968
CWindowProjectorGUI::~CWindowProjectorGUI()
 
969
{
 
970
}
 
971
void CWindowProjectorGUI::create_objects()
 
972
{
 
973
        int x = 10, y = 10, x1;
 
974
        Track *track = mwindow->cwindow->calculate_affected_track();
 
975
        FloatAuto *x_auto = 0;
 
976
        FloatAuto *y_auto = 0;
 
977
        FloatAuto *z_auto = 0;
 
978
        BC_Title *title;
 
979
        BC_Button *button;
 
980
 
 
981
        if(track)
 
982
        {
 
983
                mwindow->cwindow->calculate_affected_autos(&x_auto,
 
984
                        &y_auto,
 
985
                        &z_auto,
 
986
                        track,
 
987
                        0,
 
988
                        0,
 
989
                        0,
 
990
                        0);
 
991
        }
 
992
 
 
993
        add_subwindow(title = new BC_Title(x, y, _("X:")));
 
994
        x += title->get_w();
 
995
        this->x = new CWindowCoord(this, 
 
996
                x, 
 
997
                y, 
 
998
                x_auto ? x_auto->value : (float)0);
 
999
        this->x->create_objects();
 
1000
        y += 30;
 
1001
        x = 10;
 
1002
        add_subwindow(title = new BC_Title(x, y, _("Y:")));
 
1003
        x += title->get_w();
 
1004
        this->y = new CWindowCoord(this, 
 
1005
                x, 
 
1006
                y, 
 
1007
                y_auto ? y_auto->value : (float)0);
 
1008
        this->y->create_objects();
 
1009
        y += 30;
 
1010
        x = 10;
 
1011
        add_subwindow(title = new BC_Title(x, y, _("Z:")));
 
1012
        x += title->get_w();
 
1013
        this->z = new CWindowCoord(this, 
 
1014
                x, 
 
1015
                y, 
 
1016
                z_auto ? z_auto->value : (float)1,
 
1017
                1);
 
1018
        this->z->create_objects();
 
1019
        this->z->set_boundaries((float).0001, (float)256.0);
 
1020
 
 
1021
        y += 30;
 
1022
        x1 = 10;
 
1023
        add_subwindow(button = new CWindowProjectorLeft(mwindow, this, x1, y));
 
1024
        x1 += button->get_w();
 
1025
        add_subwindow(button = new CWindowProjectorCenter(mwindow, this, x1, y));
 
1026
        x1 += button->get_w();
 
1027
        add_subwindow(button = new CWindowProjectorRight(mwindow, this, x1, y));
 
1028
 
 
1029
        y += button->get_h();
 
1030
        x1 = 10;
 
1031
        add_subwindow(button = new CWindowProjectorTop(mwindow, this, x1, y));
 
1032
        x1 += button->get_w();
 
1033
        add_subwindow(button = new CWindowProjectorMiddle(mwindow, this, x1, y));
 
1034
        x1 += button->get_w();
 
1035
        add_subwindow(button = new CWindowProjectorBottom(mwindow, this, x1, y));
 
1036
 
 
1037
}
 
1038
 
 
1039
void CWindowProjectorGUI::update_preview()
 
1040
{
 
1041
        mwindow->restart_brender();
 
1042
        mwindow->sync_parameters(CHANGE_PARAMS);
 
1043
        mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
 
1044
                        CHANGE_NONE,
 
1045
                        mwindow->edl,
 
1046
                        1);
 
1047
        mwindow->cwindow->gui->lock_window("CWindowProjectorGUI::update_preview");
 
1048
        mwindow->cwindow->gui->canvas->draw_refresh();
 
1049
        mwindow->cwindow->gui->unlock_window();
 
1050
}
 
1051
 
 
1052
void CWindowProjectorGUI::handle_event()
 
1053
{
 
1054
        FloatAuto *x_auto = 0;
 
1055
        FloatAuto *y_auto = 0;
 
1056
        FloatAuto *z_auto = 0;
 
1057
        Track *track = mwindow->cwindow->calculate_affected_track();
 
1058
 
 
1059
        if(track)
 
1060
        {
 
1061
                if(event_caller == x)
 
1062
                {
 
1063
                        x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
 
1064
                                track->automation->autos[AUTOMATION_PROJECTOR_X],
 
1065
                                1);
 
1066
                        if(x_auto)
 
1067
                        {
 
1068
                                x_auto->value = atof(x->get_text());
 
1069
                                update_preview();
 
1070
                        }
 
1071
                }
 
1072
                else
 
1073
                if(event_caller == y)
 
1074
                {
 
1075
                        y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
 
1076
                                track->automation->autos[AUTOMATION_PROJECTOR_Y],
 
1077
                                1);
 
1078
                        if(y_auto)
 
1079
                        {
 
1080
                                y_auto->value = atof(y->get_text());
 
1081
                                update_preview();
 
1082
                        }
 
1083
                }
 
1084
                else
 
1085
                if(event_caller == z)
 
1086
                {
 
1087
                        z_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
 
1088
                                track->automation->autos[AUTOMATION_PROJECTOR_Z],
 
1089
                                1);
 
1090
                        if(z_auto)
 
1091
                        {
 
1092
                                float zoom = atof(z->get_text());
 
1093
                                if(zoom > 10000) zoom = 10000; 
 
1094
                                else 
 
1095
                                if(zoom < 0) zoom = 0;
 
1096
//                      if (zoom != atof(z->get_text())) 
 
1097
//                              z->update(zoom);
 
1098
                                z_auto->value = zoom;
 
1099
 
 
1100
                                mwindow->gui->lock_window("CWindowProjectorGUI::handle_event");
 
1101
                                mwindow->gui->canvas->draw_overlays();
 
1102
                                mwindow->gui->canvas->flash();
 
1103
                                mwindow->gui->unlock_window();
 
1104
 
 
1105
                                update_preview();
 
1106
                        }
 
1107
                }
 
1108
        }
 
1109
}
 
1110
 
 
1111
void CWindowProjectorGUI::update()
 
1112
{
 
1113
        FloatAuto *x_auto = 0;
 
1114
        FloatAuto *y_auto = 0;
 
1115
        FloatAuto *z_auto = 0;
 
1116
        Track *track = mwindow->cwindow->calculate_affected_track();
 
1117
 
 
1118
        if(track)
 
1119
        {
 
1120
                mwindow->cwindow->calculate_affected_autos(&x_auto,
 
1121
                        &y_auto,
 
1122
                        &z_auto,
 
1123
                        track,
 
1124
                        0,
 
1125
                        0,
 
1126
                        0,
 
1127
                        0);
 
1128
        }
 
1129
 
 
1130
        if(x_auto)
 
1131
                x->update(x_auto->value);
 
1132
        if(y_auto)
 
1133
                y->update(y_auto->value);
 
1134
        if(z_auto)
 
1135
                z->update(z_auto->value);
 
1136
}
 
1137
 
 
1138
// BezierAuto* CWindowProjectorGUI::get_keyframe()
 
1139
// {
 
1140
//      BezierAuto *keyframe = 0;
 
1141
//      Track *track = mwindow->cwindow->calculate_affected_track();
 
1142
//      if(track)
 
1143
//              keyframe = (BezierAuto*)mwindow->cwindow->calculate_affected_auto(
 
1144
//                      track->automation->autos[AUTOMATION_PROJECTOR]);
 
1145
//      return keyframe;
 
1146
// }
 
1147
 
 
1148
 
 
1149
 
 
1150
 
 
1151
 
 
1152
 
 
1153
 
 
1154
 
 
1155
 
 
1156
 
 
1157
 
 
1158
 
 
1159
 
 
1160
 
 
1161
 
 
1162
 
 
1163
 
 
1164
 
 
1165
 
 
1166
 
 
1167
 
 
1168
 
 
1169
 
 
1170
 
 
1171
 
 
1172
 
 
1173
 
 
1174
 
 
1175
 
 
1176
 
 
1177
 
 
1178
 
 
1179
 
 
1180
 
 
1181
 
 
1182
 
 
1183
 
 
1184
 
 
1185
CWindowProjectorLeft::CWindowProjectorLeft(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
 
1186
 : BC_Button(x, y, mwindow->theme->get_image_set("left_justify"))
 
1187
{
 
1188
        this->gui = gui;
 
1189
        this->mwindow = mwindow;
 
1190
        set_tooltip(_("Left justify"));
 
1191
}
 
1192
int CWindowProjectorLeft::handle_event()
 
1193
{
 
1194
        FloatAuto *x_auto = 0;
 
1195
        FloatAuto *z_auto = 0;
 
1196
        Track *track = mwindow->cwindow->calculate_affected_track();
 
1197
        if(track)
 
1198
        {
 
1199
                mwindow->cwindow->calculate_affected_autos(&x_auto,
 
1200
                        0,
 
1201
                        &z_auto,
 
1202
                        track,
 
1203
                        0,
 
1204
                        1,
 
1205
                        0,
 
1206
                        0);
 
1207
        }
 
1208
        if(x_auto && z_auto)
 
1209
        {
 
1210
                x_auto->value = (double)track->track_w * z_auto->value / 2 - 
 
1211
                        (double)mwindow->edl->session->output_w / 2;
 
1212
                gui->update();
 
1213
                gui->update_preview();
 
1214
        }
 
1215
 
 
1216
        return 1;
 
1217
}
 
1218
 
 
1219
 
 
1220
CWindowProjectorCenter::CWindowProjectorCenter(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
 
1221
 : BC_Button(x, y, mwindow->theme->get_image_set("center_justify"))
 
1222
{
 
1223
        this->gui = gui;
 
1224
        this->mwindow = mwindow;
 
1225
        set_tooltip(_("Center horizontal"));
 
1226
}
 
1227
int CWindowProjectorCenter::handle_event()
 
1228
{
 
1229
        FloatAuto *x_auto = 0;
 
1230
        Track *track = mwindow->cwindow->calculate_affected_track();
 
1231
        if(track)
 
1232
                x_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
 
1233
                        track->automation->autos[AUTOMATION_PROJECTOR_X],
 
1234
                        1);
 
1235
 
 
1236
        if(x_auto)
 
1237
        {
 
1238
                x_auto->value = 0;
 
1239
                gui->update();
 
1240
                gui->update_preview();
 
1241
        }
 
1242
 
 
1243
        return 1;
 
1244
}
 
1245
 
 
1246
 
 
1247
CWindowProjectorRight::CWindowProjectorRight(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
 
1248
 : BC_Button(x, y, mwindow->theme->get_image_set("right_justify"))
 
1249
{
 
1250
        this->gui = gui;
 
1251
        this->mwindow = mwindow;
 
1252
        set_tooltip(_("Right justify"));
 
1253
}
 
1254
int CWindowProjectorRight::handle_event()
 
1255
{
 
1256
        FloatAuto *x_auto = 0;
 
1257
        FloatAuto *z_auto = 0;
 
1258
        Track *track = mwindow->cwindow->calculate_affected_track();
 
1259
        if(track)
 
1260
        {
 
1261
                mwindow->cwindow->calculate_affected_autos(&x_auto,
 
1262
                        0,
 
1263
                        &z_auto,
 
1264
                        track,
 
1265
                        0,
 
1266
                        1,
 
1267
                        0,
 
1268
                        0);
 
1269
        }
 
1270
 
 
1271
        if(x_auto && z_auto)
 
1272
        {
 
1273
                x_auto->value = -((double)track->track_w * z_auto->value / 2 - 
 
1274
                        (double)mwindow->edl->session->output_w / 2);
 
1275
                gui->update();
 
1276
                gui->update_preview();
 
1277
        }
 
1278
 
 
1279
        return 1;
 
1280
}
 
1281
 
 
1282
 
 
1283
CWindowProjectorTop::CWindowProjectorTop(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
 
1284
 : BC_Button(x, y, mwindow->theme->get_image_set("top_justify"))
 
1285
{
 
1286
        this->gui = gui;
 
1287
        this->mwindow = mwindow;
 
1288
        set_tooltip(_("Top justify"));
 
1289
}
 
1290
int CWindowProjectorTop::handle_event()
 
1291
{
 
1292
        FloatAuto *y_auto = 0;
 
1293
        FloatAuto *z_auto = 0;
 
1294
        Track *track = mwindow->cwindow->calculate_affected_track();
 
1295
        if(track)
 
1296
        {
 
1297
                mwindow->cwindow->calculate_affected_autos(0,
 
1298
                        &y_auto,
 
1299
                        &z_auto,
 
1300
                        track,
 
1301
                        0,
 
1302
                        0,
 
1303
                        1,
 
1304
                        0);
 
1305
        }
 
1306
 
 
1307
        if(y_auto && z_auto)
 
1308
        {
 
1309
                y_auto->value = (double)track->track_h * z_auto->value / 2 - 
 
1310
                        (double)mwindow->edl->session->output_h / 2;
 
1311
                gui->update();
 
1312
                gui->update_preview();
 
1313
        }
 
1314
 
 
1315
        return 1;
 
1316
}
 
1317
 
 
1318
 
 
1319
CWindowProjectorMiddle::CWindowProjectorMiddle(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
 
1320
 : BC_Button(x, y, mwindow->theme->get_image_set("middle_justify"))
 
1321
{
 
1322
        this->gui = gui;
 
1323
        this->mwindow = mwindow;
 
1324
        set_tooltip(_("Center vertical"));
 
1325
}
 
1326
int CWindowProjectorMiddle::handle_event()
 
1327
{
 
1328
        FloatAuto *y_auto = 0;
 
1329
        Track *track = mwindow->cwindow->calculate_affected_track();
 
1330
        if(track)
 
1331
                y_auto = (FloatAuto*)mwindow->cwindow->calculate_affected_auto(
 
1332
                        track->automation->autos[AUTOMATION_PROJECTOR_Y], 1);
 
1333
 
 
1334
        if(y_auto)
 
1335
        {
 
1336
                y_auto->value = 0;
 
1337
                gui->update();
 
1338
                gui->update_preview();
 
1339
        }
 
1340
 
 
1341
        return 1;
 
1342
}
 
1343
 
 
1344
 
 
1345
CWindowProjectorBottom::CWindowProjectorBottom(MWindow *mwindow, CWindowProjectorGUI *gui, int x, int y)
 
1346
 : BC_Button(x, y, mwindow->theme->get_image_set("bottom_justify"))
 
1347
{
 
1348
        this->gui = gui;
 
1349
        this->mwindow = mwindow;
 
1350
        set_tooltip(_("Bottom justify"));
 
1351
}
 
1352
int CWindowProjectorBottom::handle_event()
 
1353
{
 
1354
        FloatAuto *y_auto = 0;
 
1355
        FloatAuto *z_auto = 0;
 
1356
        Track *track = mwindow->cwindow->calculate_affected_track();
 
1357
        if(track)
 
1358
        {
 
1359
                mwindow->cwindow->calculate_affected_autos(0,
 
1360
                        &y_auto,
 
1361
                        &z_auto,
 
1362
                        track,
 
1363
                        0,
 
1364
                        0,
 
1365
                        1,
 
1366
                        0);
 
1367
        }
 
1368
 
 
1369
        if(y_auto && z_auto)
 
1370
        {
 
1371
                y_auto->value = -((double)track->track_h * z_auto->value / 2 - 
 
1372
                        (double)mwindow->edl->session->output_h / 2);
 
1373
                gui->update();
 
1374
                gui->update_preview();
 
1375
        }
 
1376
 
 
1377
        return 1;
 
1378
}
 
1379
 
 
1380
 
 
1381
 
 
1382
 
 
1383
 
 
1384
 
 
1385
 
 
1386
 
 
1387
CWindowMaskMode::CWindowMaskMode(MWindow *mwindow, 
 
1388
        CWindowToolGUI *gui, 
 
1389
        int x, 
 
1390
        int y,
 
1391
        char *text)
 
1392
 : BC_PopupMenu(x,
 
1393
        y,
 
1394
        200,
 
1395
        text,
 
1396
        1)
 
1397
{
 
1398
        this->mwindow = mwindow;
 
1399
        this->gui = gui;
 
1400
}
 
1401
 
 
1402
void CWindowMaskMode::create_objects()
 
1403
{
 
1404
        add_item(new BC_MenuItem(mode_to_text(MASK_MULTIPLY_ALPHA)));
 
1405
        add_item(new BC_MenuItem(mode_to_text(MASK_SUBTRACT_ALPHA)));
 
1406
}
 
1407
 
 
1408
char* CWindowMaskMode::mode_to_text(int mode)
 
1409
{
 
1410
        switch(mode)
 
1411
        {
 
1412
                case MASK_MULTIPLY_ALPHA:
 
1413
                        return _("Multiply alpha");
 
1414
                        break;
 
1415
                
 
1416
                case MASK_SUBTRACT_ALPHA:
 
1417
                        return _("Subtract alpha");
 
1418
                        break;
 
1419
        }
 
1420
 
 
1421
        return _("Subtract alpha");
 
1422
}
 
1423
 
 
1424
int CWindowMaskMode::text_to_mode(char *text)
 
1425
{
 
1426
        if(!strcasecmp(text, _("Multiply alpha")))
 
1427
                return MASK_MULTIPLY_ALPHA;
 
1428
        else
 
1429
        if(!strcasecmp(text, _("Subtract alpha")))
 
1430
                return MASK_SUBTRACT_ALPHA;
 
1431
 
 
1432
        return MASK_SUBTRACT_ALPHA;
 
1433
}
 
1434
 
 
1435
int CWindowMaskMode::handle_event()
 
1436
{
 
1437
        MaskAuto *keyframe;
 
1438
        Track *track;
 
1439
        MaskPoint *point;
 
1440
        SubMask *mask;
 
1441
        ((CWindowMaskGUI*)gui)->get_keyframe(track, 
 
1442
                keyframe, 
 
1443
                mask,
 
1444
                point,
 
1445
                0);
 
1446
 
 
1447
        if(track)
 
1448
        {
 
1449
                ((MaskAuto*)track->automation->autos[AUTOMATION_MASK]->default_auto)->mode = 
 
1450
                        text_to_mode(get_text());
 
1451
        }
 
1452
 
 
1453
//printf("CWindowMaskMode::handle_event 1\n");
 
1454
        gui->update_preview();
 
1455
        return 1;
 
1456
}
 
1457
 
 
1458
 
 
1459
 
 
1460
 
 
1461
 
 
1462
 
 
1463
 
 
1464
 
 
1465
CWindowMaskDelete::CWindowMaskDelete(MWindow *mwindow, 
 
1466
        CWindowToolGUI *gui, 
 
1467
        int x, 
 
1468
        int y)
 
1469
 : BC_GenericButton(x, y, _("Delete"))
 
1470
{
 
1471
        this->mwindow = mwindow;
 
1472
        this->gui = gui;
 
1473
}
 
1474
 
 
1475
int CWindowMaskDelete::handle_event()
 
1476
{
 
1477
        MaskAuto *keyframe;
 
1478
        Track *track = mwindow->cwindow->calculate_affected_track();
 
1479
        MaskPoint *point;
 
1480
        SubMask *mask;
 
1481
 
 
1482
 
 
1483
        if(track)
 
1484
        {
 
1485
                MaskAutos *mask_autos = (MaskAutos*)track->automation->autos[AUTOMATION_MASK];
 
1486
                for(MaskAuto *current = (MaskAuto*)mask_autos->default_auto;
 
1487
                        current; )
 
1488
                {
 
1489
                        SubMask *submask = current->get_submask(mwindow->edl->session->cwindow_mask);
 
1490
 
 
1491
 
 
1492
                        
 
1493
                        for(int i = mwindow->cwindow->gui->affected_point;
 
1494
                                i < submask->points.total - 1;
 
1495
                                i++)
 
1496
                        {
 
1497
                                *submask->points.values[i] = *submask->points.values[i + 1];
 
1498
                        }
 
1499
 
 
1500
                        if(submask->points.total)
 
1501
                        {
 
1502
                                submask->points.remove_object(
 
1503
                                        submask->points.values[submask->points.total - 1]);
 
1504
                        }
 
1505
 
 
1506
 
 
1507
                        if(current == (MaskAuto*)mask_autos->default_auto)
 
1508
                                current = (MaskAuto*)mask_autos->first;
 
1509
                        else
 
1510
                                current = (MaskAuto*)NEXT;
 
1511
                }
 
1512
                gui->update();
 
1513
                gui->update_preview();
 
1514
        }
 
1515
 
 
1516
 
 
1517
//      ((CWindowMaskGUI*)gui)->get_keyframe(track, 
 
1518
//              keyframe, 
 
1519
//              mask, 
 
1520
//              point,
 
1521
//              0);
 
1522
 
 
1523
// Need to apply to every keyframe
 
1524
        
 
1525
//      if(keyframe)
 
1526
//      {
 
1527
//              for(int i = mwindow->cwindow->gui->affected_point;
 
1528
//                      i < mask->points.total - 1;
 
1529
//                      i++)
 
1530
//              {
 
1531
//                      *mask->points.values[i] = *mask->points.values[i + 1];
 
1532
//              }
 
1533
//              
 
1534
//              if(mask->points.total)
 
1535
//              {
 
1536
//                      mask->points.remove_object(mask->points.values[mask->points.total - 1]);
 
1537
//              }
 
1538
// 
 
1539
//              gui->update();
 
1540
//              gui->update_preview();
 
1541
//      }
 
1542
 
 
1543
        return 1;
 
1544
}
 
1545
 
 
1546
int CWindowMaskDelete::keypress_event()
 
1547
{
 
1548
        if(get_keypress() == BACKSPACE ||
 
1549
                get_keypress() == DELETE) 
 
1550
                return handle_event();
 
1551
        return 0;
 
1552
}
 
1553
 
 
1554
 
 
1555
CWindowMaskCycleNext::CWindowMaskCycleNext(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
 
1556
 : BC_GenericButton(x, y, _("Cycle next"))
 
1557
{
 
1558
        this->mwindow = mwindow;
 
1559
        this->gui = gui;
 
1560
}
 
1561
int CWindowMaskCycleNext::handle_event()
 
1562
{
 
1563
        MaskAuto *keyframe;
 
1564
        Track *track;
 
1565
        MaskPoint *point;
 
1566
        SubMask *mask;
 
1567
        ((CWindowMaskGUI*)gui)->get_keyframe(track, 
 
1568
                keyframe,
 
1569
                mask,  
 
1570
                point,
 
1571
                0);
 
1572
 
 
1573
        MaskPoint *temp;
 
1574
 
 
1575
// Should apply to all keyframes
 
1576
        if(keyframe && mask->points.total)
 
1577
        {
 
1578
                temp = mask->points.values[0];
 
1579
 
 
1580
                for(int i = 0; i < mask->points.total - 1; i++)
 
1581
                {
 
1582
                        mask->points.values[i] = mask->points.values[i + 1];
 
1583
                }
 
1584
                mask->points.values[mask->points.total - 1] = temp;
 
1585
 
 
1586
                mwindow->cwindow->gui->affected_point--;
 
1587
                if(mwindow->cwindow->gui->affected_point < 0)
 
1588
                        mwindow->cwindow->gui->affected_point = mask->points.total - 1;
 
1589
 
 
1590
                gui->update();
 
1591
                gui->update_preview();
 
1592
        }
 
1593
        
 
1594
        return 1;
 
1595
}
 
1596
 
 
1597
CWindowMaskCyclePrev::CWindowMaskCyclePrev(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
 
1598
 : BC_GenericButton(x, y, _("Cycle prev"))
 
1599
{
 
1600
        this->mwindow = mwindow;
 
1601
        this->gui = gui;
 
1602
}
 
1603
int CWindowMaskCyclePrev::handle_event()
 
1604
{
 
1605
        MaskAuto *keyframe;
 
1606
        Track *track;
 
1607
        MaskPoint *point;
 
1608
        SubMask *mask;
 
1609
        ((CWindowMaskGUI*)gui)->get_keyframe(track, 
 
1610
                keyframe,
 
1611
                mask, 
 
1612
                point,
 
1613
                0);
 
1614
 
 
1615
// Should apply to all keyframes
 
1616
        MaskPoint *temp;
 
1617
        if(keyframe && mask->points.total)
 
1618
        {
 
1619
                temp = mask->points.values[mask->points.total - 1];
 
1620
 
 
1621
                for(int i = mask->points.total - 1; i > 0; i--)
 
1622
                {
 
1623
                        mask->points.values[i] = mask->points.values[i - 1];
 
1624
                }
 
1625
                mask->points.values[0] = temp;
 
1626
 
 
1627
                mwindow->cwindow->gui->affected_point++;
 
1628
                if(mwindow->cwindow->gui->affected_point >= mask->points.total)
 
1629
                        mwindow->cwindow->gui->affected_point = 0;
 
1630
 
 
1631
                gui->update();
 
1632
                gui->update_preview();
 
1633
        }
 
1634
        return 1;
 
1635
}
 
1636
 
 
1637
 
 
1638
CWindowMaskNumber::CWindowMaskNumber(MWindow *mwindow, 
 
1639
        CWindowToolGUI *gui, 
 
1640
        int x, 
 
1641
        int y)
 
1642
 : BC_TumbleTextBox(gui, 
 
1643
                (int64_t)mwindow->edl->session->cwindow_mask,
 
1644
                (int64_t)0,
 
1645
                (int64_t)SUBMASKS - 1,
 
1646
                x, 
 
1647
                y, 
 
1648
                100)
 
1649
{
 
1650
        this->mwindow = mwindow;
 
1651
        this->gui = gui;
 
1652
}
 
1653
 
 
1654
CWindowMaskNumber::~CWindowMaskNumber()
 
1655
{
 
1656
}
 
1657
 
 
1658
int CWindowMaskNumber::handle_event()
 
1659
{
 
1660
        mwindow->edl->session->cwindow_mask = atol(get_text());
 
1661
        gui->update();
 
1662
        gui->update_preview();
 
1663
        return 1;
 
1664
}
 
1665
 
 
1666
 
 
1667
 
 
1668
 
 
1669
 
 
1670
CWindowMaskFeather::CWindowMaskFeather(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
 
1671
 : BC_TumbleTextBox(gui, 
 
1672
                (int64_t)0,
 
1673
                (int64_t)0,
 
1674
                (int64_t)0xff,
 
1675
                x, 
 
1676
                y, 
 
1677
                100)
 
1678
{
 
1679
        this->mwindow = mwindow;
 
1680
        this->gui = gui;
 
1681
}
 
1682
CWindowMaskFeather::~CWindowMaskFeather()
 
1683
{
 
1684
}
 
1685
int CWindowMaskFeather::handle_event()
 
1686
{
 
1687
        MaskAuto *keyframe;
 
1688
        Track *track;
 
1689
        MaskPoint *point;
 
1690
        SubMask *mask;
 
1691
        ((CWindowMaskGUI*)gui)->get_keyframe(track, 
 
1692
                keyframe,
 
1693
                mask, 
 
1694
                point,
 
1695
                1);
 
1696
 
 
1697
        keyframe->feather = atof(get_text());
 
1698
        gui->update_preview();
 
1699
        return 1;
 
1700
}
 
1701
 
 
1702
CWindowMaskValue::CWindowMaskValue(MWindow *mwindow, CWindowToolGUI *gui, int x, int y)
 
1703
 : BC_ISlider(x, 
 
1704
                        y,
 
1705
                        0,
 
1706
                        200, 
 
1707
                        200, 
 
1708
                        0, 
 
1709
                        100, 
 
1710
                        0)
 
1711
{
 
1712
        this->mwindow = mwindow;
 
1713
        this->gui = gui;
 
1714
}
 
1715
 
 
1716
CWindowMaskValue::~CWindowMaskValue()
 
1717
{
 
1718
}
 
1719
 
 
1720
int CWindowMaskValue::handle_event()
 
1721
{
 
1722
        MaskAuto *keyframe;
 
1723
        Track *track;
 
1724
        MaskPoint *point;
 
1725
        SubMask *mask;
 
1726
        ((CWindowMaskGUI*)gui)->get_keyframe(track, 
 
1727
                keyframe,
 
1728
                mask, 
 
1729
                point,
 
1730
                1);
 
1731
 
 
1732
        keyframe->value = get_value();
 
1733
        gui->update_preview();
 
1734
        return 1;
 
1735
}
 
1736
 
 
1737
 
 
1738
 
 
1739
CWindowMaskBeforePlugins::CWindowMaskBeforePlugins(CWindowToolGUI *gui, int x, int y)
 
1740
 : BC_CheckBox(x, 
 
1741
        y, 
 
1742
        1, 
 
1743
        _("Apply mask before plugins"))
 
1744
{
 
1745
        this->gui = gui;
 
1746
}
 
1747
 
 
1748
int CWindowMaskBeforePlugins::handle_event()
 
1749
{
 
1750
        MaskAuto *keyframe;
 
1751
        Track *track;
 
1752
        MaskPoint *point;
 
1753
        SubMask *mask;
 
1754
        ((CWindowMaskGUI*)gui)->get_keyframe(track, 
 
1755
                keyframe,
 
1756
                mask, 
 
1757
                point,
 
1758
                1);
 
1759
 
 
1760
        if (keyframe) {
 
1761
                keyframe->apply_before_plugins = get_value();
 
1762
                gui->update_preview();
 
1763
        }
 
1764
        return 1;
 
1765
}
 
1766
 
 
1767
 
 
1768
 
 
1769
 
 
1770
 
 
1771
 
 
1772
 
 
1773
 
 
1774
CWindowMaskGUI::CWindowMaskGUI(MWindow *mwindow, CWindowTool *thread)
 
1775
 : CWindowToolGUI(mwindow, 
 
1776
        thread,
 
1777
        PROGRAM_NAME ": Mask",
 
1778
        330,
 
1779
        280)
 
1780
{
 
1781
        this->mwindow = mwindow;
 
1782
        this->thread = thread;
 
1783
}
 
1784
CWindowMaskGUI::~CWindowMaskGUI()
 
1785
{
 
1786
        delete number;
 
1787
        delete feather;
 
1788
}
 
1789
 
 
1790
void CWindowMaskGUI::create_objects()
 
1791
{
 
1792
        int x = 10, y = 10;
 
1793
        MaskAuto *keyframe = 0;
 
1794
        Track *track = mwindow->cwindow->calculate_affected_track();
 
1795
        if(track)
 
1796
                keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(track->automation->autos[AUTOMATION_MASK], 0);
 
1797
 
 
1798
        BC_Title *title;
 
1799
        add_subwindow(title = new BC_Title(x, y, _("Mode:")));
 
1800
        add_subwindow(mode = new CWindowMaskMode(mwindow, 
 
1801
                this, 
 
1802
                x + title->get_w(), 
 
1803
                y,
 
1804
                ""));
 
1805
        mode->create_objects();
 
1806
        y += 40;
 
1807
        add_subwindow(new BC_Title(x, y, _("Value:")));
 
1808
        add_subwindow(value = new CWindowMaskValue(mwindow, this, x + 50, y));
 
1809
        y += 30;
 
1810
        add_subwindow(delete_point = new CWindowMaskDelete(mwindow, this, x, y));
 
1811
        y += 30;
 
1812
        add_subwindow(new BC_Title(x, y, _("Mask number:")));
 
1813
        number = new CWindowMaskNumber(mwindow, 
 
1814
                this, 
 
1815
                x + 110, 
 
1816
                y);
 
1817
        number->create_objects();
 
1818
        y += 30;
 
1819
        add_subwindow(new BC_Title(x, y, _("Feather:")));
 
1820
        feather = new CWindowMaskFeather(mwindow,
 
1821
                this,
 
1822
                x + 110,
 
1823
                y);
 
1824
        feather->create_objects();
 
1825
        y += 30;
 
1826
        add_subwindow(title = new BC_Title(x, y, _("X:")));
 
1827
        x += title->get_w();
 
1828
        this->x = new CWindowCoord(this, 
 
1829
                x, 
 
1830
                y, 
 
1831
                (float)0.0);
 
1832
        this->x->create_objects();
 
1833
        x += 150;
 
1834
        add_subwindow(title = new BC_Title(x, y, _("Y:")));
 
1835
        x += title->get_w();
 
1836
        this->y = new CWindowCoord(this, 
 
1837
                x, 
 
1838
                y, 
 
1839
                (float)0.0);
 
1840
        this->y->create_objects();
 
1841
 
 
1842
        y += 30;
 
1843
//      add_subwindow(title = new BC_Title(x, y, _("Apply mask before plugins:")));
 
1844
        
 
1845
        add_subwindow(this->apply_before_plugins = new CWindowMaskBeforePlugins(this, 
 
1846
                10, 
 
1847
                y));
 
1848
//      this->apply_before_plugins->create_objects();
 
1849
 
 
1850
 
 
1851
        update();
 
1852
}
 
1853
 
 
1854
void CWindowMaskGUI::get_keyframe(Track* &track, 
 
1855
        MaskAuto* &keyframe, 
 
1856
        SubMask* &mask, 
 
1857
        MaskPoint* &point,
 
1858
        int create_it)
 
1859
{
 
1860
        keyframe = 0;
 
1861
        track = mwindow->cwindow->calculate_affected_track();
 
1862
        if(track)
 
1863
                keyframe = (MaskAuto*)mwindow->cwindow->calculate_affected_auto(track->automation->autos[AUTOMATION_MASK], create_it);
 
1864
        else
 
1865
                keyframe = 0;
 
1866
 
 
1867
        if(keyframe)
 
1868
                mask = keyframe->get_submask(mwindow->edl->session->cwindow_mask);
 
1869
        else
 
1870
                mask = 0;
 
1871
 
 
1872
        point = 0;
 
1873
        if(keyframe)
 
1874
        {
 
1875
                if(mwindow->cwindow->gui->affected_point < mask->points.total &&
 
1876
                        mwindow->cwindow->gui->affected_point >= 0)
 
1877
                {
 
1878
                        point =  mask->points.values[mwindow->cwindow->gui->affected_point];
 
1879
                }
 
1880
        }
 
1881
}
 
1882
 
 
1883
void CWindowMaskGUI::update()
 
1884
{
 
1885
        MaskAuto *keyframe;
 
1886
        Track *track;
 
1887
        MaskPoint *point;
 
1888
        SubMask *mask;
 
1889
//printf("CWindowMaskGUI::update 1\n");
 
1890
        get_keyframe(track, 
 
1891
                keyframe, 
 
1892
                mask,
 
1893
                point,
 
1894
                0);
 
1895
 
 
1896
//printf("CWindowMaskGUI::update 1\n");
 
1897
        if(point)
 
1898
        {
 
1899
                x->update(point->x);
 
1900
                y->update(point->y);
 
1901
        }
 
1902
//printf("CWindowMaskGUI::update 1\n");
 
1903
 
 
1904
        if(mask)
 
1905
        {
 
1906
                feather->update((int64_t)keyframe->feather);
 
1907
                value->update((int64_t)keyframe->value);
 
1908
                apply_before_plugins->update((int64_t)keyframe->apply_before_plugins);
 
1909
        }
 
1910
//printf("CWindowMaskGUI::update 1\n");
 
1911
 
 
1912
        number->update((int64_t)mwindow->edl->session->cwindow_mask);
 
1913
 
 
1914
//printf("CWindowMaskGUI::update 1\n");
 
1915
        if(track)
 
1916
        {
 
1917
                mode->set_text(
 
1918
                        CWindowMaskMode::mode_to_text(((MaskAuto*)track->automation->autos[AUTOMATION_MASK]->default_auto)->mode));
 
1919
        }
 
1920
//printf("CWindowMaskGUI::update 2\n");
 
1921
}
 
1922
 
 
1923
void CWindowMaskGUI::handle_event()
 
1924
{
 
1925
        MaskAuto *keyframe;
 
1926
        Track *track;
 
1927
        MaskPoint *point;
 
1928
        SubMask *mask;
 
1929
        get_keyframe(track, 
 
1930
                keyframe, 
 
1931
                mask,
 
1932
                point,
 
1933
                0);
 
1934
 
 
1935
        if(point)
 
1936
        {
 
1937
                point->x = atof(x->get_text());
 
1938
                point->y = atof(y->get_text());
 
1939
        }
 
1940
 
 
1941
        update_preview();
 
1942
}
 
1943
 
 
1944
void CWindowMaskGUI::update_preview()
 
1945
{
 
1946
        mwindow->restart_brender();
 
1947
        mwindow->sync_parameters(CHANGE_PARAMS);
 
1948
        mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
 
1949
                        CHANGE_NONE,
 
1950
                        mwindow->edl,
 
1951
                        1);
 
1952
        mwindow->cwindow->gui->lock_window("CWindowMaskGUI::update_preview");
 
1953
        mwindow->cwindow->gui->canvas->draw_refresh();
 
1954
        mwindow->cwindow->gui->unlock_window();
 
1955
}
 
1956
 
 
1957
 
 
1958
 
 
1959
 
 
1960
 
 
1961
 
 
1962
 
 
1963
 
 
1964
 
 
1965