@@ -1012,24 +1012,32 @@ STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_AUTO
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_NORMAL :Normal
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_2X_ZOOM :Double size
STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_4X_ZOOM :Quad size
STR_GAME_OPTIONS_FONT_ZOOM :{BLACK}Font size
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_TOOLTIP :{BLACK}Select the interface font size to use
STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_AUTO :(auto-detect)
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_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 :{NUM}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}
STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP :{BLACK}Additional information about the base graphics set
STR_GAME_OPTIONS_BASE_SFX :{BLACK}Base sounds set
STR_GAME_OPTIONS_BASE_SFX_TOOLTIP :{BLACK}Select the base sounds set to use
STR_GAME_OPTIONS_BASE_SFX_DESCRIPTION_TOOLTIP :{BLACK}Additional information about the base sounds set
STR_GAME_OPTIONS_BASE_MUSIC :{BLACK}Base music set
STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP :{BLACK}Select the base music set to use
STR_GAME_OPTIONS_BASE_MUSIC_STATUS :{RED}{NUM} corrupted file{P "" s}
@@ -29,26 +29,28 @@
#include "core/geometry_func.hpp"
#include "ai/ai.hpp"
#include "blitter/factory.hpp"
#include "language.h"
#include "textfile_gui.h"
#include "stringfilter_type.h"
#include "querystring_gui.h"
#include "fontcache.h"
#include "zoom_func.h"
#include "video/video_driver.hpp"
#include <vector>
#include <iterator>
#include "safeguards.h"
static const StringID _autosave_dropdown[] = {
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_1_MONTH,
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_3_MONTHS,
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_6_MONTHS,
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_12_MONTHS,
INVALID_STRING_ID,
};
static const StringID _gui_zoom_dropdown[] = {
@@ -131,33 +133,51 @@ struct BaseSetTextfileWindow : public Te
* Open the BaseSet version of the textfile window.
* @param file_type The type of textfile to display.
* @param baseset The BaseSet to use.
* @param content_type STR_CONTENT_TYPE_xxx for title.
*/
template <class TBaseSet>
void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type)
{
DeleteWindowById(WC_TEXTFILE, file_type);
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. */
_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;
GameOptionsWindow(WindowDesc *desc) : Window(desc)
this->opt = &GetGameSettings();
this->reload = false;
AddRefreshRatesAndSelect();
this->InitNested(WN_GAME_OPTIONS_GAME_OPTIONS);
this->OnInvalidateData(0);
~GameOptionsWindow()
DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
DeleteWindowByClass(WC_TEXTFILE);
if (this->reload) _switch_mode = SM_MENU;
@@ -206,24 +226,34 @@ struct GameOptionsWindow : Window {
break;
case WID_GO_RESOLUTION_DROPDOWN: // Setup resolution dropdown
if (_resolutions.empty()) break;
*selected_index = GetCurRes();
for (uint i = 0; i < _resolutions.size(); i++) {
list.emplace_back(new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false));
case WID_GO_REFRESH_RATE_DROPDOWN: // Setup refresh rate dropdown
for (auto it = _refresh_rates.begin(); it != _refresh_rates.end(); it++) {
auto i = std::distance(_refresh_rates.begin(), it);
if (*it == _settings_client.gui.refresh_rate) *selected_index = i;
auto item = new DropDownListParamStringItem(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, i, false);
item->SetParam(0, *it);
list.emplace_back(item);
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;
for (int i = 0; *items != INVALID_STRING_ID; items++, i++) {
list.emplace_back(new DropDownListStringItem(*items, i, i != 0 && _settings_client.gui.zoom_min > ZOOM_LVL_OUT_4X - i + 1));
case WID_GO_FONT_ZOOM_DROPDOWN: {
*selected_index = _font_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _font_zoom + 1 : 0;
const StringID *items = _font_zoom_dropdown;
@@ -243,35 +273,36 @@ struct GameOptionsWindow : Window {
case WID_GO_BASE_MUSIC_DROPDOWN:
list = BuildMusicSetDropDownList(selected_index);
return list;
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_REFRESH_RATE_DROPDOWN: SetDParam(0, _settings_client.gui.refresh_rate); break;
void DrawWidget(const Rect &r, int widget) const override
case WID_GO_BASE_GRF_DESCRIPTION:
SetDParamStr(0, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
case WID_GO_BASE_SFX_DESCRIPTION:
@@ -442,24 +473,34 @@ struct GameOptionsWindow : Window {
ClearAllCachedNames();
UpdateAllVirtCoords();
CheckBlitter();
ReInitAllWindows();
case WID_GO_RESOLUTION_DROPDOWN: // Change resolution
if ((uint)index < _resolutions.size() && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
this->SetDirty();
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);
int8 new_zoom = index > 0 ? ZOOM_LVL_OUT_4X - index + 1 : ZOOM_LVL_CFG_AUTO;
if (new_zoom != _gui_zoom_cfg) {
GfxClearSpriteCache();
_gui_zoom_cfg = new_zoom;
UpdateGUIZoom();
UpdateCursorSize();
FixTitleGameZoom();
@@ -519,54 +560,65 @@ struct GameOptionsWindow : Window {
static const NWidgetPart _nested_game_options_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY, WID_GO_BACKGROUND), SetPIP(6, 6, 10),
NWidget(NWID_HORIZONTAL), SetPIP(10, 10, 10),
NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
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),
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),
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),
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),
NWidget(NWID_SPACER), SetMinimalSize(0, 0), SetFill(0, 1),
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),
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),
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),
NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_GRAPHICS, STR_NULL), SetPadding(0, 10, 0, 10),
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_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(100, 12), SetDataTip(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, 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_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),
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
@@ -227,24 +227,34 @@ static bool CreateMainSurface(uint w, ui
return true;
bool VideoDriver_Allegro::ClaimMousePointer()
select_mouse_cursor(MOUSE_CURSOR_NONE);
show_mouse(nullptr);
disable_hardware_cursor();
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;
byte map_to;
#define AS(x, z) {x, 0, z}
#define AM(x, y, z, w) {x, y - x, z}
static const AllegroVkMapping _vk_mapping[] = {
/* Pageup stuff + up/down */
AM(KEY_PGUP, KEY_PGDN, WKC_PAGEUP, WKC_PAGEDOWN),
@@ -22,24 +22,26 @@ public:
void MakeDirty(int left, int top, int width, int height) override;
void MainLoop() override;
bool ChangeResolution(int w, int h) override;
bool ToggleFullscreen(bool fullscreen) override;
bool AfterBlitterChange() override;
bool ClaimMousePointer() override;
std::vector<int> GetListOfMonitorRefreshRates() override;
const char *GetName() const override { return "allegro"; }
protected:
void InputLoop() override;
void Paint() override;
void CheckPaletteAnim() override;
bool PollEvent() override;
/** Factory for the allegro video driver. */
class FVideoDriver_Allegro : public DriverFactoryBase {
public:
@@ -38,24 +38,26 @@ public:
void Stop() override;
void EditBoxLostFocus() override;
/* --- The following methods should be private, but can't be due to Obj-C limitations. --- */
void MainLoopReal();
virtual void AllocateBackingStore(bool force = false) = 0;
Rect dirty_rect; ///< Region of the screen that needs redrawing.
bool buffer_locked; ///< Video buffer was locked by the main thread.
Dimension GetScreenSize() const override;
float GetDPIScale() override;
@@ -34,24 +34,25 @@
#include "../../blitter/factory.hpp"
#include "../../framerate_type.h"
#include "../../gfx_func.h"
#include "../../thread.h"
#include "../../core/random_func.hpp"
#include "../../progress.h"
#include "../../settings_type.h"
#include "../../window_func.h"
#include "../../window_gui.h"
#import <sys/param.h> /* for MAXPATHLEN */
#import <sys/time.h> /* gettimeofday */
#include <array>
* Important notice regarding all modifications!!!!!!!
* There are certain limitations because the file is objective C++.
* gdb has limitations.
* C++ and objective C code can't be joined in all cases (classes stuff).
* Read http://developer.apple.com/releasenotes/Cocoa/Objective-C++.html for more information.
/* On some old versions of MAC OS this may not be defined.
* Those versions generally only produce code for PPC. So it should be safe to
* set this to 0. */
@@ -220,24 +221,48 @@ bool VideoDriver_Cocoa::AfterBlitterChan
* An edit box lost the input focus. Abort character compositing if necessary.
void VideoDriver_Cocoa::EditBoxLostFocus()
[ [ this->cocoaview inputContext ] discardMarkedText ];
/* Clear any marked string from the current edit box. */
HandleTextInput(nullptr, true);
* Get refresh rates of all connected monitors.
std::vector<int> VideoDriver_Cocoa::GetListOfMonitorRefreshRates()
std::vector<int> rates{};
if (MacOSVersionIsAtLeast(10, 6, 0)) {
std::array<CGDirectDisplayID, 16> displays;
uint32_t count = 0;
CGGetActiveDisplayList(displays.size(), displays.data(), &count);
for (uint32_t i = 0; i < count; i++) {
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displays[i]);
int rate = (int)CGDisplayModeGetRefreshRate(mode);
if (rate > 0) rates.push_back(rate);
CGDisplayModeRelease(mode);
* Get the resolution of the main screen.
Dimension VideoDriver_Cocoa::GetScreenSize() const
NSRect frame = [ [ NSScreen mainScreen ] frame ];
return { static_cast<uint>(NSWidth(frame)), static_cast<uint>(NSHeight(frame)) };
/** Get DPI scale of our window. */
float VideoDriver_Cocoa::GetDPIScale()
return this->cocoaview != nil ? [ this->cocoaview getContentsScale ] : 1.0f;
@@ -228,24 +228,35 @@ void VideoDriver_SDL_Base::EditBoxGained
* This is called to indicate that an edit box has lost focus, text input mode should be disabled.
void VideoDriver_SDL_Base::EditBoxLostFocus()
if (this->edit_box_focused) {
SDL_StopTextInput();
this->edit_box_focused = false;
std::vector<int> VideoDriver_SDL_Base::GetListOfMonitorRefreshRates()
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);
struct SDLVkMapping {
SDL_Keycode vk_from;
bool unprintable;
#define AS(x, z) {x, 0, z, false}
#define AM(x, y, z, w) {x, (byte)(y - x), z, false}
#define AS_UP(x, z) {x, 0, z, true}
#define AM_UP(x, y, z, w) {x, (byte)(y - x), z, true}
@@ -30,24 +30,26 @@ public:
void EditBoxGainedFocus() override;
const char *GetName() const override { return "sdl"; }
struct SDL_Window *sdl_window; ///< Main SDL window.
Palette local_palette; ///< Copy of _cur_palette.
Rect dirty_rect; ///< Rectangle encompassing the dirty area of the video buffer.
bool LockVideoBuffer() override;
void UnlockVideoBuffer() override;
@@ -141,24 +141,33 @@ public:
virtual void EditBoxLostFocus() {}
* An edit box gained the input focus
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.
virtual ZoomLevel GetSuggestedUIZoom()
float dpi_scale = this->GetDPIScale();
if (dpi_scale >= 3.0f) return ZOOM_LVL_NORMAL;
if (dpi_scale >= 1.5f) return ZOOM_LVL_OUT_2X;
return ZOOM_LVL_OUT_4X;
@@ -907,24 +907,45 @@ bool VideoDriver_Win32Base::ToggleFullsc
InvalidateWindowClassesData(WC_GAME_OPTIONS, 3);
return res;
void VideoDriver_Win32Base::EditBoxLostFocus()
CancelIMEComposition(this->main_wnd);
SetCompositionPos(this->main_wnd);
SetCandidatePos(this->main_wnd);
std::vector<int> VideoDriver_Win32Base::GetListOfMonitorRefreshRates()
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);
}, reinterpret_cast<LPARAM>(&rates));
Dimension VideoDriver_Win32Base::GetScreenSize() const
return { static_cast<uint>(GetSystemMetrics(SM_CXSCREEN)), static_cast<uint>(GetSystemMetrics(SM_CYSCREEN)) };
float VideoDriver_Win32Base::GetDPIScale()
typedef UINT (WINAPI *PFNGETDPIFORWINDOW)(HWND hwnd);
typedef UINT (WINAPI *PFNGETDPIFORSYSTEM)(VOID);
typedef HRESULT (WINAPI *PFNGETDPIFORMONITOR)(HMONITOR hMonitor, int dpiType, UINT *dpiX, UINT *dpiY);
static PFNGETDPIFORWINDOW _GetDpiForWindow = nullptr;
@@ -24,24 +24,26 @@ public:
HWND main_wnd; ///< Handle to system window.
bool fullscreen; ///< Whether to use (true) fullscreen mode.
bool has_focus = false; ///< Does our window have system focus?
int width = 0; ///< Width in pixels of our display surface.
int height = 0; ///< Height in pixels of our display surface.
int width_org = 0; ///< Original monitor resolution width, before we changed it.
int height_org = 0; ///< Original monitor resolution height, before we changed it.
@@ -24,24 +24,25 @@ enum GameOptionsWidgets {
WID_GO_BASE_GRF_STATUS, ///< Info about missing files etc.
WID_GO_BASE_GRF_TEXTFILE, ///< Open base GRF readme, changelog (+1) or license (+2).
WID_GO_BASE_GRF_DESCRIPTION = WID_GO_BASE_GRF_TEXTFILE + TFT_END, ///< Description of selected base GRF.
WID_GO_BASE_SFX_DROPDOWN, ///< Use to select a base SFX.
WID_GO_BASE_SFX_TEXTFILE, ///< Open base SFX readme, changelog (+1) or license (+2).
WID_GO_BASE_SFX_DESCRIPTION = WID_GO_BASE_SFX_TEXTFILE + TFT_END, ///< Description of selected base SFX.
WID_GO_BASE_MUSIC_DROPDOWN, ///< Use to select a base music set.
WID_GO_BASE_MUSIC_STATUS, ///< Info about corrupted files etc.
WID_GO_BASE_MUSIC_TEXTFILE, ///< Open base music readme, changelog (+1) or license (+2).
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. */
enum GameSettingsWidgets {
WID_GS_FILTER, ///< Text filter.
WID_GS_OPTIONSPANEL, ///< Panel widget containing the option lists.
WID_GS_SCROLLBAR, ///< Scrollbar.
WID_GS_HELP_TEXT, ///< Information area to display help text of the selected option.
WID_GS_EXPAND_ALL, ///< Expand all button.
WID_GS_COLLAPSE_ALL, ///< Collapse all button.
WID_GS_RESTRICT_CATEGORY, ///< Label upfront to the category drop-down box to restrict the list of settings to show
WID_GS_RESTRICT_TYPE, ///< Label upfront to the type drop-down box to restrict the list of settings to show
Status change: