49 load(
"optresolution");
51 WidgetPanel *guiPanel = getPanel(
"TGuiPanel");
52 guiPanel->setPosition(-guiPanel->getWidth()/2, -guiPanel->getHeight()/2, 0);
54 int currentIndex = -1;
55 std::vector<Graphics::DisplayMode> modes =
WindowMan.getDisplayModes();
58 std::sort(modes.begin(), modes.end());
67 modes.push_back(mode);
70 std::sort(modes.begin(), modes.end());
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)
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]);
85 if (modes[i].w ==
WindowMan.getWindowWidth() && modes[i].h ==
WindowMan.getWindowHeight())
86 currentIndex = _modes.size() - 1;
90 WidgetListBox *listBox = getListBox(
"LB_RESOLUTIONS");
91 listBox->createItemWidgets(_modes.size());
92 for (
size_t i = 0; i < _modes.size(); ++i) {
97 listBox->setAdjustHeight(
true);
98 listBox->setItemSelectionEnabled(
true);
99 if (currentIndex != -1)
100 listBox->selectItemByIndex(currentIndex);
101 listBox->refreshItemWidgets();
104 void OptionsResolutionMenu::callbackActive(
Widget &widget) {
105 if (widget.
getTag() ==
"BTN_OK") {
106 const int index = getListBox(
"LB_RESOLUTIONS")->getSelectedIndex();
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);
114 _returnCode = kReturnCodeAbort;
118 if (widget.
getTag() ==
"BTN_CANCEL") {
119 _returnCode = kReturnCodeAbort;
The global config manager.
UString composeString(T value)
Convert any POD integer, float/double or bool type into a string.
The graphics resolution menu.
The global window manager.
#define ARRAYSIZE(x)
Macro which determines the number of entries in a fixed size array.
A panel widget for Star Wars: Knights of the Old Republic and Jade Empire.
Utility templates and functions for working with strings and streams.
#define ConfigMan
Shortcut for accessing the config manager.
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)
#define WindowMan
Shortcut for accessing the window manager.
static const Resolution kResolutions[]
SDL_DisplayMode DisplayMode
A list common video resolutions.