Skip to content

Commit

Permalink
Add: Display refresh rate game option
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda committed Mar 8, 2021
1 parent 8946b41 commit ab68e2c
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 39 deletions.
30 changes: 19 additions & 11 deletions src/lang/english.txt
Expand Up @@ -994,17 +994,6 @@ STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_12_MONTHS :Every 12 months
STR_GAME_OPTIONS_LANGUAGE :{BLACK}Language
STR_GAME_OPTIONS_LANGUAGE_TOOLTIP :{BLACK}Select the interface language to use

STR_GAME_OPTIONS_FULLSCREEN :{BLACK}Fullscreen
STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP :{BLACK}Check this box to play OpenTTD fullscreen mode

STR_GAME_OPTIONS_RESOLUTION :{BLACK}Screen resolution
STR_GAME_OPTIONS_RESOLUTION_TOOLTIP :{BLACK}Select the screen resolution to use
STR_GAME_OPTIONS_RESOLUTION_OTHER :other

STR_GAME_OPTIONS_VIDEO_ACCELERATION :{BLACK}Hardware acceleration
STR_GAME_OPTIONS_VIDEO_ACCELERATION_TOOLTIP :{BLACK}Check this box to allow OpenTTD to try to use hardware acceleration. A changed setting will only be applied upon game restart
STR_GAME_OPTIONS_VIDEO_ACCELERATION_RESTART :{WHITE}The setting will only take effect after a game restart

STR_GAME_OPTIONS_GUI_ZOOM_FRAME :{BLACK}Interface size
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_TOOLTIP :{BLACK}Select the interface element size to use

Expand All @@ -1021,6 +1010,25 @@ STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_NORMAL :Normal
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_2X_ZOOM :Double size
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_4X_ZOOM :Quad size

STR_GAME_OPTIONS_GRAPHICS :{BLACK}Graphics

STR_GAME_OPTIONS_FULLSCREEN :{BLACK}Fullscreen
STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP :{BLACK}Check this box to play OpenTTD fullscreen mode

STR_GAME_OPTIONS_RESOLUTION :{BLACK}Screen resolution
STR_GAME_OPTIONS_RESOLUTION_TOOLTIP :{BLACK}Select the screen resolution to use
STR_GAME_OPTIONS_RESOLUTION_OTHER :other

STR_GAME_OPTIONS_VIDEO_ACCELERATION :{BLACK}Hardware acceleration
STR_GAME_OPTIONS_VIDEO_ACCELERATION_TOOLTIP :{BLACK}Check this box to allow OpenTTD to try to use hardware acceleration. A changed setting will only be applied upon game restart
STR_GAME_OPTIONS_VIDEO_ACCELERATION_RESTART :{WHITE}The setting will only take effect after a game restart

STR_GAME_OPTIONS_REFRESH_RATE :{BLACK}Display refresh rate
STR_GAME_OPTIONS_REFRESH_RATE_TOOLTIP :{BLACK}Select the screen refresh rate to use
STR_GAME_OPTIONS_REFRESH_RATE_OTHER :other
STR_GAME_OPTIONS_REFRESH_RATE_ITEM :{BLACK}{COMMA}Hz
STR_GAME_OPTIONS_REFRESH_RATE_WARNING :{WHITE}Refresh rates higher than 60Hz might impact performance.

STR_GAME_OPTIONS_BASE_GRF :{BLACK}Base graphics set
STR_GAME_OPTIONS_BASE_GRF_TOOLTIP :{BLACK}Select the base graphics set to use
STR_GAME_OPTIONS_BASE_GRF_STATUS :{RED}{NUM} missing/corrupted file{P "" s}
Expand Down
111 changes: 83 additions & 28 deletions src/settings_gui.cpp
Expand Up @@ -38,8 +38,11 @@
#include "video/video_driver.hpp"

#include <vector>
#include <iterator>

#include "safeguards.h"
#include "video/video_driver.hpp"
#include <unordered_set>


static const StringID _autosave_dropdown[] = {
Expand Down Expand Up @@ -140,6 +143,23 @@ void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset,
new BaseSetTextfileWindow<TBaseSet>(file_type, baseset, content_type);
}

std::set<int> _refresh_rates = { 30, 60, 75, 90, 100, 120, 144, 240 };

