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"
34 #define LISTWIDTH xS(200)
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, y, _("RenderProfile:")));
89 rwindow->add_subwindow(title = new BC_Title(x, y, _("Render profile:")));
91 rwindow->add_subwindow(textbox = new BC_TextBox(x, y, LISTWIDTH, 1, default_text));
92 x += textbox->get_w();
93 rwindow->add_subwindow(listbox = new RenderProfileListBox(rwindow, this, x, y));
96 x += listbox->get_w() + xS(10);
97 rwindow->add_subwindow(saveprofile = new SaveRenderProfileButton(this, x, y));
99 rwindow->add_subwindow(deleteprofile = new DeleteRenderProfileButton(this, x, y));
104 int RenderProfile::get_h()
107 result = MAX(result, title->get_h());
108 result = MAX(result, textbox->get_h());
112 int RenderProfile::get_x()
117 int RenderProfile::get_y()
122 int RenderProfile::reposition_window(int x, int y)
126 title->reposition_window(x, y);
128 textbox->reposition_window(x, y);
129 x += textbox->get_w();
130 listbox->reposition_window(x,
137 RenderProfileListBox::RenderProfileListBox(BC_WindowBase *window,
138 RenderProfile *renderprofile, int x, int y)
139 : BC_ListBox(x, y, LISTWIDTH, yS(150), LISTBOX_TEXT,
140 (ArrayList<BC_ListBoxItem *>*)&renderprofile->profiles,
143 this->window = window;
144 this->renderprofile = renderprofile;
147 RenderProfileListBox::~RenderProfileListBox()
151 int RenderProfileListBox::handle_event()
153 RenderProfileItem *item = (RenderProfileItem *)get_selection(0, 0);
155 renderprofile->textbox->update(item->get_text());
156 renderprofile->rwindow->load_profile(item->value);
161 int RenderProfile::get_profile_slot_by_name(const char *profile_name)
163 for (int i = 1; i < MAX_PROFILES; i++)
165 char string_name[100];
167 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
169 mwindow->defaults->get(string_name, name);
170 if (strcmp(name, profile_name) == 0)
173 // No free profile slots!
177 int RenderProfile::get_new_profile_slot()
179 for (int i = 1; i < MAX_PROFILES; i++)
181 char string_name[100];
183 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
184 mwindow->defaults->get(string_name, name);
185 if (strlen(name) == 0)
192 int RenderProfile::save_to_slot(int profile_slot, const char *profile_name)
194 char string_name[100];
195 sprintf(string_name, "RENDER_%i_PROFILE_NAME", profile_slot);
196 mwindow->defaults->update(string_name, profile_name);
198 sprintf(string_name, "RENDER_%i_FILE_PER_LABEL", profile_slot);
199 mwindow->defaults->update(string_name,
200 rwindow->render->use_labels ? FILE_PER_LABEL : SINGLE_PASS);
201 sprintf(string_name, "RENDER_%i_LOADMODE", profile_slot);
202 mwindow->defaults->update(string_name, rwindow->render->load_mode);
203 sprintf(string_name, "RENDER_%i_RANGE_TYPE", profile_slot);
204 mwindow->defaults->update(string_name, rwindow->render->range_type);
206 sprintf(string_name, "RENDER_%i_", profile_slot);
207 rwindow->asset->save_defaults(mwindow->defaults,
208 string_name, 1, 1, 1, 1, 1);
210 mwindow->save_defaults();
216 SaveRenderProfileButton::SaveRenderProfileButton(RenderProfile *profile, int x, int y)
217 : BC_GenericButton(x, y, _("Save profile"))
219 this->profile = profile;
221 int SaveRenderProfileButton::handle_event()
224 const char *profile_name = profile->textbox->get_text();
225 if (strlen(profile_name) == 0) // Don't save when name not defined
227 int slot = profile->get_profile_slot_by_name(profile_name);
230 slot = profile->get_new_profile_slot();
233 ErrorBox error_box(_(PROGRAM_NAME ": Error"),
234 profile->mwindow->gui->get_abs_cursor_x(1),
235 profile->mwindow->gui->get_abs_cursor_y(1));
236 error_box.create_objects(_("Maximum number of render profiles reached"));
237 error_box.raise_window();
238 error_box.run_window();
242 profile->profiles.append(new RenderProfileItem(profile_name, slot));
243 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
249 profile->save_to_slot(slot, profile_name);
255 DeleteRenderProfileButton::DeleteRenderProfileButton(RenderProfile *profile, int x, int y)
256 : BC_GenericButton(x, y, _("Delete profile"))
258 this->profile = profile;
260 int DeleteRenderProfileButton::handle_event()
262 const char *profile_name = profile->textbox->get_text();
263 int slot = profile->get_profile_slot_by_name(profile_name);
266 for(int i = 0; i < profile->profiles.total; i++)
268 if(profile->profiles.values[i]->value == slot)
270 profile->profiles.remove_object_number(i);
271 profile->save_to_slot(slot, "");
276 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
277 profile->textbox->update("");