From 93659a2207f6384beb13488234332f42a2a7e2b6 Mon Sep 17 00:00:00 2001 From: oddMLan Date: Sun, 26 Apr 2020 02:07:13 -0700 Subject: [PATCH] GLideNUI-wtl: Fix windowed resolution handling --- src/GLideNUI-wtl/config-video.cpp | 20 ++++++++------------ src/GLideNUI-wtl/util.h | 5 +++++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/GLideNUI-wtl/config-video.cpp b/src/GLideNUI-wtl/config-video.cpp index ef65d0f7..d9b9e8db 100644 --- a/src/GLideNUI-wtl/config-video.cpp +++ b/src/GLideNUI-wtl/config-video.cpp @@ -383,18 +383,14 @@ void CVideoTab::SaveSettings() getFullscreenRefreshRate(CComboBox(GetDlgItem(IDC_CMB_REFRESH_RATE)).GetCurSel(), config.video.fullscreenRefresh); CComboBox WindowResCB(GetDlgItem(IDC_CMB_WINDOWED_RESOLUTION)); - int WindowResIndx = WindowResCB.GetItemData(WindowResCB.GetCurSel()); - if (WindowResIndx >= 0 && WindowResIndx < numWindowedModes) { - config.video.windowedWidth = WindowedModes[WindowResIndx].width; - config.video.windowedHeight = WindowedModes[WindowResIndx].height; - } else { // custom resolution - CString WindowResStr; - WindowResCB.GetWindowText(WindowResStr); - std::string resolution(CW2A(WindowResStr.GetString())); - // matches w x h where w is 300-7999 and h is 200-3999, spaces around x optional - std::regex parseRes("([3-9][0-9]{2}|[1-7][0-9]{3}) ?x ?([2-9][0-9]{2}|[1-3][0-9]{3})"); - std::smatch tokens; - if (std::regex_search(resolution, tokens, parseRes) && tokens.size() > 1) { + CString WindowResStr; + WindowResCB.GetWindowText(WindowResStr); + std::string resolution(CW2A(WindowResStr.GetString())); + std::regex parseRes("(\\d+) ?x ?(\\d+)"); + std::smatch tokens; + if (std::regex_search(resolution, tokens, parseRes) && tokens.size() > 1) { + // matches w x h where w is 300-7999 and h is 200-3999 + if (range<300, 8000>::contains(std::stoi(tokens[1])) && range<200, 4000>::contains(std::stoi(tokens[2]))) { config.video.windowedWidth = std::stoi(tokens[1]); config.video.windowedHeight = std::stoi(tokens[2]); } diff --git a/src/GLideNUI-wtl/util.h b/src/GLideNUI-wtl/util.h index d7afd0a0..51a05825 100644 --- a/src/GLideNUI-wtl/util.h +++ b/src/GLideNUI-wtl/util.h @@ -4,3 +4,8 @@ std::string FromUTF16(const wchar_t * UTF16Source); std::wstring ToUTF16(const char * Source); std::wstring FormatStrW(const wchar_t * Source, ...); + +template class range { +public: + static bool contains(int i) { return min <= i && i < max; } +}; \ No newline at end of file