affine + perspective plugin rework, info popup tweaks
[goodguy/history.git] / cinelerra-5.1 / cinelerra / clipedit.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 "awindow.h"
23 #include "awindowgui.h"
24 #include "bcsignals.h"
25 #include "clipedit.h"
26 #include "edl.h"
27 #include "fonts.h"
28 #include "language.h"
29 #include "localsession.h"
30 #include "mainerror.h"
31 #include "mainsession.h"
32 #include "mwindow.h"
33 #include "mwindowgui.h"
34 #include "vwindow.h"
35 #include "vwindowgui.h"
36 #include "errorbox.h"
37 #include "tracks.h"
38
39
40
41 ClipEdit::ClipEdit(MWindow *mwindow, AWindow *awindow, VWindow *vwindow)
42  : BC_DialogThread()
43 {
44         this->mwindow = mwindow;
45         this->awindow = awindow;
46         this->vwindow = vwindow;
47         this->clip = 0;
48         this->create_it = 0;
49 }
50
51 ClipEdit::~ClipEdit()
52 {
53         close_window();
54 }
55
56 // After the window is closed and deleted, this is called.
57 void ClipEdit::handle_close_event(int result)
58 {
59         if(!result)
60         {
61                 int name_ok = 1;
62                 for( int i = 0; name_ok && i < mwindow->edl->clips.total; ++i ) {
63                         if( !strcasecmp(clip->local_session->clip_title,
64                               mwindow->edl->clips.values[i]->local_session->clip_title) &&
65                             (create_it || strcasecmp(clip->local_session->clip_title,
66                                original->local_session->clip_title)) )
67                                 name_ok = 0;
68                 }
69                 if( !name_ok ) {
70                         eprintf(_("A clip with that name already exists."));
71                         result = 1;
72                 }
73         }
74
75         if(!result)
76         {
77 // Add to EDL
78                 if(create_it)
79                         mwindow->edl->add_clip(clip);
80                 else // Copy clip to existing clip in EDL
81                         original->copy_session(clip);
82 //              mwindow->vwindow->gui->update_sources(mwindow->vwindow->gui->source->get_text());
83                 mwindow->awindow->gui->async_update_assets();
84
85 // Change VWindow to it if vwindow was called
86 // But this doesn't let you easily create a lot of clips.
87                 if(vwindow && create_it)
88                 {
89 //                              vwindow->change_source(new_edl);
90                 }
91         }
92         else
93         {
94                 mwindow->session->clip_number--;
95         }
96
97
98
99 // For creating new clips, the original was copied in add_clip.
100 // For editing old clips, the original was transferred to another variable.
101         if(!create_it) clip->remove_user();
102         original = 0;
103         clip = 0;
104         create_it = 0;
105 }
106
107
108 // User creates the window and initializes it here.
109 BC_Window* ClipEdit::new_gui()
110 {
111         original = clip;
112
113         if(!create_it)
114         {
115                 this->clip = new EDL(mwindow->edl);
116                 clip->create_objects();
117                 clip->copy_all(original);
118         }
119
120
121         window = new ClipEditWindow(mwindow, this);
122         window->create_objects();
123         return window;
124 }
125
126
127
128 void ClipEdit::edit_clip(EDL *clip)
129 {
130         close_window();
131 // Allow more than one window so we don't have to delete the clip in handle_event
132         if(!this->clip)
133         {
134                 this->clip = clip;
135                 this->create_it = 0;
136                 start();
137         }
138 }
139
140 void ClipEdit::create_clip(EDL *clip)
141 {
142 // Allow more than one window so we don't have to delete the clip in handle_event
143         if(!this->clip)
144         {
145                 this->clip = clip;
146                 this->create_it = 1;
147                 start();
148         }
149 }
150
151
152
153
154
155
156
157
158 ClipEditWindow::ClipEditWindow(MWindow *mwindow, ClipEdit *thread)
159  : BC_Window(_(PROGRAM_NAME ": Clip Info"),
160         mwindow->gui->get_abs_cursor_x(1) - 400 / 2,
161         mwindow->gui->get_abs_cursor_y(1) - 350 / 2,
162         400,
163         350,
164         400,
165         430,
166         0,
167         0,
168         1)
169 {
170         this->mwindow = mwindow;
171         this->thread = thread;
172 }
173
174 ClipEditWindow::~ClipEditWindow()
175 {
176 }
177
178
179 void ClipEditWindow::create_objects()
180 {
181         lock_window("ClipEditWindow::create_objects");
182         this->create_it = thread->create_it;
183
184         int x = 10, y = 10;
185         int x1 = x;
186         BC_TextBox *textbox;
187         BC_Title *title;
188
189         add_subwindow(title = new BC_Title(x1, y, _("Title:")));
190         y += title->get_h() + 5;
191         add_subwindow(titlebox = new ClipEditTitle(this, x1, y, get_w() - x1 * 2));
192
193         int end = strlen(titlebox->get_text());
194         titlebox->set_selection(0, end, end);
195
196         y += titlebox->get_h() + 10;
197         add_subwindow(title = new BC_Title(x1, y, _("Comments:")));
198         y += title->get_h() + 5;
199         add_subwindow(textbox = new ClipEditComments(this,
200                 x1,
201                 y,
202                 get_w() - x1 * 2,
203                 BC_TextBox::pixels_to_rows(this,
204                         MEDIUMFONT,
205                         get_h() - 10 - BC_OKButton::calculate_h() - y)));
206
207
208
209         add_subwindow(new BC_OKButton(this));
210         add_subwindow(new BC_CancelButton(this));
211         show_window();
212         titlebox->activate();
213         unlock_window();
214 }
215
216
217
218
219
220 ClipEditTitle::ClipEditTitle(ClipEditWindow *window, int x, int y, int w)
221  : BC_TextBox(x, y, w, 1, window->thread->clip->local_session->clip_title)
222 {
223         this->window = window;
224 }
225
226 int ClipEditTitle::handle_event()
227 {
228         strcpy(window->thread->clip->local_session->clip_title, get_text());
229         return 1;
230 }
231
232
233
234
235
236 ClipEditComments::ClipEditComments(ClipEditWindow *window, int x, int y, int w, int rows)
237  : BC_TextBox(x, y, w, rows, window->thread->clip->local_session->clip_notes)
238 {
239         this->window = window;
240 }
241
242 int ClipEditComments::handle_event()
243 {
244         strcpy(window->thread->clip->local_session->clip_notes, get_text());
245         return 1;
246 }