From 75774837f1e80211ab887015b282adf1e3a1413b Mon Sep 17 00:00:00 2001 From: Richard Wheeler <2762690+zephyris@users.noreply.github.com> Date: Mon, 19 Feb 2024 20:09:27 +0000 Subject: [PATCH] Fix: Scale graph gridlines and axes with GUI scale --- src/graph_gui.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index da5ba21c53..9cdfe6ec3e 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -347,18 +347,19 @@ protected: /* Draw the background of the graph itself. */ GfxFillRect(r.left, r.top, r.right, r.bottom, GRAPH_BASE_COLOUR); - /* Draw the vertical grid lines. */ + /* Draw the grid lines. */ + int gridline_width = WidgetDimensions::scaled.bevel.top; + int grid_colour = GRAPH_GRID_COLOUR; - /* Don't draw the first line, as that's where the axis will be. */ + /* Draw the vertical grid lines, skipping the first as that's where the axis will be. */ x = r.left + x_sep; - int grid_colour = GRAPH_GRID_COLOUR; for (int i = 1; i < this->num_vert_lines + 1; i++) { /* If using wallclock units, we separate periods with a lighter line. */ if (TimerGameEconomy::UsingWallclockUnits()) { grid_colour = (i % 4 == 0) ? GRAPH_YEAR_LINE_COLOUR : GRAPH_GRID_COLOUR; } - GfxFillRect(x, r.top, x, r.bottom, grid_colour); + GfxFillRect(x, r.top, x + gridline_width - 1, r.bottom, grid_colour); x += x_sep; } @@ -366,17 +367,17 @@ protected: y = r.bottom; for (int i = 0; i < (num_hori_lines + 1); i++) { - GfxFillRect(r.left - ScaleGUITrad(3), y, r.left - 1, y, GRAPH_AXIS_LINE_COLOUR); - GfxFillRect(r.left, y, r.right, y, GRAPH_GRID_COLOUR); + GfxFillRect(r.left - ScaleGUITrad(3), y, r.left - 1, y + gridline_width - 1, GRAPH_AXIS_LINE_COLOUR); + GfxFillRect(r.left, y, r.right + gridline_width - 1, y + gridline_width - 1, GRAPH_GRID_COLOUR); y -= y_sep; } /* Draw the y axis. */ - GfxFillRect(r.left, r.top, r.left, r.bottom, GRAPH_AXIS_LINE_COLOUR); + GfxFillRect(r.left, r.top, r.left + gridline_width - 1, r.bottom + gridline_width - 1, GRAPH_AXIS_LINE_COLOUR); /* Draw the x axis. */ y = x_axis_offset + r.top; - GfxFillRect(r.left, y, r.right, y, GRAPH_ZERO_LINE_COLOUR); + GfxFillRect(r.left, y, r.right + gridline_width - 1, y + gridline_width - 1, GRAPH_ZERO_LINE_COLOUR); /* Find the largest value that will be drawn. */ if (this->num_on_x_axis == 0) return; @@ -415,7 +416,7 @@ protected: year++; /* Draw a lighter grid line between years. Top and bottom adjustments ensure we don't draw over top and bottom horizontal grid lines. */ - GfxFillRect(x + x_sep, r.top + 1, x + x_sep, r.bottom - 1, GRAPH_YEAR_LINE_COLOUR); + GfxFillRect(x + x_sep, r.top + gridline_width, x + x_sep + gridline_width - 1, r.bottom - 1, GRAPH_YEAR_LINE_COLOUR); } x += x_sep; } @@ -434,10 +435,11 @@ protected: } } - /* draw lines and dots */ - uint linewidth = _settings_client.gui.graph_line_thickness; - uint pointoffs1 = (linewidth + 1) / 2; - uint pointoffs2 = linewidth + 1 - pointoffs1; + /* Draw lines and dots. */ + uint linewidth = ScaleGUITrad(_settings_client.gui.graph_line_thickness); + uint pointwidth = ScaleGUITrad(_settings_client.gui.graph_line_thickness + 1); + uint pointoffs1 = pointwidth / 2; + uint pointoffs2 = pointwidth - pointoffs1; for (int i = 0; i < this->num_dataset; i++) { if (!HasBit(this->excluded_data, i)) { /* Centre the dot between the grid lines. */