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
24 #include "renderprofiles.h"
32 #include "mwindowgui.h"
36 RenderProfileItem::RenderProfileItem(const char *text, int value)
37 : BC_ListBoxItem(text)
43 RenderProfile::RenderProfile(MWindow *mwindow,
44 RenderWindow *rwindow,
49 this->mwindow = mwindow;
50 this->rwindow = rwindow;
53 this->use_nothing = use_nothing;
54 for (int i = 1; i < MAX_PROFILES; i++)
56 char string_name[100];
58 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
59 mwindow->defaults->get(string_name, name);
60 if (strlen(name) != 0)
61 profiles.append(new RenderProfileItem(name, i));
66 RenderProfile::~RenderProfile()
71 for(int i = 0; i < profiles.total; i++)
72 delete profiles.values[i];
77 int RenderProfile::calculate_h(BC_WindowBase *gui)
79 return BC_TextBox::calculate_h(gui, MEDIUMFONT, 1, 1);
82 int RenderProfile::create_objects()
84 int x = this->x, y = this->y;
85 const char *default_text = "";
86 rwindow->add_subwindow(new BC_Title(x,
88 _("RenderProfile:")));
92 rwindow->add_subwindow(title = new BC_Title(x, y, _("Render profile:")));
94 rwindow->add_subwindow(textbox = new BC_TextBox(x,
99 x += textbox->get_w();
100 rwindow->add_subwindow(listbox = new RenderProfileListBox(rwindow, this, x, y));
103 x += listbox->get_w() + 10;
104 rwindow->add_subwindow(saveprofile = new SaveRenderProfileButton(this,
108 rwindow->add_subwindow(deleteprofile = new DeleteRenderProfileButton(this,
117 int RenderProfile::get_h()
120 result = MAX(result, title->get_h());
121 result = MAX(result, textbox->get_h());
125 int RenderProfile::get_x()
130 int RenderProfile::get_y()
135 int RenderProfile::reposition_window(int x, int y)
139 title->reposition_window(x, y);
141 textbox->reposition_window(x, y);
142 x += textbox->get_w();
143 listbox->reposition_window(x,
150 RenderProfileListBox::RenderProfileListBox(BC_WindowBase *window,
151 RenderProfile *renderprofile,
159 (ArrayList<BC_ListBoxItem *>*)&renderprofile->profiles,
166 this->window = window;
167 this->renderprofile = renderprofile;
170 RenderProfileListBox::~RenderProfileListBox()
174 int RenderProfileListBox::handle_event()
176 RenderProfileItem *item = (RenderProfileItem *)get_selection(0, 0);
178 renderprofile->textbox->update(item->get_text());
179 renderprofile->rwindow->load_profile(item->value);
184 int RenderProfile::get_profile_slot_by_name(const char *profile_name)
186 for (int i = 1; i < MAX_PROFILES; i++)
188 char string_name[100];
190 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
192 mwindow->defaults->get(string_name, name);
193 if (strcmp(name, profile_name) == 0)
196 // No free profile slots!
200 int RenderProfile::get_new_profile_slot()
202 for (int i = 1; i < MAX_PROFILES; i++)
204 char string_name[100];
206 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
207 mwindow->defaults->get(string_name, name);
208 if (strlen(name) == 0)
215 int RenderProfile::save_to_slot(int profile_slot, const char *profile_name)
217 char string_name[100];
218 sprintf(string_name, "RENDER_%i_PROFILE_NAME", profile_slot);
219 mwindow->defaults->update(string_name, profile_name);
221 sprintf(string_name, "RENDER_%i_FILE_PER_LABEL", profile_slot);
222 mwindow->defaults->update(string_name,
223 rwindow->render->use_labels ? FILE_PER_LABEL : SINGLE_PASS);
224 sprintf(string_name, "RENDER_%i_LOADMODE", profile_slot);
225 mwindow->defaults->update(string_name, rwindow->render->load_mode);
226 sprintf(string_name, "RENDER_%i_RANGE_TYPE", profile_slot);
227 mwindow->defaults->update(string_name, rwindow->render->range_type);
229 sprintf(string_name, "RENDER_%i_", profile_slot);
230 rwindow->asset->save_defaults(mwindow->defaults,
231 string_name, 1, 1, 1, 1, 1);
233 mwindow->save_defaults();
239 SaveRenderProfileButton::SaveRenderProfileButton(RenderProfile *profile, int x, int y)
240 : BC_GenericButton(x, y, _("Save profile"))
242 this->profile = profile;
244 int SaveRenderProfileButton::handle_event()
247 const char *profile_name = profile->textbox->get_text();
248 if (strlen(profile_name) == 0) // Don't save when name not defined
250 int slot = profile->get_profile_slot_by_name(profile_name);
253 slot = profile->get_new_profile_slot();
256 ErrorBox error_box(_(PROGRAM_NAME ": Error"),
257 profile->mwindow->gui->get_abs_cursor_x(1),
258 profile->mwindow->gui->get_abs_cursor_y(1));
259 error_box.create_objects(_("Maximum number of render profiles reached"));
260 error_box.raise_window();
261 error_box.run_window();
265 profile->profiles.append(new RenderProfileItem(profile_name, slot));
266 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
272 profile->save_to_slot(slot, profile_name);
278 DeleteRenderProfileButton::DeleteRenderProfileButton(RenderProfile *profile, int x, int y)
279 : BC_GenericButton(x, y, _("Delete profile"))
281 this->profile = profile;
283 int DeleteRenderProfileButton::handle_event()
285 const char *profile_name = profile->textbox->get_text();
286 int slot = profile->get_profile_slot_by_name(profile_name);
289 for(int i = 0; i < profile->profiles.total; i++)
291 if(profile->profiles.values[i]->value == slot)
293 profile->profiles.remove_object_number(i);
294 profile->save_to_slot(slot, "");
299 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
300 profile->textbox->update("");