00001 #include "clip.h"
00002 #include "renderprofiles.h"
00003 #include "mwindow.h"
00004 #include "theme.h"
00005 #include "bchash.h"
00006 #include "string.h"
00007 #include "render.h"
00008 #include "asset.h"
00009 #include "errorbox.h"
00010 #include "mwindowgui.h"
00011
00012 #include <libintl.h>
00013 #define _(String) gettext(String)
00014 #define gettext_noop(String) String
00015 #define N_(String) gettext_noop (String)
00016
00017 #define LISTWIDTH 200
00018
00019 RenderProfileItem::RenderProfileItem(char *text, int value)
00020 : BC_ListBoxItem(text)
00021 {
00022 this->value = value;
00023 }
00024
00025
00026 RenderProfile::RenderProfile(MWindow *mwindow,
00027 RenderWindow *rwindow,
00028 int x,
00029 int y,
00030 int use_nothing)
00031 {
00032 this->mwindow = mwindow;
00033 this->rwindow = rwindow;
00034 this->x = x;
00035 this->y = y;
00036 this->use_nothing = use_nothing;
00037 for (int i = 1; i < MAX_PROFILES; i++)
00038 {
00039 char string_name[100];
00040 char name[100] = "";
00041 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
00042 mwindow->defaults->get(string_name, name);
00043 if (strlen(name) != 0)
00044 profiles.append(new RenderProfileItem(name, i));
00045
00046 }
00047 }
00048
00049 RenderProfile::~RenderProfile()
00050 {
00051
00052
00053
00054 for(int i = 0; i < profiles.total; i++)
00055 delete profiles.values[i];
00056 }
00057
00058
00059
00060 int RenderProfile::calculate_h(BC_WindowBase *gui)
00061 {
00062 return BC_TextBox::calculate_h(gui, MEDIUMFONT, 1, 1);
00063 }
00064
00065 int RenderProfile::create_objects()
00066 {
00067 int x = this->x, y = this->y;
00068 char *default_text = "";
00069 rwindow->add_subwindow(new BC_Title(x,
00070 y,
00071 _("RenderProfile:")));
00072
00073
00074 int old_y = y;
00075 rwindow->add_subwindow(title = new BC_Title(x, y, _("Render profile:")));
00076 y += 25;
00077 rwindow->add_subwindow(textbox = new BC_TextBox(x,
00078 y,
00079 LISTWIDTH,
00080 1,
00081 default_text));
00082 x += textbox->get_w();
00083 rwindow->add_subwindow(listbox = new RenderProfileListBox(rwindow, this, x, y));
00084
00085 y = old_y;
00086 x += listbox->get_w() + 10;
00087 rwindow->add_subwindow(saveprofile = new SaveRenderProfileButton(this,
00088 x,
00089 y));
00090 y += 25;
00091 rwindow->add_subwindow(deleteprofile = new DeleteRenderProfileButton(this,
00092 x,
00093 y));
00094
00095
00096
00097 return 0;
00098 }
00099
00100 int RenderProfile::get_h()
00101 {
00102 int result = 0;
00103 result = MAX(result, title->get_h());
00104 result = MAX(result, textbox->get_h());
00105 return result;
00106 }
00107
00108 int RenderProfile::get_x()
00109 {
00110 return x;
00111 }
00112
00113 int RenderProfile::get_y()
00114 {
00115 return y;
00116 }
00117
00118 int RenderProfile::reposition_window(int x, int y)
00119 {
00120 this->x = x;
00121 this->y = y;
00122 title->reposition_window(x, y);
00123 y += 20;
00124 textbox->reposition_window(x, y);
00125 x += textbox->get_w();
00126 listbox->reposition_window(x,
00127 y,
00128 LISTWIDTH);
00129 return 0;
00130 }
00131
00132
00133 RenderProfileListBox::RenderProfileListBox(BC_WindowBase *window,
00134 RenderProfile *renderprofile,
00135 int x,
00136 int y)
00137 : BC_ListBox(x,
00138 y,
00139 LISTWIDTH,
00140 150,
00141 LISTBOX_TEXT,
00142 (ArrayList<BC_ListBoxItem *>*)&renderprofile->profiles,
00143 0,
00144 0,
00145 1,
00146 0,
00147 1)
00148 {
00149 this->window = window;
00150 this->renderprofile = renderprofile;
00151 }
00152
00153 RenderProfileListBox::~RenderProfileListBox()
00154 {
00155 }
00156
00157 int RenderProfileListBox::handle_event()
00158 {
00159 if(get_selection(0, 0) >= 0)
00160 {
00161 renderprofile->textbox->update(get_selection(0, 0)->get_text());
00162 renderprofile->rwindow->load_profile(((RenderProfileItem*)get_selection(0, 0))->value);
00163 }
00164 return 1;
00165 }
00166
00167 int RenderProfile::get_profile_slot_by_name(char * profile_name)
00168 {
00169 for (int i = 1; i < MAX_PROFILES; i++)
00170 {
00171 char string_name[100];
00172 char name[100] = "";
00173 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
00174
00175 mwindow->defaults->get(string_name, name);
00176 if (strcmp(name, profile_name) == 0)
00177 return i;
00178 }
00179
00180 return -1;
00181 }
00182
00183 int RenderProfile::get_new_profile_slot()
00184 {
00185 for (int i = 1; i < MAX_PROFILES; i++)
00186 {
00187 char string_name[100];
00188 char name[100] = "";
00189 sprintf(string_name, "RENDER_%i_PROFILE_NAME", i);
00190 mwindow->defaults->get(string_name, name);
00191 if (strlen(name) == 0)
00192 return i;
00193 }
00194 return -1;
00195 }
00196
00197
00198 int RenderProfile::save_to_slot(int profile_slot, char *profile_name)
00199 {
00200 char string_name[100];
00201 sprintf(string_name, "RENDER_%i_PROFILE_NAME", profile_slot);
00202 mwindow->defaults->update(string_name, profile_name);
00203
00204 sprintf(string_name, "RENDER_%i_STRATEGY", profile_slot);
00205 mwindow->defaults->update(string_name, rwindow->render->strategy);
00206 sprintf(string_name, "RENDER_%i_LOADMODE", profile_slot);
00207 mwindow->defaults->update(string_name, rwindow->render->load_mode);
00208 sprintf(string_name, "RENDER_%i_RANGE_TYPE", profile_slot);
00209 mwindow->defaults->update(string_name, rwindow->render->range_type);
00210
00211 sprintf(string_name, "RENDER_%i_", profile_slot);
00212 rwindow->asset->save_defaults(mwindow->defaults,
00213 string_name,
00214 1,
00215 1,
00216 1,
00217 1,
00218 1);
00219
00220 mwindow->save_defaults();
00221 return 0;
00222 }
00223
00224
00225
00226 SaveRenderProfileButton::SaveRenderProfileButton(RenderProfile *profile, int x, int y)
00227 : BC_GenericButton(x, y, _("Save profile"))
00228 {
00229 this->profile = profile;
00230 }
00231 int SaveRenderProfileButton::handle_event()
00232 {
00233
00234 char *profile_name = profile->textbox->get_text();
00235 if (strlen(profile_name) == 0)
00236 return 1;
00237 int slot = profile->get_profile_slot_by_name(profile_name);
00238 if (slot < 0)
00239 {
00240 slot = profile->get_new_profile_slot();
00241 if (slot < 0)
00242 {
00243 ErrorBox error_box(PROGRAM_NAME ": Error",
00244 profile->mwindow->gui->get_abs_cursor_x(1),
00245 profile->mwindow->gui->get_abs_cursor_y(1));
00246 error_box.create_objects("Maximum number of render profiles reached");
00247 error_box.raise_window();
00248 error_box.run_window();
00249 return 1;
00250 }
00251
00252 profile->profiles.append(new RenderProfileItem(profile_name, slot));
00253 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
00254
00255 }
00256
00257 if (slot >= 0)
00258 {
00259 profile->save_to_slot(slot, profile_name);
00260 }
00261 return 1;
00262 }
00263
00264
00265 DeleteRenderProfileButton::DeleteRenderProfileButton(RenderProfile *profile, int x, int y)
00266 : BC_GenericButton(x, y, _("Delete profile"))
00267 {
00268 this->profile = profile;
00269 }
00270 int DeleteRenderProfileButton::handle_event()
00271 {
00272 char *profile_name = profile->textbox->get_text();
00273 int slot = profile->get_profile_slot_by_name(profile_name);
00274 if (slot >= 0)
00275 {
00276 for(int i = 0; i < profile->profiles.total; i++)
00277 {
00278 if(profile->profiles.values[i]->value == slot)
00279 {
00280 profile->profiles.remove_object_number(i);
00281 profile->save_to_slot(slot, "");
00282
00283 break;
00284 }
00285 }
00286 profile->listbox->update((ArrayList<BC_ListBoxItem *>*)&(profile->profiles), 0, 0, 1);
00287 profile->textbox->update("");
00288
00289 }
00290
00291
00292 return 1;
00293 }
00294
00295
00296
00297
00298