/**
* Add the refresh rate from the config and the refresh rates from all the monitors to
* our list of refresh rates shown in the GUI.
*/
static void AddRefreshRatesAndSelect()
{
/* Add the refresh rate as selected in the config. */
int wantedRate = _settings_client.gui.refresh_rate;
_refresh_rates.insert(_settings_client.gui.refresh_rate);

/* Add all the refresh rates of all monitors connected to the machine. */
std::vector<int> monitorRates = VideoDriver::GetInstance()->GetListOfMonitorRefreshRates();
std::copy(monitorRates.begin(), monitorRates.end(), std::inserter(_refresh_rates, _refresh_rates.end()));
}

struct GameOptionsWindow : Window {
GameSettings *opt;
bool reload;
Expand All @@ -149,6 +169,8 @@ struct GameOptionsWindow : Window {
this->opt = &GetGameSettings();
this->reload = false;

AddRefreshRatesAndSelect();

this->InitNested(WN_GAME_OPTIONS_GAME_OPTIONS);
this->OnInvalidateData(0);
}
Expand Down Expand Up @@ -215,6 +237,14 @@ struct GameOptionsWindow : Window {
}
break;

case WID_GO_REFRESH_RATE_DROPDOWN: // Setup refresh rate dropdown
for (uint i = 0; i < _refresh_rates.size(); i++) {
auto item = new DropDownListParamStringItem(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, i, false);
item->SetParam(0, *std::next(_refresh_rates.begin(), i));
list.emplace_back(item);
}
break;

case WID_GO_GUI_ZOOM_DROPDOWN: {
*selected_index = _gui_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _gui_zoom + 1 : 0;
const StringID *items = _gui_zoom_dropdown;
Expand Down Expand Up @@ -252,17 +282,21 @@ struct GameOptionsWindow : Window {
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_GO_CURRENCY_DROPDOWN: SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _resolutions.size() ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
case WID_GO_GUI_ZOOM_DROPDOWN: SetDParam(0, _gui_zoom_dropdown[_gui_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _gui_zoom_cfg + 1 : 0]); break;
case WID_GO_FONT_ZOOM_DROPDOWN: SetDParam(0, _font_zoom_dropdown[_font_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _font_zoom_cfg + 1 : 0]); break;
case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name.c_str()); break;
case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name.c_str()); break;
case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->name.c_str()); break;
case WID_GO_BASE_MUSIC_STATUS: SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
case WID_GO_CURRENCY_DROPDOWN: SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _resolutions.size() ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
case WID_GO_GUI_ZOOM_DROPDOWN: SetDParam(0, _gui_zoom_dropdown[_gui_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _gui_zoom_cfg + 1 : 0]); break;
case WID_GO_FONT_ZOOM_DROPDOWN: SetDParam(0, _font_zoom_dropdown[_font_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _font_zoom_cfg + 1 : 0]); break;
case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name.c_str()); break;
case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name.c_str()); break;
case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->name.c_str()); break;
case WID_GO_BASE_MUSIC_STATUS: SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
case WID_GO_REFRESH_RATE_DROPDOWN: {
SetDParam(0, STR_GAME_OPTIONS_REFRESH_RATE_ITEM);
SetDParam(1, _settings_client.gui.refresh_rate);
}
}
}

Expand Down Expand Up @@ -451,6 +485,16 @@ struct GameOptionsWindow : Window {
}
break;

case WID_GO_REFRESH_RATE_DROPDOWN: {
_settings_client.gui.refresh_rate = *std::next(_refresh_rates.begin(), index);
if (_settings_client.gui.refresh_rate > 60) {
/* Show warning to the user that this refresh rate might not be suitable on
* larger maps with many NewGRFs and vehicles. */
ShowErrorMessage(STR_GAME_OPTIONS_REFRESH_RATE_WARNING, INVALID_STRING_ID, WL_INFO);
}
break;
}

