Skip to content

Commit

Permalink
Merge pull request OpenRCT2#22414 from mrmbernardi/fix-graphs
Browse files Browse the repository at this point in the history
Improve financial and park history graphs
  • Loading branch information
mrmbernardi authored Aug 5, 2024
2 parents 03bc1e5 + 380cdb0 commit 0e1ba1c
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 490 deletions.
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

0 comments on commit 0e1ba1c

Please sign in to comment.