Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / renderprofiles.C
blob0e3ca4b955e844f8171af6efa2ace3e080c51eab
1 #include "clip.h"
2 #include "renderprofiles.h"
3 #include "mwindow.h"
4 #include "theme.h"
5 #include "bchash.h"
6 #include "string.h"
7 #include "render.h"
8 #include "asset.h"
9 #include "errorbox.h"
10 #include "mwindowgui.h"
12 #include <libintl.h>
13 #define _(String) gettext(String)
14 #define gettext_noop(String) String
15 #define N_(String) gettext_noop (String)
17 #define LISTWIDTH 200
19 RenderProfileItem::RenderProfileItem(char *text, int value)
20  : BC_ListBoxItem(text)
22         this->value = value;
26 RenderProfile::RenderProfile(MWindow *mwindow,
27         RenderWindow *rwindow, 
28         int x, 
29         int y, 
30         int use_nothing)
32         this->mwindow = mwindow;
33         this->rwindow = rwindow;
34         this->x = x;
35         this->y = y;
36         this->use_nothing = use_nothing;
37         for (int i = 1; i < MAX_PROFILES; i++)
38         {
39                 char string_name[100];
40                 char name[100] = "";
41                 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
42                 mwindow->defaults->get(string_name, name);
43                 if (strlen(name) != 0)
44                         profiles.append(new RenderProfileItem(name, i));
45                                         
46         }
49 RenderProfile::~RenderProfile()
51 //      delete title;
52 //      delete textbox;
53 //      delete listbox;
54         for(int i = 0; i < profiles.total; i++)
55                 delete profiles.values[i];
60 int RenderProfile::calculate_h(BC_WindowBase *gui)
62         return BC_TextBox::calculate_h(gui, MEDIUMFONT, 1, 1);
65 int RenderProfile::create_objects()
67         int x = this->x, y = this->y;
68         char *default_text = "";
69         rwindow->add_subwindow(new BC_Title(x, 
70                 y, 
71                         _("RenderProfile:")));
74         int old_y = y;
75         rwindow->add_subwindow(title = new BC_Title(x, y, _("Render profile:")));
76         y += 25;
77         rwindow->add_subwindow(textbox = new BC_TextBox(x, 
78                 y, 
79                 LISTWIDTH, 
80                 1, 
81                 default_text));
82         x += textbox->get_w();
83         rwindow->add_subwindow(listbox = new RenderProfileListBox(rwindow, this, x, y));
85         y = old_y;
86         x += listbox->get_w() + 10;
87         rwindow->add_subwindow(saveprofile = new SaveRenderProfileButton(this, 
88                 x, 
89                 y));
90         y += 25;
91         rwindow->add_subwindow(deleteprofile = new DeleteRenderProfileButton(this, 
92                 x, 
93                 y));
97         return 0;
100 int RenderProfile::get_h()
102         int result = 0;
103         result = MAX(result, title->get_h());
104         result = MAX(result, textbox->get_h());
105         return result;
108 int RenderProfile::get_x()
110         return x;
113 int RenderProfile::get_y()
115         return y;
118 int RenderProfile::reposition_window(int x, int y)
120         this->x = x;
121         this->y = y;
122         title->reposition_window(x, y);
123         y += 20;
124         textbox->reposition_window(x, y);
125         x += textbox->get_w();
126         listbox->reposition_window(x, 
127                 y, 
128                 LISTWIDTH);
129         return 0;
133 RenderProfileListBox::RenderProfileListBox(BC_WindowBase *window, 
134         RenderProfile *renderprofile, 
135         int x, 
136         int y)
137  : BC_ListBox(x,
138         y,
139         LISTWIDTH,
140         150,
141         LISTBOX_TEXT,
142         (ArrayList<BC_ListBoxItem *>*)&renderprofile->profiles,
143         0,
144         0,
145         1,
146         0,
147         1)
149         this->window = window;
150         this->renderprofile = renderprofile;
153 RenderProfileListBox::~RenderProfileListBox()
157 int RenderProfileListBox::handle_event()
159         if(get_selection(0, 0) >= 0)
160         {
161                 renderprofile->textbox->update(get_selection(0, 0)->get_text());
162                 renderprofile->rwindow->load_profile(((RenderProfileItem*)get_selection(0, 0))->value);
163         }
164         return 1;
167 int RenderProfile::get_profile_slot_by_name(char * profile_name)
169         for (int i = 1; i < MAX_PROFILES; i++)
170         {
171                 char string_name[100];
172                 char name[100] = "";
173                 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
174                 
175                 mwindow->defaults->get(string_name, name);
176                 if (strcmp(name, profile_name) == 0)
177                         return i;
178         }
179 // No free profile slots!
180         return -1;
183 int RenderProfile::get_new_profile_slot()
185         for (int i = 1; i < MAX_PROFILES; i++)
186         {
187                 char string_name[100];
188                 char name[100] = "";
189                 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
190                 mwindow->defaults->get(string_name, name);
191                 if (strlen(name) == 0)
192                         return i;
193         }
194         return -1;
198 int RenderProfile::save_to_slot(int profile_slot, char *profile_name)
200         char string_name[100];
201         sprintf(string_name, "RENDER_%i_PROFILE_NAME", profile_slot);
202         mwindow->defaults->update(string_name, profile_name);
204         sprintf(string_name, "RENDER_%i_STRATEGY", profile_slot);
205         mwindow->defaults->update(string_name, rwindow->render->strategy);
206         sprintf(string_name, "RENDER_%i_LOADMODE", profile_slot);
207         mwindow->defaults->update(string_name, rwindow->render->load_mode);
208         sprintf(string_name, "RENDER_%i_RANGE_TYPE", profile_slot);
209         mwindow->defaults->update(string_name, rwindow->render->range_type);
211         sprintf(string_name, "RENDER_%i_", profile_slot);
212         rwindow->asset->save_defaults(mwindow->defaults, 
213                 string_name,
214                 1,
215                 1,
216                 1,
217                 1,
218                 1);
220         mwindow->save_defaults();
221         return 0;
226 SaveRenderProfileButton::SaveRenderProfileButton(RenderProfile *profile, int x, int y)
227  : BC_GenericButton(x, y, _("Save profile"))
229         this->profile = profile;
231 int SaveRenderProfileButton::handle_event()
233         
234         char *profile_name = profile->textbox->get_text();
235         if (strlen(profile_name) == 0)     // Don't save when name not defined
236                 return 1;
237         int slot = profile->get_profile_slot_by_name(profile_name);
238         if (slot < 0)
239         {
240                 slot = profile->get_new_profile_slot();
241                 if (slot < 0)
242                 {
243                         ErrorBox error_box(PROGRAM_NAME ": Error",
244                                            profile->mwindow->gui->get_abs_cursor_x(1),
245                                            profile->mwindow->gui->get_abs_cursor_y(1));
246                         error_box.create_objects("Maximum number of render profiles reached");
247                         error_box.raise_window();
248                         error_box.run_window();
249                         return 1;
250                 }
251                 
252                 profile->profiles.append(new RenderProfileItem(profile_name, slot));
253                 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
254         
255         }
256         
257         if (slot >= 0)
258         {
259                 profile->save_to_slot(slot, profile_name);
260         }
261         return 1;
265 DeleteRenderProfileButton::DeleteRenderProfileButton(RenderProfile *profile, int x, int y)
266  : BC_GenericButton(x, y, _("Delete profile"))
268         this->profile = profile;
270 int DeleteRenderProfileButton::handle_event()
272         char *profile_name = profile->textbox->get_text();
273         int slot = profile->get_profile_slot_by_name(profile_name);
274         if (slot >= 0)
275         {
276                 for(int i = 0; i < profile->profiles.total; i++)
277                 {
278                         if(profile->profiles.values[i]->value == slot)
279                         {
280                                 profile->profiles.remove_object_number(i);
281                                 profile->save_to_slot(slot, "");
283                                 break;
284                         }
285                 }
286                 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
287                 profile->textbox->update("");
289         }
292         return 1;
300 //      Local Variables:
301 //      mode: C++
302 //      c-file-style: "linux"
303 //      End: