4 * Copyright (C) 2007 Andraz Tori
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.
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.
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
23 #include "renderprofiles.h"
31 #include "mwindowgui.h"
34 #define _(String) gettext(String)
35 #define gettext_noop(String) String
36 #define N_(String) gettext_noop (String)
40 RenderProfileItem::RenderProfileItem(const char *text, int value)
41 : BC_ListBoxItem(text)
47 RenderProfile::RenderProfile(MWindow *mwindow,
48 RenderWindow *rwindow,
53 this->mwindow = mwindow;
54 this->rwindow = rwindow;
57 this->use_nothing = use_nothing;
58 for (int i = 1; i < MAX_PROFILES; i++)
60 char string_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));
70 RenderProfile::~RenderProfile()
75 for(int i = 0; i < profiles.total; i++)
76 delete profiles.values[i];
81 int RenderProfile::calculate_h(BC_WindowBase *gui)
83 return BC_TextBox::calculate_h(gui, MEDIUMFONT, 1, 1);
86 int RenderProfile::create_objects()
88 int x = this->x, y = this->y;
89 const char *default_text = "";
90 rwindow->add_subwindow(new BC_Title(x,
92 _("RenderProfile:")));
96 rwindow->add_subwindow(title = new BC_Title(x, y, _("Render profile:")));
98 rwindow->add_subwindow(textbox = new BC_TextBox(x,
103 x += textbox->get_w();
104 rwindow->add_subwindow(listbox = new RenderProfileListBox(rwindow, this, x, y));
107 x += listbox->get_w() + 10;
108 rwindow->add_subwindow(saveprofile = new SaveRenderProfileButton(this,
112 rwindow->add_subwindow(deleteprofile = new DeleteRenderProfileButton(this,
121 int RenderProfile::get_h()
124 result = MAX(result, title->get_h());
125 result = MAX(result, textbox->get_h());
129 int RenderProfile::get_x()
134 int RenderProfile::get_y()
139 int RenderProfile::reposition_window(int x, int y)
143 title->reposition_window(x, y);
145 textbox->reposition_window(x, y);
146 x += textbox->get_w();
147 listbox->reposition_window(x,
154 RenderProfileListBox::RenderProfileListBox(BC_WindowBase *window,
155 RenderProfile *renderprofile,
163 (ArrayList<BC_ListBoxItem *>*)&renderprofile->profiles,
170 this->window = window;
171 this->renderprofile = renderprofile;
174 RenderProfileListBox::~RenderProfileListBox()
178 int RenderProfileListBox::handle_event()
180 if(get_selection(0, 0) >= 0)
182 renderprofile->textbox->update(get_selection(0, 0)->get_text());
183 renderprofile->rwindow->load_profile(((RenderProfileItem*)get_selection(0, 0))->value);
188 int RenderProfile::get_profile_slot_by_name(const char *profile_name)
190 for (int i = 1; i < MAX_PROFILES; i++)
192 char string_name[100];
194 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
196 mwindow->defaults->get(string_name, name);
197 if (strcmp(name, profile_name) == 0)
200 // No free profile slots!
204 int RenderProfile::get_new_profile_slot()
206 for (int i = 1; i < MAX_PROFILES; i++)
208 char string_name[100];
210 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
211 mwindow->defaults->get(string_name, name);
212 if (strlen(name) == 0)
219 int RenderProfile::save_to_slot(int profile_slot, const char *profile_name)
221 char string_name[100];
222 sprintf(string_name, "RENDER_%i_PROFILE_NAME", profile_slot);
223 mwindow->defaults->update(string_name, profile_name);
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);
232 sprintf(string_name, "RENDER_%i_", profile_slot);
233 rwindow->asset->save_defaults(mwindow->defaults,
241 mwindow->save_defaults();
247 SaveRenderProfileButton::SaveRenderProfileButton(RenderProfile *profile, int x, int y)
248 : BC_GenericButton(x, y, _("Save profile"))
250 this->profile = profile;
252 int SaveRenderProfileButton::handle_event()
255 const char *profile_name = profile->textbox->get_text();
256 if (strlen(profile_name) == 0) // Don't save when name not defined
258 int slot = profile->get_profile_slot_by_name(profile_name);
261 slot = profile->get_new_profile_slot();
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();
273 profile->profiles.append(new RenderProfileItem(profile_name, slot));
274 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
280 profile->save_to_slot(slot, profile_name);
286 DeleteRenderProfileButton::DeleteRenderProfileButton(RenderProfile *profile, int x, int y)
287 : BC_GenericButton(x, y, _("Delete profile"))
289 this->profile = profile;
291 int DeleteRenderProfileButton::handle_event()
293 const char *profile_name = profile->textbox->get_text();
294 int slot = profile->get_profile_slot_by_name(profile_name);
297 for(int i = 0; i < profile->profiles.total; i++)
299 if(profile->profiles.values[i]->value == slot)
301 profile->profiles.remove_object_number(i);
302 profile->save_to_slot(slot, "");
307 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
308 profile->textbox->update("");