2 #include "renderprofiles.h"
10 #include "mwindowgui.h"
13 #define _(String) gettext(String)
14 #define gettext_noop(String) String
15 #define N_(String) gettext_noop (String)
19 RenderProfileItem::RenderProfileItem(char *text, int value)
20 : BC_ListBoxItem(text)
26 RenderProfile::RenderProfile(MWindow *mwindow,
27 RenderWindow *rwindow,
32 this->mwindow = mwindow;
33 this->rwindow = rwindow;
36 this->use_nothing = use_nothing;
37 for (int i = 1; i < MAX_PROFILES; i++)
39 char string_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));
49 RenderProfile::~RenderProfile()
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,
71 _("RenderProfile:")));
75 rwindow->add_subwindow(title = new BC_Title(x, y, _("Render profile:")));
77 rwindow->add_subwindow(textbox = new BC_TextBox(x,
82 x += textbox->get_w();
83 rwindow->add_subwindow(listbox = new RenderProfileListBox(rwindow, this, x, y));
86 x += listbox->get_w() + 10;
87 rwindow->add_subwindow(saveprofile = new SaveRenderProfileButton(this,
91 rwindow->add_subwindow(deleteprofile = new DeleteRenderProfileButton(this,
100 int RenderProfile::get_h()
103 result = MAX(result, title->get_h());
104 result = MAX(result, textbox->get_h());
108 int RenderProfile::get_x()
113 int RenderProfile::get_y()
118 int RenderProfile::reposition_window(int x, int y)
122 title->reposition_window(x, y);
124 textbox->reposition_window(x, y);
125 x += textbox->get_w();
126 listbox->reposition_window(x,
133 RenderProfileListBox::RenderProfileListBox(BC_WindowBase *window,
134 RenderProfile *renderprofile,
142 (ArrayList<BC_ListBoxItem *>*)&renderprofile->profiles,
149 this->window = window;
150 this->renderprofile = renderprofile;
153 RenderProfileListBox::~RenderProfileListBox()
157 int RenderProfileListBox::handle_event()
159 if(get_selection(0, 0) >= 0)
161 renderprofile->textbox->update(get_selection(0, 0)->get_text());
162 renderprofile->rwindow->load_profile(((RenderProfileItem*)get_selection(0, 0))->value);
167 int RenderProfile::get_profile_slot_by_name(char * profile_name)
169 for (int i = 1; i < MAX_PROFILES; i++)
171 char string_name[100];
173 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
175 mwindow->defaults->get(string_name, name);
176 if (strcmp(name, profile_name) == 0)
179 // No free profile slots!
183 int RenderProfile::get_new_profile_slot()
185 for (int i = 1; i < MAX_PROFILES; i++)
187 char string_name[100];
189 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
190 mwindow->defaults->get(string_name, name);
191 if (strlen(name) == 0)
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,
220 mwindow->save_defaults();
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()
234 char *profile_name = profile->textbox->get_text();
235 if (strlen(profile_name) == 0) // Don't save when name not defined
237 int slot = profile->get_profile_slot_by_name(profile_name);
240 slot = profile->get_new_profile_slot();
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();
252 profile->profiles.append(new RenderProfileItem(profile_name, slot));
253 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
259 profile->save_to_slot(slot, profile_name);
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);
276 for(int i = 0; i < profile->profiles.total; i++)
278 if(profile->profiles.values[i]->value == slot)
280 profile->profiles.remove_object_number(i);
281 profile->save_to_slot(slot, "");
286 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
287 profile->textbox->update("");
302 // c-file-style: "linux"