Move Viewport struct to Viewport.h

This commit is contained in:
Aaron van Geffen committed 2025-01-24 22:44:21 +01:00
1 parent e3929c1ca9
commit c8da126c95
6 files changed
+79 -76

No files matched your search

+1
View File
@@ -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"
@@ -20,6 +20,7 @@
#include <openrct2/core/UTF8.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/interface/Colour.h>
#include <openrct2/interface/Viewport.h>
#include <openrct2/interface/Window.h>
#include <openrct2/localisation/Language.h>
#include <openrct2/localisation/LocalisationService.h>
@@ -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"
+43
View File
@@ -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
+1 -76
View File
@@ -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<CoordinateFocus, EntityFocus> data;
template<typename T>
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)
+32
View File
@@ -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<CoordinateFocus, EntityFocus> data;
template<typename T>
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