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/util.h"
27 
28 #include "src/graphics/graphics.h"
29 
32 
34 
35 namespace Engines {
36 
37 namespace NWN {
38 
39 
41  load("options_vidmodes");
42 
43  if (isMain) {
44  WidgetPanel *backdrop = new WidgetPanel(*this, "PNL_MAINMENU", "pnl_mainmenu");
45  backdrop->setPosition(0.0f, 0.0f, 100.0f);
46  addWidget(backdrop);
47  }
48 }
49 
51 }
52 
54  initResolutionsBox(*getListBox("VideoModeList", true));
55 
56  _width = WindowMan.getWindowWidth ();
57  _height = WindowMan.getWindowHeight();
58 
59  GUI::show();
60 }
61 
63  if (tag == "VideoModeList")
64  type = kWidgetTypeListBox;
65 }
66 
68  if (widget.getTag() == "VideoModeList") {
69  dynamic_cast<WidgetListBox &>(widget).setMode(WidgetListBox::kModeSelectable);
70  return;
71  }
72 }
73 
75  if ((widget.getTag() == "CancelButton") ||
76  (widget.getTag() == "XButton")) {
77 
78  revertChanges();
79  _returnCode = 1;
80  return;
81  }
82 
83  if (widget.getTag() == "OkButton") {
84 
85  setResolution(getListBox("VideoModeList", true)->getSelected());
86  adoptChanges();
87  _returnCode = 2;
88  return;
89  }
90 
91  if (widget.getTag() == "ApplyButton") {
92  setResolution(getListBox("VideoModeList", true)->getSelected());
93  return;
94  }
95 }
96 
98  _useableResolutions.clear();
99 
100  int maxWidth = WindowMan.getSystemWidth ();
101  int maxHeight = WindowMan.getSystemHeight();
102  int curWidth = WindowMan.getWindowWidth ();
103  int curHeight = WindowMan.getWindowHeight();
104 
105  // Find the max allowed resolution in the list
106  size_t maxRes = 0;
107  for (size_t i = 0; i < ARRAYSIZE(Graphics::kResolutions); i++) {
108  if ((Graphics::kResolutions[i].width <= maxWidth) && (Graphics::kResolutions[i].height <= maxHeight)) {
109  maxRes = i;
110  break;
111  }
112  }
113 
114  // Find the current resolution in the list
115  size_t currentResolution = SIZE_MAX;
116  for (size_t i = maxRes; i < ARRAYSIZE(Graphics::kResolutions); i++) {
117  if ((Graphics::kResolutions[i].width == curWidth) && (Graphics::kResolutions[i].height == curHeight)) {
118  currentResolution = i - maxRes;
119  break;
120  }
121  }
122 
123  // Doesn't exist, add it at the top
124  if (currentResolution == SIZE_MAX) {
125  currentResolution = 0;
126  Graphics::Resolution curRes;
127  curRes.height = curHeight;
128  curRes.width = curWidth;
129  _useableResolutions.push_back(curRes);
130  }
131 
132  // Put the rest of the useable resolutions into the list
133  for (size_t i = maxRes; i < ARRAYSIZE(Graphics::kResolutions); i++)
135 
136 
137  resList.lock();
138 
139  resList.clear();
140  for (std::vector<Graphics::Resolution>::const_iterator r = _useableResolutions.begin(); r != _useableResolutions.end(); ++r)
141  resList.add(new WidgetListItemTextLine(*this, "fnt_dialog16x16",
142  Common::UString::format("%dx%d", r->width, r->height), 0.0f));
143 
144  resList.unlock();
145 
146  resList.select(currentResolution);
147 }
148 
150  if (n >= _useableResolutions.size())
151  return;
152 
153  WindowMan.setWindowSize(_useableResolutions[n].width, _useableResolutions[n].height);
154 }
155 
157  ConfigMan.setInt("width" , WindowMan.getWindowWidth (), true);
158  ConfigMan.setInt("height", WindowMan.getWindowHeight(), true);
159 }
160 
162  WindowMan.setWindowSize(_width, _height);
163 }
164 
165 } // End of namespace NWN
166 
167 } // End of namespace Engines
A NWN panel widget.
Definition: panel.h:41
The global graphics manager.
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
void initWidget(Widget &widget)
Definition: resolution.cpp:67
A class holding an UTF-8 string.
Definition: ustring.h:48
WidgetListBox * getListBox(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:318
void add(WidgetListItem *item, bool noTag=false)
Definition: listbox.cpp:411
The global config manager.
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: resolution.cpp:74
void initResolutionsBox(WidgetListBox &resList)
Definition: resolution.cpp:97
#define ARRAYSIZE(x)
Macro which determines the number of entries in a fixed size array.
Definition: util.h:131
void fixWidgetType(const Common::UString &tag, WidgetType &type)
Definition: resolution.cpp:62
A NWN listbox widget.
virtual void show()
Show the GUI.
Definition: gui.cpp:62
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
#define ConfigMan
Shortcut for accessing the config manager.
Definition: configman.h:176
A NWN GUI.
Definition: gui.h:54
Utility templates and functions.
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
The NWN resolution options menu.
std::vector< Graphics::Resolution > _useableResolutions
Definition: resolution.h:53
void load(const Common::UString &resref)
Definition: gui.cpp:77
A NWN listbox widget.
Definition: listbox.h:116
OptionsResolutionMenu(bool isMain=false, ::Engines::Console *console=0)
Definition: resolution.cpp:40
#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
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: modelwidget.cpp:71
void select(size_t item)
Definition: listbox.cpp:618
#define SIZE_MAX
Definition: types.h:172
void addWidget(Widget *widget)
Add a widget.
Definition: gui.cpp:250
A NWN panel widget.
A text line widget within a NWN listbox widget.
Definition: listbox.h:82