rework keyframe hide popup, keyframe auto render, textbox set_selection wide text
[goodguy/history.git] / cinelerra-5.1 / cinelerra / renderprofiles.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2007 Andraz Tori
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 "clip.h"
23 #include "renderprofiles.h"
24 #include "mwindow.h"
25 #include "theme.h"
26 #include "bchash.h"
27 #include "string.h"
28 #include "render.h"
29 #include "asset.h"
30 #include "errorbox.h"
31 #include "mwindowgui.h"
32
33 #include <libintl.h>
34 #define _(String) gettext(String)
35 #define gettext_noop(String) String
36 #define N_(String) gettext_noop (String)
37
38 #define LISTWIDTH 200
39
40 RenderProfileItem::RenderProfileItem(const char *text, int value)
41  : BC_ListBoxItem(text)
42 {
43         this->value = value;
44 }
45
46
47 RenderProfile::RenderProfile(MWindow *mwindow,
48         RenderWindow *rwindow, 
49         int x, 
50         int y, 
51         int use_nothing)
52 {
53         this->mwindow = mwindow;
54         this->rwindow = rwindow;
55         this->x = x;
56         this->y = y;
57         this->use_nothing = use_nothing;
58         for (int i = 1; i < MAX_PROFILES; i++)
59         {
60                 char string_name[100];
61                 char name[100] = "";
62                 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
63                 mwindow->defaults->get(string_name, name);
64                 if (strlen(name) != 0)
65                         profiles.append(new RenderProfileItem(name, i));
66                                         
67         }
68 }
69
70 RenderProfile::~RenderProfile()
71 {
72 //      delete title;
73 //      delete textbox;
74 //      delete listbox;
75         for(int i = 0; i < profiles.total; i++)
76                 delete profiles.values[i];
77 }
78
79
80
81 int RenderProfile::calculate_h(BC_WindowBase *gui)
82 {
83         return BC_TextBox::calculate_h(gui, MEDIUMFONT, 1, 1);
84 }
85
86 int RenderProfile::create_objects()
87 {
88         int x = this->x, y = this->y;
89         const char *default_text = "";
90         rwindow->add_subwindow(new BC_Title(x, 
91                 y, 
92                         _("RenderProfile:")));
93
94
95         int old_y = y;
96         rwindow->add_subwindow(title = new BC_Title(x, y, _("Render profile:")));
97         y += 25;
98         rwindow->add_subwindow(textbox = new BC_TextBox(x, 
99                 y, 
100                 LISTWIDTH, 
101                 1, 
102                 default_text));
103         x += textbox->get_w();
104         rwindow->add_subwindow(listbox = new RenderProfileListBox(rwindow, this, x, y));
105
106         y = old_y;
107         x += listbox->get_w() + 10;
108         rwindow->add_subwindow(saveprofile = new SaveRenderProfileButton(this, 
109                 x, 
110                 y));
111         y += 25;
112         rwindow->add_subwindow(deleteprofile = new DeleteRenderProfileButton(this, 
113                 x, 
114                 y));
115
116
117
118         return 0;
119 }
120
121 int RenderProfile::get_h()
122 {
123         int result = 0;
124         result = MAX(result, title->get_h());
125         result = MAX(result, textbox->get_h());
126         return result;
127 }
128
129 int RenderProfile::get_x()
130 {
131         return x;
132 }
133
134 int RenderProfile::get_y()
135 {
136         return y;
137 }
138
139 int RenderProfile::reposition_window(int x, int y)
140 {
141         this->x = x;
142         this->y = y;
143         title->reposition_window(x, y);
144         y += 20;
145         textbox->reposition_window(x, y);
146         x += textbox->get_w();
147         listbox->reposition_window(x, 
148                 y, 
149                 LISTWIDTH);
150         return 0;
151 }
152
153
154 RenderProfileListBox::RenderProfileListBox(BC_WindowBase *window, 
155         RenderProfile *renderprofile, 
156         int x, 
157         int y)
158  : BC_ListBox(x,
159         y,
160         LISTWIDTH,
161         150,
162         LISTBOX_TEXT,
163         (ArrayList<BC_ListBoxItem *>*)&renderprofile->profiles,
164         0,
165         0,
166         1,
167         0,
168         1)
169 {
170         this->window = window;
171         this->renderprofile = renderprofile;
172 }
173
174 RenderProfileListBox::~RenderProfileListBox()
175 {
176 }
177
178 int RenderProfileListBox::handle_event()
179 {
180         if(get_selection(0, 0) >= 0)
181         {
182                 renderprofile->textbox->update(get_selection(0, 0)->get_text());
183                 renderprofile->rwindow->load_profile(((RenderProfileItem*)get_selection(0, 0))->value);
184         }
185         return 1;
186 }
187
188 int RenderProfile::get_profile_slot_by_name(const char *profile_name)
189 {
190         for (int i = 1; i < MAX_PROFILES; i++)
191         {
192                 char string_name[100];
193                 char name[100] = "";
194                 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
195                 
196                 mwindow->defaults->get(string_name, name);
197                 if (strcmp(name, profile_name) == 0)
198                         return i;
199         }
200 // No free profile slots!
201         return -1;
202 }
203
204 int RenderProfile::get_new_profile_slot()
205 {
206         for (int i = 1; i < MAX_PROFILES; i++)
207         {
208                 char string_name[100];
209                 char name[100] = "";
210                 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
211                 mwindow->defaults->get(string_name, name);
212                 if (strlen(name) == 0)
213                         return i;
214         }
215         return -1;
216 }
217
218
219 int RenderProfile::save_to_slot(int profile_slot, const char *profile_name)
220 {
221         char string_name[100];
222         sprintf(string_name, "RENDER_%i_PROFILE_NAME", profile_slot);
223         mwindow->defaults->update(string_name, profile_name);
224
225         sprintf(string_name, "RENDER_%i_STRATEGY", profile_slot);
226         mwindow->defaults->update(string_name, rwindow->render->strategy);
227         sprintf(string_name, "RENDER_%i_LOADMODE", profile_slot);
228         mwindow->defaults->update(string_name, rwindow->render->load_mode);
229         sprintf(string_name, "RENDER_%i_RANGE_TYPE", profile_slot);
230         mwindow->defaults->update(string_name, rwindow->render->range_type);
231
232         sprintf(string_name, "RENDER_%i_", profile_slot);
233         rwindow->asset->save_defaults(mwindow->defaults, 
234                 string_name,
235                 1,
236                 1,
237                 1,
238                 1,
239                 1);
240
241         mwindow->save_defaults();
242         return 0;
243 }
244
245
246
247 SaveRenderProfileButton::SaveRenderProfileButton(RenderProfile *profile, int x, int y)
248  : BC_GenericButton(x, y, _("Save profile"))
249 {
250         this->profile = profile;
251 }
252 int SaveRenderProfileButton::handle_event()
253 {
254         
255         const char *profile_name = profile->textbox->get_text();
256         if (strlen(profile_name) == 0)     // Don't save when name not defined
257                 return 1;
258         int slot = profile->get_profile_slot_by_name(profile_name);
259         if (slot < 0)
260         {
261                 slot = profile->get_new_profile_slot();
262                 if (slot < 0)
263                 {
264                         ErrorBox error_box(PROGRAM_NAME ": Error",
265                                            profile->mwindow->gui->get_abs_cursor_x(1),
266                                            profile->mwindow->gui->get_abs_cursor_y(1));
267                         error_box.create_objects("Maximum number of render profiles reached");
268                         error_box.raise_window();
269                         error_box.run_window();
270                         return 1;
271                 }
272                 
273                 profile->profiles.append(new RenderProfileItem(profile_name, slot));
274                 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
275         
276         }
277         
278         if (slot >= 0)
279         {
280                 profile->save_to_slot(slot, profile_name);
281         }
282         return 1;
283 }
284
285
286 DeleteRenderProfileButton::DeleteRenderProfileButton(RenderProfile *profile, int x, int y)
287  : BC_GenericButton(x, y, _("Delete profile"))
288 {
289         this->profile = profile;
290 }
291 int DeleteRenderProfileButton::handle_event()
292 {
293         const char *profile_name = profile->textbox->get_text();
294         int slot = profile->get_profile_slot_by_name(profile_name);
295         if (slot >= 0)
296         {
297                 for(int i = 0; i < profile->profiles.total; i++)
298                 {
299                         if(profile->profiles.values[i]->value == slot)
300                         {
301                                 profile->profiles.remove_object_number(i);
302                                 profile->save_to_slot(slot, "");
303
304                                 break;
305                         }
306                 }
307                 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
308                 profile->textbox->update("");
309
310         }
311
312
313         return 1;
314 }
315
316
317
318
319