From c8da126c955d5e5d3e5b7bfb198de9254fc591a6 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 24 Jan 2025 22:44:21 +0100 Subject: [PATCH] Move Viewport struct to Viewport.h --- src/openrct2-ui/UiContext.cpp | 1 + src/openrct2-ui/interface/InGameConsole.cpp | 1 + src/openrct2/interface/InteractiveConsole.cpp | 1 + src/openrct2/interface/Viewport.h | 43 +++++++++++ src/openrct2/interface/Window.h | 77 +------------------ src/openrct2/interface/Window_internal.h | 32 ++++++++ 6 files changed, 79 insertions(+), 76 deletions(-) diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index 5c2a0dfda4..e724c685d6 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -18,6 +18,7 @@ #include "input/ShortcutManager.h" #include "interface/InGameConsole.h" #include "interface/Theme.h" +#include "interface/Viewport.h" #include "scripting/UiExtensions.h" #include "title/TitleSequencePlayer.h" diff --git a/src/openrct2-ui/interface/InGameConsole.cpp b/src/openrct2-ui/interface/InGameConsole.cpp index 4074de17c6..0f6f112733 100644 --- a/src/openrct2-ui/interface/InGameConsole.cpp +++ b/src/openrct2-ui/interface/InGameConsole.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index bdc439f109..35929f9be6 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -43,6 +43,7 @@ #include "../entity/Staff.h" #include "../interface/Chat.h" #include "../interface/Colour.h" +#include "../interface/Viewport.h" #include "../interface/Window_internal.h" #include "../localisation/Formatting.h" #include "../localisation/StringIds.h" diff --git a/src/openrct2/interface/Viewport.h b/src/openrct2/interface/Viewport.h index fc2e3a2efe..bcaeab07c4 100644 --- a/src/openrct2/interface/Viewport.h +++ b/src/openrct2/interface/Viewport.h @@ -29,6 +29,49 @@ namespace OpenRCT2 { struct WindowBase; + struct Viewport + { + int32_t width{}; + int32_t height{}; + ScreenCoordsXY pos{}; + ScreenCoordsXY viewPos{}; + uint32_t flags{}; + ZoomLevel zoom{}; + uint8_t rotation{}; + VisibilityCache visibility{}; + + [[nodiscard]] constexpr int32_t ViewWidth() const + { + return zoom.ApplyTo(width); + } + + [[nodiscard]] constexpr int32_t ViewHeight() const + { + return zoom.ApplyTo(height); + } + + // Use this function on coordinates that are relative to the viewport zoom i.e. a peeps x, y position after transforming + // from its x, y, z + [[nodiscard]] constexpr bool Contains(const ScreenCoordsXY& vpos) const + { + return ( + vpos.y >= viewPos.y && vpos.y < viewPos.y + ViewHeight() && vpos.x >= viewPos.x + && vpos.x < viewPos.x + ViewWidth()); + } + + // Use this function on coordinates that are relative to the screen that is been drawn i.e. the cursor position + [[nodiscard]] constexpr bool ContainsScreen(const ScreenCoordsXY& sPos) const + { + return (sPos.x >= pos.x && sPos.x < pos.x + width && sPos.y >= pos.y && sPos.y < pos.y + height); + } + + [[nodiscard]] ScreenCoordsXY ScreenToViewportCoord(const ScreenCoordsXY& screenCoord) const; + + void Invalidate() const; + }; + + struct Focus; + // Flags must currenly retain their values to avoid breaking plugins. // Values can be changed when plugins move to using named constants. enum : uint32_t diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index 5e5b4726cb..c40f975a97 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -54,88 +54,13 @@ namespace OpenRCT2 extern WindowCloseModifier gLastCloseModifier; - /** - * Viewport structure - */ - struct Viewport - { - int32_t width{}; - int32_t height{}; - ScreenCoordsXY pos{}; - ScreenCoordsXY viewPos{}; - uint32_t flags{}; - ZoomLevel zoom{}; - uint8_t rotation{}; - VisibilityCache visibility{}; - - [[nodiscard]] constexpr int32_t ViewWidth() const - { - return zoom.ApplyTo(width); - } - - [[nodiscard]] constexpr int32_t ViewHeight() const - { - return zoom.ApplyTo(height); - } - - // Use this function on coordinates that are relative to the viewport zoom i.e. a peeps x, y position after transforming - // from its x, y, z - [[nodiscard]] constexpr bool Contains(const ScreenCoordsXY& vpos) const - { - return ( - vpos.y >= viewPos.y && vpos.y < viewPos.y + ViewHeight() && vpos.x >= viewPos.x - && vpos.x < viewPos.x + ViewWidth()); - } - - // Use this function on coordinates that are relative to the screen that is been drawn i.e. the cursor position - [[nodiscard]] constexpr bool ContainsScreen(const ScreenCoordsXY& sPos) const - { - return (sPos.x >= pos.x && sPos.x < pos.x + width && sPos.y >= pos.y && sPos.y < pos.y + height); - } - - [[nodiscard]] ScreenCoordsXY ScreenToViewportCoord(const ScreenCoordsXY& screenCoord) const; - - void Invalidate() const; - }; - - struct Focus - { - using CoordinateFocus = CoordsXYZ; - using EntityFocus = EntityId; - - ZoomLevel zoom{}; - std::variant data; - - template - constexpr explicit Focus(T newValue, ZoomLevel newZoom = {}) - { - data = newValue; - zoom = newZoom; - } - - CoordsXYZ GetPos() const; - - constexpr bool operator==(const Focus& other) const - { - if (zoom != other.zoom) - { - return false; - } - return data == other.data; - } - constexpr bool operator!=(const Focus& other) const - { - return !(*this == other); - } - }; - struct WindowCloseModifier { WindowIdentifier window; CloseWindowModifier modifier; }; - struct WindowBase; + struct Viewport; #define RCT_WINDOW_RIGHT(w) ((w)->windowPos.x + (w)->width) #define RCT_WINDOW_BOTTOM(w) ((w)->windowPos.y + (w)->height) diff --git a/src/openrct2/interface/Window_internal.h b/src/openrct2/interface/Window_internal.h index 471989b5eb..a5aade3cc9 100644 --- a/src/openrct2/interface/Window_internal.h +++ b/src/openrct2/interface/Window_internal.h @@ -32,6 +32,38 @@ struct RCTObjectEntry; namespace OpenRCT2 { + // TODO: move to Viewport.h? + struct Focus + { + using CoordinateFocus = CoordsXYZ; + using EntityFocus = EntityId; + + ZoomLevel zoom{}; + std::variant data; + + template + constexpr explicit Focus(T newValue, ZoomLevel newZoom = {}) + { + data = newValue; + zoom = newZoom; + } + + CoordsXYZ GetPos() const; + + constexpr bool operator==(const Focus& other) const + { + if (zoom != other.zoom) + { + return false; + } + return data == other.data; + } + constexpr bool operator!=(const Focus& other) const + { + return !(*this == other); + } + }; + /** * Window structure * size: 0x4C0