case WID_GO_GUI_ZOOM_DROPDOWN: {
int8 new_zoom = index > 0 ? ZOOM_LVL_OUT_4X - index + 1 : ZOOM_LVL_CFG_AUTO;
if (new_zoom != _gui_zoom_cfg) {
Expand Down Expand Up @@ -528,36 +572,47 @@ static const NWidgetPart _nested_game_options_widgets[] = {
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_AUTOSAVE_FRAME, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_AUTOSAVE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_RESOLUTION, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_RESOLUTION_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_RESOLUTION_TOOLTIP), SetFill(1, 0), SetPadding(0, 0, 3, 0),
NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0), SetPadding(0, 0, 3, 0),
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN, STR_NULL),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_FULLSCREEN_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_VIDEO_ACCELERATION, STR_NULL),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_VIDEO_ACCEL_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_VIDEO_ACCELERATION_TOOLTIP),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_GUI_ZOOM_FRAME, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_GUI_ZOOM_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_CURRENCY_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_CURRENCY_UNITS_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 0), SetFill(0, 1),
EndContainer(),

NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_LANGUAGE, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_LANG_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_LANGUAGE_TOOLTIP), SetFill(1, 0),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_CURRENCY_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_CURRENCY_UNITS_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_GUI_ZOOM_FRAME, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_GUI_ZOOM_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_FONT_ZOOM, STR_NULL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_FONT_ZOOM_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_TOOLTIP), SetFill(1, 0),
EndContainer(),
EndContainer(),
EndContainer(),

NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_GRAPHICS, STR_NULL), SetPadding(0, 10, 0, 10),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_VERTICAL),
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_RESOLUTION, STR_NULL), SetPadding(0, 0, 2, 0),
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_REFRESH_RATE, STR_NULL), SetPadding(0, 0, 2, 0),
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN, STR_NULL), SetPadding(0, 0, 2, 0),
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_VIDEO_ACCELERATION, STR_NULL),
EndContainer(),
NWidget(NWID_VERTICAL),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_RESOLUTION_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_RESOLUTION_TOOLTIP), SetFill(1, 0), SetPadding(0, 0, 2, 0),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_REFRESH_RATE_DROPDOWN), SetMinimalSize(120, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_REFRESH_RATE_TOOLTIP), SetFill(1, 0), SetPadding(0, 0, 2, 0),
NWidget(NWID_HORIZONTAL), SetPadding(0, 0, 2, 0),
NWidget(NWID_SPACER), SetMinimalSize(1, 0), SetFill(1, 0),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_FULLSCREEN_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(1, 0), SetFill(1, 0),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_VIDEO_ACCEL_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_VIDEO_ACCELERATION_TOOLTIP),
EndContainer(),
EndContainer(),
EndContainer(),
EndContainer(),

NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_GRF, STR_NULL), SetPadding(0, 10, 0, 10),
NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_GRF_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP),
Expand Down
10 changes: 10 additions & 0 deletions src/video/allegro_v.cpp
Expand Up @@ -236,6 +236,16 @@ bool VideoDriver_Allegro::ClaimMousePointer()
return true;
}

std::vector<int> VideoDriver_Allegro::GetListOfMonitorRefreshRates()
{
std::vector<int> rates = {};

int refresh_rate = get_refresh_rate();
if (refresh_rate != 0) rates.push_back(refresh_rate);

return rates;
}

