diff options
author | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2005-02-27 12:11:30 +0000 |
---|---|---|
committer | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2005-02-27 12:11:30 +0000 |
commit | 0f76be59bf9a2a085cd34bfb7a42952b870f9f60 (patch) | |
tree | c4f6b3b57d2915feafac5799bf859175878deb0c /src/gui | |
parent | f847ae831e6a1cfb29a7045683e308ff668b1717 (diff) | |
download | mana-0f76be59bf9a2a085cd34bfb7a42952b870f9f60.tar.gz mana-0f76be59bf9a2a085cd34bfb7a42952b870f9f60.tar.bz2 mana-0f76be59bf9a2a085cd34bfb7a42952b870f9f60.tar.xz mana-0f76be59bf9a2a085cd34bfb7a42952b870f9f60.zip |
Video modes are taken from SDL
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/setup.cpp | 79 | ||||
-rw-r--r-- | src/gui/setup.h | 18 |
2 files changed, 68 insertions, 29 deletions
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 151c3ab6..5d8f3ca5 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -35,25 +35,48 @@ #include "ok_dialog.h" #include "../main.h" -struct Modes { - int height, width; - char *desc; -}; +SDL_Rect **modes; + +ModeListModel::ModeListModel() { + int i; + + modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); + + // Check if any modes available + if(modes == (SDL_Rect **)0) { + nmode=0; + puts("No modes"); + } + + // Check if modes restricted + if(modes == (SDL_Rect **)-1) + puts("Modes restricted"); + + for(nmode=0;modes[nmode];++nmode); + + mode = (char **) calloc(nmode,sizeof(char *)); + + for(i=0;modes[i];++i) { + if(asprintf(&mode[i], "%d x %d", modes[i]->w, modes[i]->h) == -1) + puts("Cannot allocate mode list"); + } +} -static Modes modes[] = { - { 640,480, "640x480"}, - { 800,600, "800x600" }, - { 1024,768, "1024x768" } -}; +ModeListModel::~ModeListModel() { + int i; + + // Cleanup + for(i=0;i<nmode;i++) + free(mode[i]); + free(mode); +} int ModeListModel::getNumberOfElements() { - // TODO after moving to SDL - return 3; + return nmode; } std::string ModeListModel::getElementAt(int i) { - // TODO: after moving to SDL - return modes[i].desc; + return mode[i]; } Setup::Setup(): @@ -70,6 +93,9 @@ Setup::Setup(): applyButton = new Button("Apply"); cancelButton = new Button("Cancel"); + // Set selections + last_sel = 0; + sel = 1; // Set events applyButton->setEventId("apply"); @@ -131,16 +157,21 @@ void Setup::action(const std::string& eventId) { if (eventId == "apply") { setVisible(false); - int sel = 0; + + // Select video mode sel = modeList->getSelected(); - + + if(sel != last_sel) { + last_sel = sel; + screen = SDL_SetVideoMode(modes[sel]->w, modes[sel]->h, 32, SDL_FULLSCREEN | SDL_HWSURFACE); + } + // Display settings if (fsCheckBox->isMarked() && config.getValue("screen", 0) == 0) { config.setValue("screen", 1); #if __USE_UNIX98 SDL_WM_ToggleFullScreen(screen); - #else int displayFlags = 0; displayFlags |= SDL_FULLSCREEN; @@ -150,12 +181,8 @@ void Setup::action(const std::string& eventId) else { displayFlags |= SDL_SWSURFACE; } - screen = SDL_SetVideoMode(800, 600, 32, displayFlags); - #endif - - // FIXME : Need to handle resolution - //set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, - // modes[sel].height, modes[sel].width, 0, 0); + screen = SDL_SetVideoMode(modes[sel]->w, modes[sel]->h, 32, displayFlags); + #endif } else if (!fsCheckBox->isMarked() && config.getValue("screen", 0) == 1) @@ -163,7 +190,6 @@ void Setup::action(const std::string& eventId) config.setValue("screen", 0); #if __USE_UNIX98 SDL_WM_ToggleFullScreen(screen); - #else int displayFlags = 0; if ((int)config.getValue("hwaccel", 0)) { @@ -172,11 +198,8 @@ void Setup::action(const std::string& eventId) else { displayFlags |= SDL_SWSURFACE; } - screen = SDL_SetVideoMode(800, 600, 32, displayFlags); - #endif - // FIXME : Need to handle resolution - //set_gfx_mode(GFX_AUTODETECT_WINDOWED, - // modes[sel].height, modes[sel].width, 0, 0); + screen = SDL_SetVideoMode(modes[sel]->w, modes[sel]->h, 32, displayFlags); + #endif } // Sound settings diff --git a/src/gui/setup.h b/src/gui/setup.h index 6d0e8f5c..e1f28beb 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -43,6 +43,20 @@ class ModeListModel : public gcn::ListModel { * Returns element from container. */ std::string getElementAt(int i); + + /** + * Constructor. + */ + ModeListModel(); + + /** + * Destructor. + */ + virtual ~ModeListModel(); + + private: + int nmode; + char **mode; }; /** @@ -64,7 +78,9 @@ class Setup : public Window, public gcn::ActionListener { gcn::Button *applyButton; gcn::Button *cancelButton; - + // Video selections + int last_sel, sel; + public: /** |