00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef HAVE_CONFIG_H
00020 # include <config.h>
00021 #endif
00022
00023 #include <iostream>
00024 #include <string>
00025 #include <cstring>
00026
00027 #include "SDL_events.h"
00028
00029 #include "Configuration.h"
00030 #include "Gump_button.h"
00031 #include "Gump_ToggleButton.h"
00032 #include "VideoOptions_gump.h"
00033 #include "exult.h"
00034 #include "exult_flx.h"
00035 #include "gamewin.h"
00036 #include "gameclk.h"
00037 #include "mouse.h"
00038 #include "Text_button.h"
00039 #include "palette.h"
00040
00041 using std::cerr;
00042 using std::endl;
00043 using std::string;
00044
00045 static const int rowy[] = { 5, 20, 35, 50, 80 };
00046 static const int colx[] = { 35, 50, 115, 127, 130 };
00047
00048 static const char* oktext = "OK";
00049 static const char* canceltext = "CANCEL";
00050
00051 static int resolutions[] = { 320, 200,
00052 320, 240,
00053 400, 300,
00054 512, 384,
00055 640, 480,
00056 800, 600,
00057 -1, -1 };
00058
00059
00060 static int num_default_res = sizeof(resolutions)/(2*sizeof(resolutions[0])) -1;
00061
00062 static string resolutionstring(int w, int h)
00063 {
00064 char buf[100];
00065 sprintf(buf, "%ix%i", w, h);
00066 return buf;
00067 }
00068
00069
00070 class VideoOptions_button : public Text_button {
00071 public:
00072 VideoOptions_button(Gump *par, string text, int px, int py)
00073 : Text_button(par, text, px, py, 59, 11)
00074 { }
00075
00076 virtual void activate();
00077 };
00078
00079 void VideoOptions_button::activate()
00080 {
00081 if (text == canceltext) {
00082 ((VideoOptions_gump*)parent)->cancel();
00083 } else if (text == oktext) {
00084 ((VideoOptions_gump*)parent)->close();
00085 }
00086 }
00087
00088 class VideoTextToggle : public Gump_ToggleTextButton {
00089 public:
00090 VideoTextToggle(Gump* par, std::string *s, int px, int py, int width,
00091 int selectionnum, int numsel)
00092 : Gump_ToggleTextButton(par, s, selectionnum, numsel, px, py, width) {}
00093
00094 friend class VideoOptions_gump;
00095 virtual void toggle(int state) {
00096 ((VideoOptions_gump*)parent)->toggle((Gump_button*)this, state);
00097 }
00098 };
00099 void VideoOptions_gump::close()
00100 {
00101 save_settings();
00102
00103
00104 gwin->set_all_dirty();
00105 done = 1;
00106 }
00107
00108 void VideoOptions_gump::cancel()
00109 {
00110 done = 1;
00111 }
00112
00113 void VideoOptions_gump::toggle(Gump_button* btn, int state)
00114 {
00115 if(btn==buttons[0])
00116 resolution = state;
00117 else if(btn==buttons[1])
00118 scaling = state;
00119 else if(btn==buttons[2])
00120 scaler = state;
00121 else if(btn==buttons[3])
00122 fullscreen = state;
00123 }
00124
00125 void VideoOptions_gump::build_buttons()
00126 {
00127
00128
00129 buttons[0] = new VideoTextToggle (this, restext, colx[4], rowy[0], 59,
00130 resolution, num_resolutions);
00131
00132 std::string *scalingtext = new std::string[2];
00133 scalingtext[0] = "x1";
00134 scalingtext[1] = "x2";
00135 buttons[1] = new VideoTextToggle (this, scalingtext, colx[4], rowy[1], 59,
00136 scaling, 2);
00137
00138 std::string *enabledtext = new std::string[2];
00139 enabledtext[0] = "Disabled";
00140 enabledtext[1] = "Enabled";
00141 buttons[3] = new VideoTextToggle (this, enabledtext, colx[4], rowy[3], 59,
00142 fullscreen, 2);
00143
00144 std::string *scalers = new std::string[Image_window::NumScalers];
00145 for (int i = 0; i < Image_window::NumScalers; i++)
00146 scalers[i] = Image_window::get_name_for_scaler(i);
00147
00148 buttons[2] = new VideoTextToggle (this, scalers, colx[2], rowy[2], 74,
00149 scaler, Image_window::NumScalers);
00150 }
00151
00152 void VideoOptions_gump::load_settings()
00153 {
00154 int w = gwin->get_width();
00155 int h = gwin->get_height();
00156
00157 resolutions[2*num_default_res] = w;
00158 resolutions[2*num_default_res+1] = h;
00159
00160 num_resolutions = num_default_res;
00161
00162 resolution = -1;
00163 int i;
00164 for (i = 0; i < num_default_res; i++) {
00165 if (resolutions[2*i] == w && resolutions[2*i+1] == h) {
00166 resolution = i;
00167 break;
00168 }
00169 }
00170
00171 if (resolution == -1) {
00172 num_resolutions++;
00173 resolution = num_default_res;
00174 }
00175
00176 restext = new std::string[num_resolutions];
00177 for (i = 0; i < num_resolutions; i++) {
00178 restext[i] = resolutionstring(resolutions[2*i], resolutions[2*i+1]);
00179 }
00180
00181 old_resolution = resolution;
00182 scaling = gwin->get_win()->get_scale()-1;
00183 scaler = gwin->get_win()->get_scaler();
00184 fullscreen = gwin->get_win()->is_fullscreen()?1:0;
00185 gclock->set_palette();
00186
00187 }
00188
00189 VideoOptions_gump::VideoOptions_gump() : Modal_gump(0, EXULT_FLX_VIDEOOPTIONS_SHP, SF_EXULT_FLX)
00190 {
00191 set_object_area(Rectangle(0,0,0,0), 8, 95);
00192
00193 for (int i=0; i<10; i++) buttons[i] = 0;
00194
00195 load_settings();
00196
00197 build_buttons();
00198
00199
00200 buttons[8] = new VideoOptions_button(this, oktext, colx[0], rowy[4]);
00201
00202 buttons[9] = new VideoOptions_button(this, canceltext, colx[4], rowy[4]);
00203 }
00204
00205 VideoOptions_gump::~VideoOptions_gump()
00206 {
00207 for (int i=0; i<10; i++)
00208 if (buttons[i]) delete buttons[i];
00209 }
00210
00211 void VideoOptions_gump::save_settings()
00212 {
00213
00214 int resx = resolutions[2*resolution];
00215 int resy = resolutions[2*resolution+1];
00216 config->set("config/video/width", resx, true);
00217 config->set("config/video/height", resy, true);
00218 config->set("config/video/scale", scaling+1, true);
00219 if (scaler > Image_window::NoScaler && scaler < Image_window::NumScalers)
00220 config->set("config/video/scale_method",Image_window::get_name_for_scaler(scaler),true);
00221 config->set("config/video/fullscreen", fullscreen ? "yes" : "no", true);
00222
00223 gwin->resized(resx,resy,scaling+1,scaler);
00224 if(((fullscreen==0)&&(gwin->get_win()->is_fullscreen()))||
00225 ((fullscreen==1)&&(!gwin->get_win()->is_fullscreen())))
00226 {
00227 gwin->get_win()->toggle_fullscreen();
00228 gwin->get_pal()->apply(false);
00229 gwin->paint();
00230 }
00231 gwin->set_painted();
00232 }
00233
00234 void VideoOptions_gump::paint()
00235 {
00236 Gump::paint();
00237 for (int i=0; i<10; i++)
00238 if (buttons[i])
00239 buttons[i]->paint();
00240
00241 sman->paint_text(2, "Resolution:", x + colx[0], y + rowy[0] + 1);
00242 sman->paint_text(2, "Scaling:", x + colx[0], y + rowy[1] + 1);
00243 sman->paint_text(2, "Scaler:", x + colx[0], y + rowy[2] + 1);
00244 sman->paint_text(2, "Full Screen:", x + colx[0], y + rowy[3] + 1);
00245 gwin->set_painted();
00246 }
00247
00248 void VideoOptions_gump::mouse_down(int mx, int my)
00249 {
00250 pushed = Gump::on_button(mx, my);
00251
00252
00253 if (!pushed)
00254 for (int i=0; i<10; i++)
00255 if (buttons[i] && buttons[i]->on_button(mx, my)) {
00256 pushed = buttons[i];
00257 break;
00258 }
00259
00260 if (pushed)
00261 {
00262 pushed->push();
00263 return;
00264 }
00265 }
00266
00267 void VideoOptions_gump::mouse_up(int mx, int my)
00268 {
00269 if (pushed)
00270 {
00271 pushed->unpush();
00272 if (pushed->on_button(mx, my))
00273 ((Gump_button*)pushed)->activate();
00274 pushed = 0;
00275 }
00276 }