OpenTTD Source: src/graph_gui.cpp Source File

OpenTTD Source 14.1

graph_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "graph_gui.h"
12 #include "window_gui.h"
13 #include "company_base.h"
14 #include "company_gui.h"
15 #include "economy_func.h"
16 #include "cargotype.h"
17 #include "strings_func.h"
18 #include "window_func.h"
19 #include "gfx_func.h"
20 #include "core/geometry_func.hpp"
21 #include "currency.h"
22 #include "timer/timer.h"
23 #include "timer/timer_window.h"
24 #include "timer/timer_game_tick.h"
25 #include "timer/timer_game_calendar.h"
26 #include "timer/timer_game_economy.h"
27 #include "zoom_func.h"
28
29 #include "widgets/graph_widget.h"
30
31 #include "table/strings.h"
32 #include "table/sprites.h"
33
34 #include "safeguards.h"
35
36 /* Bitmasks of company and cargo indices that shouldn't be drawn. */
37 static CompanyMask _legend_excluded_companies;
38 static CargoTypes _legend_excluded_cargo;
39
40 /* Apparently these don't play well with enums. */
41 static const OverflowSafeInt64 INVALID_DATAPOINT(INT64_MAX); // Value used for a datapoint that shouldn't be drawn.
42 static const uint INVALID_DATAPOINT_POS = UINT_MAX; // Used to determine if the previous point was drawn.
43
44 constexpr double INT64_MAX_IN_DOUBLE = static_cast<double>(INT64_MAX - 512);
45 static_assert(static_cast<int64_t>(INT64_MAX_IN_DOUBLE) < INT64_MAX);
46
47 /****************/
48 /* GRAPH LEGEND */
49 /****************/
50
51 struct GraphLegendWindow : Window {
52 GraphLegendWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
53 {
54 this->InitNested(window_number);
55
56 for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
57 if (!HasBit(_legend_excluded_companies, c)) this->LowerWidget(WID_GL_FIRST_COMPANY + c);
58
59 this->OnInvalidateData(c);
60 }
61 }
62
63 void DrawWidget(const Rect &r, WidgetID widget) const override
64 {
65 if (!IsInsideMM(widget, WID_GL_FIRST_COMPANY, WID_GL_FIRST_COMPANY + MAX_COMPANIES)) return;
66
67 CompanyID cid = (CompanyID)(widget - WID_GL_FIRST_COMPANY);
68
69 if (!Company::IsValidID(cid)) return;
70
71 bool rtl = _current_text_dir == TD_RTL;
72
73 const Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
74 Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
75 DrawCompanyIcon(cid, rtl ? ir.right - d.width : ir.left, CenterBounds(ir.top, ir.bottom, d.height));
76
77 const Rect tr = ir.Indent(d.width + WidgetDimensions::scaled.hsep_normal, rtl);
78 SetDParam(0, cid);
79 SetDParam(1, cid);
80 DrawString(tr.left, tr.right, CenterBounds(tr.top, tr.bottom, GetCharacterHeight(FS_NORMAL)), STR_COMPANY_NAME_COMPANY_NUM, HasBit(_legend_excluded_companies, cid) ? TC_BLACK : TC_WHITE);
81 }
82
83 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
84 {
85 if (!IsInsideMM(widget, WID_GL_FIRST_COMPANY, WID_GL_FIRST_COMPANY + MAX_COMPANIES)) return;
86
87 ToggleBit(_legend_excluded_companies, widget - WID_GL_FIRST_COMPANY);
88 this->ToggleWidgetLoweredState(widget);
89 this->SetDirty();
90 InvalidateWindowData(WC_INCOME_GRAPH, 0);
91 InvalidateWindowData(WC_OPERATING_PROFIT, 0);
92 InvalidateWindowData(WC_DELIVERED_CARGO, 0);
93 InvalidateWindowData(WC_PERFORMANCE_HISTORY, 0);
94 InvalidateWindowData(WC_COMPANY_VALUE, 0);
95 }
96
102 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
103 {
104 if (!gui_scope) return;
105 if (Company::IsValidID(data)) return;
106
107 SetBit(_legend_excluded_companies, data);
108 this->RaiseWidget(data + WID_GL_FIRST_COMPANY);
109 }
110 };
111
116 static std::unique_ptr<NWidgetBase> MakeNWidgetCompanyLines()
117 {
118 auto vert = std::make_unique<NWidgetVertical>(NC_EQUALSIZE);
119 vert->SetPadding(2, 2, 2, 2);
120 uint sprite_height = GetSpriteSize(SPR_COMPANY_ICON, nullptr, ZOOM_LVL_OUT_4X).height;
121
122 for (WidgetID widnum = WID_GL_FIRST_COMPANY; widnum <= WID_GL_LAST_COMPANY; widnum++) {
123 auto panel = std::make_unique<NWidgetBackground>(WWT_PANEL, COLOUR_BROWN, widnum);
124 panel->SetMinimalSize(246, sprite_height + WidgetDimensions::unscaled.framerect.Vertical());
125 panel->SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical(), FS_NORMAL);
126 panel->SetFill(1, 1);
127 panel->SetDataTip(0x0, STR_GRAPH_KEY_COMPANY_SELECTION_TOOLTIP);
128 vert->Add(std::move(panel));
129 }
130 return vert;
131 }
132
133 static constexpr NWidgetPart _nested_graph_legend_widgets[] = {
134 NWidget(NWID_HORIZONTAL),
135 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
136 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_KEY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
137 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
138 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
139 EndContainer(),
140 NWidget(WWT_PANEL, COLOUR_BROWN, WID_GL_BACKGROUND),
141 NWidgetFunction(MakeNWidgetCompanyLines),
142 EndContainer(),
143 };
144
145 static WindowDesc _graph_legend_desc(__FILE__, __LINE__,
146 WDP_AUTO, "graph_legend", 0, 0,
147 WC_GRAPH_LEGEND, WC_NONE,
148 0,
149 std::begin(_nested_graph_legend_widgets), std::end(_nested_graph_legend_widgets)
150 );
151
152 static void ShowGraphLegend()
153 {
154 AllocateWindowDescFront<GraphLegendWindow>(&_graph_legend_desc, 0);
155 }
156
158 struct ValuesInterval {
159 OverflowSafeInt64 highest;
160 OverflowSafeInt64 lowest;
161 };
162
163 /******************/
164 /* BASE OF GRAPHS */
165 /*****************/
166
167 struct BaseGraphWindow : Window {
168 protected:
169 static const int GRAPH_MAX_DATASETS = 64;
170 static const int GRAPH_BASE_COLOUR = GREY_SCALE(2);
171 static const int GRAPH_GRID_COLOUR = GREY_SCALE(3);
172 static const int GRAPH_AXIS_LINE_COLOUR = GREY_SCALE(1);
173 static const int GRAPH_ZERO_LINE_COLOUR = GREY_SCALE(8);
174 static const int GRAPH_YEAR_LINE_COLOUR = GREY_SCALE(5);
175 static const int GRAPH_NUM_MONTHS = 24;
176 static const int PAYMENT_GRAPH_X_STEP_DAYS = 10;
177 static const int PAYMENT_GRAPH_X_STEP_SECONDS = 20;
178 static const int ECONOMY_QUARTER_MINUTES = 3;
179
180 static const TextColour GRAPH_AXIS_LABEL_COLOUR = TC_BLACK;
181
182 static const int MIN_GRAPH_NUM_LINES_Y = 9;
183 static const int MIN_GRID_PIXEL_SIZE = 20;
184
185 uint64_t excluded_data;
186 byte num_dataset;
187 byte num_on_x_axis;
188 byte num_vert_lines;
189
190 /* The starting month and year that values are plotted against. */
191 TimerGameEconomy::Month month;
192 TimerGameEconomy::Year year;
193
194 bool draw_dates = true;
195
196 /* These values are used if the graph is being plotted against values
197 * rather than the dates specified by month and year. */
198 uint16_t x_values_start;
199 uint16_t x_values_increment;
200
201 StringID format_str_y_axis;
202 byte colours[GRAPH_MAX_DATASETS];
203 OverflowSafeInt64 cost[GRAPH_MAX_DATASETS][GRAPH_NUM_MONTHS];
204
211 ValuesInterval GetValuesInterval(int num_hori_lines) const
212 {
213 assert(num_hori_lines > 0);
214
215 ValuesInterval current_interval;
216 current_interval.highest = INT64_MIN;
217 current_interval.lowest = INT64_MAX;
218
219 for (int i = 0; i < this->num_dataset; i++) {
220 if (HasBit(this->excluded_data, i)) continue;
221 for (int j = 0; j < this->num_on_x_axis; j++) {
222 OverflowSafeInt64 datapoint = this->cost[i][j];
223
224 if (datapoint != INVALID_DATAPOINT) {
225 current_interval.highest = std::max(current_interval.highest, datapoint);
226 current_interval.lowest = std::min(current_interval.lowest, datapoint);
227 }
228 }
229 }
230
231 /* Always include zero in the shown range. */
232 double abs_lower = (current_interval.lowest > 0) ? 0 : (double)abs(current_interval.lowest);
233 double abs_higher = (current_interval.highest < 0) ? 0 : (double)current_interval.highest;
234
235 /* Prevent showing values too close to the graph limits. */
236 abs_higher = (11.0 * abs_higher) / 10.0;
237 abs_lower = (11.0 * abs_lower) / 10.0;
238
239 int num_pos_grids;
240 OverflowSafeInt64 grid_size;
241
242 if (abs_lower != 0 || abs_higher != 0) {
243 /* The number of grids to reserve for the positive part is: */
244 num_pos_grids = (int)floor(0.5 + num_hori_lines * abs_higher / (abs_higher + abs_lower));
245
246 /* If there are any positive or negative values, force that they have at least one grid. */
247 if (num_pos_grids == 0 && abs_higher != 0) num_pos_grids++;
248 if (num_pos_grids == num_hori_lines && abs_lower != 0) num_pos_grids--;
249
250 /* Get the required grid size for each side and use the maximum one. */
251
252 OverflowSafeInt64 grid_size_higher = 0;
253 if (abs_higher > 0) {
254 grid_size_higher = abs_higher > INT64_MAX_IN_DOUBLE ? INT64_MAX : static_cast<int64_t>(abs_higher);
255 grid_size_higher = (grid_size_higher + num_pos_grids - 1) / num_pos_grids;
256 }
257
258 OverflowSafeInt64 grid_size_lower = 0;
259 if (abs_lower > 0) {
260 grid_size_lower = abs_lower > INT64_MAX_IN_DOUBLE ? INT64_MAX : static_cast<int64_t>(abs_lower);
261 grid_size_lower = (grid_size_lower + num_hori_lines - num_pos_grids - 1) / (num_hori_lines - num_pos_grids);
262 }
263
264 grid_size = std::max(grid_size_higher, grid_size_lower);
265 } else {
266 /* If both values are zero, show an empty graph. */
267 num_pos_grids = num_hori_lines / 2;
268 grid_size = 1;
269 }
270
271 current_interval.highest = num_pos_grids * grid_size;
272 current_interval.lowest = -(num_hori_lines - num_pos_grids) * grid_size;
273 return current_interval;
274 }
275
281 uint GetYLabelWidth(ValuesInterval current_interval, int num_hori_lines) const
282 {
283 /* draw text strings on the y axis */
284 int64_t y_label = current_interval.highest;
285 int64_t y_label_separation = (current_interval.highest - current_interval.lowest) / num_hori_lines;
286
287 uint max_width = 0;
288
289 for (int i = 0; i < (num_hori_lines + 1); i++) {
290 SetDParam(0, this->format_str_y_axis);
291 SetDParam(1, y_label);
292 Dimension d = GetStringBoundingBox(STR_GRAPH_Y_LABEL);
293 if (d.width > max_width) max_width = d.width;
294
295 y_label -= y_label_separation;
296 }
297
298 return max_width;
299 }
300
305 void DrawGraph(Rect r) const
306 {
307 uint x, y;
308 ValuesInterval interval;
309 int x_axis_offset;
310
311 /* the colours and cost array of GraphDrawer must accommodate
312 * both values for cargo and companies. So if any are higher, quit */
313 static_assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_COMPANIES);
314 assert(this->num_vert_lines > 0);
315
316 /* Rect r will be adjusted to contain just the graph, with labels being
317 * placed outside the area. */
318 r.top += ScaleGUITrad(5) + GetCharacterHeight(FS_SMALL) / 2;
319 r.bottom -= (this->draw_dates ? 2 : 1) * GetCharacterHeight(FS_SMALL) + ScaleGUITrad(4);
320 r.left += ScaleGUITrad(9);
321 r.right -= ScaleGUITrad(5);
322
323 /* Initial number of horizontal lines. */
324 int num_hori_lines = 160 / ScaleGUITrad(MIN_GRID_PIXEL_SIZE);
325 /* For the rest of the height, the number of horizontal lines will increase more slowly. */
326 int resize = (r.bottom - r.top - 160) / (2 * ScaleGUITrad(MIN_GRID_PIXEL_SIZE));
327 if (resize > 0) num_hori_lines += resize;
328
329 interval = GetValuesInterval(num_hori_lines);
330
331 int label_width = GetYLabelWidth(interval, num_hori_lines);
332
333 r.left += label_width;
334
335 int x_sep = (r.right - r.left) / this->num_vert_lines;
336 int y_sep = (r.bottom - r.top) / num_hori_lines;
337
338 /* Redetermine right and bottom edge of graph to fit with the integer
339 * separation values. */
340 r.right = r.left + x_sep * this->num_vert_lines;
341 r.bottom = r.top + y_sep * num_hori_lines;
342
343 OverflowSafeInt64 interval_size = interval.highest + abs(interval.lowest);
344 /* Where to draw the X axis. Use floating point to avoid overflowing and results of zero. */
345 x_axis_offset = (int)((r.bottom - r.top) * (double)interval.highest / (double)interval_size);
346
347 /* Draw the background of the graph itself. */
348 GfxFillRect(r.left, r.top, r.right, r.bottom, GRAPH_BASE_COLOUR);
349
350 /* Draw the vertical grid lines. */
351
352 /* Don't draw the first line, as that's where the axis will be. */
353 x = r.left + x_sep;
354
355 int grid_colour = GRAPH_GRID_COLOUR;
356 for (int i = 1; i < this->num_vert_lines + 1; i++) {
357 /* If using wallclock units, we separate periods with a lighter line. */
358 if (TimerGameEconomy::UsingWallclockUnits()) {
359 grid_colour = (i % 4 == 0) ? GRAPH_YEAR_LINE_COLOUR : GRAPH_GRID_COLOUR;
360 }
361 GfxFillRect(x, r.top, x, r.bottom, grid_colour);
362 x += x_sep;
363 }
364
365 /* Draw the horizontal grid lines. */
366 y = r.bottom;
367
368 for (int i = 0; i < (num_hori_lines + 1); i++) {
369 GfxFillRect(r.left - ScaleGUITrad(3), y, r.left - 1, y, GRAPH_AXIS_LINE_COLOUR);
370 GfxFillRect(r.left, y, r.right, y, GRAPH_GRID_COLOUR);
371 y -= y_sep;
372 }
373
374 /* Draw the y axis. */
375 GfxFillRect(r.left, r.top, r.left, r.bottom, GRAPH_AXIS_LINE_COLOUR);
376
377 /* Draw the x axis. */
378 y = x_axis_offset + r.top;
379 GfxFillRect(r.left, y, r.right, y, GRAPH_ZERO_LINE_COLOUR);
380
381 /* Find the largest value that will be drawn. */
382 if (this->num_on_x_axis == 0) return;
383
384 assert(this->num_on_x_axis > 0);
385
386 /* draw text strings on the y axis */
387 int64_t y_label = interval.highest;
388 int64_t y_label_separation = abs(interval.highest - interval.lowest) / num_hori_lines;
389
390 y = r.top - GetCharacterHeight(FS_SMALL) / 2;
391
392 for (int i = 0; i < (num_hori_lines + 1); i++) {
393 SetDParam(0, this->format_str_y_axis);
394 SetDParam(1, y_label);
395 DrawString(r.left - label_width - ScaleGUITrad(4), r.left - ScaleGUITrad(4), y, STR_GRAPH_Y_LABEL, GRAPH_AXIS_LABEL_COLOUR, SA_RIGHT);
396
397 y_label -= y_label_separation;
398 y += y_sep;
399 }
400
401 /* Draw x-axis labels and markings for graphs based on financial quarters and years. */
402 if (this->draw_dates) {
403 x = r.left;
404 y = r.bottom + ScaleGUITrad(2);
405 TimerGameEconomy::Month month = this->month;
406 TimerGameEconomy::Year year = this->year;
407 for (int i = 0; i < this->num_on_x_axis; i++) {
408 SetDParam(0, month + STR_MONTH_ABBREV_JAN);
409 SetDParam(1, year);
410 DrawStringMultiLine(x, x + x_sep, y, this->height, month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, GRAPH_AXIS_LABEL_COLOUR, SA_LEFT);
411
412 month += 3;
413 if (month >= 12) {
414 month = 0;
415 year++;
416
417 /* Draw a lighter grid line between years. Top and bottom adjustments ensure we don't draw over top and bottom horizontal grid lines. */
418 GfxFillRect(x + x_sep, r.top + 1, x + x_sep, r.bottom - 1, GRAPH_YEAR_LINE_COLOUR);
419 }
420 x += x_sep;
421 }
422 } else {
423 /* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates, and all graphs when using wallclock units). */
424 x = r.left;
425 y = r.bottom + ScaleGUITrad(2);
426 uint16_t label = this->x_values_start;
427
428 for (int i = 0; i < this->num_on_x_axis; i++) {
429 SetDParam(0, label);
430 DrawString(x + 1, x + x_sep - 1, y, STR_GRAPH_Y_LABEL_NUMBER, GRAPH_AXIS_LABEL_COLOUR, SA_HOR_CENTER);
431
432 label += this->x_values_increment;
433 x += x_sep;
434 }
435 }
436
437 /* draw lines and dots */
438 uint linewidth = _settings_client.gui.graph_line_thickness;
439 uint pointoffs1 = (linewidth + 1) / 2;
440 uint pointoffs2 = linewidth + 1 - pointoffs1;
441 for (int i = 0; i < this->num_dataset; i++) {
442 if (!HasBit(this->excluded_data, i)) {
443 /* Centre the dot between the grid lines. */
444 x = r.left + (x_sep / 2);
445
446 byte colour = this->colours[i];
447 uint prev_x = INVALID_DATAPOINT_POS;
448 uint prev_y = INVALID_DATAPOINT_POS;
449
450 for (int j = 0; j < this->num_on_x_axis; j++) {
451 OverflowSafeInt64 datapoint = this->cost[i][j];
452
453 if (datapoint != INVALID_DATAPOINT) {
454 /*
455 * Check whether we need to reduce the 'accuracy' of the
456 * datapoint value and the highest value to split overflows.
457 * And when 'drawing' 'one million' or 'one million and one'
458 * there is no significant difference, so the least
459 * significant bits can just be removed.
460 *
461 * If there are more bits needed than would fit in a 32 bits
462 * integer, so at about 31 bits because of the sign bit, the
463 * least significant bits are removed.
464 */
465 int mult_range = FindLastBit<uint32_t>(x_axis_offset) + FindLastBit<uint64_t>(abs(datapoint));
466 int reduce_range = std::max(mult_range - 31, 0);
467
468 /* Handle negative values differently (don't shift sign) */
469 if (datapoint < 0) {
470 datapoint = -(abs(datapoint) >> reduce_range);
471 } else {
472 datapoint >>= reduce_range;
473 }
474 y = r.top + x_axis_offset - ((r.bottom - r.top) * datapoint) / (interval_size >> reduce_range);
475
476 /* Draw the point. */
477 GfxFillRect(x - pointoffs1, y - pointoffs1, x + pointoffs2, y + pointoffs2, colour);
478
479 /* Draw the line connected to the previous point. */
480 if (prev_x != INVALID_DATAPOINT_POS) GfxDrawLine(prev_x, prev_y, x, y, colour, linewidth);
481
482 prev_x = x;
483 prev_y = y;
484 } else {
485 prev_x = INVALID_DATAPOINT_POS;
486 prev_y = INVALID_DATAPOINT_POS;
487 }
488
489 x += x_sep;
490 }
491 }
492 }
493 }
494
495
496 BaseGraphWindow(WindowDesc *desc, StringID format_str_y_axis) :
497 Window(desc),
498 format_str_y_axis(format_str_y_axis)
499 {
500 SetWindowDirty(WC_GRAPH_LEGEND, 0);
501 this->num_vert_lines = 24;
502 }
503
504 void InitializeWindow(WindowNumber number)
505 {
506 /* Initialise the dataset */
507 this->UpdateStatistics(true);
508
509 this->CreateNestedTree();
510
511 auto *wid = this->GetWidget<NWidgetCore>(WID_GRAPH_FOOTER);
512 if (wid != nullptr && TimerGameEconomy::UsingWallclockUnits()) {
513 wid->SetDataTip(STR_GRAPH_LAST_72_MINUTES_TIME_LABEL, STR_NULL);
514 }
515
516 this->FinishInitNested(number);
517 }
518
519 public:
520 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
521 {
522 if (widget != WID_GRAPH_GRAPH) return;
523
524 uint x_label_width = 0;
525
526 /* Draw x-axis labels and markings for graphs based on financial quarters and years. */
527 if (this->draw_dates) {
528 TimerGameEconomy::Month month = this->month;
529 TimerGameEconomy::Year year = this->year;
530 for (int i = 0; i < this->num_on_x_axis; i++) {
531 SetDParam(0, month + STR_MONTH_ABBREV_JAN);
532 SetDParam(1, year);
533 x_label_width = std::max(x_label_width, GetStringBoundingBox(month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH).width);
534
535 month += 3;
536 if (month >= 12) {
537 month = 0;
538 year++;
539 }
540 }
541 } else {
542 /* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates). */
543 SetDParamMaxValue(0, this->x_values_start + this->num_on_x_axis * this->x_values_increment, 0, FS_SMALL);
544 x_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL_NUMBER).width;
545 }
546
547 SetDParam(0, this->format_str_y_axis);
548 SetDParam(1, INT64_MAX);
549 uint y_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL).width;
550
551 size->width = std::max<uint>(size->width, ScaleGUITrad(5) + y_label_width + this->num_vert_lines * (x_label_width + ScaleGUITrad(5)) + ScaleGUITrad(9));
552 size->height = std::max<uint>(size->height, ScaleGUITrad(5) + (1 + MIN_GRAPH_NUM_LINES_Y * 2 + (this->draw_dates ? 3 : 1)) * GetCharacterHeight(FS_SMALL) + ScaleGUITrad(4));
553 size->height = std::max<uint>(size->height, size->width / 3);
554 }
555
556 void DrawWidget(const Rect &r, WidgetID widget) const override
557 {
558 if (widget != WID_GRAPH_GRAPH) return;
559
560 DrawGraph(r);
561 }
562
563 virtual OverflowSafeInt64 GetGraphData(const Company *, int)
564 {
565 return INVALID_DATAPOINT;
566 }
567
568 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
569 {
570 /* Clicked on legend? */
571 if (widget == WID_GRAPH_KEY_BUTTON) ShowGraphLegend();
572 }
573
574 void OnGameTick() override
575 {
576 this->UpdateStatistics(false);
577 }
578
584 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
585 {
586 if (!gui_scope) return;
587 this->UpdateStatistics(true);
588 }
589
594 void UpdateStatistics(bool initialize)
595 {
596 CompanyMask excluded_companies = _legend_excluded_companies;
597
598 /* Exclude the companies which aren't valid */
599 for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
600 if (!Company::IsValidID(c)) SetBit(excluded_companies, c);
601 }
602
603 byte nums = 0;
604 for (const Company *c : Company::Iterate()) {
605 nums = std::min(this->num_vert_lines, std::max(nums, c->num_valid_stat_ent));
606 }
607
608 int mo = (TimerGameEconomy::month / 3 - nums) * 3;
609 auto yr = TimerGameEconomy::year;
610 while (mo < 0) {
611 yr--;
612 mo += 12;
613 }
614
615 if (!initialize && this->excluded_data == excluded_companies && this->num_on_x_axis == nums &&
616 this->year == yr && this->month == mo) {
617 /* There's no reason to get new stats */
618 return;
619 }
620
621 this->excluded_data = excluded_companies;
622 this->num_on_x_axis = nums;
623 this->year = yr;
624 this->month = mo;
625
626 int numd = 0;
627 for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) {
628 const Company *c = Company::GetIfValid(k);
629 if (c != nullptr) {
630 this->colours[numd] = _colour_gradient[c->colour][6];
631 for (int j = this->num_on_x_axis, i = 0; --j >= 0;) {
632 if (j >= c->num_valid_stat_ent) {
633 this->cost[numd][i] = INVALID_DATAPOINT;
634 } else {
635 /* Ensure we never assign INVALID_DATAPOINT, as that has another meaning.
636 * Instead, use the value just under it. Hopefully nobody will notice. */
637 this->cost[numd][i] = std::min(GetGraphData(c, j), INVALID_DATAPOINT - 1);
638 }
639 i++;
640 }
641 }
642 numd++;
643 }
644
645 this->num_dataset = numd;
646 }
647 };
648
649
650 /********************/
651 /* OPERATING PROFIT */
652 /********************/
653
654 struct OperatingProfitGraphWindow : BaseGraphWindow {
655 OperatingProfitGraphWindow(WindowDesc *desc, WindowNumber window_number) :
656 BaseGraphWindow(desc, STR_JUST_CURRENCY_SHORT)
657 {
658 this->num_on_x_axis = GRAPH_NUM_MONTHS;
659 this->num_vert_lines = GRAPH_NUM_MONTHS;
660 this->x_values_start = ECONOMY_QUARTER_MINUTES;
661 this->x_values_increment = ECONOMY_QUARTER_MINUTES;
662 this->draw_dates = !TimerGameEconomy::UsingWallclockUnits();
663
664 this->InitializeWindow(window_number);
665 }
666
667 OverflowSafeInt64 GetGraphData(const Company *c, int j) override
668 {
669 return c->old_economy[j].income + c->old_economy[j].expenses;
670 }
671 };
672
673 static constexpr NWidgetPart _nested_operating_profit_widgets[] = {
674 NWidget(NWID_HORIZONTAL),
675 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
676 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_OPERATING_PROFIT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
677 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GRAPH_KEY_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
678 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
679 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
680 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
681 EndContainer(),
682 NWidget(WWT_PANEL, COLOUR_BROWN, WID_GRAPH_BACKGROUND),
683 NWidget(NWID_VERTICAL),
684 NWidget(WWT_EMPTY, COLOUR_BROWN, WID_GRAPH_GRAPH), SetMinimalSize(576, 160), SetFill(1, 1), SetResize(1, 1),
685 NWidget(NWID_HORIZONTAL),
686 NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
687 NWidget(WWT_TEXT, COLOUR_BROWN, WID_GRAPH_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_EMPTY, STR_NULL),
688 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
689 NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_GRAPH_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
690 EndContainer(),
691 EndContainer(),
692 EndContainer(),
693 };
694
695 static WindowDesc _operating_profit_desc(__FILE__, __LINE__,
696 WDP_AUTO, "graph_operating_profit", 0, 0,
697 WC_OPERATING_PROFIT, WC_NONE,
698 0,
699 std::begin(_nested_operating_profit_widgets), std::end(_nested_operating_profit_widgets)
700 );
701
702
703 void ShowOperatingProfitGraph()
704 {
705 AllocateWindowDescFront<OperatingProfitGraphWindow>(&_operating_profit_desc, 0);
706 }
707
708
709 /****************/
710 /* INCOME GRAPH */
711 /****************/
712
713 struct IncomeGraphWindow : BaseGraphWindow {
714 IncomeGraphWindow(WindowDesc *desc, WindowNumber window_number) :
715 BaseGraphWindow(desc, STR_JUST_CURRENCY_SHORT)
716 {
717 this->num_on_x_axis = GRAPH_NUM_MONTHS;
718 this->num_vert_lines = GRAPH_NUM_MONTHS;
719 this->x_values_start = ECONOMY_QUARTER_MINUTES;
720 this->x_values_increment = ECONOMY_QUARTER_MINUTES;
721 this->draw_dates = !TimerGameEconomy::UsingWallclockUnits();
722
723 this->InitializeWindow(window_number);
724 }
725
726 OverflowSafeInt64 GetGraphData(const Company *c, int j) override
727 {
728 return c->old_economy[j].income;
729 }
730 };
731
732 static constexpr NWidgetPart _nested_income_graph_widgets[] = {
733 NWidget(NWID_HORIZONTAL),
734 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
735 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_INCOME_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
736 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GRAPH_KEY_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
737 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
738 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
739 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
740 EndContainer(),
741 NWidget(WWT_PANEL, COLOUR_BROWN, WID_GRAPH_BACKGROUND),
742 NWidget(NWID_VERTICAL),
743 NWidget(WWT_EMPTY, COLOUR_BROWN, WID_GRAPH_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
744 NWidget(NWID_HORIZONTAL),
745 NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
746 NWidget(WWT_TEXT, COLOUR_BROWN, WID_GRAPH_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_EMPTY, STR_NULL),
747 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
748 NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_GRAPH_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
749 EndContainer(),
750 EndContainer(),
751 EndContainer(),
752 };
753
754 static WindowDesc _income_graph_desc(__FILE__, __LINE__,
755 WDP_AUTO, "graph_income", 0, 0,
756 WC_INCOME_GRAPH, WC_NONE,
757 0,
758 std::begin(_nested_income_graph_widgets), std::end(_nested_income_graph_widgets)
759 );
760
761 void ShowIncomeGraph()
762 {
763 AllocateWindowDescFront<IncomeGraphWindow>(&_income_graph_desc, 0);
764 }
765
766 /*******************/
767 /* DELIVERED CARGO */
768 /*******************/
769
770 struct DeliveredCargoGraphWindow : BaseGraphWindow {
771 DeliveredCargoGraphWindow(WindowDesc *desc, WindowNumber window_number) :
772 BaseGraphWindow(desc, STR_JUST_COMMA)
773 {
774 this->num_on_x_axis = GRAPH_NUM_MONTHS;
775 this->num_vert_lines = GRAPH_NUM_MONTHS;
776 this->x_values_start = ECONOMY_QUARTER_MINUTES;
777 this->x_values_increment = ECONOMY_QUARTER_MINUTES;
778 this->draw_dates = !TimerGameEconomy::UsingWallclockUnits();
779
780 this->InitializeWindow(window_number);
781 }
782
783 OverflowSafeInt64 GetGraphData(const Company *c, int j) override
784 {
785 return c->old_economy[j].delivered_cargo.GetSum<OverflowSafeInt64>();
786 }
787 };
788
789 static constexpr NWidgetPart _nested_delivered_cargo_graph_widgets[] = {
790 NWidget(NWID_HORIZONTAL),
791 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
792 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_CARGO_DELIVERED_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
793 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GRAPH_KEY_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
794 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
795 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
796 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
797 EndContainer(),
798 NWidget(WWT_PANEL, COLOUR_BROWN, WID_GRAPH_BACKGROUND),
799 NWidget(NWID_VERTICAL),
800 NWidget(WWT_EMPTY, COLOUR_BROWN, WID_GRAPH_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
801 NWidget(NWID_HORIZONTAL),
802 NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
803 NWidget(WWT_TEXT, COLOUR_BROWN, WID_GRAPH_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_EMPTY, STR_NULL),
804 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
805 NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_GRAPH_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
806 EndContainer(),
807 EndContainer(),
808 EndContainer(),
809 };
810
811 static WindowDesc _delivered_cargo_graph_desc(__FILE__, __LINE__,
812 WDP_AUTO, "graph_delivered_cargo", 0, 0,
813 WC_DELIVERED_CARGO, WC_NONE,
814 0,
815 std::begin(_nested_delivered_cargo_graph_widgets), std::end(_nested_delivered_cargo_graph_widgets)
816 );
817
818 void ShowDeliveredCargoGraph()
819 {
820 AllocateWindowDescFront<DeliveredCargoGraphWindow>(&_delivered_cargo_graph_desc, 0);
821 }
822
823 /***********************/
824 /* PERFORMANCE HISTORY */
825 /***********************/
826
827 struct PerformanceHistoryGraphWindow : BaseGraphWindow {
828 PerformanceHistoryGraphWindow(WindowDesc *desc, WindowNumber window_number) :
829 BaseGraphWindow(desc, STR_JUST_COMMA)
830 {
831 this->num_on_x_axis = GRAPH_NUM_MONTHS;
832 this->num_vert_lines = GRAPH_NUM_MONTHS;
833 this->x_values_start = ECONOMY_QUARTER_MINUTES;
834 this->x_values_increment = ECONOMY_QUARTER_MINUTES;
835 this->draw_dates = !TimerGameEconomy::UsingWallclockUnits();
836
837 this->InitializeWindow(window_number);
838 }
839
840 OverflowSafeInt64 GetGraphData(const Company *c, int j) override
841 {
842 return c->old_economy[j].performance_history;
843 }
844
845 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
846 {
847 if (widget == WID_PHG_DETAILED_PERFORMANCE) ShowPerformanceRatingDetail();
848 this->BaseGraphWindow::OnClick(pt, widget, click_count);
849 }
850 };
851
852 static constexpr NWidgetPart _nested_performance_history_widgets[] = {
853 NWidget(NWID_HORIZONTAL),
854 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
855 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_COMPANY_PERFORMANCE_RATINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
856 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_PHG_DETAILED_PERFORMANCE), SetMinimalSize(50, 0), SetDataTip(STR_PERFORMANCE_DETAIL_KEY, STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP),
857 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GRAPH_KEY_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
858 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
859 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
860 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
861 EndContainer(),
862 NWidget(WWT_PANEL, COLOUR_BROWN, WID_GRAPH_BACKGROUND),
863 NWidget(NWID_VERTICAL),
864 NWidget(WWT_EMPTY, COLOUR_BROWN, WID_GRAPH_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
865 NWidget(NWID_HORIZONTAL),
866 NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
867 NWidget(WWT_TEXT, COLOUR_BROWN, WID_GRAPH_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_EMPTY, STR_NULL),
868 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
869 NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_GRAPH_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
870 EndContainer(),
871 EndContainer(),
872 EndContainer(),
873 };
874
875 static WindowDesc _performance_history_desc(__FILE__, __LINE__,
876 WDP_AUTO, "graph_performance", 0, 0,
877 WC_PERFORMANCE_HISTORY, WC_NONE,
878 0,
879 std::begin(_nested_performance_history_widgets), std::end(_nested_performance_history_widgets)
880 );
881
882 void ShowPerformanceHistoryGraph()
883 {
884 AllocateWindowDescFront<PerformanceHistoryGraphWindow>(&_performance_history_desc, 0);
885 }
886
887 /*****************/
888 /* COMPANY VALUE */
889 /*****************/
890
891 struct CompanyValueGraphWindow : BaseGraphWindow {
892 CompanyValueGraphWindow(WindowDesc *desc, WindowNumber window_number) :
893 BaseGraphWindow(desc, STR_JUST_CURRENCY_SHORT)
894 {
895 this->num_on_x_axis = GRAPH_NUM_MONTHS;
896 this->num_vert_lines = GRAPH_NUM_MONTHS;
897 this->x_values_start = ECONOMY_QUARTER_MINUTES;
898 this->x_values_increment = ECONOMY_QUARTER_MINUTES;
899 this->draw_dates = !TimerGameEconomy::UsingWallclockUnits();
900
901 this->InitializeWindow(window_number);
902 }
903
904 OverflowSafeInt64 GetGraphData(const Company *c, int j) override
905 {
906 return c->old_economy[j].company_value;
907 }
908 };
909
910 static constexpr NWidgetPart _nested_company_value_graph_widgets[] = {
911 NWidget(NWID_HORIZONTAL),
912 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
913 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_COMPANY_VALUES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
914 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GRAPH_KEY_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
915 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
916 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
917 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
918 EndContainer(),
919 NWidget(WWT_PANEL, COLOUR_BROWN, WID_GRAPH_BACKGROUND),
920 NWidget(NWID_VERTICAL),
921 NWidget(WWT_EMPTY, COLOUR_BROWN, WID_GRAPH_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
922 NWidget(NWID_HORIZONTAL),
923 NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
924 NWidget(WWT_TEXT, COLOUR_BROWN, WID_GRAPH_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_EMPTY, STR_NULL),
925 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
926 NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_GRAPH_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
927 EndContainer(),
928 EndContainer(),
929 EndContainer(),
930 };
931
932 static WindowDesc _company_value_graph_desc(__FILE__, __LINE__,
933 WDP_AUTO, "graph_company_value", 0, 0,
934 WC_COMPANY_VALUE, WC_NONE,
935 0,
936 std::begin(_nested_company_value_graph_widgets), std::end(_nested_company_value_graph_widgets)
937 );
938
939 void ShowCompanyValueGraph()
940 {
941 AllocateWindowDescFront<CompanyValueGraphWindow>(&_company_value_graph_desc, 0);
942 }
943
944 /*****************/
945 /* PAYMENT RATES */
946 /*****************/
947
948 struct PaymentRatesGraphWindow : BaseGraphWindow {
949 uint line_height;
950 Scrollbar *vscroll;
951 uint legend_width;
952
953 PaymentRatesGraphWindow(WindowDesc *desc, WindowNumber window_number) :
954 BaseGraphWindow(desc, STR_JUST_CURRENCY_SHORT)
955 {
956 this->num_on_x_axis = 20;
957 this->num_vert_lines = 20;
958 this->draw_dates = false;
959 /* The x-axis is labeled in either seconds or days. A day is two seconds, so we adjust the label if needed. */
960 this->x_values_start = (TimerGameEconomy::UsingWallclockUnits() ? PAYMENT_GRAPH_X_STEP_SECONDS : PAYMENT_GRAPH_X_STEP_DAYS);
961 this->x_values_increment = (TimerGameEconomy::UsingWallclockUnits() ? PAYMENT_GRAPH_X_STEP_SECONDS : PAYMENT_GRAPH_X_STEP_DAYS);
962
963 this->CreateNestedTree();
964 this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR);
965 this->vscroll->SetCount(_sorted_standard_cargo_specs.size());
966
967 auto *wid = this->GetWidget<NWidgetCore>(WID_GRAPH_FOOTER);
968 wid->SetDataTip(TimerGameEconomy::UsingWallclockUnits() ? STR_GRAPH_CARGO_PAYMENT_RATES_SECONDS: STR_GRAPH_CARGO_PAYMENT_RATES_DAYS, STR_NULL);
969
970 /* Initialise the dataset */
971 this->UpdatePaymentRates();
972
973 this->FinishInitNested(window_number);
974 }
975
976 void OnInit() override
977 {
978 /* Width of the legend blob. */
979 this->legend_width = GetCharacterHeight(FS_SMALL) * 9 / 6;
980 }
981
982 void UpdateExcludedData()
983 {
984 this->excluded_data = 0;
985
986 int i = 0;
987 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
988 if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i);
989 i++;
990 }
991 }
992
993 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
994 {
995 if (widget != WID_CPR_MATRIX) {
996 BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
997 return;
998 }
999
1000 size->height = GetCharacterHeight(FS_SMALL) + WidgetDimensions::scaled.framerect.Vertical();
1001
1002 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1003 SetDParam(0, cs->name);
1004 Dimension d = GetStringBoundingBox(STR_GRAPH_CARGO_PAYMENT_CARGO);
1005 d.width += this->legend_width + WidgetDimensions::scaled.hsep_normal; // colour field
1006 d.width += WidgetDimensions::scaled.framerect.Horizontal();
1007 d.height += WidgetDimensions::scaled.framerect.Vertical();
1008 *size = maxdim(d, *size);
1009 }
1010
1011 this->line_height = size->height;
1012 size->height = this->line_height * 11; /* Default number of cargo types in most climates. */
1013 resize->width = 0;
1014 resize->height = this->line_height;
1015 }
1016
1017 void DrawWidget(const Rect &r, WidgetID widget) const override
1018 {
1019 if (widget != WID_CPR_MATRIX) {
1020 BaseGraphWindow::DrawWidget(r, widget);
1021 return;
1022 }
1023
1024 bool rtl = _current_text_dir == TD_RTL;
1025
1026 int pos = this->vscroll->GetPosition();
1027 int max = pos + this->vscroll->GetCapacity();
1028
1029 Rect line = r.WithHeight(this->line_height);
1030 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1031 if (pos-- > 0) continue;
1032 if (--max < 0) break;
1033
1034 bool lowered = !HasBit(_legend_excluded_cargo, cs->Index());
1035
1036 /* Redraw frame if lowered */
1037 if (lowered) DrawFrameRect(line, COLOUR_BROWN, FR_LOWERED);
1038
1039 const Rect text = line.Shrink(WidgetDimensions::scaled.framerect);
1040
1041 /* Cargo-colour box with outline */
1042 const Rect cargo = text.WithWidth(this->legend_width, rtl);
1043 GfxFillRect(cargo, PC_BLACK);
1044 GfxFillRect(cargo.Shrink(WidgetDimensions::scaled.bevel), cs->legend_colour);
1045
1046 /* Cargo name */
1047 SetDParam(0, cs->name);
1048 DrawString(text.Indent(this->legend_width + WidgetDimensions::scaled.hsep_normal, rtl), STR_GRAPH_CARGO_PAYMENT_CARGO);
1049
1050 line = line.Translate(0, this->line_height);
1051 }
1052 }
1053
1054 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1055 {
1056 switch (widget) {
1057 case WID_CPR_ENABLE_CARGOES:
1058 /* Remove all cargoes from the excluded lists. */
1059 _legend_excluded_cargo = 0;
1060 this->excluded_data = 0;
1061 this->SetDirty();
1062 break;
1063
1064 case WID_CPR_DISABLE_CARGOES: {
1065 /* Add all cargoes to the excluded lists. */
1066 int i = 0;
1067 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1068 SetBit(_legend_excluded_cargo, cs->Index());
1069 SetBit(this->excluded_data, i);
1070 i++;
1071 }
1072 this->SetDirty();
1073 break;
1074 }
1075
1076 case WID_CPR_MATRIX: {
1077 auto it = this->vscroll->GetScrolledItemFromWidget(_sorted_standard_cargo_specs, pt.y, this, WID_CPR_MATRIX);
1078 if (it != _sorted_standard_cargo_specs.end()) {
1079 ToggleBit(_legend_excluded_cargo, (*it)->Index());
1080 this->UpdateExcludedData();
1081 this->SetDirty();
1082 break;
1083 }
1084 break;
1085 }
1086 }
1087 }
1088
1089 void OnResize() override
1090 {
1091 this->vscroll->SetCapacityFromWidget(this, WID_CPR_MATRIX);
1092 }
1093
1094 void OnGameTick() override
1095 {
1096 /* Override default OnGameTick */
1097 }
1098
1104 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1105 {
1106 if (!gui_scope) return;
1107 this->UpdatePaymentRates();
1108 }
1109
1111 IntervalTimer<TimerWindow> update_payment_interval = {std::chrono::seconds(3), [this](auto) {
1112 this->UpdatePaymentRates();
1113 }};
1114
1118 void UpdatePaymentRates()
1119 {
1120 this->UpdateExcludedData();
1121
1122 int i = 0;
1123 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1124 this->colours[i] = cs->legend_colour;
1125 for (uint j = 0; j != this->num_on_x_axis; j++) {
1126 this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
1127 }
1128 i++;
1129 }
1130 this->num_dataset = i;
1131 }
1132 };
1133
1134 static constexpr NWidgetPart _nested_cargo_payment_rates_widgets[] = {
1135 NWidget(NWID_HORIZONTAL),
1136 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1137 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1138 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1139 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1140 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1141 EndContainer(),
1142 NWidget(WWT_PANEL, COLOUR_BROWN, WID_GRAPH_BACKGROUND), SetMinimalSize(568, 128),
1143 NWidget(NWID_HORIZONTAL),
1144 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1145 NWidget(WWT_TEXT, COLOUR_BROWN, WID_GRAPH_HEADER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE, STR_NULL),
1146 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1147 EndContainer(),
1148 NWidget(NWID_HORIZONTAL),
1149 NWidget(WWT_EMPTY, COLOUR_BROWN, WID_GRAPH_GRAPH), SetMinimalSize(495, 0), SetFill(1, 1), SetResize(1, 1),
1150 NWidget(NWID_VERTICAL),
1151 NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
1152 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CPR_ENABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0),
1153 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CPR_DISABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL), SetFill(1, 0),
1154 NWidget(NWID_SPACER), SetMinimalSize(0, 4),
1155 NWidget(NWID_HORIZONTAL),
1156 NWidget(WWT_MATRIX, COLOUR_BROWN, WID_CPR_MATRIX), SetFill(1, 0), SetResize(0, 2), SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO), SetScrollbar(WID_CPR_MATRIX_SCROLLBAR),
1157 NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_CPR_MATRIX_SCROLLBAR),
1158 EndContainer(),
1159 NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
1160 EndContainer(),
1161 NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1),
1162 EndContainer(),
1163 NWidget(NWID_HORIZONTAL),
1164 NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
1165 NWidget(WWT_TEXT, COLOUR_BROWN, WID_GRAPH_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_NULL, STR_NULL),
1166 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1167 NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_GRAPH_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
1168 EndContainer(),
1169 EndContainer(),
1170 };
1171
1172 static WindowDesc _cargo_payment_rates_desc(__FILE__, __LINE__,
1173 WDP_AUTO, "graph_cargo_payment_rates", 0, 0,
1174 WC_PAYMENT_RATES, WC_NONE,
1175 0,
1176 std::begin(_nested_cargo_payment_rates_widgets), std::end(_nested_cargo_payment_rates_widgets)
1177 );
1178
1179
1180 void ShowCargoPaymentRates()
1181 {
1182 AllocateWindowDescFront<PaymentRatesGraphWindow>(&_cargo_payment_rates_desc, 0);
1183 }
1184
1185 /*****************************/
1186 /* PERFORMANCE RATING DETAIL */
1187 /*****************************/
1188
1189 struct PerformanceRatingDetailWindow : Window {
1190 static CompanyID company;
1191 int timeout;
1192
1193 PerformanceRatingDetailWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
1194 {
1195 this->UpdateCompanyStats();
1196
1197 this->InitNested(window_number);
1198 this->OnInvalidateData(INVALID_COMPANY);
1199 }
1200
1201 void UpdateCompanyStats()
1202 {
1203 /* Update all company stats with the current data
1204 * (this is because _score_info is not saved to a savegame) */
1205 for (Company *c : Company::Iterate()) {
1206 UpdateCompanyRatingAndValue(c, false);
1207 }
1208
1209 this->timeout = Ticks::DAY_TICKS * 5;
1210 }
1211
1212 uint score_info_left;
1213 uint score_info_right;
1214 uint bar_left;
1215 uint bar_right;
1216 uint bar_width;
1217 uint bar_height;
1218 uint score_detail_left;
1219 uint score_detail_right;
1220
1221 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
1222 {
1223 switch (widget) {
1224 case WID_PRD_SCORE_FIRST:
1225 this->bar_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.fullbevel.Vertical();
1226 size->height = this->bar_height + WidgetDimensions::scaled.matrix.Vertical();
1227
1228 uint score_info_width = 0;
1229 for (uint i = SCORE_BEGIN; i < SCORE_END; i++) {
1230 score_info_width = std::max(score_info_width, GetStringBoundingBox(STR_PERFORMANCE_DETAIL_VEHICLES + i).width);
1231 }
1232 SetDParamMaxValue(0, 1000);
1233 score_info_width += GetStringBoundingBox(STR_JUST_COMMA).width + WidgetDimensions::scaled.hsep_wide;
1234
1235 SetDParamMaxValue(0, 100);
1236 this->bar_width = GetStringBoundingBox(STR_PERFORMANCE_DETAIL_PERCENT).width + WidgetDimensions::scaled.hsep_indent * 2; // Wide bars!
1237
1238 /* At this number we are roughly at the max; it can become wider,
1239 * but then you need at 1000 times more money. At that time you're
1240 * not that interested anymore in the last few digits anyway.
1241 * The 500 is because 999 999 500 to 999 999 999 are rounded to
1242 * 1 000 M, and not 999 999 k. Use negative numbers to account for
1243 * the negative income/amount of money etc. as well. */
1244 int max = -(999999999 - 500);
1245
1246 /* Scale max for the display currency. Prior to rendering the value
1247 * is converted into the display currency, which may cause it to
1248 * raise significantly. We need to compensate for that since {{CURRCOMPACT}}
1249 * is used, which can produce quite short renderings of very large
1250 * values. Otherwise the calculated width could be too narrow.
1251 * Note that it doesn't work if there was a currency with an exchange
1252 * rate greater than max.
1253 * When the currency rate is more than 1000, the 999 999 k becomes at
1254 * least 999 999 M which roughly is equally long. Furthermore if the
1255 * exchange rate is that high, 999 999 k is usually not enough anymore
1256 * to show the different currency numbers. */
1257 if (_currency->rate < 1000) max /= _currency->rate;
1258 SetDParam(0, max);
1259 SetDParam(1, max);
1260 uint score_detail_width = GetStringBoundingBox(STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY).width;
1261
1262 size->width = WidgetDimensions::scaled.frametext.Horizontal() + score_info_width + WidgetDimensions::scaled.hsep_wide + this->bar_width + WidgetDimensions::scaled.hsep_wide + score_detail_width;
1263 uint left = WidgetDimensions::scaled.frametext.left;
1264 uint right = size->width - WidgetDimensions::scaled.frametext.right;
1265
1266 bool rtl = _current_text_dir == TD_RTL;
1267 this->score_info_left = rtl ? right - score_info_width : left;
1268 this->score_info_right = rtl ? right : left + score_info_width;
1269
1270 this->score_detail_left = rtl ? left : right - score_detail_width;
1271 this->score_detail_right = rtl ? left + score_detail_width : right;
1272
1273 this->bar_left = left + (rtl ? score_detail_width : score_info_width) + WidgetDimensions::scaled.hsep_wide;
1274 this->bar_right = this->bar_left + this->bar_width - 1;
1275 break;
1276 }
1277 }
1278
1279 void DrawWidget(const Rect &r, WidgetID widget) const override
1280 {
1281 /* No need to draw when there's nothing to draw */
1282 if (this->company == INVALID_COMPANY) return;
1283
1284 if (IsInsideMM(widget, WID_PRD_COMPANY_FIRST, WID_PRD_COMPANY_LAST + 1)) {
1285 if (this->IsWidgetDisabled(widget)) return;
1286 CompanyID cid = (CompanyID)(widget - WID_PRD_COMPANY_FIRST);
1287 Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
1288 DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width), CenterBounds(r.top, r.bottom, sprite_size.height));
1289 return;
1290 }
1291
1292 if (!IsInsideMM(widget, WID_PRD_SCORE_FIRST, WID_PRD_SCORE_LAST + 1)) return;
1293
1294 ScoreID score_type = (ScoreID)(widget - WID_PRD_SCORE_FIRST);
1295
1296 /* The colours used to show how the progress is going */
1297 int colour_done = _colour_gradient[COLOUR_GREEN][4];
1298 int colour_notdone = _colour_gradient[COLOUR_RED][4];
1299
1300 /* Draw all the score parts */
1301 int64_t val = _score_part[company][score_type];
1302 int64_t needed = _score_info[score_type].needed;
1303 int score = _score_info[score_type].score;
1304
1305 /* SCORE_TOTAL has its own rules ;) */
1306 if (score_type == SCORE_TOTAL) {
1307 for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) score += _score_info[i].score;
1308 needed = SCORE_MAX;
1309 }
1310
1311 uint bar_top = CenterBounds(r.top, r.bottom, this->bar_height);
1312 uint text_top = CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL));
1313
1314 DrawString(this->score_info_left, this->score_info_right, text_top, STR_PERFORMANCE_DETAIL_VEHICLES + score_type);
1315
1316 /* Draw the score */
1317 SetDParam(0, score);
1318 DrawString(this->score_info_left, this->score_info_right, text_top, STR_JUST_COMMA, TC_BLACK, SA_RIGHT);
1319
1320 /* Calculate the %-bar */
1321 uint x = Clamp<int64_t>(val, 0, needed) * this->bar_width / needed;
1322 bool rtl = _current_text_dir == TD_RTL;
1323 if (rtl) {
1324 x = this->bar_right - x;
1325 } else {
1326 x = this->bar_left + x;
1327 }
1328
1329 /* Draw the bar */
1330 if (x != this->bar_left) GfxFillRect(this->bar_left, bar_top, x, bar_top + this->bar_height - 1, rtl ? colour_notdone : colour_done);
1331 if (x != this->bar_right) GfxFillRect(x, bar_top, this->bar_right, bar_top + this->bar_height - 1, rtl ? colour_done : colour_notdone);
1332
1333 /* Draw it */
1334 SetDParam(0, Clamp<int64_t>(val, 0, needed) * 100 / needed);
1335 DrawString(this->bar_left, this->bar_right, text_top, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING, SA_HOR_CENTER);
1336
1337 /* SCORE_LOAN is inversed */
1338 if (score_type == SCORE_LOAN) val = needed - val;
1339
1340 /* Draw the amount we have against what is needed
1341 * For some of them it is in currency format */
1342 SetDParam(0, val);
1343 SetDParam(1, needed);
1344 switch (score_type) {
1345 case SCORE_MIN_PROFIT:
1346 case SCORE_MIN_INCOME:
1347 case SCORE_MAX_INCOME:
1348 case SCORE_MONEY:
1349 case SCORE_LOAN:
1350 DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY);
1351 break;
1352 default:
1353 DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_INT);
1354 }
1355 }
1356
1357 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1358 {
1359 /* Check which button is clicked */
1360 if (IsInsideMM(widget, WID_PRD_COMPANY_FIRST, WID_PRD_COMPANY_LAST + 1)) {
1361 /* Is it no on disable? */
1362 if (!this->IsWidgetDisabled(widget)) {
1363 this->RaiseWidget(WID_PRD_COMPANY_FIRST + this->company);
1364 this->company = (CompanyID)(widget - WID_PRD_COMPANY_FIRST);
1365 this->LowerWidget(WID_PRD_COMPANY_FIRST + this->company);
1366 this->SetDirty();
1367 }
1368 }
1369 }
1370
1371 void OnGameTick() override
1372 {
1373 /* Update the company score every 5 days */
1374 if (--this->timeout == 0) {
1375 this->UpdateCompanyStats();
1376 this->SetDirty();
1377 }
1378 }
1379
1385 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1386 {
1387 if (!gui_scope) return;
1388 /* Disable the companies who are not active */
1389 for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
1390 this->SetWidgetDisabledState(WID_PRD_COMPANY_FIRST + i, !Company::IsValidID(i));
1391 }
1392
1393 /* Check if the currently selected company is still active. */
1394 if (this->company != INVALID_COMPANY && !Company::IsValidID(this->company)) {
1395 /* Raise the widget for the previous selection. */
1396 this->RaiseWidget(WID_PRD_COMPANY_FIRST + this->company);
1397 this->company = INVALID_COMPANY;
1398 }
1399
1400 if (this->company == INVALID_COMPANY) {
1401 for (const Company *c : Company::Iterate()) {
1402 this->company = c->index;
1403 break;
1404 }
1405 }
1406
1407 /* Make sure the widget is lowered */
1408 this->LowerWidget(WID_PRD_COMPANY_FIRST + this->company);
1409 }
1410 };
1411
1412 CompanyID PerformanceRatingDetailWindow::company = INVALID_COMPANY;
1413
1418 static std::unique_ptr<NWidgetBase> MakePerformanceDetailPanels()
1419 {
1420 auto realtime = TimerGameEconomy::UsingWallclockUnits();
1421 const StringID performance_tips[] = {
1422 realtime ? STR_PERFORMANCE_DETAIL_VEHICLES_TOOLTIP_PERIODS : STR_PERFORMANCE_DETAIL_VEHICLES_TOOLTIP_YEARS,
1423 STR_PERFORMANCE_DETAIL_STATIONS_TOOLTIP,
1424 realtime ? STR_PERFORMANCE_DETAIL_MIN_PROFIT_TOOLTIP_PERIODS : STR_PERFORMANCE_DETAIL_MIN_PROFIT_TOOLTIP_YEARS,
1425 STR_PERFORMANCE_DETAIL_MIN_INCOME_TOOLTIP,
1426 STR_PERFORMANCE_DETAIL_MAX_INCOME_TOOLTIP,
1427 STR_PERFORMANCE_DETAIL_DELIVERED_TOOLTIP,
1428 STR_PERFORMANCE_DETAIL_CARGO_TOOLTIP,
1429 STR_PERFORMANCE_DETAIL_MONEY_TOOLTIP,
1430 STR_PERFORMANCE_DETAIL_LOAN_TOOLTIP,
1431 STR_PERFORMANCE_DETAIL_TOTAL_TOOLTIP,
1432 };
1433
1434 static_assert(lengthof(performance_tips) == SCORE_END - SCORE_BEGIN);
1435
1436 auto vert = std::make_unique<NWidgetVertical>(NC_EQUALSIZE);
1437 for (WidgetID widnum = WID_PRD_SCORE_FIRST; widnum <= WID_PRD_SCORE_LAST; widnum++) {
1438 auto panel = std::make_unique<NWidgetBackground>(WWT_PANEL, COLOUR_BROWN, widnum);
1439 panel->SetFill(1, 1);
1440 panel->SetDataTip(0x0, performance_tips[widnum - WID_PRD_SCORE_FIRST]);
1441 vert->Add(std::move(panel));
1442 }
1443 return vert;
1444 }
1445
1447 std::unique_ptr<NWidgetBase> MakeCompanyButtonRowsGraphGUI()
1448 {
1449 return MakeCompanyButtonRows(WID_PRD_COMPANY_FIRST, WID_PRD_COMPANY_LAST, COLOUR_BROWN, 8, STR_PERFORMANCE_DETAIL_SELECT_COMPANY_TOOLTIP);
1450 }
1451
1452 static constexpr NWidgetPart _nested_performance_rating_detail_widgets[] = {
1453 NWidget(NWID_HORIZONTAL),
1454 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1455 NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_PERFORMANCE_DETAIL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1456 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1457 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1458 EndContainer(),
1459 NWidget(WWT_PANEL, COLOUR_BROWN),
1460 NWidgetFunction(MakeCompanyButtonRowsGraphGUI), SetPadding(2),
1461 EndContainer(),
1462 NWidgetFunction(MakePerformanceDetailPanels),
1463 };
1464
1465 static WindowDesc _performance_rating_detail_desc(__FILE__, __LINE__,
1466 WDP_AUTO, "league_details", 0, 0,
1467 WC_PERFORMANCE_DETAIL, WC_NONE,
1468 0,
1469 std::begin(_nested_performance_rating_detail_widgets), std::end(_nested_performance_rating_detail_widgets)
1470 );
1471
1472 void ShowPerformanceRatingDetail()
1473 {
1474 AllocateWindowDescFront<PerformanceRatingDetailWindow>(&_performance_rating_detail_desc, 0);
1475 }
1476
1477 void InitializeGraphGui()
1478 {
1479 _legend_excluded_companies = 0;
1480 _legend_excluded_cargo = 0;
1481 }
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1143
INT64_MAX_IN_DOUBLE
constexpr double INT64_MAX_IN_DOUBLE
The biggest double that when cast to int64_t still fits in a int64_t.
Definition: graph_gui.cpp:44
PaymentRatesGraphWindow::legend_width
uint legend_width
Width of legend 'blob'.
Definition: graph_gui.cpp:951
CargoArray::GetSum
const T GetSum() const
Get the sum of all cargo amounts.
Definition: cargo_type.h:120
InvalidateWindowData
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-...
Definition: window.cpp:3204
CompanyEconomyEntry::company_value
Money company_value
The value of the company.
Definition: company_base.h:29
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3086
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
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:268
BaseGraphWindow::PAYMENT_GRAPH_X_STEP_DAYS
static const int PAYMENT_GRAPH_X_STEP_DAYS
X-axis step label for cargo payment rates "Days in transit".
Definition: graph_gui.cpp:176
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
BaseGraphWindow::excluded_data
uint64_t excluded_data
bitmask of the datasets that shouldn't be displayed.
Definition: graph_gui.cpp:185
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:350
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
SCORE_TOTAL
@ SCORE_TOTAL
This must always be the last entry.
Definition: economy_type.h:71
company_base.h
timer_game_calendar.h
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
PerformanceRatingDetailWindow
Definition: graph_gui.cpp:1189
company_gui.h
currency.h
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WID_PRD_COMPANY_FIRST
@ WID_PRD_COMPANY_FIRST
First company.
Definition: graph_widget.h:46
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
IntervalTimer< TimerWindow >
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
TimerGameEconomy::month
static Month month
Current month (0..11).
Definition: timer_game_economy.h:36
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
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
WC_PERFORMANCE_HISTORY
@ WC_PERFORMANCE_HISTORY
Performance history graph; Window numbers:
Definition: window_type.h:552
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1153
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1176
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
zoom_func.h
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2341
WID_PHG_DETAILED_PERFORMANCE
@ WID_PHG_DETAILED_PERFORMANCE
Detailed performance.
Definition: graph_widget.h:33
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:68
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition: timer_game_economy.cpp:97
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
FR_LOWERED
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
Definition: window_gui.h:28
economy_func.h
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:340
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
ValuesInterval::highest
OverflowSafeInt64 highest
Highest value of this interval. Must be zero or greater.
Definition: graph_gui.cpp:159
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:680
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:211
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1757
BaseGraphWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: graph_gui.cpp:584
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1040
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:722
PerformanceRatingDetailWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: graph_gui.cpp:1385
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: palette.cpp:26
BaseGraphWindow
Definition: graph_gui.cpp:167
PaymentRatesGraphWindow
Definition: graph_gui.cpp:948
PaymentRatesGraphWindow::update_payment_interval
IntervalTimer< TimerWindow > update_payment_interval
Update the payment rates on a regular interval.
Definition: graph_gui.cpp:1111
WC_DELIVERED_CARGO
@ WC_DELIVERED_CARGO
Delivered cargo graph; Window numbers:
Definition: window_type.h:546
gfx_func.h
ScoreInfo::score
int score
How much score it will give.
Definition: economy_type.h:82
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:63
COMPANY_FIRST
@ COMPANY_FIRST
First company, same as owner.
Definition: company_type.h:22
ScaleGUITrad
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
WC_GRAPH_LEGEND
@ WC_GRAPH_LEGEND
Legend for graphs; Window numbers:
Definition: window_type.h:522
window_gui.h
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:510
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
MakeCompanyButtonRows
std::unique_ptr< NWidgetBase > MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable)
Make a number of rows with button-like graphics, for enabling/disabling each company.
Definition: widget.cpp:3203
_sorted_standard_cargo_specs
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:169
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
BaseGraphWindow::GetValuesInterval
ValuesInterval GetValuesInterval(int num_hori_lines) const
Get the interval that contains the graph's data.
Definition: graph_gui.cpp:211
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
WID_CPR_ENABLE_CARGOES
@ WID_CPR_ENABLE_CARGOES
Enable cargoes button.
Definition: graph_widget.h:35
BaseGraphWindow::PAYMENT_GRAPH_X_STEP_SECONDS
static const int PAYMENT_GRAPH_X_STEP_SECONDS
X-axis step label for cargo payment rates "Seconds in transit".
Definition: graph_gui.cpp:177
WID_GRAPH_RESIZE
@ WID_GRAPH_RESIZE
Resize button.
Definition: graph_widget.h:29
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
MakePerformanceDetailPanels
static std::unique_ptr< NWidgetBase > MakePerformanceDetailPanels()
Make a vertical list of panels for outputting score details.
Definition: graph_gui.cpp:1418
WidgetDimensions::matrix
RectPadding matrix
Padding of WWT_MATRIX items.
Definition: window_gui.h:44
CompanyProperties::num_valid_stat_ent
byte num_valid_stat_ent
Number of valid statistical entries in old_economy.
Definition: company_base.h:113
GUISettings::graph_line_thickness
uint8_t graph_line_thickness
the thickness of the lines in the various graph guis
Definition: settings_type.h:194
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:732
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:174
BaseGraphWindow::draw_dates
bool draw_dates
Should we draw months and years on the time axis?
Definition: graph_gui.cpp:194
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1747
GraphLegendWindow
Definition: graph_gui.cpp:51
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1246
PaymentRatesGraphWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: graph_gui.cpp:976
SCORE_END
@ SCORE_END
How many scores are there..
Definition: economy_type.h:72
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:306
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:204
CompanyProperties::colour
Colours colour
Company colour.
Definition: company_base.h:85
BaseGraphWindow::GRAPH_AXIS_LABEL_COLOUR
static const TextColour GRAPH_AXIS_LABEL_COLOUR
colour of the graph axis label.
Definition: graph_gui.cpp:180
BaseGraphWindow::UpdateStatistics
void UpdateStatistics(bool initialize)
Update the statistics.
Definition: graph_gui.cpp:594
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
PaymentRatesGraphWindow::line_height
uint line_height
Pixel height of each cargo type row.
Definition: graph_gui.cpp:949
Scrollbar::GetCapacity
uint16_t GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:713
timer_game_tick.h
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
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
safeguards.h
Window::LowerWidget
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition: window_gui.h:460
timer.h
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:303
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition: stdafx.h:303
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
ValuesInterval::lowest
OverflowSafeInt64 lowest
Lowest value of this interval. Must be zero or less.
Definition: graph_gui.cpp:160
UpdateCompanyRatingAndValue
int UpdateCompanyRatingAndValue(Company *c, bool update)
if update is set to true, the economy is updated with this score (also the house is updated,...
Definition: economy.cpp:201
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
sprites.h
PaymentRatesGraphWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: graph_gui.cpp:1094
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
PerformanceHistoryGraphWindow
Definition: graph_gui.cpp:827
Window::IsWidgetDisabled
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:410
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:166
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition: widget_type.h:847
WC_INCOME_GRAPH
@ WC_INCOME_GRAPH
Income graph; Window numbers:
Definition: window_type.h:534
stdafx.h
WID_PRD_SCORE_FIRST
@ WID_PRD_SCORE_FIRST
First entry in the score list.
Definition: graph_widget.h:43
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:113
SCORE_MAX
@ SCORE_MAX
The max score that can be in the performance history.
Definition: economy_type.h:74
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:339
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
CompanyEconomyEntry::delivered_cargo
CargoArray delivered_cargo
The amount of delivered cargo.
Definition: company_base.h:27
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:159
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
BaseGraphWindow::DrawGraph
void DrawGraph(Rect r) const
Actually draw the graph.
Definition: graph_gui.cpp:305
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
WC_PAYMENT_RATES
@ WC_PAYMENT_RATES
Payment rates graph; Window numbers:
Definition: window_type.h:570
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:937
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
ValuesInterval
Contains the interval of a graph's data.
Definition: graph_gui.cpp:158
BaseGraphWindow::ECONOMY_QUARTER_MINUTES
static const int ECONOMY_QUARTER_MINUTES
Minutes per economic quarter.
Definition: graph_gui.cpp:178
WC_COMPANY_VALUE
@ WC_COMPANY_VALUE
Company value graph; Window numbers:
Definition: window_type.h:558
CompanyEconomyEntry::expenses
Money expenses
The amount of expenses.
Definition: company_base.h:26
WID_GL_BACKGROUND
@ WID_GL_BACKGROUND
Background of the window.
Definition: graph_widget.h:18
WID_GRAPH_HEADER
@ WID_GRAPH_HEADER
Header.
Definition: graph_widget.h:30
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:771
WID_CPR_MATRIX
@ WID_CPR_MATRIX
Cargo list.
Definition: graph_widget.h:37
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:388
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
strings_func.h
CompanyEconomyEntry::performance_history
int32_t performance_history
Company score (scale 0-1000)
Definition: company_base.h:28
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
TimerGameEconomy::year
static Year year
Current year, starting at 0.
Definition: timer_game_economy.h:35
graph_gui.h
WID_CPR_DISABLE_CARGOES
@ WID_CPR_DISABLE_CARGOES
Disable cargoes button.
Definition: graph_widget.h:36
WC_PERFORMANCE_DETAIL
@ WC_PERFORMANCE_DETAIL
Performance detail window; Window numbers:
Definition: window_type.h:576
IncomeGraphWindow
Definition: graph_gui.cpp:713
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:60
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
SetDParamMaxValue
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:127
abs
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:23
WID_CPR_MATRIX_SCROLLBAR
@ WID_CPR_MATRIX_SCROLLBAR
Cargo list scrollbar.
Definition: graph_widget.h:38
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
geometry_func.hpp
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
BaseGraphWindow::MIN_GRID_PIXEL_SIZE
static const int MIN_GRID_PIXEL_SIZE
Minimum distance between graph lines.
Definition: graph_gui.cpp:183
MakeNWidgetCompanyLines
static std::unique_ptr< NWidgetBase > MakeNWidgetCompanyLines()
Construct a vertical list of buttons, one for each company.
Definition: graph_gui.cpp:116
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:762
WID_PRD_COMPANY_LAST
@ WID_PRD_COMPANY_LAST
Last company.
Definition: graph_widget.h:47
cargotype.h
ScoreInfo::needed
int needed
How much you need to get the perfect score.
Definition: economy_type.h:81
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
BaseGraphWindow::GetYLabelWidth
uint GetYLabelWidth(ValuesInterval current_interval, int num_hori_lines) const
Get width for Y labels.
Definition: graph_gui.cpp:281
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:55
CompanyValueGraphWindow
Definition: graph_gui.cpp:891
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:81
BaseGraphWindow::MIN_GRAPH_NUM_LINES_Y
static const int MIN_GRAPH_NUM_LINES_Y
Minimal number of horizontal lines to draw.
Definition: graph_gui.cpp:182
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel thickness.
Definition: window_gui.h:41
Window::RaiseWidget
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition: window_gui.h:469
ScoreID
ScoreID
Score categories in the detailed performance rating.
Definition: economy_type.h:60
CompanyEconomyEntry::income
Money income
The amount of income.
Definition: company_base.h:25
BaseGraphWindow::cost
OverflowSafeInt64 cost[GRAPH_MAX_DATASETS][GRAPH_NUM_MONTHS]
Stored costs for the last GRAPH_NUM_MONTHS months.
Definition: graph_gui.cpp:203
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:338
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:281
PaymentRatesGraphWindow::UpdatePaymentRates
void UpdatePaymentRates()
Update the payment rates according to the latest information.
Definition: graph_gui.cpp:1118
PaymentRatesGraphWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: graph_gui.cpp:1089
window_func.h
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
graph_widget.h
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1099
OverflowSafeInt
Overflow safe template for integers, i.e.
Definition: overflowsafe_type.hpp:29
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:654
timer_window.h
BaseGraphWindow::GRAPH_NUM_MONTHS
static const int GRAPH_NUM_MONTHS
Number of months displayed in the graph.
Definition: graph_gui.cpp:175
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
PaymentRatesGraphWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: graph_gui.cpp:1104
WID_GL_FIRST_COMPANY
@ WID_GL_FIRST_COMPANY
First company in the legend.
Definition: graph_widget.h:20
DeliveredCargoGraphWindow
Definition: graph_gui.cpp:770
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition: window_gui.h:40
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition: window_gui.h:43
PaymentRatesGraphWindow::vscroll
Scrollbar * vscroll
Cargo list scrollbar.
Definition: graph_gui.cpp:950
Window
Data structure for an opened window.
Definition: window_gui.h:267
Ticks::DAY_TICKS
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
Definition: timer_game_tick.h:75
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:328
ZOOM_LVL_OUT_4X
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
Definition: zoom_type.h:24
BaseGraphWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: graph_gui.cpp:574
NUM_CARGO
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
Definition: cargo_type.h:74
WID_PRD_SCORE_LAST
@ WID_PRD_SCORE_LAST
Last entry in the score list.
Definition: graph_widget.h:44
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1164
PerformanceRatingDetailWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: graph_gui.cpp:1371
WC_OPERATING_PROFIT
@ WC_OPERATING_PROFIT
Operating profit graph; Window numbers:
Definition: window_type.h:540
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:450
Company
Definition: company_base.h:129
CompanyProperties::old_economy
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Definition: company_base.h:112
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
GREY_SCALE
#define GREY_SCALE(level)
Return the colour for a particular greyscale level.
Definition: palette_func.h:53
GraphLegendWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: graph_gui.cpp:102
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
TimerGame< struct Economy >::Month
uint8_t Month
Type for the month, note: 0 based, i.e.
Definition: timer_game_common.h:44
OperatingProfitGraphWindow
Definition: graph_gui.cpp:654
ToggleBit
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Definition: bitmath_func.hpp:181
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:848
timer_game_economy.h
WID_GL_LAST_COMPANY
@ WID_GL_LAST_COMPANY
Last company in the legend.
Definition: graph_widget.h:21
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:635
WID_GRAPH_BACKGROUND
@ WID_GRAPH_BACKGROUND
Background of the window.
Definition: graph_widget.h:27
_score_info
const ScoreInfo _score_info[]
Score info, values used for computing the detailed performance rating.
Definition: economy.cpp:90
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103