struct AllegroVkMapping {
uint16 vk_from;
byte vk_count;
Expand Down
2 changes: 2 additions & 0 deletions src/video/allegro_v.h
Expand Up @@ -31,6 +31,8 @@ class VideoDriver_Allegro : public VideoDriver {

bool ClaimMousePointer() override;

std::vector<int> GetListOfMonitorRefreshRates() override;

const char *GetName() const override { return "allegro"; }

protected:
Expand Down
2 changes: 2 additions & 0 deletions src/video/cocoa/cocoa_v.h
Expand Up @@ -47,6 +47,8 @@ class VideoDriver_Cocoa : public VideoDriver {

void EditBoxLostFocus() override;

std::vector<int> GetListOfMonitorRefreshRates() override;

/* --- The following methods should be private, but can't be due to Obj-C limitations. --- */

void MainLoopReal();
Expand Down
18 changes: 18 additions & 0 deletions src/video/cocoa/cocoa_v.mm
Expand Up @@ -228,6 +228,24 @@
HandleTextInput(nullptr, true);
}

/**
* Get refresh rate of the current screen.
*/
std::vector<int> VideoDriver_Cocoa::GetListOfMonitorRefreshRates()
{
std::vector<int> rates{};

NSNumber *scr = [ [ [ this->window screen ] deviceDescription ] objectForKey:@"NSScreenNumber" ];
if (scr != nil && MacOSVersionIsAtLeast(10, 6, 0)) {
CGDisplayModeRef mode = CGDisplayCopyDisplayMode((CGDirectDisplayID)[ scr unsignedIntValue ]);
int rate = (int)CGDisplayModeGetRefreshRate(mode);
if (rate > 0) rates.push_back(rate);
CGDisplayModeRelease(mode);
}

return rates;
}

/**
* Get the resolution of the main screen.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/video/sdl2_v.cpp
Expand Up @@ -237,6 +237,17 @@ void VideoDriver_SDL_Base::EditBoxLostFocus()
}
}

std::vector<int> VideoDriver_SDL_Base::GetListOfMonitorRefreshRates()
{
std::vector<int> rates = {};
for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
SDL_DisplayMode mode = {};
if (SDL_GetDisplayMode(i, 0, &mode) != 0) continue;
if (mode.refresh_rate != 0) rates.push_back(mode.refresh_rate);
}
return rates;
}


struct SDLVkMapping {
SDL_Keycode vk_from;
Expand Down
2 changes: 2 additions & 0 deletions src/video/sdl2_v.h
Expand Up @@ -39,6 +39,8 @@ class VideoDriver_SDL_Base : public VideoDriver {

void EditBoxLostFocus() override;

std::vector<int> GetListOfMonitorRefreshRates() override;

const char *GetName() const override { return "sdl"; }

protected:
Expand Down
9 changes: 9 additions & 0 deletions src/video/video_driver.hpp
Expand Up @@ -149,6 +149,15 @@ class VideoDriver : public Driver {
*/
virtual void EditBoxGainedFocus() {}

/**
* Get a list of refresh rates of each available monitor.
* @return A vector of the refresh rates of all available monitors.
*/
virtual std::vector<int> GetListOfMonitorRefreshRates()
{
return {};
}

/**
* Get a suggested default GUI zoom taking screen DPI into account.
*/
Expand Down
21 changes: 21 additions & 0 deletions src/video/win32_v.cpp
Expand Up @@ -916,6 +916,27 @@ void VideoDriver_Win32Base::EditBoxLostFocus()
SetCandidatePos(this->main_wnd);
}

std::vector<int> VideoDriver_Win32Base::GetListOfMonitorRefreshRates()
{
std::vector<int> rates = {};
EnumDisplayMonitors(nullptr, nullptr, [](HMONITOR hMonitor, HDC hDC, LPRECT rc, LPARAM data) -> BOOL {
auto &list = *reinterpret_cast<std::vector<int>*>(data);

MONITORINFOEX monitorInfo = {};
monitorInfo.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(hMonitor, &monitorInfo);

DEVMODE devMode = {};
devMode.dmSize = sizeof(DEVMODE);
devMode.dmDriverExtra = 0;
EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode);

if (devMode.dmDisplayFrequency != 0) list.push_back(devMode.dmDisplayFrequency);
return true;
}, reinterpret_cast<LPARAM>(&rates));
return rates;
}

Dimension VideoDriver_Win32Base::GetScreenSize() const
{
return { static_cast<uint>(GetSystemMetrics(SM_CXSCREEN)), static_cast<uint>(GetSystemMetrics(SM_CYSCREEN)) };
Expand Down
2 changes: 2 additions & 0 deletions src/video/win32_v.h
Expand Up @@ -33,6 +33,8 @@ class VideoDriver_Win32Base : public VideoDriver {

void EditBoxLostFocus() override;

std::vector<int> GetListOfMonitorRefreshRates() override;

protected:
HWND main_wnd; ///< Handle to system window.
bool fullscreen; ///< Whether to use (true) fullscreen mode.
Expand Down
1 change: 1 addition & 0 deletions src/widgets/settings_widget.h
Expand Up @@ -33,6 +33,7 @@ enum GameOptionsWidgets {
WID_GO_BASE_MUSIC_DESCRIPTION = WID_GO_BASE_MUSIC_TEXTFILE + TFT_END, ///< Description of selected base music set.
WID_GO_FONT_ZOOM_DROPDOWN, ///< Dropdown for the font zoom level.
WID_GO_VIDEO_ACCEL_BUTTON, ///< Toggle for video acceleration.
WID_GO_REFRESH_RATE_DROPDOWN, ///< Dropdown for all available refresh rates.
};

/** Widgets of the #GameSettingsWindow class. */
Expand Down

0 comments on commit ab68e2c

Please sign in to comment.