| 1 | /* |
| 2 | * Copyright (C) 2002-2010 The DOSBox Team |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | /* $Id: sdl_gui.cpp,v 1.11 2009-02-25 19:58:11 c2woody Exp $ */ |
| 20 | |
| 21 | #if 0 |
| 22 | #include "SDL.h" |
| 23 | #include "../libs/gui_tk/gui_tk.h" |
| 24 | |
| 25 | #include "dosbox.h" |
| 26 | #include "keyboard.h" |
| 27 | #include "video.h" |
| 28 | #include "render.h" |
| 29 | #include "mapper.h" |
| 30 | #include "setup.h" |
| 31 | #include "control.h" |
| 32 | #include "shell.h" |
| 33 | |
| 34 | #include <iostream> |
| 35 | #include <sstream> |
| 36 | #include <stdexcept> |
| 37 | #include <algorithm> |
| 38 | #include <cctype> |
| 39 | #include <assert.h> |
| 40 | |
| 41 | extern Bit8u int10_font_14[256 * 14]; |
| 42 | extern Program * first_shell; |
| 43 | extern void MSG_Write(const char *); |
| 44 | extern void GFX_SetTitle(Bit32s cycles, Bits frameskip, bool paused); |
| 45 | |
| 46 | static int cursor, saved_bpp; |
| 47 | static int old_unicode; |
| 48 | static bool mousetoggle, running, shell_idle; |
| 49 | |
| 50 | static SDL_Surface *screenshot, *background; |
| 51 | |
| 52 | /* Prepare screen for UI */ |
| 53 | void UI_Init(void) { |
| 54 | GUI::Font::addFont("default",new GUI::BitmapFont(int10_font_14,14,10)); |
| 55 | } |
| 56 | |
| 57 | static void getPixel(Bits x, Bits y, int &r, int &g, int &b, int shift) |
| 58 | { |
| 59 | if (x >= (Bits)render.src.width) x = (Bits)render.src.width-1; |
| 60 | if (y >= (Bits)render.src.height) x = (Bits)render.src.height-1; |
| 61 | if (x < 0) x = 0; |
| 62 | if (y < 0) y = 0; |
| 63 | |
| 64 | Bit8u* src = (Bit8u *)&scalerSourceCache; |
| 65 | Bit32u pixel; |
| 66 | switch (render.scale.inMode) { |
| 67 | case scalerMode8: |
| 68 | pixel = *(x+(Bit8u*)(src+y*render.scale.cachePitch)); |
| 69 | r += render.pal.rgb[pixel].red >> shift; |
| 70 | g += render.pal.rgb[pixel].green >> shift; |
| 71 | b += render.pal.rgb[pixel].blue >> shift; |
| 72 | break; |
| 73 | case scalerMode15: |
| 74 | pixel = *(x+(Bit16u*)(src+y*render.scale.cachePitch)); |
| 75 | r += (pixel >> (7+shift)) & (0xf8 >> shift); |
| 76 | g += (pixel >> (2+shift)) & (0xf8 >> shift); |
| 77 | b += (pixel << (3-shift)) & (0xf8 >> shift); |
| 78 | break; |
| 79 | case scalerMode16: |
| 80 | pixel = *(x+(Bit16u*)(src+y*render.scale.cachePitch)); |
| 81 | r += (pixel >> (8+shift)) & (0xf8 >> shift); |
| 82 | g += (pixel >> (3+shift)) & (0xfc >> shift); |
| 83 | b += (pixel << (3-shift)) & (0xf8 >> shift); |
| 84 | break; |
| 85 | case scalerMode32: |
| 86 | pixel = *(x+(Bit32u*)(src+y*render.scale.cachePitch)); |
| 87 | r += (pixel >> (16+shift)) & (0xff >> shift); |
| 88 | g += (pixel >> (8+shift)) & (0xff >> shift); |
| 89 | b += (pixel >> shift) & (0xff >> shift); |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | static GUI::ScreenSDL *UI_Startup(GUI::ScreenSDL *screen) { |
| 95 | GFX_EndUpdate(0); |
| 96 | GFX_SetTitle(-1,-1,true); |
| 97 | if(!screen) { //Coming from DOSBox. Clean up the keyboard buffer. |
| 98 | KEYBOARD_ClrBuffer();//Clear buffer |
| 99 | } |
| 100 | GFX_LosingFocus();//Release any keys pressed (buffer gets filled again). (could be in above if, but clearing the mapper input when exiting the mapper is sensible as well |
| 101 | SDL_Delay(500); |
| 102 | |
| 103 | // Comparable to the code of intro.com, but not the same! (the code of intro.com is called from within a com file) |
| 104 | shell_idle = first_shell && (DOS_PSP(dos.psp()).GetSegment() == DOS_PSP(dos.psp()).GetParent()); |
| 105 | |
| 106 | int w, h; |
| 107 | bool fs; |
| 108 | GFX_GetSize(w, h, fs); |
| 109 | if (w < 512) w = 640; |
| 110 | if (h < 350) h = 400; |
| 111 | |
| 112 | old_unicode = SDL_EnableUNICODE(1); |
| 113 | SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL); |
| 114 | screenshot = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, GUI::Color::RedMask, GUI::Color::GreenMask, GUI::Color::BlueMask, 0); |
| 115 | |
| 116 | // create screenshot for fade effect |
| 117 | int rs = screenshot->format->Rshift, gs = screenshot->format->Gshift, bs = screenshot->format->Bshift, am = GUI::Color::AlphaMask; |
| 118 | for (int y = 0; y < h; y++) { |
| 119 | Bit32u *bg = (Bit32u*)(y*screenshot->pitch + (char*)screenshot->pixels); |
| 120 | for (int x = 0; x < w; x++) { |
| 121 | int r = 0, g = 0, b = 0; |
| 122 | getPixel(x *(int)render.src.width/w, y *(int)render.src.height/h, r, g, b, 0); |
| 123 | bg[x] = r << rs | g << gs | b << bs; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | background = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, GUI::Color::RedMask, GUI::Color::GreenMask, GUI::Color::BlueMask, GUI::Color::AlphaMask); |
| 128 | // use a blurred and sepia-toned screenshot as menu background |
| 129 | for (int y = 0; y < h; y++) { |
| 130 | Bit32u *bg = (Bit32u*)(y*background->pitch + (char*)background->pixels); |
| 131 | for (int x = 0; x < w; x++) { |
| 132 | int r = 0, g = 0, b = 0; |
| 133 | getPixel(x *(int)render.src.width/w, y *(int)render.src.height/h, r, g, b, 3); |
| 134 | getPixel((x-1)*(int)render.src.width/w, y *(int)render.src.height/h, r, g, b, 3); |
| 135 | getPixel(x *(int)render.src.width/w, (y-1)*(int)render.src.height/h, r, g, b, 3); |
| 136 | getPixel((x-1)*(int)render.src.width/w, (y-1)*(int)render.src.height/h, r, g, b, 3); |
| 137 | getPixel((x+1)*(int)render.src.width/w, y *(int)render.src.height/h, r, g, b, 3); |
| 138 | getPixel(x *(int)render.src.width/w, (y+1)*(int)render.src.height/h, r, g, b, 3); |
| 139 | getPixel((x+1)*(int)render.src.width/w, (y+1)*(int)render.src.height/h, r, g, b, 3); |
| 140 | getPixel((x-1)*(int)render.src.width/w, (y+1)*(int)render.src.height/h, r, g, b, 3); |
| 141 | int r1 = (int)((r * 393 + g * 769 + b * 189) / 1351); |
| 142 | int g1 = (int)((r * 349 + g * 686 + b * 168) / 1203); |
| 143 | int b1 = (int)((r * 272 + g * 534 + b * 131) / 2140); |
| 144 | bg[x] = r1 << rs | g1 << gs | b1 << bs | am; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | cursor = SDL_ShowCursor(SDL_QUERY); |
| 149 | SDL_ShowCursor(SDL_ENABLE); |
| 150 | |
| 151 | mousetoggle = mouselocked; |
| 152 | if (mouselocked) GFX_CaptureMouse(); |
| 153 | |
| 154 | SDL_Surface* sdlscreen = SDL_SetVideoMode(w, h, 32, SDL_SWSURFACE|(fs?SDL_FULLSCREEN:0)); |
| 155 | if (sdlscreen == NULL) E_Exit("Could not initialize video mode %ix%ix32 for UI: %s", w, h, SDL_GetError()); |
| 156 | |
| 157 | // fade out |
| 158 | SDL_Event event; |
| 159 | for (int i = 0xff; i > 0; i -= 0x11) { |
| 160 | SDL_SetAlpha(screenshot, SDL_SRCALPHA, i); |
| 161 | SDL_BlitSurface(background, NULL, sdlscreen, NULL); |
| 162 | SDL_BlitSurface(screenshot, NULL, sdlscreen, NULL); |
| 163 | SDL_UpdateRect(sdlscreen, 0, 0, 0, 0); |
| 164 | while (SDL_PollEvent(&event)) {}; |
| 165 | SDL_Delay(40); |
| 166 | } |
| 167 | |
| 168 | SDL_BlitSurface(background, NULL, sdlscreen, NULL); |
| 169 | SDL_UpdateRect(sdlscreen, 0, 0, 0, 0); |
| 170 | |
| 171 | if (screen) screen->setSurface(sdlscreen); |
| 172 | else screen = new GUI::ScreenSDL(sdlscreen); |
| 173 | |
| 174 | saved_bpp = render.src.bpp; |
| 175 | render.src.bpp = 0; |
| 176 | running = true; |
| 177 | return screen; |
| 178 | } |
| 179 | |
| 180 | /* Restore screen */ |
| 181 | static void UI_Shutdown(GUI::ScreenSDL *screen) { |
| 182 | SDL_Surface *sdlscreen = screen->getSurface(); |
| 183 | render.src.bpp = saved_bpp; |
| 184 | |
| 185 | // fade in |
| 186 | SDL_Event event; |
| 187 | for (int i = 0x00; i < 0xff; i += 0x11) { |
| 188 | SDL_SetAlpha(screenshot, SDL_SRCALPHA, i); |
| 189 | SDL_BlitSurface(background, NULL, sdlscreen, NULL); |
| 190 | SDL_BlitSurface(screenshot, NULL, sdlscreen, NULL); |
| 191 | SDL_UpdateRect(sdlscreen, 0, 0, 0, 0); |
| 192 | while (SDL_PollEvent(&event)) {}; |
| 193 | SDL_Delay(40); |
| 194 | } |
| 195 | |
| 196 | // clean up |
| 197 | if (mousetoggle) GFX_CaptureMouse(); |
| 198 | SDL_ShowCursor(cursor); |
| 199 | SDL_FreeSurface(background); |
| 200 | SDL_FreeSurface(screenshot); |
| 201 | SDL_FreeSurface(sdlscreen); |
| 202 | screen->setSurface(NULL); |
| 203 | GFX_ResetScreen(); |
| 204 | SDL_EnableUNICODE(old_unicode); |
| 205 | SDL_EnableKeyRepeat(0,0); |
| 206 | GFX_SetTitle(-1,-1,false); |
| 207 | } |
| 208 | |
| 209 | /* helper class for command execution */ |
| 210 | class VirtualBatch : public BatchFile { |
| 211 | protected: |
| 212 | std::istringstream lines; |
| 213 | public: |
| 214 | VirtualBatch(DOS_Shell *host, const std::string& cmds) : BatchFile(host, "CON", ""), lines(cmds) { |
| 215 | } |
| 216 | bool ReadLine(char *line) { |
| 217 | std::string l; |
| 218 | if (!std::getline(lines,l)) { |
| 219 | delete this; |
| 220 | return false; |
| 221 | } |
| 222 | strcpy(line,l.c_str()); |
| 223 | return true; |
| 224 | } |
| 225 | }; |
| 226 | |
| 227 | static void UI_RunCommands(GUI::ScreenSDL *s, const std::string &cmds) { |
| 228 | DOS_Shell temp; |
| 229 | temp.call = true; |
| 230 | UI_Shutdown(s); |
| 231 | temp.bf = new VirtualBatch(&temp, cmds); |
| 232 | temp.RunInternal(); |
| 233 | temp.ShowPrompt(); |
| 234 | UI_Startup(s); |
| 235 | } |
| 236 | |
| 237 | |
| 238 | /* stringification and conversion from the c++ FAQ */ |
| 239 | class BadConversion : public std::runtime_error { |
| 240 | public: BadConversion(const std::string& s) : std::runtime_error(s) { } |
| 241 | }; |
| 242 | |
| 243 | template<typename T> inline std::string stringify(const T& x, std::ios_base& ( *pf )(std::ios_base&) = NULL) { |
| 244 | std::ostringstream o; |
| 245 | if (pf) o << pf; |
| 246 | if (!(o << x)) throw BadConversion(std::string("stringify(") + typeid(x).name() + ")"); |
| 247 | return o.str(); |
| 248 | } |
| 249 | |
| 250 | template<typename T> inline void convert(const std::string& s, T& x, bool failIfLeftoverChars = true, std::ios_base& ( *pf )(std::ios_base&) = NULL) { |
| 251 | std::istringstream i(s); |
| 252 | if (pf) i >> pf; |
| 253 | char c; |
| 254 | if (!(i >> x) || (failIfLeftoverChars && i.get(c))) throw BadConversion(s); |
| 255 | } |
| 256 | |
| 257 | /*****************************************************************************************************************************************/ |
| 258 | /* UI classes */ |
| 259 | |
| 260 | class PropertyEditor : public GUI::Window, public GUI::ActionEventSource_Callback { |
| 261 | protected: |
| 262 | Section_prop * section; |
| 263 | Property *prop; |
| 264 | public: |
| 265 | PropertyEditor(Window *parent, int x, int y, Section_prop *section, Property *prop) : |
| 266 | Window(parent, x, y, 240, 30), section(section), prop(prop) { } |
| 267 | |
| 268 | virtual bool prepare(std::string &buffer) = 0; |
| 269 | |
| 270 | void actionExecuted(GUI::ActionEventSource *b, const GUI::String &arg) { |
| 271 | std::string line; |
| 272 | if (prepare(line)) { |
| 273 | if (first_shell) section->ExecuteDestroy(false); |
| 274 | prop->SetValue(GUI::String(line)); |
| 275 | if (first_shell) section->ExecuteInit(false); |
| 276 | } |
| 277 | } |
| 278 | }; |
| 279 | |
| 280 | class PropertyEditorBool : public PropertyEditor { |
| 281 | GUI::Checkbox *input; |
| 282 | public: |
| 283 | PropertyEditorBool(Window *parent, int x, int y, Section_prop *section, Property *prop) : |
| 284 | PropertyEditor(parent, x, y, section, prop) { |
| 285 | input = new GUI::Checkbox(this, 0, 3, prop->propname.c_str()); |
| 286 | input->setChecked(static_cast<bool>(prop->GetValue())); |
| 287 | } |
| 288 | |
| 289 | bool prepare(std::string &buffer) { |
| 290 | if (input->isChecked() == static_cast<bool>(prop->GetValue())) return false; |
| 291 | buffer.append(input->isChecked()?"true":"false"); |
| 292 | return true; |
| 293 | } |
| 294 | }; |
| 295 | |
| 296 | class PropertyEditorString : public PropertyEditor { |
| 297 | protected: |
| 298 | GUI::Input *input; |
| 299 | public: |
| 300 | PropertyEditorString(Window *parent, int x, int y, Section_prop *section, Property *prop) : |
| 301 | PropertyEditor(parent, x, y, section, prop) { |
| 302 | new GUI::Label(this, 0, 5, prop->propname); |
| 303 | input = new GUI::Input(this, 130, 0, 110); |
| 304 | std::string temps = prop->GetValue().ToString(); |
| 305 | input->setText(stringify(temps)); |
| 306 | } |
| 307 | |
| 308 | bool prepare(std::string &buffer) { |
| 309 | std::string temps = prop->GetValue().ToString(); |
| 310 | if (input->getText() == GUI::String(temps)) return false; |
| 311 | buffer.append(static_cast<const std::string&>(input->getText())); |
| 312 | return true; |
| 313 | } |
| 314 | }; |
| 315 | |
| 316 | class PropertyEditorFloat : public PropertyEditor { |
| 317 | protected: |
| 318 | GUI::Input *input; |
| 319 | public: |
| 320 | PropertyEditorFloat(Window *parent, int x, int y, Section_prop *section, Property *prop) : |
| 321 | PropertyEditor(parent, x, y, section, prop) { |
| 322 | new GUI::Label(this, 0, 5, prop->propname); |
| 323 | input = new GUI::Input(this, 130, 0, 50); |
| 324 | input->setText(stringify((double)prop->GetValue())); |
| 325 | } |
| 326 | |
| 327 | bool prepare(std::string &buffer) { |
| 328 | double val; |
| 329 | convert(input->getText(), val, false); |
| 330 | if (val == (double)prop->GetValue()) return false; |
| 331 | buffer.append(stringify(val)); |
| 332 | return true; |
| 333 | } |
| 334 | }; |
| 335 | |
| 336 | class PropertyEditorHex : public PropertyEditor { |
| 337 | protected: |
| 338 | GUI::Input *input; |
| 339 | public: |
| 340 | PropertyEditorHex(Window *parent, int x, int y, Section_prop *section, Property *prop) : |
| 341 | PropertyEditor(parent, x, y, section, prop) { |
| 342 | new GUI::Label(this, 0, 5, prop->propname); |
| 343 | input = new GUI::Input(this, 130, 0, 50); |
| 344 | std::string temps = prop->GetValue().ToString(); |
| 345 | input->setText(temps.c_str()); |
| 346 | } |
| 347 | |
| 348 | bool prepare(std::string &buffer) { |
| 349 | int val; |
| 350 | convert(input->getText(), val, false, std::hex); |
| 351 | if ((Hex)val == prop->GetValue()) return false; |
| 352 | buffer.append(stringify(val, std::hex)); |
| 353 | return true; |
| 354 | } |
| 355 | }; |
| 356 | |
| 357 | class PropertyEditorInt : public PropertyEditor { |
| 358 | protected: |
| 359 | GUI::Input *input; |
| 360 | public: |
| 361 | PropertyEditorInt(Window *parent, int x, int y, Section_prop *section, Property *prop) : |
| 362 | PropertyEditor(parent, x, y, section, prop) { |
| 363 | new GUI::Label(this, 0, 5, prop->propname); |
| 364 | input = new GUI::Input(this, 130, 0, 50); |
| 365 | //Maybe use ToString() of Value |
| 366 | input->setText(stringify(static_cast<int>(prop->GetValue()))); |
| 367 | } |
| 368 | |
| 369 | bool prepare(std::string &buffer) { |
| 370 | int val; |
| 371 | convert(input->getText(), val, false); |
| 372 | if (val == static_cast<int>(prop->GetValue())) return false; |
| 373 | buffer.append(stringify(val)); |
| 374 | return true; |
| 375 | } |
| 376 | }; |
| 377 | |
| 378 | class HelpWindow : public GUI::MessageBox { |
| 379 | public: |
| 380 | HelpWindow(GUI::Screen *parent, int x, int y, Section *section) : |
| 381 | MessageBox(parent, x, y, 580, "", "") { |
| 382 | std::string title(section->GetName()); |
| 383 | title.at(0) = std::toupper(title.at(0)); |
| 384 | setTitle("Help for "+title); |
| 385 | std::string name = section->GetName(); |
| 386 | std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))std::toupper); |
| 387 | name += "_CONFIGFILE_HELP"; |
| 388 | setText(MSG_Get(name.c_str())); |
| 389 | } |
| 390 | }; |
| 391 | |
| 392 | class SectionEditor : public GUI::ToplevelWindow { |
| 393 | Section_prop * section; |
| 394 | public: |
| 395 | SectionEditor(GUI::Screen *parent, int x, int y, Section_prop *section) : |
| 396 | ToplevelWindow(parent, x, y, 510, 300, ""), section(section) { |
| 397 | std::string title(section->GetName()); |
| 398 | title[0] = std::toupper(title[0]); |
| 399 | setTitle("Configuration for "+title); |
| 400 | new GUI::Label(this, 5, 10, "Settings:"); |
| 401 | GUI::Button *b = new GUI::Button(this, 120, 220, "Cancel", 70); |
| 402 | b->addActionHandler(this); |
| 403 | b = new GUI::Button(this, 200, 220, "Help", 70); |
| 404 | b->addActionHandler(this); |
| 405 | b = new GUI::Button(this, 280, 220, "OK", 70); |
| 406 | |
| 407 | int i = 0; |
| 408 | Property *prop; |
| 409 | while ((prop = section->Get_prop(i))) { |
| 410 | Prop_bool *pbool = dynamic_cast<Prop_bool*>(prop); |
| 411 | Prop_int *pint = dynamic_cast<Prop_int*>(prop); |
| 412 | Prop_double *pdouble = dynamic_cast<Prop_double*>(prop); |
| 413 | Prop_hex *phex = dynamic_cast<Prop_hex*>(prop); |
| 414 | Prop_string *pstring = dynamic_cast<Prop_string*>(prop); |
| 415 | |
| 416 | PropertyEditor *p; |
| 417 | if (pbool) p = new PropertyEditorBool(this, 5+250*(i/6), 40+(i%6)*30, section, prop); |
| 418 | else if (phex) p = new PropertyEditorHex(this, 5+250*(i/6), 40+(i%6)*30, section, prop); |
| 419 | else if (pint) p = new PropertyEditorInt(this, 5+250*(i/6), 40+(i%6)*30, section, prop); |
| 420 | else if (pdouble) p = new PropertyEditorFloat(this, 5+250*(i/6), 40+(i%6)*30, section, prop); |
| 421 | else if (pstring) p = new PropertyEditorString(this, 5+250*(i/6), 40+(i%6)*30, section, prop); |
| 422 | else { i++; continue; } |
| 423 | b->addActionHandler(p); |
| 424 | i++; |
| 425 | } |
| 426 | b->addActionHandler(this); |
| 427 | } |
| 428 | |
| 429 | void actionExecuted(GUI::ActionEventSource *b, const GUI::String &arg) { |
| 430 | if (arg == "OK" || arg == "Cancel") close(); |
| 431 | else if (arg == "Help") new HelpWindow(static_cast<GUI::Screen*>(parent), getX()-10, getY()-10, section); |
| 432 | else ToplevelWindow::actionExecuted(b, arg); |
| 433 | } |
| 434 | }; |
| 435 | |
| 436 | class AutoexecEditor : public GUI::ToplevelWindow { |
| 437 | Section_line * section; |
| 438 | GUI::Input *content; |
| 439 | public: |
| 440 | AutoexecEditor(GUI::Screen *parent, int x, int y, Section_line *section) : |
| 441 | ToplevelWindow(parent, x, y, 450, 300, ""), section(section) { |
| 442 | std::string title(section->GetName()); |
| 443 | title[0] = std::toupper(title[0]); |
| 444 | setTitle("Edit "+title); |
| 445 | new GUI::Label(this, 5, 10, "Content:"); |
| 446 | content = new GUI::Input(this, 5, 30, 420, 185); |
| 447 | content->setText(section->data); |
| 448 | if (first_shell) (new GUI::Button(this, 5, 220, "Append History"))->addActionHandler(this); |
| 449 | if (shell_idle) (new GUI::Button(this, 180, 220, "Execute Now"))->addActionHandler(this); |
| 450 | (new GUI::Button(this, 290, 220, "Cancel", 70))->addActionHandler(this); |
| 451 | (new GUI::Button(this, 360, 220, "OK", 70))->addActionHandler(this); |
| 452 | } |
| 453 | |
| 454 | void actionExecuted(GUI::ActionEventSource *b, const GUI::String &arg) { |
| 455 | if (arg == "OK") section->data = *(std::string*)content->getText(); |
| 456 | if (arg == "OK" || arg == "Cancel") close(); |
| 457 | else if (arg == "Append Shell Commands") { |
| 458 | DOS_Shell *s = static_cast<DOS_Shell *>(first_shell); |
| 459 | std::list<std::string>::reverse_iterator i = s->l_history.rbegin(); |
| 460 | std::string lines = *(std::string*)content->getText(); |
| 461 | while (i != s->l_history.rend()) { |
| 462 | lines += "\n"; |
| 463 | lines += *i; |
| 464 | ++i; |
| 465 | } |
| 466 | content->setText(lines); |
| 467 | } else if (arg == "Execute Now") { |
| 468 | UI_RunCommands(dynamic_cast<GUI::ScreenSDL*>(getScreen()), content->getText()); |
| 469 | } else ToplevelWindow::actionExecuted(b, arg); |
| 470 | } |
| 471 | }; |
| 472 | |
| 473 | class SaveDialog : public GUI::ToplevelWindow { |
| 474 | protected: |
| 475 | GUI::Input *name; |
| 476 | public: |
| 477 | SaveDialog(GUI::Screen *parent, int x, int y, const char *title) : |
| 478 | ToplevelWindow(parent, x, y, 400, 150, title) { |
| 479 | new GUI::Label(this, 5, 10, "Enter filename for configuration file:"); |
| 480 | name = new GUI::Input(this, 5, 30, 350); |
| 481 | name->setText("dosbox.conf"); |
| 482 | (new GUI::Button(this, 120, 70, "Cancel", 70))->addActionHandler(this); |
| 483 | (new GUI::Button(this, 210, 70, "OK", 70))->addActionHandler(this); |
| 484 | } |
| 485 | |
| 486 | void actionExecuted(GUI::ActionEventSource *b, const GUI::String &arg) { |
| 487 | if (arg == "OK") control->PrintConfig(name->getText()); |
| 488 | close(); |
| 489 | } |
| 490 | }; |
| 491 | |
| 492 | class SaveLangDialog : public GUI::ToplevelWindow { |
| 493 | protected: |
| 494 | GUI::Input *name; |
| 495 | public: |
| 496 | SaveLangDialog(GUI::Screen *parent, int x, int y, const char *title) : |
| 497 | ToplevelWindow(parent, x, y, 400, 150, title) { |
| 498 | new GUI::Label(this, 5, 10, "Enter filename for language file:"); |
| 499 | name = new GUI::Input(this, 5, 30, 350); |
| 500 | name->setText("messages.txt"); |
| 501 | (new GUI::Button(this, 120, 70, "Cancel", 70))->addActionHandler(this); |
| 502 | (new GUI::Button(this, 210, 70, "OK", 70))->addActionHandler(this); |
| 503 | } |
| 504 | |
| 505 | void actionExecuted(GUI::ActionEventSource *b, const GUI::String &arg) { |
| 506 | if (arg == "OK") MSG_Write(name->getText()); |
| 507 | close(); |
| 508 | } |
| 509 | }; |
| 510 | |
| 511 | class ConfigurationWindow : public GUI::ToplevelWindow { |
| 512 | public: |
| 513 | ConfigurationWindow(GUI::Screen *parent, GUI::Size x, GUI::Size y, GUI::String title) : |
| 514 | GUI::ToplevelWindow(parent, x, y, 470, 290, title) { |
| 515 | |
| 516 | (new GUI::Button(this, 180, 215, "Close", 70))->addActionHandler(this); |
| 517 | |
| 518 | GUI::Menubar *bar = new GUI::Menubar(this, 0, 0, getWidth()); |
| 519 | bar->addMenu("Configuration"); |
| 520 | bar->addItem(0,"Save..."); |
| 521 | bar->addItem(0,"Save Language File..."); |
| 522 | bar->addItem(0,""); |
| 523 | bar->addItem(0,"Close"); |
| 524 | bar->addMenu("Settings"); |
| 525 | bar->addMenu("Help"); |
| 526 | bar->addItem(2,"Introduction"); |
| 527 | bar->addItem(2,"Getting Started"); |
| 528 | bar->addItem(2,"CD-ROM Support"); |
| 529 | bar->addItem(2,"Special Keys"); |
| 530 | bar->addItem(2,""); |
| 531 | bar->addItem(2,"About"); |
| 532 | bar->addActionHandler(this); |
| 533 | |
| 534 | new GUI::Label(this, 10, 30, "Choose a settings group to configure:"); |
| 535 | |
| 536 | Section *sec; |
| 537 | int i = 0; |
| 538 | while ((sec = control->GetSection(i))) { |
| 539 | std::string name = sec->GetName(); |
| 540 | name[0] = std::toupper(name[0]); |
| 541 | GUI::Button *b = new GUI::Button(this, 12+(i/5)*160, 50+(i%5)*30, name, 100); |
| 542 | b->addActionHandler(this); |
| 543 | bar->addItem(1, name); |
| 544 | i++; |
| 545 | } |
| 546 | |
| 547 | if (first_shell) { |
| 548 | (new GUI::Button(this, 12+(i/5)*160, 50+(i%5)*30, "Keyboard", 100))->addActionHandler(this); |
| 549 | bar->addItem(1, ""); |
| 550 | bar->addItem(1, "Keyboard"); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | ~ConfigurationWindow() { running = false; } |
| 555 | |
| 556 | void actionExecuted(GUI::ActionEventSource *b, const GUI::String &arg) { |
| 557 | GUI::String sname = arg; |
| 558 | sname.at(0) = std::tolower(sname.at(0)); |
| 559 | Section *sec; |
| 560 | if (arg == "Close" || arg == "Cancel") { |
| 561 | running = false; |
| 562 | } else if (arg == "Keyboard") { |
| 563 | UI_Shutdown(dynamic_cast<GUI::ScreenSDL*>(getScreen())); |
| 564 | MAPPER_Run(false); |
| 565 | UI_Startup(dynamic_cast<GUI::ScreenSDL*>(getScreen())); |
| 566 | } else if (sname == "autoexec") { |
| 567 | Section_line *section = static_cast<Section_line *>(control->GetSection((const char *)sname)); |
| 568 | new AutoexecEditor(getScreen(), 50, 30, section); |
| 569 | } else if ((sec = control->GetSection((const char *)sname))) { |
| 570 | Section_prop *section = static_cast<Section_prop *>(sec); |
| 571 | new SectionEditor(getScreen(), 50, 30, section); |
| 572 | } else if (arg == "About") { |
| 573 | new GUI::MessageBox(getScreen(), 200, 150, 280, "About DOSBox", "\nDOSBox 0.72\nAn emulator for old DOS Games\n\nCopyright 2002-2009\nThe DOSBox Team"); |
| 574 | } else if (arg == "Introduction") { |
| 575 | new GUI::MessageBox(getScreen(), 20, 50, 600, "Introduction", MSG_Get("PROGRAM_INTRO")); |
| 576 | } else if (arg == "Getting Started") { |
| 577 | std::string msg = MSG_Get("PROGRAM_INTRO_MOUNT_START"); |
| 578 | #ifdef WIN32 |
| 579 | msg += MSG_Get("PROGRAM_INTRO_MOUNT_WINDOWS"); |
| 580 | #else |
| 581 | msg += MSG_Get("PROGRAM_INTRO_MOUNT_OTHER"); |
| 582 | #endif |
| 583 | msg += MSG_Get("PROGRAM_INTRO_MOUNT_END"); |
| 584 | |
| 585 | new GUI::MessageBox(getScreen(), 20, 50, 600, std::string("Introduction"), msg); |
| 586 | } else if (arg == "CD-ROM Support") { |
| 587 | new GUI::MessageBox(getScreen(), 20, 50, 600, "Introduction", MSG_Get("PROGRAM_INTRO_CDROM")); |
| 588 | } else if (arg == "Special Keys") { |
| 589 | new GUI::MessageBox(getScreen(), 20, 50, 600, "Introduction", MSG_Get("PROGRAM_INTRO_SPECIAL")); |
| 590 | } else if (arg == "Save...") { |
| 591 | new SaveDialog(getScreen(), 90, 100, "Save Configuration..."); |
| 592 | } else if (arg == "Save Language File...") { |
| 593 | new SaveLangDialog(getScreen(), 90, 100, "Save Language File..."); |
| 594 | } else { |
| 595 | return ToplevelWindow::actionExecuted(b, arg); |
| 596 | } |
| 597 | } |
| 598 | }; |
| 599 | |
| 600 | /*********************************************************************************************************************/ |
| 601 | /* UI control functions */ |
| 602 | |
| 603 | static void UI_Execute(GUI::ScreenSDL *screen) { |
| 604 | SDL_Surface *sdlscreen = screen->getSurface(); |
| 605 | new ConfigurationWindow(screen, 30, 30, "DOSBox Configuration"); |
| 606 | |
| 607 | // event loop |
| 608 | SDL_Event event; |
| 609 | while (running) { |
| 610 | while (SDL_PollEvent(&event)) { |
| 611 | if (!screen->event(event)) { |
| 612 | if (event.type == SDL_QUIT) running = false; |
| 613 | } |
| 614 | } |
| 615 | //Selecting keyboard will create a new surface. |
| 616 | sdlscreen = screen->getSurface(); |
| 617 | SDL_BlitSurface(background, NULL, sdlscreen, NULL); |
| 618 | screen->update(4); |
| 619 | SDL_UpdateRect(sdlscreen, 0, 0, 0, 0); |
| 620 | |
| 621 | SDL_Delay(40); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | void UI_Run(bool pressed) { |
| 626 | if (pressed) return; |
| 627 | GUI::ScreenSDL *screen = UI_Startup(NULL); |
| 628 | UI_Execute(screen); |
| 629 | UI_Shutdown(screen); |
| 630 | delete screen; |
| 631 | } |
| 632 | #endif |