Files
OpenRCT2-Web/src/openrct2-ui/interface/Graph.cpp
T

175 lines
5.8 KiB
C++
Raw Normal View History

/*****************************************************************************
2018-06-15 14:07:34 +02:00
* Copyright (c) 2014-2018 OpenRCT2 developers
*
2018-06-15 14:07:34 +02:00
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2018-01-06 18:32:25 +01:00
#include <openrct2/localisation/Date.h>
#include <openrct2/localisation/Localisation.h>
2017-12-07 02:47:26 +01:00
#include <openrct2-ui/interface/Graph.h>
2018-05-08 09:20:13 +02:00
static void graph_draw_months_uint8(rct_drawpixelinfo * dpi, const uint8 * history, sint32 count, sint32 baseX, sint32 baseY)
{
2017-06-06 23:24:18 +02:00
sint32 i, x, y, yearOver32, currentMonth, currentDay;
2017-06-06 23:24:18 +02:00
currentMonth = date_get_month(gDateMonthsElapsed);
currentDay = gDateMonthTicks;
yearOver32 = (currentMonth * 4) + (currentDay >> 14) - 31;
x = baseX;
y = baseY;
2018-05-08 09:20:13 +02:00
for (i = count - 1; i >= 0; i--)
{
if (history[i] != 255 && yearOver32 % 4 == 0)
{
2017-06-06 23:24:18 +02:00
// Draw month text
2018-04-29 20:46:46 +02:00
set_format_arg(0, uint32, DateGameShortMonthNames[date_get_month((yearOver32 / 4) + MONTH_COUNT)]);
2017-06-06 23:24:18 +02:00
gfx_draw_string_centred(dpi, STR_GRAPH_LABEL, x, y - 10, COLOUR_BLACK, gCommonFormatArgs);
2017-06-06 23:24:18 +02:00
// Draw month mark
gfx_fill_rect(dpi, x, y, x, y + 3, PALETTE_INDEX_10);
}
2017-06-06 23:24:18 +02:00
yearOver32 = (yearOver32 + 1) % 32;
x += 6;
}
}
2018-05-08 09:20:13 +02:00
static void graph_draw_line_a_uint8(rct_drawpixelinfo * dpi, const uint8 * history, sint32 count, sint32 baseX, sint32 baseY)
{
2017-06-06 23:24:18 +02:00
sint32 i, x, y, lastX, lastY;
lastX = -1;
lastY = -1;
x = baseX;
2018-05-08 09:20:13 +02:00
for (i = count - 1; i >= 0; i--)
{
if (history[i] != 255)
{
2017-06-06 23:24:18 +02:00
y = baseY + ((255 - history[i]) * 100) / 256;
2018-05-08 09:20:13 +02:00
if (lastX != -1)
{
2017-06-06 23:24:18 +02:00
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);
}
if (i == 0)
gfx_fill_rect(dpi, x, y, x + 2, y + 2, PALETTE_INDEX_10);
2017-06-06 23:24:18 +02:00
lastX = x;
lastY = y;
}
x += 6;
}
}
2018-05-08 09:20:13 +02:00
static void graph_draw_line_b_uint8(rct_drawpixelinfo * dpi, const uint8 * history, sint32 count, sint32 baseX, sint32 baseY)
{
2017-06-06 23:24:18 +02:00
sint32 i, x, y, lastX, lastY;
2017-06-06 23:24:18 +02:00
lastX = -1;
lastY = -1;
x = baseX;
2018-05-08 09:20:13 +02:00
for (i = count - 1; i >= 0; i--)
{
if (history[i] != 255)
{
2017-06-06 23:24:18 +02:00
y = baseY + ((255 - history[i]) * 100) / 256;
2017-06-06 23:24:18 +02:00
if (lastX != -1)
gfx_draw_line(dpi, lastX, lastY, x, y, PALETTE_INDEX_21);
if (i == 0)
gfx_fill_rect(dpi, x - 1, y - 1, x + 1, y + 1, PALETTE_INDEX_21);
2017-06-06 23:24:18 +02:00
lastX = x;
lastY = y;
}
x += 6;
}
}
2018-05-08 09:20:13 +02:00
void graph_draw_uint8(rct_drawpixelinfo * dpi, uint8 * history, sint32 count, sint32 baseX, sint32 baseY)
{
2017-06-06 23:24:18 +02:00
graph_draw_months_uint8(dpi, history, count, baseX, baseY);
graph_draw_line_a_uint8(dpi, history, count, baseX, baseY);
graph_draw_line_b_uint8(dpi, history, count, baseX, baseY);
}
2018-01-10 23:23:11 +01:00
static void graph_draw_months_money32(rct_drawpixelinfo *dpi, const money32 *history, sint32 count, sint32 baseX, sint32 baseY)
{
2017-06-06 23:24:18 +02:00
sint32 i, x, y, yearOver32, currentMonth, currentDay;
2017-06-06 23:24:18 +02:00
currentMonth = date_get_month(gDateMonthsElapsed);
currentDay = gDateMonthTicks;
yearOver32 = (currentMonth * 4) + (currentDay >> 14) - 31;
x = baseX;
y = baseY;
for (i = count - 1; i >= 0; i--) {
2017-12-07 02:40:09 +01:00
if (history[i] != MONEY32_UNDEFINED && yearOver32 % 4 == 0) {
2017-06-06 23:24:18 +02:00
// Draw month text
2018-04-29 20:46:46 +02:00
sint32 monthFormat = DateGameShortMonthNames[date_get_month((yearOver32 / 4) + MONTH_COUNT)];
2017-06-06 23:24:18 +02:00
gfx_draw_string_centred(dpi, STR_GRAPH_LABEL, x, y - 10, COLOUR_BLACK, &monthFormat);
2017-06-06 23:24:18 +02:00
// Draw month mark
gfx_fill_rect(dpi, x, y, x, y + 3, PALETTE_INDEX_10);
}
2017-06-06 23:24:18 +02:00
yearOver32 = (yearOver32 + 1) % 32;
x += 6;
}
}
2018-01-10 23:23:11 +01:00
static void graph_draw_line_a_money32(rct_drawpixelinfo *dpi, const money32 *history, sint32 count, sint32 baseX, sint32 baseY, sint32 modifier, sint32 offset)
{
2017-06-06 23:24:18 +02:00
sint32 i, x, y, lastX, lastY;
lastX = -1;
lastY = -1;
x = baseX;
for (i = count - 1; i >= 0; i--) {
2017-12-07 02:40:09 +01:00
if (history[i] != MONEY32_UNDEFINED) {
2017-06-06 23:24:18 +02:00
y = baseY + 170 - 6 - ((((history[i] >> modifier) + offset) * 170) / 256);
2017-06-06 23:24:18 +02:00
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);
}
if (i == 0)
gfx_fill_rect(dpi, x, y, x + 2, y + 2, PALETTE_INDEX_10);
2017-06-06 23:24:18 +02:00
lastX = x;
lastY = y;
}
x += 6;
}
}
2018-01-10 23:23:11 +01:00
static void graph_draw_line_b_money32(rct_drawpixelinfo *dpi, const money32 *history, sint32 count, sint32 baseX, sint32 baseY, sint32 modifier, sint32 offset)
{
2017-06-06 23:24:18 +02:00
sint32 i, x, y, lastX, lastY;
2017-06-06 23:24:18 +02:00
lastX = -1;
lastY = -1;
x = baseX;
for (i = count - 1; i >= 0; i--) {
2017-12-07 02:40:09 +01:00
if (history[i] != MONEY32_UNDEFINED) {
2017-06-06 23:24:18 +02:00
y = baseY + 170 - 6 - ((((history[i] >> modifier) + offset) * 170) / 256);
2017-06-06 23:24:18 +02:00
if (lastX != -1)
gfx_draw_line(dpi, lastX, lastY, x, y, PALETTE_INDEX_21);
if (i == 0)
gfx_fill_rect(dpi, x - 1, y - 1, x + 1, y + 1, PALETTE_INDEX_21);
2017-06-06 23:24:18 +02:00
lastX = x;
lastY = y;
}
x += 6;
}
}
2017-01-04 22:17:08 +01:00
void graph_draw_money32(rct_drawpixelinfo *dpi, money32 *history, sint32 count, sint32 baseX, sint32 baseY, sint32 modifier, sint32 offset)
{
2017-06-06 23:24:18 +02:00
graph_draw_months_money32(dpi, history, count, baseX, baseY);
graph_draw_line_a_money32(dpi, history, count, baseX, baseY, modifier, offset);
graph_draw_line_b_money32(dpi, history, count, baseX, baseY, modifier, offset);
2015-12-20 22:03:37 -06:00
}