diff --git a/src/openrct2-ui/CursorRepository.cpp b/src/openrct2-ui/CursorRepository.cpp index 61b027c2b2..fc0a973e84 100644 --- a/src/openrct2-ui/CursorRepository.cpp +++ b/src/openrct2-ui/CursorRepository.cpp @@ -22,7 +22,17 @@ using namespace OpenRCT2::Ui; -CursorRepository::CursorRepository() +CursorRepository::~CursorRepository() +{ + for (size_t i = 0; i < CURSOR_COUNT; i++) + { + SDL_FreeCursor(_loadedCursors[i]); + _loadedCursors[i] = nullptr; + } + _currentCursor = CURSOR_UNDEFINED; +} + +void CursorRepository::LoadCursors() { // Using system cursors _loadedCursors[CURSOR_ARROW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); @@ -42,16 +52,6 @@ CursorRepository::CursorRepository() SetCurrentCursor(CURSOR_ARROW); } -CursorRepository::~CursorRepository() -{ - for (size_t i = 0; i < CURSOR_COUNT; i++) - { - SDL_FreeCursor(_loadedCursors[i]); - _loadedCursors[i] = nullptr; - } - _currentCursor = CURSOR_UNDEFINED; -} - CURSOR_ID CursorRepository::GetCurrentCursor() { return _currentCursor; diff --git a/src/openrct2-ui/CursorRepository.h b/src/openrct2-ui/CursorRepository.h index c15faf4a95..9a54c5ad30 100644 --- a/src/openrct2-ui/CursorRepository.h +++ b/src/openrct2-ui/CursorRepository.h @@ -28,12 +28,12 @@ namespace OpenRCT2 constexpr static sint32 CURSOR_WIDTH = 32; constexpr static sint32 CURSOR_HEIGHT = 32; - SDL_Cursor * _loadedCursors[CURSOR_COUNT]; + SDL_Cursor * _loadedCursors[CURSOR_COUNT] = { nullptr }; CURSOR_ID _currentCursor = CURSOR_UNDEFINED; public: - CursorRepository(); ~CursorRepository(); + void LoadCursors(); CURSOR_ID GetCurrentCursor(); void SetCurrentCursor(CURSOR_ID cursorId); diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index 58c03ef2de..9126c7eb69 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -83,6 +83,7 @@ public: { SDLException::Throw("SDL_Init(SDL_INIT_VIDEO)"); } + _cursorRepository.LoadCursors(); } ~UiContext() override @@ -331,13 +332,13 @@ public: // Apple sends touchscreen events for trackpads, so ignore these events on macOS #ifndef __MACOSX__ case SDL_FINGERMOTION: - _cursorState.x = (sint32)(e.tfinger.x * gScreenWidth); - _cursorState.y = (sint32)(e.tfinger.y * gScreenHeight); + _cursorState.x = (sint32)(e.tfinger.x * _width); + _cursorState.y = (sint32)(e.tfinger.y * _height); break; case SDL_FINGERDOWN: { - sint32 x = (sint32)(e.tfinger.x * gScreenWidth); - sint32 y = (sint32)(e.tfinger.y * gScreenHeight); + sint32 x = (sint32)(e.tfinger.x * _width); + sint32 y = (sint32)(e.tfinger.y * _height); _cursorState.touchIsDouble = (!_cursorState.touchIsDouble && e.tfinger.timestamp - _cursorState.touchDownTimestamp < TOUCH_DOUBLE_TIMEOUT); @@ -360,8 +361,8 @@ public: } case SDL_FINGERUP: { - sint32 x = (sint32)(e.tfinger.x * gScreenWidth); - sint32 y = (sint32)(e.tfinger.y * gScreenHeight); + sint32 x = (sint32)(e.tfinger.x * _width); + sint32 y = (sint32)(e.tfinger.y * _height); if (_cursorState.touchIsDouble) { @@ -393,7 +394,7 @@ public: // Zoom gesture constexpr sint32 tolerance = 128; - sint32 gesturePixels = (sint32)(_gestureRadius * gScreenWidth); + sint32 gesturePixels = (sint32)(_gestureRadius * _width); if (abs(gesturePixels) > tolerance) { _gestureRadius = 0; diff --git a/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp index 710c945fec..934bd751cb 100644 --- a/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp @@ -655,8 +655,8 @@ private: // Determine region in pixels uint32 left = Math::Max(0, x * _dirtyGrid.BlockWidth); uint32 top = Math::Max(0, y * _dirtyGrid.BlockHeight); - uint32 right = Math::Min((uint32)gScreenWidth, left + (columns * _dirtyGrid.BlockWidth)); - uint32 bottom = Math::Min((uint32)gScreenHeight, top + (rows * _dirtyGrid.BlockHeight)); + uint32 right = Math::Min(_width, left + (columns * _dirtyGrid.BlockWidth)); + uint32 bottom = Math::Min(_height, top + (rows * _dirtyGrid.BlockHeight)); if (right <= left || bottom <= top) { return; diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index d64c649b32..f8065494ba 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -664,4 +664,14 @@ extern "C" Memory::CopyArray(*outResolutions, resolutions.data(), count); return count; } + + sint32 context_get_width() + { + return GetContext()->GetUiContext()->GetWidth(); + } + + sint32 context_get_height() + { + return GetContext()->GetUiContext()->GetHeight(); + } } diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index 02f3d59317..219a52265f 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -100,6 +100,8 @@ extern "C" void context_trigger_resize(); void context_set_fullscreen_mode(sint32 mode); sint32 context_get_resolutions(struct Resolution * * outResolutions); + sint32 context_get_width(); + sint32 context_get_height(); #ifdef __cplusplus } diff --git a/src/openrct2/audio/audio.cpp b/src/openrct2/audio/audio.cpp index 2f88b8e5a9..1717c6fc54 100644 --- a/src/openrct2/audio/audio.cpp +++ b/src/openrct2/audio/audio.cpp @@ -14,17 +14,19 @@ *****************************************************************************/ #pragma endregion +#include "../config/Config.h" +#include "../Context.h" #include "../core/File.h" #include "../core/FileStream.hpp" #include "../core/Memory.hpp" #include "../core/Util.hpp" #include "../localisation/string_ids.h" #include "../OpenRCT2.h" +#include "../ui/UiContext.h" #include "AudioMixer.h" extern "C" { - #include "../config/Config.h" #include "../interface/viewport.h" #include "../intro.h" #include "../localisation/language.h" @@ -255,7 +257,7 @@ sint32 audio_play_sound(sint32 soundId, sint32 volume, sint32 pan) sint32 mixerPan = 0; if (pan != AUDIO_PLAY_AT_CENTRE) { sint32 x2 = pan << 16; - uint16 screenWidth = Math::Max(64, gScreenWidth); + uint16 screenWidth = Math::Max(64, OpenRCT2::GetContext()->GetUiContext()->GetWidth()); mixerPan = ((x2 / screenWidth) - 0x8000) >> 4; } diff --git a/src/openrct2/drawing/NewDrawing.cpp b/src/openrct2/drawing/NewDrawing.cpp index 1ad69e3a22..31dc499dc0 100644 --- a/src/openrct2/drawing/NewDrawing.cpp +++ b/src/openrct2/drawing/NewDrawing.cpp @@ -139,7 +139,9 @@ extern "C" { drawing_engine_init(); } - _drawingEngine->Resize(gScreenWidth, gScreenHeight); + + IUiContext * uiContext = GetContext()->GetUiContext(); + _drawingEngine->Resize(uiContext->GetWidth(), uiContext->GetHeight()); } void drawing_engine_set_palette(SDL_Color * colours) diff --git a/src/openrct2/drawing/drawing.c b/src/openrct2/drawing/drawing.c index 0b9d727850..c5a6b2875b 100644 --- a/src/openrct2/drawing/drawing.c +++ b/src/openrct2/drawing/drawing.c @@ -15,6 +15,7 @@ #pragma endregion #include "../common.h" +#include "../Context.h" #include "../core/Guard.hpp" #include "../interface/window.h" #include "../localisation/localisation.h" @@ -546,7 +547,7 @@ void load_palette(){ */ void gfx_invalidate_screen() { - gfx_set_dirty_blocks(0, 0, gScreenWidth, gScreenHeight); + gfx_set_dirty_blocks(0, 0, context_get_width(), context_get_height()); } /** diff --git a/src/openrct2/game.c b/src/openrct2/game.c index 44884b798b..dcc2e839ee 100644 --- a/src/openrct2/game.c +++ b/src/openrct2/game.c @@ -17,6 +17,7 @@ #include "audio/audio.h" #include "cheats.h" #include "config/Config.h" +#include "Context.h" #include "editor.h" #include "game.h" #include "input.h" @@ -138,7 +139,7 @@ void game_create_windows() window_main_open(); window_top_toolbar_open(); window_game_bottom_toolbar_open(); - window_resize_gui(gScreenWidth, gScreenHeight); + window_resize_gui(context_get_width(), context_get_height()); } enum { diff --git a/src/openrct2/input.c b/src/openrct2/input.c index de806bf396..3a82b54037 100644 --- a/src/openrct2/input.c +++ b/src/openrct2/input.c @@ -138,8 +138,10 @@ void game_handle_input() if (_inputFlags & INPUT_FLAG_5) { game_handle_input_mouse(x, y, state); } else if (x != 0x80000000) { - x = clamp(0, x, gScreenWidth - 1); - y = clamp(0, y, gScreenHeight - 1); + sint32 screenWidth = context_get_width(); + sint32 screenHeight = context_get_height(); + x = clamp(0, x, screenWidth - 1); + y = clamp(0, y, screenHeight - 1); game_handle_input_mouse(x, y, state); process_mouse_over(x, y); @@ -470,7 +472,7 @@ static void input_window_resize_begin(rct_window *w, rct_widgetindex widgetIndex static void input_window_resize_continue(rct_window *w, sint32 x, sint32 y) { - if (y < (sint32)gScreenHeight - 2) { + if (y < (sint32)context_get_height() - 2) { sint32 dx, dy, targetWidth, targetHeight; dx = x - gInputDragLastX; dy = y - gInputDragLastY; @@ -1623,13 +1625,13 @@ void game_handle_edge_scroll() const CursorState * cursorState = context_get_cursor_state(); if (cursorState->x == 0) scrollX = -1; - else if (cursorState->x >= gScreenWidth - 1) + else if (cursorState->x >= context_get_width() - 1) scrollX = 1; // Scroll up / down if (cursorState->y == 0) scrollY = -1; - else if (cursorState->y >= gScreenHeight - 1) + else if (cursorState->y >= context_get_height() - 1) scrollY = 1; // Scroll viewport diff --git a/src/openrct2/interface/chat.c b/src/openrct2/interface/chat.c index c39afe0f95..f87b663616 100644 --- a/src/openrct2/interface/chat.c +++ b/src/openrct2/interface/chat.c @@ -84,9 +84,9 @@ void chat_draw(rct_drawpixelinfo * dpi) } _chatLeft = 10; - _chatRight = min((gScreenWidth - 10), CHAT_MAX_WINDOW_WIDTH); + _chatRight = min((context_get_width() - 10), CHAT_MAX_WINDOW_WIDTH); _chatWidth = _chatRight - _chatLeft; - _chatBottom = gScreenHeight - 45; + _chatBottom = context_get_height() - 45; _chatTop = _chatBottom - 10; char lineBuffer[CHAT_INPUT_SIZE + 10]; diff --git a/src/openrct2/interface/console.c b/src/openrct2/interface/console.c index 8b1ff0c56f..3fd9da5bfc 100644 --- a/src/openrct2/interface/console.c +++ b/src/openrct2/interface/console.c @@ -127,7 +127,7 @@ void console_update() _consoleLeft = 0; _consoleTop = 0; - _consoleRight = gScreenWidth; + _consoleRight = context_get_width(); _consoleBottom = 322; if (gConsoleOpen) { diff --git a/src/openrct2/interface/screenshot.c b/src/openrct2/interface/screenshot.c index 6661d11b8a..ee6e677bce 100644 --- a/src/openrct2/interface/screenshot.c +++ b/src/openrct2/interface/screenshot.c @@ -16,6 +16,7 @@ #include "../audio/audio.h" #include "../config/Config.h" +#include "../Context.h" #include "../drawing/drawing.h" #include "../game.h" #include "../Imaging.h" @@ -46,7 +47,7 @@ void screenshot_check() screenshotIndex = screenshot_dump(); if (screenshotIndex != -1) { - audio_play_sound(SOUND_WINDOW_OPEN, 100, gScreenWidth / 2); + audio_play_sound(SOUND_WINDOW_OPEN, 100, context_get_width() / 2); } else { window_error_open(STR_SCREENSHOT_FAILED, STR_NONE); } diff --git a/src/openrct2/interface/viewport.c b/src/openrct2/interface/viewport.c index 58d129e2e3..6227ae75f1 100644 --- a/src/openrct2/interface/viewport.c +++ b/src/openrct2/interface/viewport.c @@ -15,6 +15,7 @@ #pragma endregion #include "../config/Config.h" +#include "../Context.h" #include "../drawing/drawing.h" #include "../game.h" #include "../input.h" @@ -424,8 +425,8 @@ static void viewport_move(sint16 x, sint16 y, rct_window* w, rct_viewport* viewp if (w->flags & WF_7){ sint32 left = max(viewport->x, 0); sint32 top = max(viewport->y, 0); - sint32 right = min(viewport->x + viewport->width, gScreenWidth); - sint32 bottom = min(viewport->y + viewport->height, gScreenHeight); + sint32 right = min(viewport->x + viewport->width, context_get_width()); + sint32 bottom = min(viewport->y + viewport->height, context_get_height()); if (left >= right) return; if (top >= bottom) return; @@ -447,7 +448,7 @@ static void viewport_move(sint16 x, sint16 y, rct_window* w, rct_viewport* viewp viewport->x = 0; } - sint32 eax = viewport->x + viewport->width - gScreenWidth; + sint32 eax = viewport->x + viewport->width - context_get_width(); if (eax > 0){ viewport->width -= eax; viewport->view_width -= eax * zoom; @@ -465,7 +466,7 @@ static void viewport_move(sint16 x, sint16 y, rct_window* w, rct_viewport* viewp viewport->y = 0; } - eax = viewport->y + viewport->height - gScreenHeight; + eax = viewport->y + viewport->height - context_get_height(); if (eax > 0){ viewport->height -= eax; viewport->view_height -= eax * zoom; diff --git a/src/openrct2/interface/window.c b/src/openrct2/interface/window.c index a153af4e24..75dfd10f12 100644 --- a/src/openrct2/interface/window.c +++ b/src/openrct2/interface/window.c @@ -500,8 +500,8 @@ rct_window *window_create(sint32 x, sint32 y, sint32 width, sint32 height, rct_w */ static bool sub_6EA8EC(sint32 x, sint32 y, sint32 width, sint32 height) { - uint16 screenWidth = gScreenWidth; - uint16 screenHeight = gScreenHeight; + uint16 screenWidth = context_get_width(); + uint16 screenHeight = context_get_height(); sint32 unk; unk = -(width / 4); @@ -527,8 +527,8 @@ static bool sub_6EA934(sint32 x, sint32 y, sint32 width, sint32 height) { if (x < 0) return false; if (y < 28) return false; - if (x + width > gScreenWidth) return false; - if (y + height > gScreenHeight) return false; + if (x + width > context_get_width()) return false; + if (y + height > context_get_height()) return false; return sub_6EA95D(x, y, width, height); } @@ -569,8 +569,8 @@ static bool sub_6EA95D(sint32 x, sint32 y, sint32 width, sint32 height) */ rct_window *window_create_auto_pos(sint32 width, sint32 height, rct_window_event_list *event_handlers, rct_windowclass cls, uint16 flags) { - uint16 screenWidth = gScreenWidth; - uint16 screenHeight = gScreenHeight; + uint16 screenWidth = context_get_width(); + uint16 screenHeight = context_get_height(); // TODO dead code, looks like it is cascading the new window offset from an existing window // we will have to re-implement this in our own way. @@ -579,11 +579,11 @@ rct_window *window_create_auto_pos(sint32 width, sint32 height, rct_window_event // cls &= ~0x80; // rct_window *w = window_find_by_number(0, 0); // if (w != NULL) { - // if (w->x > -60 && w->x < gScreenWidth - 20) { - // if (w->y < gScreenHeight - 20) { + // if (w->x > -60 && w->x < screenWidth - 20) { + // if (w->y < screenHeight - 20) { // sint32 x = w->x; - // if (w->x + width > gScreenWidth) - // x = gScreenWidth - 20 - width; + // if (w->x + width > screenWidth) + // x = screenWidth - 20 - width; // sint32 y = w->y; // return window_create(x + 10, y + 10, width, height, event_handlers, cls, flags); // } @@ -689,12 +689,13 @@ foundSpace: return window_create(x, y, width, height, event_handlers, cls, flags); } -rct_window *window_create_centred(sint32 width, sint32 height, rct_window_event_list *event_handlers, rct_windowclass cls, uint16 flags) +rct_window * window_create_centred(sint32 width, sint32 height, rct_window_event_list *event_handlers, rct_windowclass cls, uint16 flags) { - sint32 x, y; + sint32 screenWidth = context_get_width(); + sint32 screenHeight = context_get_height(); - x = (gScreenWidth - width) / 2; - y = max(28, (gScreenHeight - height) / 2); + sint32 x = (screenWidth - width) / 2; + sint32 y = max(28, (screenHeight - height) / 2); return window_create(x, y, width, height, event_handlers, cls, flags); } @@ -1233,7 +1234,7 @@ void window_push_others_right(rct_window* window) continue; window_invalidate(w); - if (window->x + window->width + 13 >= gScreenWidth) + if (window->x + window->width + 13 >= context_get_width()) continue; uint16 push_amount = window->x + window->width - w->x + 3; w->x += push_amount; @@ -1268,7 +1269,7 @@ void window_push_others_below(rct_window *w1) continue; // Check if there is room to push it down - if (w1->y + w1->height + 80 >= gScreenHeight) + if (w1->y + w1->height + 80 >= context_get_height()) continue; // Invalidate the window's current area @@ -2402,7 +2403,7 @@ static void window_snap_right(rct_window *w, sint32 proximity) leftMost = min(leftMost, w2->x); } - screenWidth = gScreenWidth; + screenWidth = context_get_width(); if (screenWidth >= wLeftProximity && screenWidth <= wRightProximity) leftMost = min(leftMost, screenWidth); @@ -2435,7 +2436,7 @@ static void window_snap_bottom(rct_window *w, sint32 proximity) topMost = min(topMost, w2->y); } - screenHeight = gScreenHeight; + screenHeight = context_get_height(); if (screenHeight >= wTopProximity && screenHeight <= wBottomProximity) topMost = min(topMost, screenHeight); @@ -2448,7 +2449,7 @@ void window_move_and_snap(rct_window *w, sint32 newWindowX, sint32 newWindowY, s sint32 originalX = w->x; sint32 originalY = w->y; - newWindowY = clamp(29, newWindowY, gScreenHeight - 34); + newWindowY = clamp(29, newWindowY, context_get_height() - 34); if (snapProximity > 0) { w->x = newWindowX; diff --git a/src/openrct2/intro.c b/src/openrct2/intro.c index 5b3b7fcd07..abd28d8c1b 100644 --- a/src/openrct2/intro.c +++ b/src/openrct2/intro.c @@ -69,7 +69,7 @@ void intro_update() _introStateCounter += 5; // Check if logo is off the screen...ish - if (_introStateCounter > gScreenHeight - 120) { + if (_introStateCounter > context_get_height() - 120) { _introStateCounter = -116; gIntroState++; } @@ -85,7 +85,7 @@ void intro_update() _introStateCounter += 5; // Check if logo is almost scrolled to the bottom - if (!_chainLiftFinished && _introStateCounter >= gScreenHeight + 40 - 421) { + if (!_chainLiftFinished && _introStateCounter >= context_get_height() + 40 - 421) { _chainLiftFinished = true; // Stop the chain lift sound @@ -99,7 +99,7 @@ void intro_update() } // Check if logo is off the screen...ish - if (_introStateCounter >= gScreenHeight + 40) { + if (_introStateCounter >= context_get_height() + 40) { // Stop the track friction sound if (_soundChannel != NULL) { Mixer_Stop_Channel(_soundChannel); @@ -160,7 +160,7 @@ void intro_update() void intro_draw(rct_drawpixelinfo *dpi) { - sint32 screenWidth = gScreenWidth; + sint32 screenWidth = context_get_width(); switch (gIntroState) { case INTRO_STATE_DISCLAIMER_1: @@ -258,7 +258,7 @@ static void screen_intro_skip_part() static void screen_intro_draw_logo(rct_drawpixelinfo *dpi) { - sint32 screenWidth = gScreenWidth; + sint32 screenWidth = context_get_width(); sint32 imageWidth = 640; sint32 imageX = (screenWidth - imageWidth) / 2; diff --git a/src/openrct2/management/news_item.c b/src/openrct2/management/news_item.c index 121270034c..6726b2821b 100644 --- a/src/openrct2/management/news_item.c +++ b/src/openrct2/management/news_item.c @@ -15,6 +15,7 @@ #pragma endregion #include "../audio/audio.h" +#include "../Context.h" #include "../input.h" #include "../interface/window.h" #include "../localisation/date.h" @@ -97,7 +98,7 @@ static void news_item_tick_current() // Only play news item sound when in normal playing mode if (ticks == 1 && (gScreenFlags == SCREEN_FLAGS_PLAYING)) { // Play sound - audio_play_sound_panned(SOUND_NEWS_ITEM, gScreenWidth / 2, 0, 0, 0); + audio_play_sound_panned(SOUND_NEWS_ITEM, context_get_width() / 2, 0, 0, 0); } } diff --git a/src/openrct2/peep/peep.c b/src/openrct2/peep/peep.c index 1110a81a55..a92c51fe84 100644 --- a/src/openrct2/peep/peep.c +++ b/src/openrct2/peep/peep.c @@ -18,6 +18,7 @@ #include "../audio/AudioMixer.h" #include "../cheats.h" #include "../config/Config.h" +#include "../Context.h" #include "../game.h" #include "../input.h" #include "../interface/window.h" @@ -6997,7 +6998,7 @@ void peep_applause() } // Play applause noise - audio_play_sound_panned(SOUND_APPLAUSE, gScreenWidth / 2, 0, 0, 0); + audio_play_sound_panned(SOUND_APPLAUSE, context_get_width() / 2, 0, 0, 0); } /** diff --git a/src/openrct2/rct2.c b/src/openrct2/rct2.c index 2fc34fdfd9..196f5244bb 100644 --- a/src/openrct2/rct2.c +++ b/src/openrct2/rct2.c @@ -20,6 +20,7 @@ #include "audio/audio.h" #include "audio/AudioMixer.h" #include "config/Config.h" +#include "Context.h" #include "drawing/drawing.h" #include "drawing/lightfx.h" #include "editor.h" @@ -114,8 +115,6 @@ uint32 gCurrentDrawCount = 0; uint8 gScreenFlags; uint32 gScreenAge; uint8 gSavePromptMode; -sint32 gScreenWidth; -sint32 gScreenHeight; char gRCT2AddressAppPath[MAX_PATH]; char gRCT2AddressSavedGamesPath[MAX_PATH]; @@ -273,7 +272,7 @@ void rct2_draw(rct_drawpixelinfo *dpi) console_draw(dpi); if ((gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && !gTitleHideVersionInfo) { - DrawOpenRCT2(dpi, 0, gScreenHeight - 20); + DrawOpenRCT2(dpi, 0, context_get_height() - 20); } if (gConfigGeneral.show_fps) { @@ -303,7 +302,7 @@ static void rct2_measure_fps() static void rct2_draw_fps(rct_drawpixelinfo *dpi) { - sint32 x = gScreenWidth / 2; + sint32 x = context_get_width() / 2; sint32 y = 2; // Measure FPS diff --git a/src/openrct2/rct2.h b/src/openrct2/rct2.h index 829fa00771..002ded8c29 100644 --- a/src/openrct2/rct2.h +++ b/src/openrct2/rct2.h @@ -161,8 +161,6 @@ extern uint32 gCurrentDrawCount; extern uint8 gScreenFlags; extern uint32 gScreenAge; extern uint8 gSavePromptMode; -extern sint32 gScreenWidth; -extern sint32 gScreenHeight; extern char gRCT2AddressAppPath[]; extern char gRCT2AddressSavedGamesPath[]; diff --git a/src/openrct2/ride/ride.c b/src/openrct2/ride/ride.c index 8d5b12707b..0ccc6a02f8 100644 --- a/src/openrct2/ride/ride.c +++ b/src/openrct2/ride/ride.c @@ -19,6 +19,7 @@ #include "../cheats.h" #include "../common.h" #include "../config/Config.h" +#include "../Context.h" #include "../editor.h" #include "../game.h" #include "../input.h" @@ -3448,7 +3449,7 @@ sint32 ride_music_params_update(sint16 x, sint16 y, sint16 z, uint8 rideIndex, u } sint32 x2 = viewport->x + ((rotatedCoords.x - viewport->view_x) >> viewport->zoom); x2 *= 0x10000; - uint16 screenwidth = gScreenWidth; + uint16 screenwidth = context_get_width(); if (screenwidth < 64) { screenwidth = 64; } @@ -3456,7 +3457,7 @@ sint32 ride_music_params_update(sint16 x, sint16 y, sint16 z, uint8 rideIndex, u sint32 y2 = viewport->y + ((rotatedCoords.y - viewport->view_y) >> viewport->zoom); y2 *= 0x10000; - uint16 screenheight = gScreenHeight; + uint16 screenheight = context_get_height(); if (screenheight < 64) { screenheight = 64; } diff --git a/src/openrct2/ride/vehicle.c b/src/openrct2/ride/vehicle.c index aa074353a5..c0b68850ca 100644 --- a/src/openrct2/ride/vehicle.c +++ b/src/openrct2/ride/vehicle.c @@ -17,6 +17,7 @@ #include "../audio/audio.h" #include "../audio/AudioMixer.h" #include "../config/Config.h" +#include "../Context.h" #include "../editor.h" #include "../game.h" #include "../interface/viewport.h" @@ -701,7 +702,7 @@ static void vehicle_update_sound_params(rct_vehicle* vehicle) pan_x >>= g_music_tracking_viewport->zoom; pan_x += g_music_tracking_viewport->x; - uint16 screenwidth = gScreenWidth; + uint16 screenwidth = context_get_width(); if (screenwidth < 64) { screenwidth = 64; } @@ -711,7 +712,7 @@ static void vehicle_update_sound_params(rct_vehicle* vehicle) pan_y >>= g_music_tracking_viewport->zoom; pan_y += g_music_tracking_viewport->y; - uint16 screenheight = gScreenHeight; + uint16 screenheight = context_get_height(); if (screenheight < 64) { screenheight = 64; } diff --git a/src/openrct2/title/TitleScreen.cpp b/src/openrct2/title/TitleScreen.cpp index 91a58229c0..bee7457ead 100644 --- a/src/openrct2/title/TitleScreen.cpp +++ b/src/openrct2/title/TitleScreen.cpp @@ -15,6 +15,7 @@ #pragma endregion #include "../core/Console.hpp" +#include "../Context.h" #include "../network/network.h" #include "../OpenRCT2.h" #include "../scenario/ScenarioRepository.h" @@ -161,7 +162,7 @@ extern "C" window_title_exit_open(); window_title_options_open(); window_title_logo_open(); - window_resize_gui(gScreenWidth, gScreenHeight); + window_resize_gui(context_get_width(), context_get_height()); gTitleHideVersionInfo = false; } diff --git a/src/openrct2/title/TitleSequencePlayer.cpp b/src/openrct2/title/TitleSequencePlayer.cpp index c113fe55ce..29ec5db5fb 100644 --- a/src/openrct2/title/TitleSequencePlayer.cpp +++ b/src/openrct2/title/TitleSequencePlayer.cpp @@ -447,13 +447,13 @@ private: sint32 z = map_element_height(x, y); window_set_location(w, x, y, z); viewport_update_position(w); - } - // Save known tile position in case of window resize - _lastScreenWidth = gScreenWidth; - _lastScreenHeight = gScreenHeight; - _viewCentreLocation.x = x; - _viewCentreLocation.y = y; + // Save known tile position in case of window resize + _lastScreenWidth = w->width; + _lastScreenHeight = w->height; + _viewCentreLocation.x = x; + _viewCentreLocation.y = y; + } } /** @@ -461,10 +461,14 @@ private: */ void FixViewLocation() { - if (gScreenWidth != _lastScreenWidth || - gScreenHeight != _lastScreenHeight) + rct_window * w = window_get_main(); + if (w != nullptr) { - SetViewLocation(_viewCentreLocation.x, _viewCentreLocation.y); + if (w->width != _lastScreenWidth || + w->height != _lastScreenHeight) + { + SetViewLocation(_viewCentreLocation.x, _viewCentreLocation.y); + } } } }; diff --git a/src/openrct2/windows/changelog.c b/src/openrct2/windows/changelog.c index a5a0468180..57b8d0e178 100644 --- a/src/openrct2/windows/changelog.c +++ b/src/openrct2/windows/changelog.c @@ -14,6 +14,8 @@ *****************************************************************************/ #pragma endregion +#include "../Context.h" +#include "../interface/themes.h" #include "../interface/viewport.h" #include "../interface/widget.h" #include "../interface/window.h" @@ -107,8 +109,8 @@ rct_window *window_changelog_open() if (!window_changelog_read_file()) return NULL; - sint32 screenWidth = gScreenWidth; - sint32 screenHeight = gScreenHeight; + sint32 screenWidth = context_get_width(); + sint32 screenHeight = context_get_height(); window = window_create_centred( screenWidth * 4 / 5, @@ -144,8 +146,8 @@ static void window_changelog_mouseup(rct_window *w, rct_widgetindex widgetIndex) static void window_changelog_resize(rct_window *w) { - sint32 screenWidth = gScreenWidth; - sint32 screenHeight = gScreenHeight; + sint32 screenWidth = context_get_width(); + sint32 screenHeight = context_get_height(); w->max_width = (screenWidth * 4) / 5; w->max_height = (screenHeight * 4) / 5; diff --git a/src/openrct2/windows/clear_scenery.c b/src/openrct2/windows/clear_scenery.c index 65db08efd8..f9b3eb6c19 100644 --- a/src/openrct2/windows/clear_scenery.c +++ b/src/openrct2/windows/clear_scenery.c @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include "../Context.h" #include "../input.h" #include "../interface/widget.h" #include "../interface/window.h" @@ -104,7 +105,7 @@ void window_clear_scenery_open() if (window_find_by_class(WC_CLEAR_SCENERY) != NULL) return; - window = window_create(gScreenWidth - 98, 29, 98, 94, &window_clear_scenery_events, WC_CLEAR_SCENERY, 0); + window = window_create(context_get_width() - 98, 29, 98, 94, &window_clear_scenery_events, WC_CLEAR_SCENERY, 0); window->widgets = window_clear_scenery_widgets; window->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_INCREMENT) | (1 << WIDX_DECREMENT) | (1 << WIDX_PREVIEW) | (1 << WIDX_SMALL_SCENERY) | (1 << WIDX_LARGE_SCENERY) | (1 << WIDX_FOOTPATH); diff --git a/src/openrct2/windows/debug_paint.c b/src/openrct2/windows/debug_paint.c index ebaf5e867e..7c3d434d0b 100644 --- a/src/openrct2/windows/debug_paint.c +++ b/src/openrct2/windows/debug_paint.c @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include "../Context.h" #include "../input.h" #include "../interface/widget.h" #include "../interface/window.h" @@ -81,15 +82,13 @@ static rct_window_event_list window_debug_paint_events = { void window_debug_paint_open() { - rct_window * window; - // Check if window is already open if (window_find_by_class(WC_DEBUG_PAINT) != NULL) return; - window = window_create( + rct_window * window = window_create( 16, - gScreenHeight - 16 - 33 - WINDOW_HEIGHT, + context_get_height() - 16 - 33 - WINDOW_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, &window_debug_paint_events, diff --git a/src/openrct2/windows/dropdown.c b/src/openrct2/windows/dropdown.c index 666efb13c7..103218af36 100644 --- a/src/openrct2/windows/dropdown.c +++ b/src/openrct2/windows/dropdown.c @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include "../Context.h" #include "../input.h" #include "../interface/widget.h" #include "../interface/window.h" @@ -176,10 +177,12 @@ void window_dropdown_show_text_custom_width(sint32 x, sint32 y, sint32 extray, u width = _dropdown_item_width * _dropdown_num_columns + 3; sint32 height = _dropdown_item_height * _dropdown_num_rows + 3; - if (x + width > gScreenWidth) - x = max(0, gScreenWidth - width); - if (y + height > gScreenHeight) - y = max(0, gScreenHeight - height); + sint32 screenWidth = context_get_width(); + sint32 screenHeight = context_get_height(); + if (x + width > screenWidth) + x = max(0, screenWidth - width); + if (y + height > screenHeight) + y = max(0, screenHeight - height); window_dropdown_widgets[WIDX_BACKGROUND].bottom = (sint16)(_dropdown_item_height * num_items + 3); window_dropdown_widgets[WIDX_BACKGROUND].right = (sint16)(_dropdown_item_width + 3); @@ -245,10 +248,13 @@ void window_dropdown_show_image(sint32 x, sint32 y, sint32 extray, uint8 colour, // Calculate position and size width = _dropdown_item_width * _dropdown_num_columns + 3; height = _dropdown_item_height * _dropdown_num_rows + 3; - if (x + width > gScreenWidth) - x = max(0, gScreenWidth - width); - if (y + height > gScreenHeight) - y = max(0, gScreenHeight - height); + + sint32 screenWidth = context_get_width(); + sint32 screenHeight = context_get_height(); + if (x + width > screenWidth) + x = max(0, screenWidth - width); + if (y + height > screenHeight) + y = max(0, screenHeight - height); window_dropdown_widgets[WIDX_BACKGROUND].right = width; window_dropdown_widgets[WIDX_BACKGROUND].bottom = height; diff --git a/src/openrct2/windows/editor_bottom_toolbar.c b/src/openrct2/windows/editor_bottom_toolbar.c index 51f8b79efb..46a75d976e 100644 --- a/src/openrct2/windows/editor_bottom_toolbar.c +++ b/src/openrct2/windows/editor_bottom_toolbar.c @@ -16,6 +16,7 @@ #include "../audio/audio.h" #include "../config/Config.h" +#include "../Context.h" #include "../game.h" #include "../editor.h" #include "../input.h" @@ -135,10 +136,8 @@ static void sub_6DFED0(); */ void window_editor_bottom_toolbar_open() { - rct_window* window; - - window = window_create(0, gScreenHeight - 32, - gScreenWidth, 32, + rct_window * window = window_create(0, context_get_height() - 32, + context_get_width(), 32, &window_editor_bottom_toolbar_events, WC_BOTTOM_TOOLBAR, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND); window->widgets = window_editor_bottom_toolbar_widgets; @@ -371,7 +370,7 @@ void window_editor_bottom_toolbar_invalidate(rct_window *w) { colour_scheme_update_by_class(w, (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) ? WC_EDITOR_SCENARIO_BOTTOM_TOOLBAR : WC_EDITOR_TRACK_BOTTOM_TOOLBAR); - uint16 screenWidth = gScreenWidth; + uint16 screenWidth = context_get_width(); window_editor_bottom_toolbar_widgets[WIDX_NEXT_IMAGE].left = screenWidth - 200; window_editor_bottom_toolbar_widgets[WIDX_NEXT_IMAGE].right = screenWidth - 1; window_editor_bottom_toolbar_widgets[WIDX_NEXT_STEP_BUTTON].left = screenWidth - 198; diff --git a/src/openrct2/windows/editor_main.c b/src/openrct2/windows/editor_main.c index fd585e133c..d8397a43ba 100644 --- a/src/openrct2/windows/editor_main.c +++ b/src/openrct2/windows/editor_main.c @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include "../Context.h" #include "../interface/viewport.h" #include "../interface/widget.h" #include "../interface/window.h" @@ -65,8 +66,8 @@ static rct_widget window_editor_main_widgets[] = { */ rct_window * window_editor_main_open() { - window_editor_main_widgets[0].right = gScreenWidth; - window_editor_main_widgets[0].bottom = gScreenHeight; + window_editor_main_widgets[0].right = context_get_width(); + window_editor_main_widgets[0].bottom = context_get_height(); rct_window *window = window_create(0, 0, window_editor_main_widgets[0].right, window_editor_main_widgets[0].bottom, &window_editor_main_events, WC_MAIN_WINDOW, WF_STICK_TO_BACK); window->widgets = window_editor_main_widgets; diff --git a/src/openrct2/windows/error.c b/src/openrct2/windows/error.c index 6c05b528d3..cc874b8693 100644 --- a/src/openrct2/windows/error.c +++ b/src/openrct2/windows/error.c @@ -121,13 +121,15 @@ void window_error_open(rct_string_id title, rct_string_id message) window_error_widgets[WIDX_BACKGROUND].right = width; window_error_widgets[WIDX_BACKGROUND].bottom = height; + sint32 screenWidth = context_get_width(); + sint32 screenHeight = context_get_height(); const CursorState * state = context_get_cursor_state(); x = state->x - (width / 2); - x = clamp(0, x, gScreenWidth); + x = clamp(0, x, screenWidth); y = state->y + 26; y = max(22, y); - maxY = gScreenHeight - height; + maxY = screenHeight - height; if (y > maxY) { y = y - height - 40; y = min(y, maxY); diff --git a/src/openrct2/windows/game_bottom_toolbar.c b/src/openrct2/windows/game_bottom_toolbar.c index 734fb837fd..61ea4d855a 100644 --- a/src/openrct2/windows/game_bottom_toolbar.c +++ b/src/openrct2/windows/game_bottom_toolbar.c @@ -15,6 +15,7 @@ #pragma endregion #include "../config/Config.h" +#include "../Context.h" #include "../game.h" #include "../input.h" #include "../interface/widget.h" @@ -127,11 +128,11 @@ static void window_game_bottom_toolbar_invalidate_dirty_widgets(rct_window *w); */ void window_game_bottom_toolbar_open() { - rct_window* window; - - window = window_create( - 0, gScreenHeight - 32, - gScreenWidth, 32, + sint32 screenWidth = context_get_width(); + sint32 screenHeight = context_get_height(); + rct_window * window = window_create( + 0, screenHeight - 32, + screenWidth, 32, &window_game_bottom_toolbar_events, WC_BOTTOM_TOOLBAR, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND @@ -242,7 +243,7 @@ static void window_game_bottom_toolbar_invalidate(rct_window *w) NewsItem *newsItem; // Anchor the middle and right panel to the right - x = gScreenWidth; + x = context_get_width(); w->width = x; x--; window_game_bottom_toolbar_widgets[WIDX_RIGHT_OUTSET].right = x; diff --git a/src/openrct2/windows/install_track.c b/src/openrct2/windows/install_track.c index 7636d4233a..11ac600b76 100644 --- a/src/openrct2/windows/install_track.c +++ b/src/openrct2/windows/install_track.c @@ -15,6 +15,7 @@ #pragma endregion #include "../audio/audio.h" +#include "../Context.h" #include "../editor.h" #include "../interface/widget.h" #include "../interface/window.h" @@ -125,8 +126,10 @@ void window_install_track_open(const utf8 *path) gTrackDesignSceneryToggle = false; _currentTrackPieceDirection = 2; - sint32 x = gScreenWidth / 2 - 201; - sint32 y = max(28, gScreenHeight / 2 - 200); + sint32 screenWidth = context_get_width(); + sint32 screenHeight = context_get_height(); + sint32 x = screenWidth / 2 - 201; + sint32 y = max(28, screenHeight / 2 - 200); rct_window *w = window_create(x, y, 402, 400, &window_install_track_events, WC_INSTALL_TRACK, 0); w->widgets = window_install_track_widgets; diff --git a/src/openrct2/windows/land.c b/src/openrct2/windows/land.c index 68acfbf88f..e56d6c614e 100644 --- a/src/openrct2/windows/land.c +++ b/src/openrct2/windows/land.c @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include "../Context.h" #include "../input.h" #include "../interface/widget.h" #include "../interface/window.h" @@ -126,7 +127,7 @@ void window_land_open() if (window_find_by_class(WC_LAND) != NULL) return; - window = window_create(gScreenWidth - 98, 29, 98, 160, &window_land_events, WC_LAND, 0); + window = window_create(context_get_width() - 98, 29, 98, 160, &window_land_events, WC_LAND, 0); window->widgets = window_land_widgets; window->enabled_widgets = (1 << WIDX_CLOSE) | diff --git a/src/openrct2/windows/land_rights.c b/src/openrct2/windows/land_rights.c index b888f1522d..f4ca519236 100644 --- a/src/openrct2/windows/land_rights.c +++ b/src/openrct2/windows/land_rights.c @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include "../Context.h" #include "../game.h" #include "../input.h" #include "../interface/viewport.h" @@ -99,7 +100,7 @@ void window_land_rights_open() if (window_find_by_class(WC_LAND_RIGHTS) != NULL) return; - window = window_create(gScreenWidth - 98, 29, 98, 94, &window_land_rights_events, WC_LAND_RIGHTS, 0); + window = window_create(context_get_width() - 98, 29, 98, 94, &window_land_rights_events, WC_LAND_RIGHTS, 0); window->widgets = window_land_rights_widgets; window->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_DECREMENT) | (1 << WIDX_INCREMENT) | (1 << WIDX_PREVIEW) | (1 << WIDX_BUY_LAND_RIGHTS) | (1 << WIDX_BUY_CONSTRUCTION_RIGHTS); diff --git a/src/openrct2/windows/main.c b/src/openrct2/windows/main.c index 908fd5b4c0..2f6e7dede1 100644 --- a/src/openrct2/windows/main.c +++ b/src/openrct2/windows/main.c @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include "../Context.h" #include "../interface/viewport.h" #include "../interface/widget.h" #include "../interface/window.h" @@ -64,11 +65,9 @@ static rct_window_event_list window_main_events = { */ void window_main_open() { - rct_window* window; - - window_main_widgets[0].right = gScreenWidth; - window_main_widgets[0].bottom = gScreenHeight; - window = window_create( + window_main_widgets[0].right = context_get_width(); + window_main_widgets[0].bottom = context_get_height(); + rct_window * window = window_create( 0, 0, window_main_widgets[0].right, window_main_widgets[0].bottom, &window_main_events, diff --git a/src/openrct2/windows/park.c b/src/openrct2/windows/park.c index d2a5b50ef9..646f643e72 100644 --- a/src/openrct2/windows/park.c +++ b/src/openrct2/windows/park.c @@ -15,6 +15,7 @@ #pragma endregion #include "../config/Config.h" +#include "../Context.h" #include "../game.h" #include "../localisation/date.h" #include "../localisation/localisation.h" @@ -1667,8 +1668,8 @@ void window_park_objective_open() window->hold_down_widgets = window_park_page_hold_down_widgets[WINDOW_PARK_PAGE_OBJECTIVE]; window->event_handlers = &window_park_objective_events; window_init_scroll_widgets(window); - window->x = gScreenWidth / 2 - 115; - window->y = gScreenHeight / 2 - 87; + window->x = context_get_width() / 2 - 115; + window->y = context_get_height() / 2 - 87; window_invalidate(window); } diff --git a/src/openrct2/windows/scenery.c b/src/openrct2/windows/scenery.c index 3a8143dc76..4969baa6c2 100644 --- a/src/openrct2/windows/scenery.c +++ b/src/openrct2/windows/scenery.c @@ -424,7 +424,7 @@ void window_scenery_open() init_scenery(); window = window_create( - gScreenWidth - WINDOW_SCENERY_WIDTH, + context_get_width() - WINDOW_SCENERY_WIDTH, 0x1D, WINDOW_SCENERY_WIDTH, WINDOW_SCENERY_HEIGHT, @@ -748,7 +748,7 @@ static void window_scenery_update(rct_window *w) } } else { sint32 windowHeight = min(463, w->scrolls[0].v_bottom + 62); - if (gScreenHeight < 600) + if (context_get_height() < 600) windowHeight = min(374, windowHeight); windowHeight = max(WINDOW_SCENERY_HEIGHT, windowHeight); diff --git a/src/openrct2/windows/title_exit.c b/src/openrct2/windows/title_exit.c index 96b4133482..4ed0482db8 100644 --- a/src/openrct2/windows/title_exit.c +++ b/src/openrct2/windows/title_exit.c @@ -15,6 +15,7 @@ #pragma endregion #include "../config/Config.h" +#include "../Context.h" #include "../game.h" #include "../sprites.h" #include "../localisation/localisation.h" @@ -75,7 +76,7 @@ void window_title_exit_open() rct_window* window; window = window_create( - gScreenWidth - 40, gScreenHeight - 64, + context_get_width() - 40, context_get_height() - 64, 40, 64, &window_title_exit_events, WC_TITLE_EXIT, diff --git a/src/openrct2/windows/title_menu.c b/src/openrct2/windows/title_menu.c index ea28d1c791..70eca7bdd8 100644 --- a/src/openrct2/windows/title_menu.c +++ b/src/openrct2/windows/title_menu.c @@ -15,6 +15,7 @@ #pragma endregion #include "../config/Config.h" +#include "../Context.h" #include "../editor.h" #include "../game.h" #include "../input.h" @@ -88,7 +89,7 @@ void window_title_menu_open() rct_window* window; window = window_create( - 0, gScreenHeight - 142, + 0, context_get_height() - 142, 0, 100, &window_title_menu_events, WC_TITLE_MENU, @@ -120,7 +121,7 @@ void window_title_menu_open() i++; } window->width = x; - window->x = (gScreenWidth - window->width) / 2; + window->x = (context_get_width() - window->width) / 2; window_init_scroll_widgets(window); } diff --git a/src/openrct2/windows/title_options.c b/src/openrct2/windows/title_options.c index 583ec59379..40af320e26 100644 --- a/src/openrct2/windows/title_options.c +++ b/src/openrct2/windows/title_options.c @@ -15,6 +15,7 @@ #pragma endregion #include "../config/Config.h" +#include "../Context.h" #include "../game.h" #include "../intro.h" #include "../localisation/localisation.h" @@ -70,10 +71,8 @@ static rct_window_event_list window_title_options_events = { */ void window_title_options_open() { - rct_window* window; - - window = window_create( - gScreenWidth - 80, 0, + rct_window * window = window_create( + context_get_width() - 80, 0, 80, 12, &window_title_options_events, WC_TITLE_OPTIONS, diff --git a/src/openrct2/windows/tooltip.c b/src/openrct2/windows/tooltip.c index 8cd8f35acc..975c1cb8bc 100644 --- a/src/openrct2/windows/tooltip.c +++ b/src/openrct2/windows/tooltip.c @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include "../Context.h" #include "../drawing/drawing.h" #include "../localisation/localisation.h" #include "../input.h" @@ -110,12 +111,14 @@ void window_tooltip_show(rct_string_id id, sint32 x, sint32 y) memcpy(_tooltipText, buffer, sizeof(_tooltipText)); - x = clamp(0, x - (width / 2), gScreenWidth - width); + sint32 screenWidth = context_get_width(); + sint32 screenHeight = context_get_height(); + x = clamp(0, x - (width / 2), screenWidth - width); // TODO The cursor size will be relative to the window DPI. // The amount to offset the y should be adjusted. - sint32 max_y = gScreenHeight - height; + sint32 max_y = screenHeight - height; y += 26; // Normally, we'd display the tooltip 26 lower if (y > max_y) // If y is too large, the tooltip could be forced below the cursor if we'd just clamped y, diff --git a/src/openrct2/windows/top_toolbar.c b/src/openrct2/windows/top_toolbar.c index bbb0b8a133..51d7a246e9 100644 --- a/src/openrct2/windows/top_toolbar.c +++ b/src/openrct2/windows/top_toolbar.c @@ -17,6 +17,7 @@ #include "../audio/audio.h" #include "../cheats.h" #include "../config/Config.h" +#include "../Context.h" #include "../editor.h" #include "../game.h" #include "../input.h" @@ -290,11 +291,9 @@ static uint16 _unkF64F15; */ void window_top_toolbar_open() { - rct_window* window; - - window = window_create( + rct_window * window = window_create( 0, 0, - gScreenWidth, 28, + context_get_width(), 28, &window_top_toolbar_events, WC_TOP_TOOLBAR, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND @@ -763,8 +762,9 @@ static void window_top_toolbar_invalidate(rct_window *w) } // Align right hand side toolbar buttons + sint32 screenWidth = context_get_width(); firstAlignment = 1; - x = max(640, gScreenWidth); + x = max(640, screenWidth); for (sint32 i = 0; i < countof(right_aligned_widgets_order); ++i) { widgetIndex = right_aligned_widgets_order[i]; widget = &window_top_toolbar_widgets[widgetIndex]; diff --git a/src/openrct2/windows/track_list.c b/src/openrct2/windows/track_list.c index 574fd0bf0f..4e44db18f0 100644 --- a/src/openrct2/windows/track_list.c +++ b/src/openrct2/windows/track_list.c @@ -16,6 +16,7 @@ #include "../audio/audio.h" #include "../config/Config.h" +#include "../Context.h" #include "../drawing/IDrawingEngine.h" #include "../editor.h" #include "../interface/widget.h" @@ -121,8 +122,10 @@ void window_track_list_open(ride_list_item item) sint32 x, y; if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) { - x = gScreenWidth / 2 - 300; - y = max(28, gScreenHeight / 2 - 200); + sint32 screenWidth = context_get_width(); + sint32 screenHeight = context_get_height(); + x = screenWidth / 2 - 300; + y = max(28, screenHeight / 2 - 200); } else { x = 0; y = 29; diff --git a/src/openrct2/windows/track_manage.c b/src/openrct2/windows/track_manage.c index b248a74dc5..ac9599a894 100644 --- a/src/openrct2/windows/track_manage.c +++ b/src/openrct2/windows/track_manage.c @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include "../Context.h" #include "../game.h" #include "../interface/widget.h" #include "../interface/window.h" @@ -252,13 +253,13 @@ static void window_track_manage_paint(rct_window *w, rct_drawpixelinfo *dpi) */ static void window_track_delete_prompt_open() { - rct_window *w; - window_close_by_class(WC_TRACK_DELETE_PROMPT); - w = window_create( - max(28, (gScreenWidth - 250) / 2), - (gScreenHeight - 44) / 2, + sint32 screenWidth = context_get_width(); + sint32 screenHeight = context_get_height(); + rct_window *w = window_create( + max(28, (screenWidth - 250) / 2), + (screenHeight - 44) / 2, 250, 74, &window_track_delete_prompt_events, diff --git a/src/openrct2/windows/water.c b/src/openrct2/windows/water.c index a4246ae32b..4871a2c7ca 100644 --- a/src/openrct2/windows/water.c +++ b/src/openrct2/windows/water.c @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include "../Context.h" #include "../input.h" #include "../interface/widget.h" #include "../interface/window.h" @@ -98,7 +99,7 @@ void window_water_open() return; window = window_create( - gScreenWidth - 76, + context_get_width() - 76, 29, 76, 77,