xoreos  0.0.5
resolution.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/configman.h"
26 #include "src/common/strutil.h"
27 #include "src/common/ustring.h"
28 
29 #include "src/graphics/windowman.h"
31 
33 
36 
37 static bool operator<(const Graphics::DisplayMode &d1, const Graphics::DisplayMode &d2) {
38  if (d1.w == d2.w)
39  return d1.h < d2.h;
40  else
41  return d1.w < d2.w;
42 }
43 
44 namespace Engines {
45 
46 namespace KotOR {
47 
48 OptionsResolutionMenu::OptionsResolutionMenu(Console *console) : GUI(console), _newWidth(0), _newHeight(0) {
49  load("optresolution");
50 
51  WidgetPanel *guiPanel = getPanel("TGuiPanel");
52  guiPanel->setPosition(-guiPanel->getWidth()/2, -guiPanel->getHeight()/2, 0);
53 
54  int currentIndex = -1;
55  std::vector<Graphics::DisplayMode> modes = WindowMan.getDisplayModes();
56 
57  // sort and then get the highest resolution.
58  std::sort(modes.begin(), modes.end());
59  Graphics::DisplayMode maxMode = modes.back();
60 
61  // If we have no fullscreen, we add some other common resolutions.
62  if (!WindowMan.isFullScreen()) {
63  for (size_t i = 0; i < ARRAYSIZE(Graphics::kResolutions); ++i) {
65  mode.w = Graphics::kResolutions[i].width;
66  mode.h = Graphics::kResolutions[i].height;
67  modes.push_back(mode);
68  }
69 
70  std::sort(modes.begin(), modes.end());
71  }
72 
73  // Filter every resolution smaller than 800x600
74  for (size_t i = 0; i < modes.size(); ++i) {
75  bool duplicate = false;
76  for (size_t j = 0; j < _modes.size(); ++j) {
77  if (_modes[j].w == modes[i].w && _modes[j].h == modes[i].h)
78  duplicate = true;
79  }
80 
81  if (modes[i].w >= 800 && modes[i].h >= 600 &&
82  modes[i].w <= maxMode.w && modes[i].h <= maxMode.h && !duplicate) {
83  _modes.push_back(modes[i]);
84 
85  if (modes[i].w == WindowMan.getWindowWidth() && modes[i].h == WindowMan.getWindowHeight())
86  currentIndex = _modes.size() - 1;
87  }
88  }
89 
90  WidgetListBox *listBox = getListBox("LB_RESOLUTIONS");
91  listBox->createItemWidgets(_modes.size());
92  for (size_t i = 0; i < _modes.size(); ++i) {
93  Graphics::DisplayMode mode = _modes[i];
94  listBox->addItem(Common::composeString(mode.w) + " x " + Common::composeString(mode.h));
95  }
96 
97  listBox->setAdjustHeight(true);
98  listBox->setItemSelectionEnabled(true);
99  if (currentIndex != -1)
100  listBox->selectItemByIndex(currentIndex);
101  listBox->refreshItemWidgets();
102 }
103 
104 void OptionsResolutionMenu::callbackActive(Widget &widget) {
105  if (widget.getTag() == "BTN_OK") {
106  const int index = getListBox("LB_RESOLUTIONS")->getSelectedIndex();
107 
108  if (index >= 0 && static_cast<size_t>(index) < _modes.size()) {
109  WindowMan.setWindowSize(_modes[index].w, _modes[index].h);
110  ConfigMan.setInt("width", _modes[index].w);
111  ConfigMan.setInt("height", _modes[index].h);
112  }
113 
114  _returnCode = kReturnCodeAbort;
115  return;
116  }
117 
118  if (widget.getTag() == "BTN_CANCEL") {
119  _returnCode = kReturnCodeAbort;
120  return;
121  }
122 }
123 
124 } // End of namespace KotOR
125 
126 } // End of namespace Engines
The global config manager.
UString composeString(T value)
Convert any POD integer, float/double or bool type into a string.
Definition: strutil.cpp:276
The graphics resolution menu.
The global window manager.
#define ARRAYSIZE(x)
Macro which determines the number of entries in a fixed size array.
Definition: util.h:131
A panel widget for Star Wars: Knights of the Old Republic and Jade Empire.
Utility templates and functions for working with strings and streams.
OptionsResolutionMenu(::Engines::Console *console=0)
#define ConfigMan
Shortcut for accessing the config manager.
Definition: configman.h:176
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
A list box widget for Star Wars: Knights of the Old Republic and Jade Empire.
static bool operator<(const Graphics::DisplayMode &d1, const Graphics::DisplayMode &d2)
Definition: resolution.cpp:37
Unicode string handling.
#define WindowMan
Shortcut for accessing the window manager.
Definition: windowman.h:137
static const Resolution kResolutions[]
Definition: resolution.h:35
A widget in a GUI.
Definition: widget.h:40
SDL_DisplayMode DisplayMode
Definition: windowman.h:36
A list common video resolutions.