Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve financial and park history graphs #22414

Merged
merged 7 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions distribution/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
0.4.14 (in development)
------------------------------------------------------------------------
- Feature: [#15750] Allow using different types of park entrance in one park.
- Feature: [#22414] Finance graphs can be resized.
- Change: [#21659] Increase the Hybrid Roller Coaster’s maximum lift speed to 17 km/h (11 mph).
- Change: [#22466] The Clear Scenery tool now uses a bulldozer cursor instead of a generic crosshair.
- Fix: [#22307] Hover tooltips in financial charts are not invalidated properly.
- Fix: [#22395, #22396] Misaligned tick marks in financial and guest count graphs (original bug).

0.4.13 (2024-08-04)
------------------------------------------------------------------------
Expand Down
339 changes: 123 additions & 216 deletions src/openrct2-ui/interface/Graph.cpp

Large diffs are not rendered by default.

56 changes: 52 additions & 4 deletions src/openrct2-ui/interface/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,62 @@

#pragma once

#include <openrct2/Context.h>
#include <openrct2/core/Money.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/world/Location.hpp>

namespace OpenRCT2::Graph
{
void Draw(DrawPixelInfo& dpi, uint8_t* history, int32_t count, const ScreenCoordsXY& screenPos);
void Draw(
DrawPixelInfo& dpi, const money64* history, const int32_t count, const ScreenCoordsXY& coords, const int32_t modifier,
const int32_t offset);
template<typename T> struct GraphProperties
{
ScreenRect internalBounds;
const T* series;
T min;
T max;
int32_t hoverIdx;
int32_t numPoints;
int32_t numYLabels;
int32_t xStepPx;
int32_t yLabelStepPx;
ColourWithFlags lineCol;

void RecalculateLayout(const ScreenRect newBounds, const int32_t newNumYLabels, const int32_t newNumPoints)
{
yLabelStepPx = (newBounds.GetBottom() - newBounds.GetTop()) / (newNumYLabels - 1);
xStepPx = (newBounds.GetRight() - newBounds.GetLeft()) / (newNumPoints - 1);
// adjust bounds to be exact multiples of the steps.
internalBounds = { newBounds.Point1,
newBounds.Point1
+ ScreenCoordsXY{ xStepPx * (newNumPoints - 1), yLabelStepPx * (newNumYLabels - 1) } };
numPoints = newNumPoints;
numYLabels = newNumYLabels;
}

bool UpdateHoverIndex()
{
const ScreenCoordsXY cursorPos = ContextGetCursorPositionScaled();

int32_t i = -1;
if (internalBounds.Contains(cursorPos))
{
i = (numPoints - 1) - (cursorPos.x - internalBounds.GetLeft() + (xStepPx / 2)) / xStepPx;
if (i < 0)
i = 1;
if (i > numPoints - 1)
i = numPoints - 1;
}

if (hoverIdx != i)
{
hoverIdx = i;
return true;
}
return false;
}
};

void DrawFinanceGraph(DrawPixelInfo& dpi, const GraphProperties<money64>& p);
void DrawRatingGraph(DrawPixelInfo& dpi, const GraphProperties<uint8_t>& p);
void DrawGuestGraph(DrawPixelInfo& dpi, const GraphProperties<uint32_t>& p);
} // namespace OpenRCT2::Graph
Loading
Loading