fast drag mode honours follow_edits labels/plugins/keyframes
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / cropvideo.C
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 "cropvideo.h"
23 #include "language.h"
24 #include "mainundo.h"
25 #include "mwindow.h"
26 #include "mainsession.h"
27 #include "tracks.h"
28 #include "videowindow.h"
29 #include "videowindowgui.h"
30
31
32
33
34 CropVideo::CropVideo(MWindow *mwindow)
35  : BC_MenuItem(_("Crop Video...")), Thread()
36 {
37         this->mwindow = mwindow;
38 }
39
40 CropVideo::~CropVideo()
41 {
42 }
43
44 int CropVideo::handle_event()
45 {
46         start();
47 }
48
49 void CropVideo::run()
50 {
51         float aspect_w, aspect_h;
52         int result = 0;
53         {
54                 mwindow->video_window->start_cropping();
55                 CropVideoWindow window(mwindow, this);
56                 window.create_objects();
57                 result = window.run_window();
58                 mwindow->video_window->get_aspect_ratio(aspect_w, aspect_h);
59                 mwindow->video_window->stop_cropping();
60         }
61
62         if(!result)
63         {
64                 int offsets[4], dummy_dimension[4];
65                 dummy_dimension[0] = dummy_dimension[1] = dummy_dimension[2] = dummy_dimension[3] = 0;
66                 offsets[0] = -(mwindow->video_window->gui->x1 + mwindow->video_window->gui->x2 - mwindow->session->output_w) / 2;
67                 offsets[1] = -(mwindow->video_window->gui->y1 + mwindow->video_window->gui->y2 - mwindow->session->output_h) / 2;
68                 offsets[2] = offsets[3] = 0;
69 //              mwindow->undo->update_undo_edits(_("Crop"), 0);
70
71                 mwindow->tracks->scale_video(dummy_dimension, offsets, 0);
72                 mwindow->session->track_w = mwindow->video_window->gui->x2 - mwindow->video_window->gui->x1;
73                 mwindow->session->track_h = mwindow->video_window->gui->y2 - mwindow->video_window->gui->y1;
74                 mwindow->session->output_w = mwindow->video_window->gui->x2 - mwindow->video_window->gui->x1;
75                 mwindow->session->output_h = mwindow->video_window->gui->y2 - mwindow->video_window->gui->y1;
76                 mwindow->session->aspect_w = aspect_w;
77                 mwindow->session->aspect_h = aspect_h;
78                 mwindow->video_window->resize_window();
79                 mwindow->draw();
80 //              mwindow->undo->update_undo_edits();
81                 mwindow->session->changes_made = 1;
82         }
83         else
84         {
85         }
86 }
87
88 int CropVideo::load_defaults()
89 {
90 }
91
92 int CropVideo::save_defaults()
93 {
94 }
95
96 CropVideoWindow::CropVideoWindow(MWindow *mwindow, CropVideo *thread)
97  : BC_Window(_(PROGRAM_NAME ": Crop"), 380, 75, 0, 0)
98 {
99         this->mwindow = mwindow;
100         this->thread = thread;
101 }
102
103 CropVideoWindow::~CropVideoWindow()
104 {
105 }
106
107 void CropVideoWindow::create_objects()
108 {
109         lock_window("CropVideoWindow::create_objects");
110         int x = 10, y = 10;
111         add_subwindow(new BC_Title(x, y, _("Select a region to crop in the video output window")));
112         y += 30;
113         add_subwindow(new BC_OKButton(x, y));
114         x = get_w() - 100;
115         add_subwindow(new BC_CancelButton(x, y));
116         unlock_window();
117 }
118