Skip to content

Commit

Permalink
Refactor code to obtain resolutions. (#8215)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt authored and janisozaur committed Nov 6, 2018
1 parent df768a3 commit 223ae74
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/openrct2-ui/UiContext.cpp
Expand Up @@ -180,7 +180,7 @@ class UiContext final : public IUiContext
}
}

std::vector<Resolution> GetFullscreenResolutions() override
const std::vector<Resolution>& GetFullscreenResolutions() override
{
UpdateFullscreenResolutions();
return _fsResolutions;
Expand Down
45 changes: 19 additions & 26 deletions src/openrct2-ui/windows/Options.cpp
Expand Up @@ -449,7 +449,6 @@ static void window_options_update_height_markers();

#pragma region Events

static void window_options_close(rct_window *w);
static void window_options_mouseup(rct_window *w, rct_widgetindex widgetIndex);
static void window_options_mousedown(rct_window *w, rct_widgetindex widgetIndex, rct_widget* widget);
static void window_options_dropdown(rct_window *w, rct_widgetindex widgetIndex, int32_t dropdownIndex);
Expand All @@ -461,7 +460,7 @@ static void window_options_text_input(rct_window *w, rct_widgetindex widgetIndex
static void window_options_tooltip(rct_window *w, rct_widgetindex widgetIndex, rct_string_id *stringid);

static rct_window_event_list window_options_events = {
window_options_close,
nullptr,
window_options_mouseup,
nullptr,
window_options_mousedown,
Expand Down Expand Up @@ -616,9 +615,6 @@ static uint64_t window_options_page_enabled_widgets[] = {

#pragma endregion

static struct Resolution* _resolutions = nullptr;
static int32_t _numResolutions = 0;

/**
*
* rct2: 0x006BAC5B
Expand All @@ -642,13 +638,6 @@ rct_window* window_options_open()
return w;
}

static void window_options_close(rct_window* w)
{
free(_resolutions);
_resolutions = nullptr;
_numResolutions = 0;
}

/**
*
* rct2: 0x006BAFCA
Expand Down Expand Up @@ -1028,26 +1017,28 @@ static void window_options_mousedown(rct_window* w, rct_widgetindex widgetIndex,
{
case WIDX_RESOLUTION_DROPDOWN:
{
_numResolutions = context_get_resolutions(&_resolutions);
const auto& resolutions = OpenRCT2::GetContext()->GetUiContext()->GetFullscreenResolutions();

int32_t selectedResolution = -1;
for (int32_t i = 0; i < _numResolutions; i++)
for (size_t i = 0; i < resolutions.size(); i++)
{
struct Resolution* resolution = &_resolutions[i];
const Resolution& resolution = resolutions[i];

gDropdownItemsFormat[i] = STR_DROPDOWN_MENU_LABEL;

uint16_t* args = (uint16_t*)&gDropdownItemsArgs[i];
args[0] = STR_RESOLUTION_X_BY_Y;
args[1] = resolution->Width;
args[2] = resolution->Height;
args[1] = resolution.Width;
args[2] = resolution.Height;

if (resolution->Width == gConfigGeneral.fullscreen_width
&& resolution->Height == gConfigGeneral.fullscreen_height)
selectedResolution = i;
if (resolution.Width == gConfigGeneral.fullscreen_width
&& resolution.Height == gConfigGeneral.fullscreen_height)
{
selectedResolution = (int32_t)i;
}
}

window_options_show_dropdown(w, widget, _numResolutions);
window_options_show_dropdown(w, widget, (int32_t)resolutions.size());

if (selectedResolution != -1 && selectedResolution < 32)
{
Expand Down Expand Up @@ -1351,12 +1342,14 @@ static void window_options_dropdown(rct_window* w, rct_widgetindex widgetIndex,
{
case WIDX_RESOLUTION_DROPDOWN:
{
struct Resolution* resolution = &_resolutions[dropdownIndex];
if (resolution->Width != gConfigGeneral.fullscreen_width
|| resolution->Height != gConfigGeneral.fullscreen_height)
const auto& resolutions = OpenRCT2::GetContext()->GetUiContext()->GetFullscreenResolutions();

const Resolution& resolution = resolutions[dropdownIndex];
if (resolution.Width != gConfigGeneral.fullscreen_width
|| resolution.Height != gConfigGeneral.fullscreen_height)
{
gConfigGeneral.fullscreen_width = resolution->Width;
gConfigGeneral.fullscreen_height = resolution->Height;
gConfigGeneral.fullscreen_width = resolution.Width;
gConfigGeneral.fullscreen_height = resolution.Height;

if (gConfigGeneral.fullscreen_mode == static_cast<int32_t>(OpenRCT2::Ui::FULLSCREEN_MODE::FULLSCREEN))
context_set_fullscreen_mode(static_cast<int32_t>(OpenRCT2::Ui::FULLSCREEN_MODE::FULLSCREEN));
Expand Down
9 changes: 0 additions & 9 deletions src/openrct2/Context.cpp
Expand Up @@ -1160,15 +1160,6 @@ void context_recreate_window()
GetContext()->GetUiContext()->RecreateWindow();
}

int32_t context_get_resolutions(Resolution** outResolutions)
{
auto resolutions = GetContext()->GetUiContext()->GetFullscreenResolutions();
int32_t count = (int32_t)resolutions.size();
*outResolutions = Memory::AllocateArray<Resolution>(count);
std::copy_n(resolutions.begin(), count, *outResolutions);
return count;
}

int32_t context_get_width()
{
return GetContext()->GetUiContext()->GetWidth();
Expand Down
1 change: 0 additions & 1 deletion src/openrct2/Context.h
Expand Up @@ -219,7 +219,6 @@ bool context_is_input_active();
void context_trigger_resize();
void context_set_fullscreen_mode(int32_t mode);
void context_recreate_window();
int32_t context_get_resolutions(struct Resolution** outResolutions);
int32_t context_get_width();
int32_t context_get_height();
bool context_has_focus();
Expand Down
5 changes: 3 additions & 2 deletions src/openrct2/ui/DummyUiContext.cpp
Expand Up @@ -59,9 +59,10 @@ namespace OpenRCT2::Ui
void SetFullscreenMode(FULLSCREEN_MODE /*mode*/) override
{
}
std::vector<Resolution> GetFullscreenResolutions() override
const std::vector<Resolution>& GetFullscreenResolutions() override
{
return std::vector<Resolution>();
static std::vector<Resolution> res;
return res;
}
bool HasFocus() override
{
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/ui/UiContext.h
Expand Up @@ -102,7 +102,7 @@ namespace OpenRCT2
virtual int32_t GetHeight() abstract;
virtual int32_t GetScaleQuality() abstract;
virtual void SetFullscreenMode(FULLSCREEN_MODE mode) abstract;
virtual std::vector<Resolution> GetFullscreenResolutions() abstract;
virtual const std::vector<Resolution>& GetFullscreenResolutions() abstract;
virtual bool HasFocus() abstract;
virtual bool IsMinimised() abstract;
virtual bool IsSteamOverlayActive() abstract;
Expand Down

0 comments on commit 223ae74

Please sign in to comment.