From e6ef627fe213f9c609c417f10dc30cf6bed3cd94 Mon Sep 17 00:00:00 2001 From: Olivier Wervers Date: Tue, 8 May 2018 09:20:13 +0200 Subject: [PATCH] Fix graphs skipping values of 0 --- distribution/changelog.txt | 1 + src/openrct2-ui/interface/Graph.cpp | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 89600ff280..9ee540d706 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -21,6 +21,7 @@ - Fix: [#7402] Edges of neigbouring footpaths stay connected after removing a path that's underneath a ride entrance. - Fix: [#7405] Rides can be covered by placing scenery underneath them. - Fix: [#7436] Only the first 32 vehicles of a train can be painted. +- Fix: [#7480] Graphs skip values of 0. - Fix: Cut-away view does not draw tile elements that have been moved down on the list. - Improved: [#2989] Multiplayer window now changes title when tab changes. - Improved: [#5339] Change eyedropper icon to actual eyedropper and change cursor to crosshair. diff --git a/src/openrct2-ui/interface/Graph.cpp b/src/openrct2-ui/interface/Graph.cpp index bc64882787..480a66cb62 100644 --- a/src/openrct2-ui/interface/Graph.cpp +++ b/src/openrct2-ui/interface/Graph.cpp @@ -18,7 +18,7 @@ #include #include -static void graph_draw_months_uint8(rct_drawpixelinfo *dpi, const uint8 *history, sint32 count, sint32 baseX, sint32 baseY) +static void graph_draw_months_uint8(rct_drawpixelinfo * dpi, const uint8 * history, sint32 count, sint32 baseX, sint32 baseY) { sint32 i, x, y, yearOver32, currentMonth, currentDay; @@ -27,8 +27,10 @@ static void graph_draw_months_uint8(rct_drawpixelinfo *dpi, const uint8 *history yearOver32 = (currentMonth * 4) + (currentDay >> 14) - 31; x = baseX; y = baseY; - for (i = count - 1; i >= 0; i--) { - if (history[i] != 0 && history[i] != 255 && yearOver32 % 4 == 0) { + for (i = count - 1; i >= 0; i--) + { + if (history[i] != 255 && yearOver32 % 4 == 0) + { // Draw month text set_format_arg(0, uint32, DateGameShortMonthNames[date_get_month((yearOver32 / 4) + MONTH_COUNT)]); gfx_draw_string_centred(dpi, STR_GRAPH_LABEL, x, y - 10, COLOUR_BLACK, gCommonFormatArgs); @@ -42,17 +44,20 @@ static void graph_draw_months_uint8(rct_drawpixelinfo *dpi, const uint8 *history } } -static void graph_draw_line_a_uint8(rct_drawpixelinfo *dpi, const uint8 *history, sint32 count, sint32 baseX, sint32 baseY) +static void graph_draw_line_a_uint8(rct_drawpixelinfo * dpi, const uint8 * history, sint32 count, sint32 baseX, sint32 baseY) { sint32 i, x, y, lastX, lastY; lastX = -1; lastY = -1; x = baseX; - for (i = count - 1; i >= 0; i--) { - if (history[i] != 0 && history[i] != 255) { + for (i = count - 1; i >= 0; i--) + { + if (history[i] != 255) + { y = baseY + ((255 - history[i]) * 100) / 256; - if (lastX != -1) { + if (lastX != -1) + { gfx_draw_line(dpi, lastX + 1, lastY + 1, x + 1, y + 1, PALETTE_INDEX_10); gfx_draw_line(dpi, lastX, lastY + 1, x, y + 1, PALETTE_INDEX_10); } @@ -66,15 +71,17 @@ static void graph_draw_line_a_uint8(rct_drawpixelinfo *dpi, const uint8 *history } } -static void graph_draw_line_b_uint8(rct_drawpixelinfo *dpi, const uint8 *history, sint32 count, sint32 baseX, sint32 baseY) +static void graph_draw_line_b_uint8(rct_drawpixelinfo * dpi, const uint8 * history, sint32 count, sint32 baseX, sint32 baseY) { sint32 i, x, y, lastX, lastY; lastX = -1; lastY = -1; x = baseX; - for (i = count - 1; i >= 0; i--) { - if (history[i] != 0 && history[i] != 255) { + for (i = count - 1; i >= 0; i--) + { + if (history[i] != 255) + { y = baseY + ((255 - history[i]) * 100) / 256; if (lastX != -1) @@ -89,7 +96,7 @@ static void graph_draw_line_b_uint8(rct_drawpixelinfo *dpi, const uint8 *history } } -void graph_draw_uint8(rct_drawpixelinfo *dpi, uint8 *history, sint32 count, sint32 baseX, sint32 baseY) +void graph_draw_uint8(rct_drawpixelinfo * dpi, uint8 * history, sint32 count, sint32 baseX, sint32 baseY) { graph_draw_months_uint8(dpi, history, count, baseX, baseY); graph_draw_line_a_uint8(dpi, history, count, baseX, baseY);