From 28bfab0c9b40383527a7b2b51dcfcdd2a27c9150 Mon Sep 17 00:00:00 2001 From: wolfreak99 Date: Fri, 22 Jun 2018 13:20:27 -0400 Subject: [PATCH 1/2] Draw dangerous G forces on graph in red --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/Ride.cpp | 54 +++++++++++++++++++++++++++++--- src/openrct2/interface/Colour.h | 1 + 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 382077c178..ebb0a41f35 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -2,6 +2,7 @@ ------------------------------------------------------------------------ - Feature: [#7956, #7964] Add sprite font glyphs for Hungarian and some Czech letters. - Fix: [#7975] Inspection flag not cleared for rides which are set to never be inspected (Original bug). +- Improved: [#7730] Draw extreme vertical and lateral Gs red in the ride window's graph tab. - Improved: [#7930] Automatically create folders for custom content. - Removed: [#7929] Support for scenario text objects. diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 4c182367b8..4464fd18e3 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -1202,6 +1202,10 @@ static constexpr const rct_window_graphs_y_axis window_graphs_y_axi[] = { { 13, -4, 1, STR_RIDE_STATS_G_FORCE_FORMAT }, // GRAPH_LATERAL }; +static constexpr auto RIDE_G_FORCES_RED_POS_VERTICAL = FIXED_2DP(5, 00); +static constexpr auto RIDE_G_FORCES_RED_NEG_VERTICAL = -FIXED_2DP(2, 00); +static constexpr auto RIDE_G_FORCES_RED_LATERAL = FIXED_2DP(2, 80); + // Used for sorting the ride type cheat dropdown. struct RideTypeLabel { @@ -5595,21 +5599,21 @@ static void window_ride_measurements_paint(rct_window* w, rct_drawpixelinfo* dpi { // Max. positive vertical G's maxPositiveVerticalGs = ride->max_positive_vertical_g; - stringId = maxPositiveVerticalGs >= FIXED_2DP(5, 00) ? STR_MAX_POSITIVE_VERTICAL_G_RED - : STR_MAX_POSITIVE_VERTICAL_G; + stringId = maxPositiveVerticalGs >= RIDE_G_FORCES_RED_POS_VERTICAL ? STR_MAX_POSITIVE_VERTICAL_G_RED + : STR_MAX_POSITIVE_VERTICAL_G; gfx_draw_string_left(dpi, stringId, &maxPositiveVerticalGs, COLOUR_BLACK, x, y); y += LIST_ROW_HEIGHT; // Max. negative vertical G's maxNegativeVerticalGs = ride->max_negative_vertical_g; - stringId = maxNegativeVerticalGs <= -FIXED_2DP(2, 00) ? STR_MAX_NEGATIVE_VERTICAL_G_RED - : STR_MAX_NEGATIVE_VERTICAL_G; + stringId = maxNegativeVerticalGs <= RIDE_G_FORCES_RED_NEG_VERTICAL ? STR_MAX_NEGATIVE_VERTICAL_G_RED + : STR_MAX_NEGATIVE_VERTICAL_G; gfx_draw_string_left(dpi, stringId, &maxNegativeVerticalGs, COLOUR_BLACK, x, y); y += LIST_ROW_HEIGHT; // Max lateral G's maxLateralGs = ride->max_lateral_g; - stringId = maxLateralGs >= FIXED_2DP(2, 80) ? STR_MAX_LATERAL_G_RED : STR_MAX_LATERAL_G; + stringId = maxLateralGs >= RIDE_G_FORCES_RED_LATERAL ? STR_MAX_LATERAL_G_RED : STR_MAX_LATERAL_G; gfx_draw_string_left(dpi, stringId, &maxLateralGs, COLOUR_BLACK, x, y); y += LIST_ROW_HEIGHT; @@ -5974,6 +5978,9 @@ static void window_ride_graphs_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi // Plot int32_t x = dpi->x; int32_t top, bottom; + // Uses the limits (used to draw high forces in red on measurement tab) to determine if line should be drawn red. + // By default they are kept 0 unless the graph type supports it. + int32_t intensityThresholdPositive = 0, intensityThresholdNegative = 0; for (int32_t width = 0; width < dpi->width; width++, x++) { if (x < 0 || x >= measurement->num_items - 1) @@ -5992,25 +5999,62 @@ static void window_ride_graphs_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi case GRAPH_VERTICAL: top = measurement->vertical[x] + 39; bottom = measurement->vertical[x + 1] + 39; + intensityThresholdPositive = (RIDE_G_FORCES_RED_POS_VERTICAL / 8) + 39; + intensityThresholdNegative = (RIDE_G_FORCES_RED_NEG_VERTICAL / 8) + 39; break; case GRAPH_LATERAL: top = measurement->lateral[x] + 52; bottom = measurement->lateral[x + 1] + 52; + intensityThresholdPositive = (RIDE_G_FORCES_RED_LATERAL / 8) + 52; + intensityThresholdNegative = -(RIDE_G_FORCES_RED_LATERAL / 8) + 52; break; default: log_error("Wrong graph type %d", listType); top = bottom = 0; } + // Adjust line to match graph widget position. top = widget->bottom - widget->top - top - 13; bottom = widget->bottom - widget->top - bottom - 13; + + // If red threshold is supported, adjust threshold line position as well. Otherwise, keep 0. + if (intensityThresholdPositive != 0 && intensityThresholdNegative != 0) + { + intensityThresholdPositive = widget->bottom - widget->top - intensityThresholdPositive - 13; + intensityThresholdNegative = widget->bottom - widget->top - intensityThresholdNegative - 13; + } + + // Line is drawn from top to bottom. if (top > bottom) { int32_t tmp = top; top = bottom; bottom = tmp; } + + // Draw the current line in gray. gfx_fill_rect(dpi, x, top, x, bottom, x > measurement->current_item ? PALETTE_INDEX_17 : PALETTE_INDEX_21); + + // Draw red over extreme values (if supported by graph type). + if (intensityThresholdPositive != 0 && intensityThresholdNegative != 0) + { + // If line exceeds negative threshold (at bottom of graph). + if (top >= intensityThresholdNegative || bottom >= intensityThresholdNegative) + { + gfx_fill_rect( + dpi, x, top >= intensityThresholdNegative ? top : intensityThresholdNegative, x, + bottom >= intensityThresholdNegative ? bottom : intensityThresholdNegative, + x > measurement->current_item ? PALETTE_INDEX_171 : PALETTE_INDEX_173); + } + // If line exceeds positive threshold (at top of graph). + if (top <= intensityThresholdPositive || bottom <= intensityThresholdPositive) + { + gfx_fill_rect( + dpi, x, top <= intensityThresholdPositive ? top : intensityThresholdPositive, x, + bottom <= intensityThresholdPositive ? bottom : intensityThresholdPositive, + x > measurement->current_item ? PALETTE_INDEX_171 : PALETTE_INDEX_173); + } + } } } diff --git a/src/openrct2/interface/Colour.h b/src/openrct2/interface/Colour.h index a8c8f874bc..2364d4302c 100644 --- a/src/openrct2/interface/Colour.h +++ b/src/openrct2/interface/Colour.h @@ -97,6 +97,7 @@ enum PALETTE_INDEX_162 = 162, // PALETTE_INDEX_171 = 171, // Saturated Red (lightest) Bright Red (middark) PALETTE_INDEX_172 = 172, // Saturated Red (10-11), Bright Red (midlight) + PALETTE_INDEX_173 = 173, // Used to draw intense lines in the Ride Graphs window PALETTE_INDEX_183 = 183, // Used to draw rides in the Map window PALETTE_INDEX_186 = 186, // PALETTE_INDEX_194 = 194, // From 64c52fa796573958e176ae5e1a40eae485ab7bca Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Sat, 8 Sep 2018 23:34:05 +0200 Subject: [PATCH 2/2] Improve readability --- src/openrct2-ui/windows/Ride.cpp | 52 ++++++++++++++++---------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 4464fd18e3..d77cafd0f3 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -5978,9 +5978,9 @@ static void window_ride_graphs_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi // Plot int32_t x = dpi->x; int32_t top, bottom; - // Uses the limits (used to draw high forces in red on measurement tab) to determine if line should be drawn red. - // By default they are kept 0 unless the graph type supports it. - int32_t intensityThresholdPositive = 0, intensityThresholdNegative = 0; + // Uses the force limits (used to draw extreme G's in red on measurement tab) to determine if line should be drawn red. + int32_t intensityThresholdPositive = 0; + int32_t intensityThresholdNegative = 0; for (int32_t width = 0; width < dpi->width; width++, x++) { if (x < 0 || x >= measurement->num_items - 1) @@ -6011,48 +6011,48 @@ static void window_ride_graphs_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi default: log_error("Wrong graph type %d", listType); top = bottom = 0; + break; } // Adjust line to match graph widget position. top = widget->bottom - widget->top - top - 13; bottom = widget->bottom - widget->top - bottom - 13; + if (top > bottom) + { + std::swap(top, bottom); + } - // If red threshold is supported, adjust threshold line position as well. Otherwise, keep 0. - if (intensityThresholdPositive != 0 && intensityThresholdNegative != 0) + // Adjust threshold line position as well + if (listType == GRAPH_VERTICAL || listType == GRAPH_LATERAL) { intensityThresholdPositive = widget->bottom - widget->top - intensityThresholdPositive - 13; intensityThresholdNegative = widget->bottom - widget->top - intensityThresholdNegative - 13; } - // Line is drawn from top to bottom. - if (top > bottom) - { - int32_t tmp = top; - top = bottom; - bottom = tmp; - } + const bool previousMeasurement = x > measurement->current_item; // Draw the current line in gray. - gfx_fill_rect(dpi, x, top, x, bottom, x > measurement->current_item ? PALETTE_INDEX_17 : PALETTE_INDEX_21); + gfx_fill_rect(dpi, x, top, x, bottom, previousMeasurement ? PALETTE_INDEX_17 : PALETTE_INDEX_21); // Draw red over extreme values (if supported by graph type). - if (intensityThresholdPositive != 0 && intensityThresholdNegative != 0) + if (listType == GRAPH_VERTICAL || listType == GRAPH_LATERAL) { - // If line exceeds negative threshold (at bottom of graph). - if (top >= intensityThresholdNegative || bottom >= intensityThresholdNegative) + const auto redLineColour = previousMeasurement ? PALETTE_INDEX_171 : PALETTE_INDEX_173; + + // Line exceeds negative threshold (at bottom of graph). + if (bottom >= intensityThresholdNegative) { - gfx_fill_rect( - dpi, x, top >= intensityThresholdNegative ? top : intensityThresholdNegative, x, - bottom >= intensityThresholdNegative ? bottom : intensityThresholdNegative, - x > measurement->current_item ? PALETTE_INDEX_171 : PALETTE_INDEX_173); + const auto redLineTop = std::max(top, intensityThresholdNegative); + const auto redLineBottom = std::max(bottom, intensityThresholdNegative); + gfx_fill_rect(dpi, x, redLineTop, x, redLineBottom, redLineColour); } - // If line exceeds positive threshold (at top of graph). - if (top <= intensityThresholdPositive || bottom <= intensityThresholdPositive) + + // Line exceeds positive threshold (at top of graph). + if (top <= intensityThresholdPositive) { - gfx_fill_rect( - dpi, x, top <= intensityThresholdPositive ? top : intensityThresholdPositive, x, - bottom <= intensityThresholdPositive ? bottom : intensityThresholdPositive, - x > measurement->current_item ? PALETTE_INDEX_171 : PALETTE_INDEX_173); + const auto redLineTop = std::min(top, intensityThresholdPositive); + const auto redLineBottom = std::min(bottom, intensityThresholdPositive); + gfx_fill_rect(dpi, x, redLineTop, x, redLineBottom, redLineColour); } } }