35#include "table/strings.h"
59 for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) {
105 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
107 if (!gui_scope)
return;
122 vert->SetPadding(2, 2, 2, 2);
129 panel->SetFill(1, 1);
130 panel->SetToolTip(STR_GRAPH_KEY_COMPANY_SELECTION_TOOLTIP);
131 vert->Add(std::move(panel));
136static constexpr std::initializer_list<NWidgetPart> _nested_graph_legend_widgets = {
151 WindowClass::GraphLegend, WindowClass::None,
153 _nested_graph_legend_widgets
156static void ShowGraphLegend()
173 static const int GRAPH_MAX_DATASETS = 64;
194 uint8_t month_increment = 0;
195 int16_t x_values_increment = 0;
205 static inline constexpr GraphScale MONTHLY_SCALE_WALLCLOCK[] = {
206 {STR_GRAPH_LAST_24_MINUTES_TIME_LABEL, HISTORY_MONTH.total_division,
ECONOMY_MONTH_MINUTES, &HISTORY_MONTH},
207 {STR_GRAPH_LAST_72_MINUTES_TIME_LABEL, HISTORY_QUARTER.total_division,
ECONOMY_QUARTER_MINUTES, &HISTORY_QUARTER},
208 {STR_GRAPH_LAST_288_MINUTES_TIME_LABEL, HISTORY_YEAR.total_division,
ECONOMY_YEAR_MINUTES, &HISTORY_YEAR},
211 static inline constexpr GraphScale MONTHLY_SCALE_CALENDAR[] = {
220 uint8_t num_on_x_axis = 0;
241 std::array<OverflowSafeInt64, GRAPH_NUM_MONTHS> values;
247 std::vector<DataSet> data{};
249 std::span<const GraphRange> ranges{};
250 std::span<const GraphScale> scales{};
251 uint8_t selected_scale = 0;
260 inline void MakeZero(uint i)
const { this->dataset.values[i] = 0; }
261 inline void MakeInvalid(uint i)
const { this->dataset.values[i] =
INVALID_DATAPOINT; }
264 template <
typename Tprojection>
268 inline void Fill(uint i,
const auto &data)
const { this->
dataset.values[i] = std::invoke(this->proj, data); }
278 return {std::begin(dataset.values), std::begin(dataset.values) + this->num_on_x_axis};
289 assert(num_hori_lines > 0);
292 current_interval.
highest = INT64_MIN;
293 current_interval.
lowest = INT64_MAX;
295 for (
const DataSet &dataset : this->data) {
296 if (
HasBit(this->excluded_data, dataset.exclude_bit))
continue;
297 if (
HasBit(this->excluded_range, dataset.range_bit))
continue;
299 for (
const OverflowSafeInt64 &datapoint : this->
GetDataSetRange(dataset)) {
301 current_interval.
highest = std::max(current_interval.
highest, datapoint);
302 current_interval.
lowest = std::min(current_interval.
lowest, datapoint);
308 double abs_lower = (current_interval.
lowest > 0) ? 0 : (double)
abs(current_interval.
lowest);
309 double abs_higher = (current_interval.
highest < 0) ? 0 : (double)current_interval.
highest;
312 abs_higher = (11.0 * abs_higher) / 10.0;
313 abs_lower = (11.0 * abs_lower) / 10.0;
316 OverflowSafeInt64 grid_size;
318 if (abs_lower != 0 || abs_higher != 0) {
320 num_pos_grids = (int)floor(0.5 + num_hori_lines * abs_higher / (abs_higher + abs_lower));
323 if (num_pos_grids == 0 && abs_higher != 0) num_pos_grids++;
324 if (num_pos_grids == num_hori_lines && abs_lower != 0) num_pos_grids--;
328 OverflowSafeInt64 grid_size_higher = 0;
329 if (abs_higher > 0) {
330 grid_size_higher = abs_higher >
INT64_MAX_IN_DOUBLE ? INT64_MAX :
static_cast<int64_t
>(abs_higher);
331 grid_size_higher = (grid_size_higher + num_pos_grids - 1) / num_pos_grids;
334 OverflowSafeInt64 grid_size_lower = 0;
336 grid_size_lower = abs_lower >
INT64_MAX_IN_DOUBLE ? INT64_MAX :
static_cast<int64_t
>(abs_lower);
337 grid_size_lower = (grid_size_lower + num_hori_lines - num_pos_grids - 1) / (num_hori_lines - num_pos_grids);
340 grid_size = std::max(grid_size_higher, grid_size_lower);
343 num_pos_grids = num_hori_lines / 2;
347 current_interval.
highest = num_pos_grids * grid_size;
348 current_interval.
lowest = -(num_hori_lines - num_pos_grids) * grid_size;
349 return current_interval;
361 int64_t y_label = current_interval.
highest;
362 int64_t y_label_separation = (current_interval.
highest - current_interval.
lowest) / num_hori_lines;
366 for (
int i = 0; i < (num_hori_lines + 1); i++) {
368 if (d.width > max_width) max_width = d.width;
370 y_label -= y_label_separation;
388 static_assert(GRAPH_MAX_DATASETS >= (int)
NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_COMPANIES);
389 assert(this->num_vert_lines > 0);
411 r.right -= label_width;
413 r.left += label_width;
416 int x_sep = (r.right - r.left) / this->num_vert_lines;
417 int y_sep = (r.bottom - r.top) / num_hori_lines;
422 r.left = r.right - x_sep * this->num_vert_lines;
424 r.right = r.left + x_sep * this->num_vert_lines;
426 r.bottom = r.top + y_sep * num_hori_lines;
430 x_axis_offset = (int)((r.bottom - r.top) * (
double)interval.
highest / (
double)interval_size);
433 GfxFillRect(r.left, r.top, r.right, r.bottom, GRAPH_BASE_COLOUR);
447 for (
int i = 1; i < this->num_vert_lines + 1; i++) {
450 grid_colour = (i % 4 == 0) ? GRAPH_YEAR_LINE_COLOUR : GRAPH_GRID_COLOUR;
452 GfxFillRect(x, r.top, x + gridline_width - 1, r.bottom, grid_colour);
459 for (
int i = 0; i < (num_hori_lines + 1); i++) {
465 GfxFillRect(r.left, y, r.right + gridline_width - 1, y + gridline_width - 1, GRAPH_GRID_COLOUR);
470 GfxFillRect(r.left, r.top, r.left + gridline_width - 1, r.bottom + gridline_width - 1, GRAPH_AXIS_LINE_COLOUR);
473 y = x_axis_offset + r.top;
474 GfxFillRect(r.left, y, r.right + gridline_width - 1, y + gridline_width - 1, GRAPH_ZERO_LINE_COLOUR);
477 if (this->num_on_x_axis == 0)
return;
479 assert(this->num_on_x_axis > 0);
482 int64_t y_label = interval.
highest;
483 int64_t y_label_separation =
abs(interval.
highest - interval.
lowest) / num_hori_lines;
487 for (
int i = 0; i < (num_hori_lines + 1); i++) {
490 GetString(STR_GRAPH_Y_LABEL, this->format_str_y_axis, y_label),
494 GetString(STR_GRAPH_Y_LABEL, this->format_str_y_axis, y_label),
498 y_label -= y_label_separation;
502 x = rtl ? r.right : r.left;
506 x += (this->num_vert_lines - this->num_on_x_axis) * x_sep;
509 if (this->draw_dates) {
512 for (
int i = 0; i < this->num_on_x_axis; i++) {
515 GetString(mo == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, STR_MONTH_ABBREV_JAN + mo, yr),
519 GetString(mo == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, STR_MONTH_ABBREV_JAN + mo, yr),
523 mo += this->month_increment;
529 GfxFillRect(x + x_sep, r.top + gridline_width, x + x_sep + gridline_width - 1, r.bottom - 1, GRAPH_YEAR_LINE_COLOUR);
537 if (this->x_values_reversed) {
538 label = this->x_values_increment * this->num_on_x_axis;
539 iterator = -this->x_values_increment;
541 label = this->x_values_increment;
542 iterator = this->x_values_increment;
545 for (
int i = 0; i < this->num_on_x_axis; i++) {
560 uint pointoffs1 = pointwidth / 2;
561 uint pointoffs2 = pointwidth - pointoffs1;
564 if (
HasBit(this->excluded_data, dataset.exclude_bit))
return;
565 if (
HasBit(this->excluded_range, dataset.range_bit))
return;
569 x = r.right + (x_sep / 2);
571 x = r.left + (x_sep / 2);
575 x += (this->num_vert_lines - this->num_on_x_axis) * x_sep;
595 int reduce_range = std::max(mult_range - 31, 0);
599 datapoint = -(
abs(datapoint) >> reduce_range);
601 datapoint >>= reduce_range;
603 y = r.top + x_axis_offset - ((r.bottom - r.top) * datapoint) / (interval_size >> reduce_range);
606 GfxFillRect(x - pointoffs1, y - pointoffs1, x + pointoffs2, y + pointoffs2, colour);
623 for (
const DataSet &dataset : this->data) {
624 if (dataset.exclude_bit != this->highlight_data && dataset.range_bit != this->highlight_range) {
625 draw_dataset(dataset, dataset.colour);
631 if (this->highlight_state && (this->highlight_data != UINT8_MAX || this->highlight_range != UINT8_MAX)) {
632 for (
const DataSet &dataset : this->data) {
633 if (dataset.exclude_bit == this->highlight_data || dataset.range_bit == this->highlight_range) {
642 format_str_y_axis(format_str_y_axis)
656 void UpdateMatrixSize(
WidgetID widget, Dimension &size, Dimension &
resize,
auto labels)
659 for (
const StringID &str : labels) {
667 size.height *=
static_cast<uint
>(std::size(labels));
683 this->UpdateMatrixSize(widget, size,
resize, this->scales | std::views::transform(&GraphScale::label));
687 uint x_label_width = 0;
690 if (this->draw_dates) {
692 for (uint mo = 0; mo < 12; ++mo) {
693 x_label_width = std::max(x_label_width,
GetStringBoundingBox(
GetString(mo == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, STR_MONTH_ABBREV_JAN + mo, yr)).
width);
705 size.height = std::max<uint>(size.height, size.width / 3);
718 if (row == INT_MAX)
return false;
735 for (
const auto &[label, tooltip] : this->ranges) {
736 bool lowered = !
HasBit(this->excluded_range, index) && !
HasBit(this->masked_range, index);
744 if (
HasBit(this->masked_range, index)) {
756 uint8_t selected_month_increment = this->scales[this->selected_scale].month_increment;
758 for (
const auto &
scale : this->scales) {
784 if (
HasBit(this->masked_range, row))
break;
793 const auto &
scale = this->scales[row];
794 if (this->selected_scale != row) {
795 this->selected_scale = row;
796 this->month_increment =
scale.month_increment;
797 this->x_values_increment =
scale.x_values_increment;
810 uint8_t new_highlight_range = UINT8_MAX;
813 if (!
HasBit(this->excluded_range, row)) new_highlight_range =
static_cast<uint8_t
>(row);
817 uint8_t new_highlight_data = UINT8_MAX;
820 if (dataset_index.has_value() && !
HasBit(this->excluded_data, *dataset_index)) new_highlight_data = *dataset_index;
823 if (this->highlight_data == new_highlight_data && this->highlight_range == new_highlight_range)
return;
826 this->highlight_data = new_highlight_data;
827 this->highlight_range = new_highlight_range;
828 this->highlight_state =
true;
842 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
844 if (!gui_scope)
return;
859 virtual std::optional<uint8_t>
GetDatasetIndex([[maybe_unused]]
int y) {
return std::nullopt; }
862class BaseCompanyGraphWindow :
public BaseGraphWindow {
864 BaseCompanyGraphWindow(
WindowDesc &desc,
StringID format_str_y_axis) : BaseGraphWindow(desc, format_str_y_axis) {}
884 for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) {
890 nums = std::min(this->num_vert_lines, std::max(nums, c->num_valid_stat_ent));
900 if (!initialize && this->excluded_data == excluded_companies.
base() && this->num_on_x_axis == nums &&
901 this->year == yr && this->month == mo) {
906 this->excluded_data = excluded_companies.
base();
907 this->num_on_x_axis = nums;
912 for (CompanyID k = CompanyID::Begin(); k < MAX_COMPANIES; ++k) {
914 if (c ==
nullptr)
continue;
916 DataSet &dataset = this->data.emplace_back();
918 dataset.exclude_bit = k.base();
920 for (
int j = this->num_on_x_axis, i = 0; --j >= 0;) {
947struct OperatingProfitGraphWindow : BaseCompanyGraphWindow {
949 BaseCompanyGraphWindow(desc, STR_JUST_CURRENCY_SHORT)
964static constexpr std::initializer_list<NWidgetPart> _nested_operating_profit_widgets = {
976 NWidget(
WWT_TEXT,
Colours::Invalid,
WID_GRAPH_FOOTER),
SetFill(1, 0),
SetResize(1, 0),
SetPadding(2, 0, 2, 0),
SetTextStyle(
TextColour::Black,
FontSize::Small),
SetAlignment({
AlignmentH::Centre,
AlignmentV::Middle}),
985 WindowClass::OperatingProfitGraph, WindowClass::None,
987 _nested_operating_profit_widgets
991void ShowOperatingProfitGraph()
1001struct IncomeGraphWindow : BaseCompanyGraphWindow {
1003 BaseCompanyGraphWindow(desc, STR_JUST_CURRENCY_SHORT)
1018static constexpr std::initializer_list<NWidgetPart> _nested_income_graph_widgets = {
1030 NWidget(
WWT_TEXT,
Colours::Invalid,
WID_GRAPH_FOOTER),
SetFill(1, 0),
SetResize(1, 0),
SetPadding(2, 0, 2, 0),
SetTextStyle(
TextColour::Black,
FontSize::Small),
SetAlignment({
AlignmentH::Centre,
AlignmentV::Middle}),
1039 WindowClass::IncomeGraph, WindowClass::None,
1041 _nested_income_graph_widgets
1044void ShowIncomeGraph()
1053struct DeliveredCargoGraphWindow : BaseCompanyGraphWindow {
1055 BaseCompanyGraphWindow(desc, STR_JUST_COMMA)
1066 return c->
old_economy[j].delivered_cargo.GetSum<OverflowSafeInt64>();
1070static constexpr std::initializer_list<NWidgetPart> _nested_delivered_cargo_graph_widgets = {
1082 NWidget(
WWT_TEXT,
Colours::Invalid,
WID_GRAPH_FOOTER),
SetFill(1, 0),
SetResize(1, 0),
SetPadding(2, 0, 2, 0),
SetTextStyle(
TextColour::Black,
FontSize::Small),
SetAlignment({
AlignmentH::Centre,
AlignmentV::Middle}),
1091 WindowClass::DeliveredCargoGraph, WindowClass::None,
1093 _nested_delivered_cargo_graph_widgets
1096void ShowDeliveredCargoGraph()
1105struct PerformanceHistoryGraphWindow : BaseCompanyGraphWindow {
1107 BaseCompanyGraphWindow(desc, STR_JUST_COMMA)
1128static constexpr std::initializer_list<NWidgetPart> _nested_performance_history_widgets = {
1141 NWidget(
WWT_TEXT,
Colours::Invalid,
WID_GRAPH_FOOTER),
SetFill(1, 0),
SetResize(1, 0),
SetPadding(2, 0, 2, 0),
SetTextStyle(
TextColour::Black,
FontSize::Small),
SetAlignment({
AlignmentH::Centre,
AlignmentV::Middle}),
1150 WindowClass::PerformanceGraph, WindowClass::None,
1152 _nested_performance_history_widgets
1155void ShowPerformanceHistoryGraph()
1164struct CompanyValueGraphWindow : BaseCompanyGraphWindow {
1166 BaseCompanyGraphWindow(desc, STR_JUST_CURRENCY_SHORT)
1181static constexpr std::initializer_list<NWidgetPart> _nested_company_value_graph_widgets = {
1193 NWidget(
WWT_TEXT,
Colours::Invalid,
WID_GRAPH_FOOTER),
SetFill(1, 0),
SetResize(1, 0),
SetPadding(2, 0, 2, 0),
SetTextStyle(
TextColour::Black,
FontSize::Small),
SetAlignment({
AlignmentH::Centre,
AlignmentV::Middle}),
1202 WindowClass::CompanyValueGraph, WindowClass::None,
1204 _nested_company_value_graph_widgets
1207void ShowCompanyValueGraph()
1212struct BaseCargoGraphWindow : BaseGraphWindow {
1221 void InitializeWindow(WindowNumber number,
StringID footer_wallclock = STR_NULL,
StringID footer_calendar = STR_NULL)
1256 if (row >= this->vscroll->
GetCount())
return std::nullopt;
1259 if (!this->cargo_types.
Test(cs->Index()))
continue;
1260 if (row-- > 0)
continue;
1265 return std::nullopt;
1283 for (
CargoType cargo_type : this->cargo_types) {
1293 this->line_height = size.height;
1294 size.height = this->line_height * 11;
1296 fill.height =
resize.height = this->line_height;
1314 if (!this->cargo_types.
Test(cs->Index()))
continue;
1316 if (pos-- > 0)
continue;
1317 if (--max < 0)
break;
1319 bool lowered = !
CargoTypes{this->excluded_data}.Test(cs->Index());
1330 if (this->highlight_data == cs->Index()) pc = this->highlight_state ?
PC_WHITE :
PC_BLACK;
1336 line = line.
Translate(0, this->line_height);
1360 if (row >= this->vscroll->
GetCount())
return;
1365 if (!this->cargo_types.
Test(cs->Index()))
continue;
1366 if (row-- > 0)
continue;
1392struct PaymentRatesGraphWindow : BaseCargoGraphWindow {
1393 static inline CargoTypes excluded_cargo_types{};
1399 this->draw_dates =
false;
1401 this->x_values_reversed =
false;
1405 this->InitializeWindow(
window_number, STR_GRAPH_CARGO_PAYMENT_RATES_SECONDS, STR_GRAPH_CARGO_PAYMENT_RATES_DAYS);
1415 return PaymentRatesGraphWindow::excluded_cargo_types;
1423 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1425 if (!gui_scope)
return;
1445 DataSet &dataset = this->data.emplace_back();
1446 dataset.colour = cs->legend_colour;
1447 dataset.exclude_bit = cs->Index();
1449 for (uint j = 0; j != this->num_on_x_axis; j++) {
1450 dataset.values[j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
1456static constexpr std::initializer_list<NWidgetPart> _nested_cargo_payment_rates_widgets = {
1465 NWidget(
WWT_TEXT,
Colours::Invalid,
WID_GRAPH_HEADER),
SetFill(1, 0),
SetResize(1, 0),
SetPadding(2, 0, 2, 0),
SetStringTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE),
SetTextStyle(
TextColour::Black,
FontSize::Small),
SetAlignment({
AlignmentH::Centre,
AlignmentV::Middle}),
1474 NWidget(
WWT_MATRIX,
Colours::Brown,
WID_GRAPH_MATRIX),
SetFill(1, 0),
SetResize(0, 2),
SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO),
SetScrollbar(
WID_GRAPH_MATRIX_SCROLLBAR),
1482 NWidget(
WWT_TEXT,
Colours::Invalid,
WID_GRAPH_FOOTER),
SetFill(1, 0),
SetResize(1, 0),
SetPadding(2, 0, 2, 0),
SetTextStyle(
TextColour::Black,
FontSize::Small),
SetAlignment({
AlignmentH::Centre,
AlignmentV::Middle}),
1491 WindowClass::CargoPaymentRatesGraph, WindowClass::None,
1493 _nested_cargo_payment_rates_widgets
1497void ShowCargoPaymentRates()
1506struct PerformanceRatingDetailWindow :
Window {
1507 static CompanyID company;
1509 uint score_info_left = 0;
1510 uint score_info_right = 0;
1514 uint bar_height = 0;
1515 uint score_detail_left = 0;
1516 uint score_detail_right = 0;
1520 this->UpdateCompanyStats();
1526 void UpdateCompanyStats()
1544 uint score_info_width = 0;
1558 int max = -(999999999 - 500);
1579 this->score_info_left = rtl ? right - score_info_width :
left;
1580 this->score_info_right = rtl ? right :
left + score_info_width;
1582 this->score_detail_left = rtl ?
left : right - score_detail_width;
1583 this->score_detail_right = rtl ?
left + score_detail_width : right;
1586 this->bar_right = this->bar_left + this->bar_width - 1;
1594 if (this->company == CompanyID::Invalid())
return;
1613 int64_t val = _score_part[company][score_type];
1623 uint bar_top =
CentreBounds(r.top, r.bottom, this->bar_height);
1626 DrawString(this->score_info_left, this->score_info_right, text_top, STR_PERFORMANCE_DETAIL_VEHICLES +
to_underlying(score_type));
1632 uint x =
Clamp<int64_t>(val, 0, needed) * this->bar_width / needed;
1635 x = this->bar_right - x;
1637 x = this->bar_left + x;
1641 if (x != this->bar_left)
GfxFillRect(this->bar_left, bar_top, x, bar_top + this->bar_height - 1, rtl ? colour_notdone : colour_done);
1642 if (x != this->bar_right)
GfxFillRect(x, bar_top, this->bar_right, bar_top + this->bar_height - 1, rtl ? colour_done : colour_notdone);
1652 switch (score_type) {
1658 DrawString(this->score_detail_left, this->score_detail_right, text_top,
GetString(STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY, val, needed));
1661 DrawString(this->score_detail_left, this->score_detail_right, text_top,
GetString(STR_PERFORMANCE_DETAIL_AMOUNT_INT, val, needed));
1683 if (--this->timeout == 0) {
1684 this->UpdateCompanyStats();
1694 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1696 if (!gui_scope)
return;
1698 for (CompanyID i = CompanyID::Begin(); i < MAX_COMPANIES; ++i) {
1706 this->company = CompanyID::Invalid();
1709 if (this->company == CompanyID::Invalid()) {
1711 this->company = c->index;
1717 if (this->company != CompanyID::Invalid()) {
1723CompanyID PerformanceRatingDetailWindow::company = CompanyID::Invalid();
1729struct IndustryProductionGraphWindow : BaseCargoGraphWindow {
1730 static inline constexpr GraphRange RANGE_LABELS[] = {
1731 {STR_GRAPH_INDUSTRY_RANGE_PRODUCED, STR_GRAPH_INDUSTRY_RANGE_PRODUCED_TOOLTIP},
1732 {STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED, STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED_TOOLTIP},
1733 {STR_GRAPH_INDUSTRY_RANGE_DELIVERED, STR_GRAPH_INDUSTRY_RANGE_DELIVERED_TOOLTIP},
1734 {STR_GRAPH_INDUSTRY_RANGE_WAITING, STR_GRAPH_INDUSTRY_RANGE_WAITING_TOOLTIP},
1737 static inline CargoTypes excluded_cargo_types{};
1740 BaseCargoGraphWindow(desc, STR_JUST_COMMA)
1744 this->month_increment = 1;
1747 this->ranges = RANGE_LABELS;
1750 if (!i->
IsCargoProduced()) this->masked_range = (1U << 0) | (1U << 1);
1751 if (!i->
IsCargoAccepted()) this->masked_range = (1U << 2) | (1U << 3);
1767 for (
const auto &a : i->
accepted) {
1770 for (
const auto &p : i->
produced) {
1778 return IndustryProductionGraphWindow::excluded_cargo_types;
1797 if (!initialize && this->excluded_data == this->
GetExcludedCargoTypes().base() && this->num_on_x_axis == this->num_vert_lines && this->year == yr && this->month == mo) {
1813 for (
const auto &p : i->
produced) {
1817 DataSet &produced = this->data.emplace_back();
1818 produced.colour = cs->legend_colour;
1819 produced.exclude_bit = cs->
Index();
1820 produced.range_bit = 0;
1822 DataSet &transported = this->data.emplace_back();
1823 transported.colour = cs->legend_colour;
1824 transported.exclude_bit = cs->
Index();
1825 transported.range_bit = 1;
1826 transported.dash = 2;
1833 for (
const auto &a : i->accepted) {
1837 DataSet &accepted = this->data.emplace_back();
1838 accepted.colour = cs->legend_colour;
1839 accepted.exclude_bit = cs->
Index();
1840 accepted.range_bit = 2;
1843 DataSet &waiting = this->data.emplace_back();
1844 waiting.colour = cs->legend_colour;
1845 waiting.exclude_bit = cs->
Index();
1846 waiting.range_bit = 3;
1858static constexpr std::initializer_list<NWidgetPart> _nested_industry_production_widgets = {
1877 NWidget(
WWT_MATRIX,
Colours::Brown,
WID_GRAPH_MATRIX),
SetFill(1, 0),
SetResize(0, 2),
SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO),
SetScrollbar(
WID_GRAPH_MATRIX_SCROLLBAR),
1881 NWidget(
WWT_MATRIX,
Colours::Brown,
WID_GRAPH_SCALE_MATRIX),
SetFill(1, 0),
SetResize(0, 0),
SetMatrixDataTip(1, 0, STR_GRAPH_SELECT_SCALE),
1887 NWidget(
WWT_TEXT,
Colours::Invalid,
WID_GRAPH_FOOTER),
SetFill(1, 0),
SetResize(1, 0),
SetPadding(2, 0, 2, 0),
SetTextStyle(
TextColour::Black,
FontSize::Small),
SetAlignment({
AlignmentH::Centre,
AlignmentV::Middle}),
1896 WindowClass::IndustryProductionGraph, WindowClass::IndustryView,
1898 _nested_industry_production_widgets
1901void ShowIndustryProductionGraph(
WindowNumber window_number)
1906struct TownCargoGraphWindow : BaseCargoGraphWindow {
1907 static inline constexpr GraphRange RANGE_LABELS[] = {
1908 {STR_GRAPH_TOWN_RANGE_PRODUCED, STR_GRAPH_TOWN_RANGE_PRODUCED_TOOLTIP},
1909 {STR_GRAPH_TOWN_RANGE_TRANSPORTED, STR_GRAPH_TOWN_RANGE_TRANSPORTED_TOOLTIP},
1910 {STR_GRAPH_TOWN_RANGE_DELIVERED, STR_GRAPH_TOWN_RANGE_DELIVERED_TOOLTIP},
1913 static inline CargoTypes excluded_cargo_types{};
1919 this->month_increment = 1;
1922 this->ranges = RANGE_LABELS;
1938 for (
const auto &s : t->
supplied) {
1941 for (
const auto &a : t->
accepted) {
1949 return TownCargoGraphWindow::excluded_cargo_types;
1968 if (!initialize && this->excluded_data == this->
GetExcludedCargoTypes().base() && this->num_on_x_axis == this->num_vert_lines && this->year == yr && this->month == mo) {
1984 for (
const auto &s : t->
supplied) {
1988 DataSet &produced = this->data.emplace_back();
1989 produced.colour = cs->legend_colour;
1990 produced.exclude_bit = cs->
Index();
1991 produced.range_bit = 0;
1993 DataSet &transported = this->data.emplace_back();
1994 transported.colour = cs->legend_colour;
1995 transported.exclude_bit = cs->
Index();
1996 transported.range_bit = 1;
1997 transported.dash = 2;
2004 for (
const auto &a : t->accepted) {
2008 DataSet &accepted = this->data.emplace_back();
2009 accepted.colour = cs->legend_colour;
2010 accepted.exclude_bit = cs->
Index();
2011 accepted.range_bit = 2;
2022static constexpr std::initializer_list<NWidgetPart> _nested_town_cargo_graph_widgets = {
2041 NWidget(
WWT_MATRIX,
Colours::Brown,
WID_GRAPH_MATRIX),
SetFill(1, 0),
SetResize(0, 2),
SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO),
SetScrollbar(
WID_GRAPH_MATRIX_SCROLLBAR),
2045 NWidget(
WWT_MATRIX,
Colours::Brown,
WID_GRAPH_SCALE_MATRIX),
SetFill(1, 0),
SetResize(0, 0),
SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO),
2051 NWidget(
WWT_TEXT,
Colours::Invalid,
WID_GRAPH_FOOTER),
SetFill(1, 0),
SetResize(1, 0),
SetPadding(2, 0, 2, 0),
SetTextStyle(
TextColour::Black,
FontSize::Small),
SetAlignment({
AlignmentH::Centre,
AlignmentV::Middle}),
2060 WindowClass::TownCargoGraph, WindowClass::TownView,
2062 _nested_town_cargo_graph_widgets
2077 const StringID performance_tips[] = {
2078 realtime ? STR_PERFORMANCE_DETAIL_VEHICLES_TOOLTIP_PERIODS : STR_PERFORMANCE_DETAIL_VEHICLES_TOOLTIP_YEARS,
2079 STR_PERFORMANCE_DETAIL_STATIONS_TOOLTIP,
2080 realtime ? STR_PERFORMANCE_DETAIL_MIN_PROFIT_TOOLTIP_PERIODS : STR_PERFORMANCE_DETAIL_MIN_PROFIT_TOOLTIP_YEARS,
2081 STR_PERFORMANCE_DETAIL_MIN_INCOME_TOOLTIP,
2082 STR_PERFORMANCE_DETAIL_MAX_INCOME_TOOLTIP,
2083 STR_PERFORMANCE_DETAIL_DELIVERED_TOOLTIP,
2084 STR_PERFORMANCE_DETAIL_CARGO_TOOLTIP,
2085 STR_PERFORMANCE_DETAIL_MONEY_TOOLTIP,
2086 STR_PERFORMANCE_DETAIL_LOAN_TOOLTIP,
2087 STR_PERFORMANCE_DETAIL_TOTAL_TOOLTIP,
2095 panel->SetFill(1, 1);
2097 vert->Add(std::move(panel));
2108static constexpr std::initializer_list<NWidgetPart> _nested_performance_rating_detail_widgets = {
2124 WindowClass::PerformanceDetail, WindowClass::None,
2126 _nested_performance_rating_detail_widgets
2129void ShowPerformanceRatingDetail()
2134void InitializeGraphGui()
2137 PaymentRatesGraphWindow::excluded_cargo_types = {};
2138 IndustryProductionGraphWindow::excluded_cargo_types = {};
constexpr uint8_t FindLastBit(T x)
Search the last set bit in a value.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
EnumBitSet< CargoType, uint64_t > CargoTypes
Bitset of CargoType elements.
static constexpr CargoType NUM_CARGO
Maximum number of cargo types in a game.
CargoType
Cargo slots to indicate a cargo type within a game.
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
CargoTypes _standard_cargo_mask
Bitmask of real cargo types available.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Types/functions related to cargoes.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
constexpr Timpl & Flip()
Flip all bits.
constexpr Timpl & Set()
Set all bits.
void UpdateStatistics(bool initialize) override
Update the statistics.
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)=0
Get the data to show in the graph for a given company at a location along the X-axis.
Iterate a range of enum values.
An interval timer will fire every interval, and will continue to fire until it is deleted.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static Year year
Current year, starting at 0.
static Month month
Current month (0..11).
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
StrongType::Typedef< int32_t, struct YearTag< struct Economy >, StrongType::Compare, StrongType::Integer > Year
Definition of stuff that is very close to a company, like the company struct itself.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
GUI Functions related to companies.
Functions to handle different currencies.
const CurrencySpec & GetCurrency()
Get the currently selected currency.
int UpdateCompanyRatingAndValue(Company *c, bool update)
if update is set to true, the economy is updated with this score (also the house is updated,...
const EnumIndexArray< ScoreInfo, ScoreID, ScoreID::End > _score_info
Score info, values used for computing the detailed performance rating.
Functions related to the economy.
ScoreID
Score categories in the detailed performance rating.
@ MinIncome
Income in the quarter with the lowest profit of the last 12 quarters.
@ End
Score ID end marker.
@ Total
Total points out of possible points ,must always be the last entry.
@ Loan
The amount of money company can take as a loan.
@ MaxIncome
Income in the quarter with the highest profit of the last 12 quarters.
@ MinProfit
The profit of the vehicle with the lowest income.
@ Money
Amount of money company has in the bank.
static constexpr int SCORE_MAX
The max score that can be in the performance history.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
@ ForceRight
Force align to the right.
@ Centre
Align to the centre.
@ End
Align to the end, LTR/RTL aware.
@ Start
Align to the start, LTR/RTL aware.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
@ Middle
Align to the middle.
bool DrawStringMultiLineWithClipping(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw a multiline string, possibly over multiple lines, if the region is within the current display cl...
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Functions related to the gfx engine.
@ Small
Index of the small font in the font tables.
@ Normal
Index of the normal font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ FromString
Marker for telling to use the colour from the string.
@ Checker
Draw only every second pixel, used for greying-out.
static WindowDesc _operating_profit_desc(WindowPosition::Automatic, "graph_operating_profit", 0, 0, WindowClass::OperatingProfitGraph, WindowClass::None, {}, _nested_operating_profit_widgets)
Window definition for the operating profit graph window.
static WindowDesc _graph_legend_desc(WindowPosition::Automatic, "graph_legend", 0, 0, WindowClass::GraphLegend, WindowClass::None, {}, _nested_graph_legend_widgets)
Window definition for the graph legend window.
constexpr double INT64_MAX_IN_DOUBLE
The biggest double that when cast to int64_t still fits in a int64_t.
static std::unique_ptr< NWidgetBase > MakeNWidgetCompanyLines()
Construct a vertical list of buttons, one for each company.
static CompanyMask _legend_excluded_companies
Bitmasks of company and cargo indices that shouldn't be drawn.
std::unique_ptr< NWidgetBase > MakeCompanyButtonRowsGraphGUI()
Make a number of rows with buttons for each company for the performance rating detail window.
static WindowDesc _industry_production_desc(WindowPosition::Automatic, "graph_industry_production", 0, 0, WindowClass::IndustryProductionGraph, WindowClass::IndustryView, {}, _nested_industry_production_widgets)
Window definition for the industry production graph window.
static WindowDesc _performance_history_desc(WindowPosition::Automatic, "graph_performance", 0, 0, WindowClass::PerformanceGraph, WindowClass::None, {}, _nested_performance_history_widgets)
Window definition for the performance history graph window.
static WindowDesc _town_cargo_graph_desc(WindowPosition::Automatic, "graph_town_cargo", 0, 0, WindowClass::TownCargoGraph, WindowClass::TownView, {}, _nested_town_cargo_graph_widgets)
Window definition for the town cargo graph window.
static WindowDesc _delivered_cargo_graph_desc(WindowPosition::Automatic, "graph_delivered_cargo", 0, 0, WindowClass::DeliveredCargoGraph, WindowClass::None, {}, _nested_delivered_cargo_graph_widgets)
Window definition for the delivered cargo graph window.
static WindowDesc _cargo_payment_rates_desc(WindowPosition::Automatic, "graph_cargo_payment_rates", 0, 0, WindowClass::CargoPaymentRatesGraph, WindowClass::None, {}, _nested_cargo_payment_rates_widgets)
Window definition for the cargo payment rates graph window.
static const OverflowSafeInt64 INVALID_DATAPOINT(INT64_MAX)
Value used for a datapoint that shouldn't be drawn.
static const uint INVALID_DATAPOINT_POS
Used to determine if the previous point was drawn.
static std::unique_ptr< NWidgetBase > MakePerformanceDetailPanels()
Make a vertical list of panels for outputting score details.
static WindowDesc _performance_rating_detail_desc(WindowPosition::Automatic, "league_details", 0, 0, WindowClass::PerformanceDetail, WindowClass::None, {}, _nested_performance_rating_detail_widgets)
Window definition for the performance rating details window.
static WindowDesc _income_graph_desc(WindowPosition::Automatic, "graph_income", 0, 0, WindowClass::IncomeGraph, WindowClass::None, {}, _nested_income_graph_widgets)
Window definition for the income graph window.
static WindowDesc _company_value_graph_desc(WindowPosition::Automatic, "graph_company_value", 0, 0, WindowClass::CompanyValueGraph, WindowClass::None, {}, _nested_company_value_graph_widgets)
Window definition for the company value graph window.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Functions for storing historical data.
void FillFromHistory(const HistoryData< T > &history, ValidHistoryMask valid_history, const HistoryRange &hr, Tfillers &&... fillers)
Fill some data with historical data.
#define Point
Macro that prevents name conflicts between included headers.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
constexpr To ClampTo(From value)
Clamp the given value down to lie within the requested type.
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
PixelColour GetColourGradient(Colours colour, Shade shade)
Get colour gradient palette index.
@ Darker
Darker colour shade.
@ Lighter
Lighter colour shade.
@ Normal
Normal colour shade.
constexpr PixelColour GREY_SCALE(uint8_t level)
Return the colour for a particular greyscale level.
static constexpr PixelColour PC_BLACK
Black palette colour.
static constexpr PixelColour PC_WHITE
White palette colour.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Functions related to sound.
This file contains all sprite-related enums and defines.
static const SpriteID SPR_COMPANY_ICON
Icon showing company colour.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
Get some number that is suitable for string size computations.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
uint legend_width
Width of legend 'blob'.
virtual CargoTypes & GetExcludedCargoTypes() const =0
Get a reference to the cargo types that should not be shown.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnInit() override
Notification that the nested widget tree gets initialized.
std::optional< uint8_t > GetDatasetIndex(int y) override
Get the dataset associated with a given Y-location within WID_GRAPH_MATRIX.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
virtual CargoTypes GetCargoTypes(WindowNumber number) const =0
Get the CargoTypes to show in this window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
CargoTypes cargo_types
Cargo types that can be selected.
void OnResize() override
Called after the window got resized.
Scrollbar * vscroll
Cargo list scrollbar.
uint line_height
Pixel height of each cargo type row.
DataSet & dataset
Dataset to fill.
Tprojection proj
Projection to apply.
Label and tooltip for a graph range.
StringID label
Label for this range.
StringID tooltip
Tooltip for this range.
uint GetYLabelWidth(ValuesInterval current_interval, int num_hori_lines) const
Get width for Y labels.
TimerGameEconomy::Year year
The starting year that values are plotted against.
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
void OnGameTick() override
Called once per (game) tick.
virtual void UpdateStatistics(bool initialize)=0
Update the statistics.
static const int MIN_GRID_PIXEL_SIZE
Minimum distance between graph lines.
static const int GRAPH_NUM_MONTHS
Number of months displayed in the graph.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
static const int ECONOMY_QUARTER_MINUTES
Minutes per economic quarter.
static const int GRAPH_PAYMENT_RATE_STEPS
Number of steps on Payment rate graph.
void OnMouseOver(Point pt, WidgetID widget) override
The mouse is currently moving over the window or has just moved outside of the window.
std::span< const OverflowSafeInt64 > GetDataSetRange(const DataSet &dataset) const
Get appropriate part of dataset values for the current number of horizontal points.
TimerGameEconomy::Month month
The starting month that values are plotted against.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
static const int ECONOMY_MONTH_MINUTES
Minutes per economic month.
uint64_t excluded_data
bitmask of datasets hidden by the player.
bool draw_dates
Should we draw months and years on the time axis?
static const int MIN_GRAPH_NUM_LINES_Y
Minimal number of horizontal lines to draw.
uint64_t excluded_range
bitmask of ranges hidden by the player.
uint8_t highlight_range
Data range that should be highlighted, or UINT8_MAX for none.
bool highlight_state
Current state of highlight, toggled every TIMER_BLINK_INTERVAL period.
uint8_t month_increment
month increment between vertical lines. must be divisor of 12.
virtual std::optional< uint8_t > GetDatasetIndex(int y)
Get the dataset associated with a given Y-location within WID_GRAPH_MATRIX.
static const int PAYMENT_GRAPH_X_STEP_DAYS
X-axis step label for cargo payment rates "Days in transit".
static const int ECONOMY_YEAR_MINUTES
Minutes per economic year.
ValuesInterval GetValuesInterval(int num_hori_lines) const
Get the interval that contains the graph's data.
uint64_t masked_range
bitmask of ranges that are not available for the current data.
static const TextColour GRAPH_AXIS_LABEL_COLOUR
colour of the graph axis label.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void DrawGraph(Rect r) const
Actually draw the graph.
bool x_values_reversed
These values are used if the graph is being plotted against values rather than the dates specified by...
int16_t x_values_increment
These values are used if the graph is being plotted against values rather than the dates specified by...
static const int PAYMENT_GRAPH_X_STEP_SECONDS
X-axis step label for cargo payment rates "Seconds in transit".
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
uint8_t highlight_data
Data set that should be highlighted, or UINT8_MAX for none.
Specification of a cargo type.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
CargoType Index() const
Determines index of this cargospec.
StringID name
Name of this type of cargo.
Colours colour
Company colour.
std::array< CompanyEconomyEntry, MAX_HISTORY_QUARTERS > old_economy
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
uint8_t num_valid_stat_ent
Number of valid statistical entries in old_economy.
OverflowSafeInt64 GetGraphData(const Company *c, int j) override
Get the data to show in the graph for a given company at a location along the X-axis.
uint16_t rate
The conversion rate compared to the base currency.
OverflowSafeInt64 GetGraphData(const Company *c, int j) override
Get the data to show in the graph for a given company at a location along the X-axis.
Dimensions (a width and height) of a rectangle in 2D.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
OverflowSafeInt64 GetGraphData(const Company *c, int j) override
Get the data to show in the graph for a given company at a location along the X-axis.
void UpdateStatistics(bool initialize) override
Update the statistics.
CargoTypes GetCargoTypes(WindowNumber window_number) const override
Get the CargoTypes to show in this window.
CargoTypes & GetExcludedCargoTypes() const override
Get a reference to the cargo types that should not be shown.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnInit() override
Notification that the nested widget tree gets initialized.
CargoType cargo
Cargo type.
uint16_t accepted
Total accepted.
uint16_t waiting
Average waiting.
CargoType cargo
Cargo type.
uint16_t transported
Total transported.
uint16_t production
Total produced.
Defines the internal data of a functional industry.
bool IsCargoAccepted() const
Test if this industry accepts any cargo.
ValidHistoryMask valid_history
Mask of valid history records.
ProducedCargoes produced
produced cargo slots
AcceptedCargoes accepted
accepted cargo slots
bool IsCargoProduced() const
Test if this industry produces any cargo.
OverflowSafeInt64 GetGraphData(const Company *c, int j) override
Get the data to show in the graph for a given company at a location along the X-axis.
void UpdateStatistics(bool) override
Update the statistics.
void UpdatePaymentRates()
Update the payment rates according to the latest information.
CargoTypes & GetExcludedCargoTypes() const override
Get a reference to the cargo types that should not be shown.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
const IntervalTimer< TimerWindow > update_payment_interval
Update the payment rates on a regular interval.
CargoTypes GetCargoTypes(WindowNumber) const override
Get the CargoTypes to show in this window.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
OverflowSafeInt64 GetGraphData(const Company *c, int j) override
Get the data to show in the graph for a given company at a location along the X-axis.
Colour for pixel/line drawing.
static Pool::IterateWrapper< Company > Iterate(size_t from=0)
static Industry * Get(auto index)
static bool IsValidID(auto index)
static Company * GetIfValid(auto index)
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
CargoTypes & GetExcludedCargoTypes() const override
Get a reference to the cargo types that should not be shown.
CargoTypes GetCargoTypes(WindowNumber window_number) const override
Get the CargoTypes to show in this window.
void UpdateStatistics(bool initialize) override
Update the statistics.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnInit() override
Notification that the nested widget tree gets initialized.
CargoType cargo
Cargo type of accepted cargo.
uint32_t accepted
Total accepted.
uint32_t transported
Total transported.
uint32_t production
Total produced.
SuppliedCargoes supplied
Cargo statistics about supplied cargo.
ValidHistoryMask valid_history
Mask of valid history records.
AcceptedCargoes accepted
Cargo statistics about accepted cargo.
Contains the interval of a graph's data.
OverflowSafeInt64 lowest
Lowest value of this interval. Must be zero or less.
OverflowSafeInt64 highest
Highest value of this interval. Must be zero or greater.
High level window description.
Number to differentiate different windows of the same class.
Data structure for an opened window.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
ResizeInfo resize
Resize information.
int scale
Scale of this window – used to determine how to resize.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
int left
x position of left edge of the window
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
int height
Height of the window (number of pixels down in y direction).
int width
width of the window (number of pixels to the right in x direction)
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
WindowNumber window_number
Window number within the window class.
Definition of Interval and OneShot timers.
Definition of the game-economy-timer.
Definition of the tick-based game-timer.
Definition of the Window system.
static constexpr std::chrono::milliseconds TIMER_BLINK_INTERVAL
Interval used by blinking interface elements.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Lowered
If set the frame is lowered and the background colour brighter (ie. buttons when pressed).
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Automatic
Find a place automatically.
Functions related to zooming.
@ Normal
The normal zoom level.