OpenTTD Source: src/graph_gui.cpp File Reference

OpenTTD Source 14.0-RC3

Data Structures | Functions | Variables
graph_gui.cpp File Reference
`#include "stdafx.h"`
`#include "graph_gui.h"`
`#include "window_gui.h"`
`#include "company_base.h"`
`#include "company_gui.h"`
`#include "economy_func.h"`
`#include "cargotype.h"`
`#include "strings_func.h"`
`#include "window_func.h"`
`#include "gfx_func.h"`
`#include "core/geometry_func.hpp"`
`#include "currency.h"`
`#include "timer/timer.h"`
`#include "timer/timer_window.h"`
`#include "timer/timer_game_tick.h"`
`#include "timer/timer_game_calendar.h"`
`#include "timer/timer_game_economy.h"`
`#include "zoom_func.h"`
`#include "widgets/graph_widget.h"`
`#include "table/strings.h"`
`#include "table/sprites.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | GraphLegendWindow
struct | ValuesInterval
| Contains the interval of a graph's data. More...
struct | BaseGraphWindow
struct | OperatingProfitGraphWindow
struct | IncomeGraphWindow
struct | DeliveredCargoGraphWindow
struct | PerformanceHistoryGraphWindow
struct | CompanyValueGraphWindow
struct | PaymentRatesGraphWindow
struct | PerformanceRatingDetailWindow

## Functions
static std::unique_ptr< NWidgetBase > | MakeNWidgetCompanyLines ()
| Construct a vertical list of buttons, one for each company. More...
static void | ShowGraphLegend ()
void | ShowOperatingProfitGraph ()
void | ShowIncomeGraph ()
void | ShowDeliveredCargoGraph ()
void | ShowPerformanceHistoryGraph ()
void | ShowCompanyValueGraph ()
void | ShowCargoPaymentRates ()
static std::unique_ptr< NWidgetBase > | MakePerformanceDetailPanels ()
| Make a vertical list of panels for outputting score details. More...
std::unique_ptr< NWidgetBase > | MakeCompanyButtonRowsGraphGUI ()
| Make a number of rows with buttons for each company for the performance rating detail window.
void | ShowPerformanceRatingDetail ()
void | InitializeGraphGui ()

## Variables
static CompanyMask | _legend_excluded_companies
static CargoTypes | _legend_excluded_cargo
static const OverflowSafeInt64 | INVALID_DATAPOINT (INT64_MAX)
static const uint | INVALID_DATAPOINT_POS = UINT_MAX
constexpr double | INT64_MAX_IN_DOUBLE = static_cast<double>(INT64_MAX - 512)
| The biggest double that when cast to int64_t still fits in a int64_t.
static constexpr NWidgetPart | _nested_graph_legend_widgets []
static WindowDesc | _graph_legend_desc (__FILE__, __LINE__, WDP_AUTO, "graph_legend", 0, 0, WC_GRAPH_LEGEND, WC_NONE, 0, std::begin(_nested_graph_legend_widgets), std::end(_nested_graph_legend_widgets))
static constexpr NWidgetPart | _nested_operating_profit_widgets []
static WindowDesc | _operating_profit_desc (__FILE__, __LINE__, WDP_AUTO, "graph_operating_profit", 0, 0, WC_OPERATING_PROFIT, WC_NONE, 0, std::begin(_nested_operating_profit_widgets), std::end(_nested_operating_profit_widgets))
static constexpr NWidgetPart | _nested_income_graph_widgets []
static WindowDesc | _income_graph_desc (__FILE__, __LINE__, WDP_AUTO, "graph_income", 0, 0, WC_INCOME_GRAPH, WC_NONE, 0, std::begin(_nested_income_graph_widgets), std::end(_nested_income_graph_widgets))
static constexpr NWidgetPart | _nested_delivered_cargo_graph_widgets []
static WindowDesc | _delivered_cargo_graph_desc (__FILE__, __LINE__, WDP_AUTO, "graph_delivered_cargo", 0, 0, WC_DELIVERED_CARGO, WC_NONE, 0, std::begin(_nested_delivered_cargo_graph_widgets), std::end(_nested_delivered_cargo_graph_widgets))
static constexpr NWidgetPart | _nested_performance_history_widgets []
static WindowDesc | _performance_history_desc (__FILE__, __LINE__, WDP_AUTO, "graph_performance", 0, 0, WC_PERFORMANCE_HISTORY, WC_NONE, 0, std::begin(_nested_performance_history_widgets), std::end(_nested_performance_history_widgets))
static constexpr NWidgetPart | _nested_company_value_graph_widgets []
static WindowDesc | _company_value_graph_desc (__FILE__, __LINE__, WDP_AUTO, "graph_company_value", 0, 0, WC_COMPANY_VALUE, WC_NONE, 0, std::begin(_nested_company_value_graph_widgets), std::end(_nested_company_value_graph_widgets))
static constexpr NWidgetPart | _nested_cargo_payment_rates_widgets []
static WindowDesc | _cargo_payment_rates_desc (__FILE__, __LINE__, WDP_AUTO, "graph_cargo_payment_rates", 0, 0, WC_PAYMENT_RATES, WC_NONE, 0, std::begin(_nested_cargo_payment_rates_widgets), std::end(_nested_cargo_payment_rates_widgets))
static constexpr NWidgetPart | _nested_performance_rating_detail_widgets []
static WindowDesc | _performance_rating_detail_desc (__FILE__, __LINE__, WDP_AUTO, "league_details", 0, 0, WC_PERFORMANCE_DETAIL, WC_NONE, 0, std::begin(_nested_performance_rating_detail_widgets), std::end(_nested_performance_rating_detail_widgets))

## Detailed Description

GUI that shows performance graphs.

Definition in file graph_gui.cpp.

## Function Documentation

## ◆ MakeNWidgetCompanyLines()

static std::unique_ptr<NWidgetBase> MakeNWidgetCompanyLines | ( |  | ) |
| static

Construct a vertical list of buttons, one for each company.

Returns
  Panel with company buttons.

Definition at line 116 of file graph_gui.cpp.

References GetSpriteSize(), and NC_EQUALSIZE.

## ◆ MakePerformanceDetailPanels()

static std::unique_ptr<NWidgetBase> MakePerformanceDetailPanels | ( |  | ) |
| static

Make a vertical list of panels for outputting score details.

Returns
  Panel with performance details.

Definition at line 1418 of file graph_gui.cpp.

References lengthof, SCORE_END, and TimerGameEconomy::UsingWallclockUnits().

## Variable Documentation

## ◆ _nested_company_value_graph_widgets

constexpr NWidgetPart _nested_company_value_graph_widgets[]
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_COMPANY_VALUES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GRAPH_KEY_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_GRAPH_BACKGROUND),
NWidget(NWID_VERTICAL),
NWidget(WWT_EMPTY, COLOUR_BROWN, WID_GRAPH_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_BROWN, WID_GRAPH_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_EMPTY, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_GRAPH_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
EndContainer(),
}

Definition at line 910 of file graph_gui.cpp.

## ◆ _nested_delivered_cargo_graph_widgets

constexpr NWidgetPart _nested_delivered_cargo_graph_widgets[]
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_CARGO_DELIVERED_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GRAPH_KEY_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_GRAPH_BACKGROUND),
NWidget(NWID_VERTICAL),
NWidget(WWT_EMPTY, COLOUR_BROWN, WID_GRAPH_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_BROWN, WID_GRAPH_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_EMPTY, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_GRAPH_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
EndContainer(),
}

Definition at line 789 of file graph_gui.cpp.

## ◆ _nested_graph_legend_widgets

constexpr NWidgetPart _nested_graph_legend_widgets[]
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_KEY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_GL_BACKGROUND),
NWidgetFunction(MakeNWidgetCompanyLines),
EndContainer(),
}

Definition at line 133 of file graph_gui.cpp.

## ◆ _nested_income_graph_widgets

constexpr NWidgetPart _nested_income_graph_widgets[]
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_INCOME_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GRAPH_KEY_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_GRAPH_BACKGROUND),
NWidget(NWID_VERTICAL),
NWidget(WWT_EMPTY, COLOUR_BROWN, WID_GRAPH_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_BROWN, WID_GRAPH_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_EMPTY, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_GRAPH_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
EndContainer(),
}

Definition at line 732 of file graph_gui.cpp.

## ◆ _nested_operating_profit_widgets

constexpr NWidgetPart _nested_operating_profit_widgets[]
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_OPERATING_PROFIT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GRAPH_KEY_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_GRAPH_BACKGROUND),
NWidget(NWID_VERTICAL),
NWidget(WWT_EMPTY, COLOUR_BROWN, WID_GRAPH_GRAPH), SetMinimalSize(576, 160), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_BROWN, WID_GRAPH_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_EMPTY, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_GRAPH_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
EndContainer(),
}

Definition at line 673 of file graph_gui.cpp.

## ◆ _nested_performance_history_widgets

constexpr NWidgetPart _nested_performance_history_widgets[]
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_COMPANY_PERFORMANCE_RATINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_PHG_DETAILED_PERFORMANCE), SetMinimalSize(50, 0), SetDataTip(STR_PERFORMANCE_DETAIL_KEY, STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GRAPH_KEY_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_GRAPH_BACKGROUND),
NWidget(NWID_VERTICAL),
NWidget(WWT_EMPTY, COLOUR_BROWN, WID_GRAPH_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_BROWN, WID_GRAPH_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_EMPTY, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_GRAPH_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
EndContainer(),
}

Definition at line 852 of file graph_gui.cpp.

## ◆ _nested_performance_rating_detail_widgets

constexpr NWidgetPart _nested_performance_rating_detail_widgets[]
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_PERFORMANCE_DETAIL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN),
NWidgetFunction(MakeCompanyButtonRowsGraphGUI), SetPadding(2),
EndContainer(),
NWidgetFunction(MakePerformanceDetailPanels),
}

Definition at line 1452 of file graph_gui.cpp.

SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1143
MakeCompanyButtonRowsGraphGUI
std::unique_ptr< NWidgetBase > MakeCompanyButtonRowsGraphGUI()
Make a number of rows with buttons for each company for the performance rating detail window.
Definition: graph_gui.cpp:1447
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
RWV_HIDE_BEVEL
@ RWV_HIDE_BEVEL
Bevel of resize box is hidden.
Definition: widget_type.h:42
WID_GRAPH_KEY_BUTTON
@ WID_GRAPH_KEY_BUTTON
Key button.
Definition: graph_widget.h:26
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1153
WID_PHG_DETAILED_PERFORMANCE
@ WID_PHG_DETAILED_PERFORMANCE
Detailed performance.
Definition: graph_widget.h:33
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
NWidgetFunction
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1281
WID_GRAPH_GRAPH
@ WID_GRAPH_GRAPH
Graph itself.
Definition: graph_widget.h:28
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1190
WID_GRAPH_FOOTER
@ WID_GRAPH_FOOTER
Footer.
Definition: graph_widget.h:31
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1088
WID_GRAPH_RESIZE
@ WID_GRAPH_RESIZE
Resize button.
Definition: graph_widget.h:29
MakePerformanceDetailPanels
static std::unique_ptr< NWidgetBase > MakePerformanceDetailPanels()
Make a vertical list of panels for outputting score details.
Definition: graph_gui.cpp:1418
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1260
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
WID_GL_BACKGROUND
@ WID_GL_BACKGROUND
Background of the window.
Definition: graph_widget.h:18
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:60
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
MakeNWidgetCompanyLines
static std::unique_ptr< NWidgetBase > MakeNWidgetCompanyLines()
Construct a vertical list of buttons, one for each company.
Definition: graph_gui.cpp:116
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:81
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1099
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1164
WID_GRAPH_BACKGROUND
@ WID_GRAPH_BACKGROUND
Background of the window.
Definition: graph_widget.h:27
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66