Skip to content

Commit

Permalink
KOTOR: Enable changing of resolutions in kotor menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Jul 22, 2018
1 parent f84342a commit f932dae
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/engines/aurora/kotorjadegui/listbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,13 @@ void WidgetListBox::applyChangesToItemWidgets() {
}
}

void WidgetListBox::mouseWheel(uint8 state, int x, int y) {
void WidgetListBox::mouseWheel(uint8 UNUSED(state), int UNUSED(x), int y) {
if (y == 0 || !_adjustHeight)
return;

_startIndex = MIN(
MAX(_startIndex - y, 0),
MIN(static_cast<int>(_itemWidgets.size()) - _numVisibleItems, 0)
MAX<int>(_itemWidgets.size() - _numVisibleItems, 0)
);
refreshItemWidgets();
}
Expand Down
49 changes: 47 additions & 2 deletions src/engines/kotor/gui/options/resolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,68 @@
* The graphics resolution menu.
*/

#include "src/common/configman.h"
#include "src/common/strutil.h"
#include "src/common/ustring.h"

#include "src/graphics/windowman.h"

#include "src/engines/kotor/gui/options/resolution.h"

#include "src/engines/aurora/kotorjadegui/panel.h"
#include "src/engines/aurora/kotorjadegui/listbox.h"

namespace Engines {

namespace KotOR {

OptionsResolutionMenu::OptionsResolutionMenu(Console *console) : GUI(console) {
OptionsResolutionMenu::OptionsResolutionMenu(Console *console) : GUI(console), _newWidth(0), _newHeight(0) {
load("optresolution");

WidgetPanel *guiPanel = getPanel("TGuiPanel");
guiPanel->setPosition(-guiPanel->getWidth()/2, -guiPanel->getHeight()/2, 0);

int currentIndex = -1;
std::vector<Graphics::DisplayMode> modes = WindowMan.getDisplayModes();

// Filter every resolution smaller than 800x600
for (size_t i = 0; i < modes.size(); ++i) {
bool duplicate = false;
for (size_t j = 0; j < _modes.size(); ++j) {
if (_modes[j].w == modes[i].w && _modes[j].h == modes[i].h)
duplicate = true;
}

if (modes[i].w >= 800 && modes[i].h >= 600 && !duplicate) {
_modes.push_back(modes[i]);
}
}

WidgetListBox *listBox = getListBox("LB_RESOLUTIONS");
listBox->createItemWidgets(_modes.size());
for (size_t i = 0; i < _modes.size(); ++i) {
Graphics::DisplayMode mode = _modes[i];
listBox->addItem(Common::composeString(mode.w) + " x " + Common::composeString(mode.h));
}

listBox->setAdjustHeight(true);
listBox->setItemSelectionEnabled(true);
listBox->refreshItemWidgets();
}

void OptionsResolutionMenu::callbackActive(Widget &widget) {
// TODO: Add changing of resolutions
if (widget.getTag() == "BTN_OK") {
const int index = getListBox("LB_RESOLUTIONS")->getSelectedIndex();

if (index >= 0 && static_cast<size_t>(index) < _modes.size()) {
WindowMan.setWindowSize(_modes[index].w, _modes[index].h);
ConfigMan.setInt("width", _modes[index].w);
ConfigMan.setInt("height", _modes[index].h);
}

_returnCode = kReturnCodeAbort;
return;
}

if (widget.getTag() == "BTN_CANCEL") {
_returnCode = kReturnCodeAbort;
Expand Down
7 changes: 7 additions & 0 deletions src/engines/kotor/gui/options/resolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef ENGINES_KOTOR_GUI_OPTIONS_RESOLUTION_H
#define ENGINES_KOTOR_GUI_OPTIONS_RESOLUTION_H

#include "src/graphics/windowman.h"

#include "src/engines/kotor/gui/gui.h"

namespace Engines {
Expand All @@ -37,6 +39,11 @@ class OptionsResolutionMenu : public GUI {

protected:
void callbackActive(Widget &widget);

private:
int _newWidth, _newHeight;

std::vector<Graphics::DisplayMode> _modes;
};

} // End of namespace KotOR
Expand Down

0 comments on commit f932dae

Please sign in to comment.