OpenTTD Source  13.0-beta1
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 "date_func.h"
20 #include "gfx_func.h"
21 #include "sortlist_type.h"
22 #include "core/geometry_func.hpp"
23 #include "currency.h"
24 #include "zoom_func.h"
25 
26 #include "widgets/graph_widget.h"
27 
28 #include "table/strings.h"
29 #include "table/sprites.h"
30 #include <math.h>
31 
32 #include "safeguards.h"
33 
34 /* Bitmasks of company and cargo indices that shouldn't be drawn. */
35 static CompanyMask _legend_excluded_companies;
36 static CargoTypes _legend_excluded_cargo;
37 
38 /* Apparently these don't play well with enums. */
39 static const OverflowSafeInt64 INVALID_DATAPOINT(INT64_MAX); // Value used for a datapoint that shouldn't be drawn.
40 static const uint INVALID_DATAPOINT_POS = UINT_MAX; // Used to determine if the previous point was drawn.
41 
42 /****************/
43 /* GRAPH LEGEND */
44 /****************/
45 
48  {
49  this->InitNested(window_number);
50 
51  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
52  if (!HasBit(_legend_excluded_companies, c)) this->LowerWidget(c + WID_GL_FIRST_COMPANY);
53 
54  this->OnInvalidateData(c);
55  }
56  }
57 
58  void DrawWidget(const Rect &r, int widget) const override
59  {
61 
62  CompanyID cid = (CompanyID)(widget - WID_GL_FIRST_COMPANY);
63 
64  if (!Company::IsValidID(cid)) return;
65 
66  bool rtl = _current_text_dir == TD_RTL;
67 
68  Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
69  DrawCompanyIcon(cid, rtl ? r.right - d.width - ScaleGUITrad(2) : r.left + ScaleGUITrad(2), CenterBounds(r.top, r.bottom, d.height));
70 
71  SetDParam(0, cid);
72  SetDParam(1, cid);
73  DrawString(r.left + (rtl ? (uint)WD_FRAMERECT_LEFT : (d.width + ScaleGUITrad(4))), r.right - (rtl ? (d.width + ScaleGUITrad(4)) : (uint)WD_FRAMERECT_RIGHT), CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), STR_COMPANY_NAME_COMPANY_NUM, HasBit(_legend_excluded_companies, cid) ? TC_BLACK : TC_WHITE);
74  }
75 
76  void OnClick(Point pt, int widget, int click_count) override
77  {
79 
80  ToggleBit(_legend_excluded_companies, widget - WID_GL_FIRST_COMPANY);
81  this->ToggleWidgetLoweredState(widget);
82  this->SetDirty();
88  }
89 
95  void OnInvalidateData(int data = 0, bool gui_scope = true) override
96  {
97  if (!gui_scope) return;
98  if (Company::IsValidID(data)) return;
99 
100  SetBit(_legend_excluded_companies, data);
101  this->RaiseWidget(data + WID_GL_FIRST_COMPANY);
102  }
103 };
104 
111 static NWidgetBase *MakeNWidgetCompanyLines(int *biggest_index)
112 {
114  vert->SetPadding(2, 2, 2, 2);
115  uint sprite_height = GetSpriteSize(SPR_COMPANY_ICON, nullptr, ZOOM_LVL_OUT_4X).height;
116 
117  for (int widnum = WID_GL_FIRST_COMPANY; widnum <= WID_GL_LAST_COMPANY; widnum++) {
118  NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_BROWN, widnum);
119  panel->SetMinimalSize(246, sprite_height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
121  panel->SetFill(1, 1);
122  panel->SetDataTip(0x0, STR_GRAPH_KEY_COMPANY_SELECTION_TOOLTIP);
123  vert->Add(panel);
124  }
125  *biggest_index = WID_GL_LAST_COMPANY;
126  return vert;
127 }
128 
129 static const NWidgetPart _nested_graph_legend_widgets[] = {
131  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
132  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_KEY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
133  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
134  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
135  EndContainer(),
136  NWidget(WWT_PANEL, COLOUR_BROWN, WID_GL_BACKGROUND),
138  EndContainer(),
139 };
140 
141 static WindowDesc _graph_legend_desc(
142  WDP_AUTO, "graph_legend", 0, 0,
144  0,
145  _nested_graph_legend_widgets, lengthof(_nested_graph_legend_widgets)
146 );
147 
148 static void ShowGraphLegend()
149 {
150  AllocateWindowDescFront<GraphLegendWindow>(&_graph_legend_desc, 0);
151 }
152 
157 };
158 
159 /******************/
160 /* BASE OF GRAPHS */
161 /*****************/
162 
164 protected:
165  static const int GRAPH_MAX_DATASETS = 64;
166  static const int GRAPH_BASE_COLOUR = GREY_SCALE(2);
167  static const int GRAPH_GRID_COLOUR = GREY_SCALE(3);
168  static const int GRAPH_AXIS_LINE_COLOUR = GREY_SCALE(1);
169  static const int GRAPH_ZERO_LINE_COLOUR = GREY_SCALE(8);
170  static const int GRAPH_YEAR_LINE_COLOUR = GREY_SCALE(5);
171  static const int GRAPH_NUM_MONTHS = 24;
172 
173  static const TextColour GRAPH_AXIS_LABEL_COLOUR = TC_BLACK;
174 
175  static const int MIN_GRAPH_NUM_LINES_Y = 9;
176  static const int MIN_GRID_PIXEL_SIZE = 20;
177 
178  uint64 excluded_data;
179  byte num_dataset;
180  byte num_on_x_axis;
181  byte num_vert_lines;
182 
183  /* The starting month and year that values are plotted against. If month is
184  * 0xFF, use x_values_start and x_values_increment below instead. */
185  byte month;
186  Year year;
187 
188  /* These values are used if the graph is being plotted against values
189  * rather than the dates specified by month and year. */
190  uint16 x_values_start;
191  uint16 x_values_increment;
192 
193  int graph_widget;
194  StringID format_str_y_axis;
195  byte colours[GRAPH_MAX_DATASETS];
196  OverflowSafeInt64 cost[GRAPH_MAX_DATASETS][GRAPH_NUM_MONTHS];
197 
204  ValuesInterval GetValuesInterval(int num_hori_lines) const
205  {
206  assert(num_hori_lines > 0);
207 
208  ValuesInterval current_interval;
209  current_interval.highest = INT64_MIN;
210  current_interval.lowest = INT64_MAX;
211 
212  for (int i = 0; i < this->num_dataset; i++) {
213  if (HasBit(this->excluded_data, i)) continue;
214  for (int j = 0; j < this->num_on_x_axis; j++) {
215  OverflowSafeInt64 datapoint = this->cost[i][j];
216 
217  if (datapoint != INVALID_DATAPOINT) {
218  current_interval.highest = std::max(current_interval.highest, datapoint);
219  current_interval.lowest = std::min(current_interval.lowest, datapoint);
220  }
221  }
222  }
223 
224  /* Prevent showing values too close to the graph limits. */
225  current_interval.highest = (11 * current_interval.highest) / 10;
226  current_interval.lowest = (11 * current_interval.lowest) / 10;
227 
228  /* Always include zero in the shown range. */
229  double abs_lower = (current_interval.lowest > 0) ? 0 : (double)abs(current_interval.lowest);
230  double abs_higher = (current_interval.highest < 0) ? 0 : (double)current_interval.highest;
231 
232  int num_pos_grids;
233  int64 grid_size;
234 
235  if (abs_lower != 0 || abs_higher != 0) {
236  /* The number of grids to reserve for the positive part is: */
237  num_pos_grids = (int)floor(0.5 + num_hori_lines * abs_higher / (abs_higher + abs_lower));
238 
239  /* If there are any positive or negative values, force that they have at least one grid. */
240  if (num_pos_grids == 0 && abs_higher != 0) num_pos_grids++;
241  if (num_pos_grids == num_hori_lines && abs_lower != 0) num_pos_grids--;
242 
243  /* Get the required grid size for each side and use the maximum one. */
244  int64 grid_size_higher = (abs_higher > 0) ? ((int64)abs_higher + num_pos_grids - 1) / num_pos_grids : 0;
245  int64 grid_size_lower = (abs_lower > 0) ? ((int64)abs_lower + num_hori_lines - num_pos_grids - 1) / (num_hori_lines - num_pos_grids) : 0;
246  grid_size = std::max(grid_size_higher, grid_size_lower);
247  } else {
248  /* If both values are zero, show an empty graph. */
249  num_pos_grids = num_hori_lines / 2;
250  grid_size = 1;
251  }
252 
253  current_interval.highest = num_pos_grids * grid_size;
254  current_interval.lowest = -(num_hori_lines - num_pos_grids) * grid_size;
255  return current_interval;
256  }
257 
263  uint GetYLabelWidth(ValuesInterval current_interval, int num_hori_lines) const
264  {
265  /* draw text strings on the y axis */
266  int64 y_label = current_interval.highest;
267  int64 y_label_separation = (current_interval.highest - current_interval.lowest) / num_hori_lines;
268 
269  uint max_width = 0;
270 
271  for (int i = 0; i < (num_hori_lines + 1); i++) {
272  SetDParam(0, this->format_str_y_axis);
273  SetDParam(1, y_label);
274  Dimension d = GetStringBoundingBox(STR_GRAPH_Y_LABEL);
275  if (d.width > max_width) max_width = d.width;
276 
277  y_label -= y_label_separation;
278  }
279 
280  return max_width;
281  }
282 
287  void DrawGraph(Rect r) const
288  {
289  uint x, y;
290  ValuesInterval interval;
291  int x_axis_offset;
292 
293  /* the colours and cost array of GraphDrawer must accommodate
294  * both values for cargo and companies. So if any are higher, quit */
295  static_assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_COMPANIES);
296  assert(this->num_vert_lines > 0);
297 
298  /* Rect r will be adjusted to contain just the graph, with labels being
299  * placed outside the area. */
300  r.top += 5 + GetCharacterHeight(FS_SMALL) / 2;
301  r.bottom -= (this->month == 0xFF ? 1 : 2) * GetCharacterHeight(FS_SMALL) + 4;
302  r.left += 9;
303  r.right -= 5;
304 
305  /* Initial number of horizontal lines. */
306  int num_hori_lines = 160 / MIN_GRID_PIXEL_SIZE;
307  /* For the rest of the height, the number of horizontal lines will increase more slowly. */
308  int resize = (r.bottom - r.top - 160) / (2 * MIN_GRID_PIXEL_SIZE);
309  if (resize > 0) num_hori_lines += resize;
310 
311  interval = GetValuesInterval(num_hori_lines);
312 
313  int label_width = GetYLabelWidth(interval, num_hori_lines);
314 
315  r.left += label_width;
316 
317  int x_sep = (r.right - r.left) / this->num_vert_lines;
318  int y_sep = (r.bottom - r.top) / num_hori_lines;
319 
320  /* Redetermine right and bottom edge of graph to fit with the integer
321  * separation values. */
322  r.right = r.left + x_sep * this->num_vert_lines;
323  r.bottom = r.top + y_sep * num_hori_lines;
324 
325  OverflowSafeInt64 interval_size = interval.highest + abs(interval.lowest);
326  /* Where to draw the X axis. Use floating point to avoid overflowing and results of zero. */
327  x_axis_offset = (int)((r.bottom - r.top) * (double)interval.highest / (double)interval_size);
328 
329  /* Draw the background of the graph itself. */
330  GfxFillRect(r.left, r.top, r.right, r.bottom, GRAPH_BASE_COLOUR);
331 
332  /* Draw the vertical grid lines. */
333 
334  /* Don't draw the first line, as that's where the axis will be. */
335  x = r.left + x_sep;
336 
337  for (int i = 0; i < this->num_vert_lines; i++) {
338  GfxFillRect(x, r.top, x, r.bottom, GRAPH_GRID_COLOUR);
339  x += x_sep;
340  }
341 
342  /* Draw the horizontal grid lines. */
343  y = r.bottom;
344 
345  for (int i = 0; i < (num_hori_lines + 1); i++) {
346  GfxFillRect(r.left - 3, y, r.left - 1, y, GRAPH_AXIS_LINE_COLOUR);
347  GfxFillRect(r.left, y, r.right, y, GRAPH_GRID_COLOUR);
348  y -= y_sep;
349  }
350 
351  /* Draw the y axis. */
352  GfxFillRect(r.left, r.top, r.left, r.bottom, GRAPH_AXIS_LINE_COLOUR);
353 
354  /* Draw the x axis. */
355  y = x_axis_offset + r.top;
356  GfxFillRect(r.left, y, r.right, y, GRAPH_ZERO_LINE_COLOUR);
357 
358  /* Find the largest value that will be drawn. */
359  if (this->num_on_x_axis == 0) return;
360 
361  assert(this->num_on_x_axis > 0);
362  assert(this->num_dataset > 0);
363 
364  /* draw text strings on the y axis */
365  int64 y_label = interval.highest;
366  int64 y_label_separation = abs(interval.highest - interval.lowest) / num_hori_lines;
367 
368  y = r.top - GetCharacterHeight(FS_SMALL) / 2;
369 
370  for (int i = 0; i < (num_hori_lines + 1); i++) {
371  SetDParam(0, this->format_str_y_axis);
372  SetDParam(1, y_label);
373  DrawString(r.left - label_width - 4, r.left - 4, y, STR_GRAPH_Y_LABEL, GRAPH_AXIS_LABEL_COLOUR, SA_RIGHT);
374 
375  y_label -= y_label_separation;
376  y += y_sep;
377  }
378 
379  /* Draw x-axis labels and markings for graphs based on financial quarters and years. */
380  if (this->month != 0xFF) {
381  x = r.left;
382  y = r.bottom + 2;
383  byte month = this->month;
384  Year year = this->year;
385  for (int i = 0; i < this->num_on_x_axis; i++) {
386  SetDParam(0, month + STR_MONTH_ABBREV_JAN);
387  SetDParam(1, year);
388  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);
389 
390  month += 3;
391  if (month >= 12) {
392  month = 0;
393  year++;
394 
395  /* Draw a lighter grid line between years. Top and bottom adjustments ensure we don't draw over top and bottom horizontal grid lines. */
396  GfxFillRect(x + x_sep, r.top + 1, x + x_sep, r.bottom - 1, GRAPH_YEAR_LINE_COLOUR);
397  }
398  x += x_sep;
399  }
400  } else {
401  /* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates). */
402  x = r.left;
403  y = r.bottom + 2;
404  uint16 label = this->x_values_start;
405 
406  for (int i = 0; i < this->num_on_x_axis; i++) {
407  SetDParam(0, label);
408  DrawString(x + 1, x + x_sep - 1, y, STR_GRAPH_Y_LABEL_NUMBER, GRAPH_AXIS_LABEL_COLOUR, SA_HOR_CENTER);
409 
410  label += this->x_values_increment;
411  x += x_sep;
412  }
413  }
414 
415  /* draw lines and dots */
416  uint linewidth = _settings_client.gui.graph_line_thickness;
417  uint pointoffs1 = (linewidth + 1) / 2;
418  uint pointoffs2 = linewidth + 1 - pointoffs1;
419  for (int i = 0; i < this->num_dataset; i++) {
420  if (!HasBit(this->excluded_data, i)) {
421  /* Centre the dot between the grid lines. */
422  x = r.left + (x_sep / 2);
423 
424  byte colour = this->colours[i];
425  uint prev_x = INVALID_DATAPOINT_POS;
426  uint prev_y = INVALID_DATAPOINT_POS;
427 
428  for (int j = 0; j < this->num_on_x_axis; j++) {
429  OverflowSafeInt64 datapoint = this->cost[i][j];
430 
431  if (datapoint != INVALID_DATAPOINT) {
432  /*
433  * Check whether we need to reduce the 'accuracy' of the
434  * datapoint value and the highest value to split overflows.
435  * And when 'drawing' 'one million' or 'one million and one'
436  * there is no significant difference, so the least
437  * significant bits can just be removed.
438  *
439  * If there are more bits needed than would fit in a 32 bits
440  * integer, so at about 31 bits because of the sign bit, the
441  * least significant bits are removed.
442  */
443  int mult_range = FindLastBit(x_axis_offset) + FindLastBit(abs(datapoint));
444  int reduce_range = std::max(mult_range - 31, 0);
445 
446  /* Handle negative values differently (don't shift sign) */
447  if (datapoint < 0) {
448  datapoint = -(abs(datapoint) >> reduce_range);
449  } else {
450  datapoint >>= reduce_range;
451  }
452  y = r.top + x_axis_offset - ((r.bottom - r.top) * datapoint) / (interval_size >> reduce_range);
453 
454  /* Draw the point. */
455  GfxFillRect(x - pointoffs1, y - pointoffs1, x + pointoffs2, y + pointoffs2, colour);
456 
457  /* Draw the line connected to the previous point. */
458  if (prev_x != INVALID_DATAPOINT_POS) GfxDrawLine(prev_x, prev_y, x, y, colour, linewidth);
459 
460  prev_x = x;
461  prev_y = y;
462  } else {
463  prev_x = INVALID_DATAPOINT_POS;
464  prev_y = INVALID_DATAPOINT_POS;
465  }
466 
467  x += x_sep;
468  }
469  }
470  }
471  }
472 
473 
474  BaseGraphWindow(WindowDesc *desc, int widget, StringID format_str_y_axis) :
475  Window(desc),
476  format_str_y_axis(format_str_y_axis)
477  {
479  this->num_vert_lines = 24;
480  this->graph_widget = widget;
481  }
482 
483  void InitializeWindow(WindowNumber number)
484  {
485  /* Initialise the dataset */
486  this->UpdateStatistics(true);
487 
488  this->InitNested(number);
489  }
490 
491 public:
492  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
493  {
494  if (widget != this->graph_widget) return;
495 
496  uint x_label_width = 0;
497 
498  /* Draw x-axis labels and markings for graphs based on financial quarters and years. */
499  if (this->month != 0xFF) {
500  byte month = this->month;
501  Year year = this->year;
502  for (int i = 0; i < this->num_on_x_axis; i++) {
503  SetDParam(0, month + STR_MONTH_ABBREV_JAN);
504  SetDParam(1, year);
505  x_label_width = std::max(x_label_width, GetStringBoundingBox(month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH).width);
506 
507  month += 3;
508  if (month >= 12) {
509  month = 0;
510  year++;
511  }
512  }
513  } else {
514  /* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates). */
515  SetDParamMaxValue(0, this->x_values_start + this->num_on_x_axis * this->x_values_increment, 0, FS_SMALL);
516  x_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL_NUMBER).width;
517  }
518 
519  SetDParam(0, this->format_str_y_axis);
520  SetDParam(1, INT64_MAX);
521  uint y_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL).width;
522 
523  size->width = std::max<uint>(size->width, 5 + y_label_width + this->num_on_x_axis * (x_label_width + 5) + 9);
524  size->height = std::max<uint>(size->height, 5 + (1 + MIN_GRAPH_NUM_LINES_Y * 2 + (this->month != 0xFF ? 3 : 1)) * FONT_HEIGHT_SMALL + 4);
525  size->height = std::max<uint>(size->height, size->width / 3);
526  }
527 
528  void DrawWidget(const Rect &r, int widget) const override
529  {
530  if (widget != this->graph_widget) return;
531 
532  DrawGraph(r);
533  }
534 
535  virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
536  {
537  return INVALID_DATAPOINT;
538  }
539 
540  void OnClick(Point pt, int widget, int click_count) override
541  {
542  /* Clicked on legend? */
543  if (widget == WID_CV_KEY_BUTTON) ShowGraphLegend();
544  }
545 
546  void OnGameTick() override
547  {
548  this->UpdateStatistics(false);
549  }
550 
556  void OnInvalidateData(int data = 0, bool gui_scope = true) override
557  {
558  if (!gui_scope) return;
559  this->UpdateStatistics(true);
560  }
561 
566  void UpdateStatistics(bool initialize)
567  {
568  CompanyMask excluded_companies = _legend_excluded_companies;
569 
570  /* Exclude the companies which aren't valid */
571  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
572  if (!Company::IsValidID(c)) SetBit(excluded_companies, c);
573  }
574 
575  byte nums = 0;
576  for (const Company *c : Company::Iterate()) {
577  nums = std::min(this->num_vert_lines, std::max(nums, c->num_valid_stat_ent));
578  }
579 
580  int mo = (_cur_month / 3 - nums) * 3;
581  int yr = _cur_year;
582  while (mo < 0) {
583  yr--;
584  mo += 12;
585  }
586 
587  if (!initialize && this->excluded_data == excluded_companies && this->num_on_x_axis == nums &&
588  this->year == yr && this->month == mo) {
589  /* There's no reason to get new stats */
590  return;
591  }
592 
593  this->excluded_data = excluded_companies;
594  this->num_on_x_axis = nums;
595  this->year = yr;
596  this->month = mo;
597 
598  int numd = 0;
599  for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) {
600  const Company *c = Company::GetIfValid(k);
601  if (c != nullptr) {
602  this->colours[numd] = _colour_gradient[c->colour][6];
603  for (int j = this->num_on_x_axis, i = 0; --j >= 0;) {
604  this->cost[numd][i] = (j >= c->num_valid_stat_ent) ? INVALID_DATAPOINT : GetGraphData(c, j);
605  i++;
606  }
607  }
608  numd++;
609  }
610 
611  this->num_dataset = numd;
612  }
613 };
614 
615 
616 /********************/
617 /* OPERATING PROFIT */
618 /********************/
619 
622  BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_CURRENCY_SHORT)
623  {
624  this->InitializeWindow(window_number);
625  }
626 
627  OverflowSafeInt64 GetGraphData(const Company *c, int j) override
628  {
629  return c->old_economy[j].income + c->old_economy[j].expenses;
630  }
631 };
632 
633 static const NWidgetPart _nested_operating_profit_widgets[] = {
635  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
636  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_OPERATING_PROFIT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
637  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
638  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
639  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
640  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
641  EndContainer(),
642  NWidget(WWT_PANEL, COLOUR_BROWN, WID_CV_BACKGROUND),
644  NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CV_GRAPH), SetMinimalSize(576, 160), SetFill(1, 1), SetResize(1, 1),
646  NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
647  NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CV_RESIZE),
648  EndContainer(),
649  EndContainer(),
650  EndContainer(),
651 };
652 
653 static WindowDesc _operating_profit_desc(
654  WDP_AUTO, "graph_operating_profit", 0, 0,
656  0,
657  _nested_operating_profit_widgets, lengthof(_nested_operating_profit_widgets)
658 );
659 
660 
661 void ShowOperatingProfitGraph()
662 {
663  AllocateWindowDescFront<OperatingProfitGraphWindow>(&_operating_profit_desc, 0);
664 }
665 
666 
667 /****************/
668 /* INCOME GRAPH */
669 /****************/
670 
673  BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_CURRENCY_SHORT)
674  {
675  this->InitializeWindow(window_number);
676  }
677 
678  OverflowSafeInt64 GetGraphData(const Company *c, int j) override
679  {
680  return c->old_economy[j].income;
681  }
682 };
683 
684 static const NWidgetPart _nested_income_graph_widgets[] = {
686  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
687  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_INCOME_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
688  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
689  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
690  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
691  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
692  EndContainer(),
693  NWidget(WWT_PANEL, COLOUR_BROWN, WID_CV_BACKGROUND),
695  NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CV_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
697  NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
698  NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CV_RESIZE),
699  EndContainer(),
700  EndContainer(),
701  EndContainer(),
702 };
703 
704 static WindowDesc _income_graph_desc(
705  WDP_AUTO, "graph_income", 0, 0,
707  0,
708  _nested_income_graph_widgets, lengthof(_nested_income_graph_widgets)
709 );
710 
711 void ShowIncomeGraph()
712 {
713  AllocateWindowDescFront<IncomeGraphWindow>(&_income_graph_desc, 0);
714 }
715 
716 /*******************/
717 /* DELIVERED CARGO */
718 /*******************/
719 
722  BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_COMMA)
723  {
724  this->InitializeWindow(window_number);
725  }
726 
727  OverflowSafeInt64 GetGraphData(const Company *c, int j) override
728  {
730  }
731 };
732 
733 static const NWidgetPart _nested_delivered_cargo_graph_widgets[] = {
735  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
736  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_CARGO_DELIVERED_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
737  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
738  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
739  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
740  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
741  EndContainer(),
742  NWidget(WWT_PANEL, COLOUR_BROWN, WID_CV_BACKGROUND),
744  NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CV_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
746  NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
747  NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CV_RESIZE),
748  EndContainer(),
749  EndContainer(),
750  EndContainer(),
751 };
752 
753 static WindowDesc _delivered_cargo_graph_desc(
754  WDP_AUTO, "graph_delivered_cargo", 0, 0,
756  0,
757  _nested_delivered_cargo_graph_widgets, lengthof(_nested_delivered_cargo_graph_widgets)
758 );
759 
760 void ShowDeliveredCargoGraph()
761 {
762  AllocateWindowDescFront<DeliveredCargoGraphWindow>(&_delivered_cargo_graph_desc, 0);
763 }
764 
765 /***********************/
766 /* PERFORMANCE HISTORY */
767 /***********************/
768 
771  BaseGraphWindow(desc, WID_PHG_GRAPH, STR_JUST_COMMA)
772  {
773  this->InitializeWindow(window_number);
774  }
775 
776  OverflowSafeInt64 GetGraphData(const Company *c, int j) override
777  {
778  return c->old_economy[j].performance_history;
779  }
780 
781  void OnClick(Point pt, int widget, int click_count) override
782  {
783  if (widget == WID_PHG_DETAILED_PERFORMANCE) ShowPerformanceRatingDetail();
784  this->BaseGraphWindow::OnClick(pt, widget, click_count);
785  }
786 };
787 
788 static const NWidgetPart _nested_performance_history_widgets[] = {
790  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
791  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_COMPANY_PERFORMANCE_RATINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
792  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_PHG_DETAILED_PERFORMANCE), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_PERFORMANCE_DETAIL_KEY, STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP),
793  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_PHG_KEY), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), 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_PHG_BACKGROUND),
800  NWidget(WWT_EMPTY, COLOUR_BROWN, WID_PHG_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
802  NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
803  NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_PHG_RESIZE),
804  EndContainer(),
805  EndContainer(),
806  EndContainer(),
807 };
808 
809 static WindowDesc _performance_history_desc(
810  WDP_AUTO, "graph_performance", 0, 0,
812  0,
813  _nested_performance_history_widgets, lengthof(_nested_performance_history_widgets)
814 );
815 
816 void ShowPerformanceHistoryGraph()
817 {
818  AllocateWindowDescFront<PerformanceHistoryGraphWindow>(&_performance_history_desc, 0);
819 }
820 
821 /*****************/
822 /* COMPANY VALUE */
823 /*****************/
824 
827  BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_CURRENCY_SHORT)
828  {
829  this->InitializeWindow(window_number);
830  }
831 
832  OverflowSafeInt64 GetGraphData(const Company *c, int j) override
833  {
834  return c->old_economy[j].company_value;
835  }
836 };
837 
838 static const NWidgetPart _nested_company_value_graph_widgets[] = {
840  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
841  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_COMPANY_VALUES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
842  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
843  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
844  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
845  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
846  EndContainer(),
847  NWidget(WWT_PANEL, COLOUR_BROWN, WID_CV_BACKGROUND),
849  NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CV_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
851  NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
852  NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CV_RESIZE),
853  EndContainer(),
854  EndContainer(),
855  EndContainer(),
856 };
857 
858 static WindowDesc _company_value_graph_desc(
859  WDP_AUTO, "graph_company_value", 0, 0,
861  0,
862  _nested_company_value_graph_widgets, lengthof(_nested_company_value_graph_widgets)
863 );
864 
865 void ShowCompanyValueGraph()
866 {
867  AllocateWindowDescFront<CompanyValueGraphWindow>(&_company_value_graph_desc, 0);
868 }
869 
870 /*****************/
871 /* PAYMENT RATES */
872 /*****************/
873 
875  uint line_height;
878 
880  BaseGraphWindow(desc, WID_CPR_GRAPH, STR_JUST_CURRENCY_SHORT)
881  {
882  this->num_on_x_axis = 20;
883  this->num_vert_lines = 20;
884  this->month = 0xFF;
885  this->x_values_start = 10;
886  this->x_values_increment = 10;
887 
888  this->CreateNestedTree();
889  this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR);
890  this->vscroll->SetCount(static_cast<int>(_sorted_standard_cargo_specs.size()));
891 
892  /* Initialise the dataset */
893  this->OnHundredthTick();
894 
895  this->FinishInitNested(window_number);
896  }
897 
898  void OnInit() override
899  {
900  /* Width of the legend blob. */
901  this->legend_width = (FONT_HEIGHT_SMALL - ScaleFontTrad(1)) * 8 / 5;
902  }
903 
904  void UpdateExcludedData()
905  {
906  this->excluded_data = 0;
907 
908  int i = 0;
909  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
910  if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i);
911  i++;
912  }
913  }
914 
915  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
916  {
917  if (widget != WID_CPR_MATRIX) {
918  BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
919  return;
920  }
921 
922  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
923  SetDParam(0, cs->name);
924  Dimension d = GetStringBoundingBox(STR_GRAPH_CARGO_PAYMENT_CARGO);
925  d.width += this->legend_width + 4; // colour field
928  *size = maxdim(d, *size);
929  }
930 
931  this->line_height = size->height;
932  size->height = this->line_height * 11; /* Default number of cargo types in most climates. */
933  resize->width = 0;
934  resize->height = this->line_height;
935  }
936 
937  void DrawWidget(const Rect &r, int widget) const override
938  {
939  if (widget != WID_CPR_MATRIX) {
940  BaseGraphWindow::DrawWidget(r, widget);
941  return;
942  }
943 
944  bool rtl = _current_text_dir == TD_RTL;
945 
946  int x = r.left + WD_FRAMERECT_LEFT;
947  int y = r.top;
948  uint row_height = FONT_HEIGHT_SMALL;
949  int padding = ScaleFontTrad(1);
950 
951  int pos = this->vscroll->GetPosition();
952  int max = pos + this->vscroll->GetCapacity();
953 
954  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
955  if (pos-- > 0) continue;
956  if (--max < 0) break;
957 
958  bool lowered = !HasBit(_legend_excluded_cargo, cs->Index());
959 
960  /* Redraw box if lowered */
961  if (lowered) DrawFrameRect(r.left, y, r.right, y + this->line_height - 1, COLOUR_BROWN, FR_LOWERED);
962 
963  byte clk_dif = lowered ? 1 : 0;
964  int rect_x = clk_dif + (rtl ? r.right - this->legend_width - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT);
965 
966  GfxFillRect(rect_x, y + padding + clk_dif, rect_x + this->legend_width, y + row_height - 1 + clk_dif, PC_BLACK);
967  GfxFillRect(rect_x + 1, y + padding + 1 + clk_dif, rect_x + this->legend_width - 1, y + row_height - 2 + clk_dif, cs->legend_colour);
968  SetDParam(0, cs->name);
969  DrawString(rtl ? r.left : x + this->legend_width + 4 + clk_dif, (rtl ? r.right - this->legend_width - 4 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
970 
971  y += this->line_height;
972  }
973  }
974 
975  void OnClick(Point pt, int widget, int click_count) override
976  {
977  switch (widget) {
979  /* Remove all cargoes from the excluded lists. */
980  _legend_excluded_cargo = 0;
981  this->excluded_data = 0;
982  this->SetDirty();
983  break;
984 
986  /* Add all cargoes to the excluded lists. */
987  int i = 0;
988  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
989  SetBit(_legend_excluded_cargo, cs->Index());
990  SetBit(this->excluded_data, i);
991  i++;
992  }
993  this->SetDirty();
994  break;
995  }
996 
997  case WID_CPR_MATRIX: {
998  uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_CPR_MATRIX);
999  if (row >= this->vscroll->GetCount()) return;
1000 
1001  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1002  if (row-- > 0) continue;
1003 
1004  ToggleBit(_legend_excluded_cargo, cs->Index());
1005  this->UpdateExcludedData();
1006  this->SetDirty();
1007  break;
1008  }
1009  break;
1010  }
1011  }
1012  }
1013 
1014  void OnResize() override
1015  {
1016  this->vscroll->SetCapacityFromWidget(this, WID_CPR_MATRIX);
1017  }
1018 
1019  void OnGameTick() override
1020  {
1021  /* Override default OnGameTick */
1022  }
1023 
1029  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1030  {
1031  if (!gui_scope) return;
1032  this->OnHundredthTick();
1033  }
1034 
1035  void OnHundredthTick() override
1036  {
1037  this->UpdateExcludedData();
1038 
1039  int i = 0;
1040  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1041  this->colours[i] = cs->legend_colour;
1042  for (uint j = 0; j != 20; j++) {
1043  this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
1044  }
1045  i++;
1046  }
1047  this->num_dataset = i;
1048  }
1049 };
1050 
1051 static const NWidgetPart _nested_cargo_payment_rates_widgets[] = {
1053  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1054  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1055  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1056  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1057  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1058  EndContainer(),
1059  NWidget(WWT_PANEL, COLOUR_BROWN, WID_CPR_BACKGROUND), SetMinimalSize(568, 128),
1061  NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1062  NWidget(WWT_TEXT, COLOUR_BROWN, WID_CPR_HEADER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE, STR_NULL),
1063  NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1064  EndContainer(),
1066  NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CPR_GRAPH), SetMinimalSize(495, 0), SetFill(1, 1), SetResize(1, 1),
1068  NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
1069  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CPR_ENABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0),
1070  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CPR_DISABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL), SetFill(1, 0),
1073  NWidget(WWT_MATRIX, COLOUR_BROWN, WID_CPR_MATRIX), SetResize(0, 2), SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO), SetScrollbar(WID_CPR_MATRIX_SCROLLBAR),
1075  EndContainer(),
1076  NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
1077  EndContainer(),
1078  NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1),
1079  EndContainer(),
1082  NWidget(WWT_TEXT, COLOUR_BROWN, WID_CPR_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL, STR_NULL),
1083  NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1084  NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CPR_RESIZE),
1085  EndContainer(),
1086  EndContainer(),
1087 };
1088 
1089 static WindowDesc _cargo_payment_rates_desc(
1090  WDP_AUTO, "graph_cargo_payment_rates", 0, 0,
1092  0,
1093  _nested_cargo_payment_rates_widgets, lengthof(_nested_cargo_payment_rates_widgets)
1094 );
1095 
1096 
1097 void ShowCargoPaymentRates()
1098 {
1099  AllocateWindowDescFront<PaymentRatesGraphWindow>(&_cargo_payment_rates_desc, 0);
1100 }
1101 
1102 /************************/
1103 /* COMPANY LEAGUE TABLE */
1104 /************************/
1105 
1106 static const StringID _performance_titles[] = {
1107  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER,
1108  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER,
1109  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER,
1110  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER,
1111  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR,
1112  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR,
1113  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR,
1114  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR,
1115  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR,
1116  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR,
1117  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE,
1118  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE,
1119  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN,
1120  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN,
1121  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_PRESIDENT,
1122  STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TYCOON,
1123 };
1124 
1125 static inline StringID GetPerformanceTitleFromValue(uint value)
1126 {
1127  return _performance_titles[std::min(value, 1000u) >> 6];
1128 }
1129 
1130 class CompanyLeagueWindow : public Window {
1131 private:
1132  GUIList<const Company*> companies;
1134  uint text_width;
1135  uint icon_width;
1137 
1142  {
1143  if (!this->companies.NeedRebuild()) return;
1144 
1145  this->companies.clear();
1146 
1147  for (const Company *c : Company::Iterate()) {
1148  this->companies.push_back(c);
1149  }
1150 
1151  this->companies.shrink_to_fit();
1152  this->companies.RebuildDone();
1153  }
1154 
1156  static bool PerformanceSorter(const Company * const &c1, const Company * const &c2)
1157  {
1159  }
1160 
1161 public:
1163  {
1164  this->InitNested(window_number);
1165  this->companies.ForceRebuild();
1166  this->companies.NeedResort();
1167  }
1168 
1169  void OnPaint() override
1170  {
1171  this->BuildCompanyList();
1172  this->companies.Sort(&PerformanceSorter);
1173 
1174  this->DrawWidgets();
1175  }
1176 
1177  void DrawWidget(const Rect &r, int widget) const override
1178  {
1179  if (widget != WID_CL_BACKGROUND) return;
1180 
1181  int icon_y_offset = 1 + (FONT_HEIGHT_NORMAL - this->line_height) / 2;
1182  uint y = r.top + WD_FRAMERECT_TOP - icon_y_offset;
1183 
1184  bool rtl = _current_text_dir == TD_RTL;
1185  uint ordinal_left = rtl ? r.right - WD_FRAMERECT_LEFT - this->ordinal_width : r.left + WD_FRAMERECT_LEFT;
1186  uint ordinal_right = rtl ? r.right - WD_FRAMERECT_LEFT : r.left + WD_FRAMERECT_LEFT + this->ordinal_width;
1187  uint icon_left = r.left + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + (rtl ? this->text_width : this->ordinal_width);
1188  uint text_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.right - WD_FRAMERECT_LEFT - this->text_width;
1189  uint text_right = rtl ? r.left + WD_FRAMERECT_LEFT + this->text_width : r.right - WD_FRAMERECT_LEFT;
1190 
1191  for (uint i = 0; i != this->companies.size(); i++) {
1192  const Company *c = this->companies[i];
1193  DrawString(ordinal_left, ordinal_right, y, i + STR_ORDINAL_NUMBER_1ST, i == 0 ? TC_WHITE : TC_YELLOW);
1194 
1195  DrawCompanyIcon(c->index, icon_left, y + icon_y_offset);
1196 
1197  SetDParam(0, c->index);
1198  SetDParam(1, c->index);
1199  SetDParam(2, GetPerformanceTitleFromValue(c->old_economy[0].performance_history));
1200  DrawString(text_left, text_right, y, STR_COMPANY_LEAGUE_COMPANY_NAME);
1201  y += this->line_height;
1202  }
1203  }
1204 
1205  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1206  {
1207  if (widget != WID_CL_BACKGROUND) return;
1208 
1209  this->ordinal_width = 0;
1210  for (uint i = 0; i < MAX_COMPANIES; i++) {
1211  this->ordinal_width = std::max(this->ordinal_width, GetStringBoundingBox(STR_ORDINAL_NUMBER_1ST + i).width);
1212  }
1213  this->ordinal_width += 5; // Keep some extra spacing
1214 
1215  uint widest_width = 0;
1216  uint widest_title = 0;
1217  for (uint i = 0; i < lengthof(_performance_titles); i++) {
1218  uint width = GetStringBoundingBox(_performance_titles[i]).width;
1219  if (width > widest_width) {
1220  widest_title = i;
1221  widest_width = width;
1222  }
1223  }
1224 
1225  Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
1226  this->icon_width = d.width + 2;
1227  this->line_height = std::max<int>(d.height + 2, FONT_HEIGHT_NORMAL);
1228 
1229  for (const Company *c : Company::Iterate()) {
1230  SetDParam(0, c->index);
1231  SetDParam(1, c->index);
1232  SetDParam(2, _performance_titles[widest_title]);
1233  widest_width = std::max(widest_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_NAME).width);
1234  }
1235 
1236  this->text_width = widest_width + 30; // Keep some extra spacing
1237 
1238  size->width = WD_FRAMERECT_LEFT + this->ordinal_width + WD_FRAMERECT_RIGHT + this->icon_width + WD_FRAMERECT_LEFT + this->text_width + WD_FRAMERECT_RIGHT;
1239  size->height = WD_FRAMERECT_TOP + this->line_height * MAX_COMPANIES + WD_FRAMERECT_BOTTOM;
1240  }
1241 
1242 
1243  void OnGameTick() override
1244  {
1245  if (this->companies.NeedResort()) {
1246  this->SetDirty();
1247  }
1248  }
1249 
1255  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1256  {
1257  if (data == 0) {
1258  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
1259  this->companies.ForceRebuild();
1260  } else {
1261  this->companies.ForceResort();
1262  }
1263  }
1264 };
1265 
1266 static const NWidgetPart _nested_company_league_widgets[] = {
1268  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1269  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_COMPANY_LEAGUE_TABLE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1270  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1271  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1272  EndContainer(),
1274 };
1275 
1276 static WindowDesc _company_league_desc(
1277  WDP_AUTO, "league", 0, 0,
1279  0,
1280  _nested_company_league_widgets, lengthof(_nested_company_league_widgets)
1281 );
1282 
1283 void ShowCompanyLeagueTable()
1284 {
1285  AllocateWindowDescFront<CompanyLeagueWindow>(&_company_league_desc, 0);
1286 }
1287 
1288 /*****************************/
1289 /* PERFORMANCE RATING DETAIL */
1290 /*****************************/
1291 
1293  static CompanyID company;
1294  int timeout;
1295 
1297  {
1298  this->UpdateCompanyStats();
1299 
1300  this->InitNested(window_number);
1302  }
1303 
1304  void UpdateCompanyStats()
1305  {
1306  /* Update all company stats with the current data
1307  * (this is because _score_info is not saved to a savegame) */
1308  for (Company *c : Company::Iterate()) {
1309  UpdateCompanyRatingAndValue(c, false);
1310  }
1311 
1312  this->timeout = DAY_TICKS * 5;
1313  }
1314 
1315  uint score_info_left;
1316  uint score_info_right;
1317  uint bar_left;
1318  uint bar_right;
1319  uint bar_width;
1320  uint bar_height;
1321  uint score_detail_left;
1322  uint score_detail_right;
1323 
1324  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1325  {
1326  switch (widget) {
1327  case WID_PRD_SCORE_FIRST:
1328  this->bar_height = FONT_HEIGHT_NORMAL + 4;
1329  size->height = this->bar_height + 2 * WD_MATRIX_TOP;
1330 
1331  uint score_info_width = 0;
1332  for (uint i = SCORE_BEGIN; i < SCORE_END; i++) {
1333  score_info_width = std::max(score_info_width, GetStringBoundingBox(STR_PERFORMANCE_DETAIL_VEHICLES + i).width);
1334  }
1335  SetDParamMaxValue(0, 1000);
1336  score_info_width += GetStringBoundingBox(STR_BLACK_COMMA).width + WD_FRAMERECT_LEFT;
1337 
1338  SetDParamMaxValue(0, 100);
1339  this->bar_width = GetStringBoundingBox(STR_PERFORMANCE_DETAIL_PERCENT).width + 20; // Wide bars!
1340 
1341  /* At this number we are roughly at the max; it can become wider,
1342  * but then you need at 1000 times more money. At that time you're
1343  * not that interested anymore in the last few digits anyway.
1344  * The 500 is because 999 999 500 to 999 999 999 are rounded to
1345  * 1 000 M, and not 999 999 k. Use negative numbers to account for
1346  * the negative income/amount of money etc. as well. */
1347  int max = -(999999999 - 500);
1348 
1349  /* Scale max for the display currency. Prior to rendering the value
1350  * is converted into the display currency, which may cause it to
1351  * raise significantly. We need to compensate for that since {{CURRCOMPACT}}
1352  * is used, which can produce quite short renderings of very large
1353  * values. Otherwise the calculated width could be too narrow.
1354  * Note that it doesn't work if there was a currency with an exchange
1355  * rate greater than max.
1356  * When the currency rate is more than 1000, the 999 999 k becomes at
1357  * least 999 999 M which roughly is equally long. Furthermore if the
1358  * exchange rate is that high, 999 999 k is usually not enough anymore
1359  * to show the different currency numbers. */
1360  if (_currency->rate < 1000) max /= _currency->rate;
1361  SetDParam(0, max);
1362  SetDParam(1, max);
1363  uint score_detail_width = GetStringBoundingBox(STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY).width;
1364 
1365  size->width = 7 + score_info_width + 5 + this->bar_width + 5 + score_detail_width + 7;
1366  uint left = 7;
1367  uint right = size->width - 7;
1368 
1369  bool rtl = _current_text_dir == TD_RTL;
1370  this->score_info_left = rtl ? right - score_info_width : left;
1371  this->score_info_right = rtl ? right : left + score_info_width;
1372 
1373  this->score_detail_left = rtl ? left : right - score_detail_width;
1374  this->score_detail_right = rtl ? left + score_detail_width : right;
1375 
1376  this->bar_left = left + (rtl ? score_detail_width : score_info_width) + 5;
1377  this->bar_right = this->bar_left + this->bar_width;
1378  break;
1379  }
1380  }
1381 
1382  void DrawWidget(const Rect &r, int widget) const override
1383  {
1384  /* No need to draw when there's nothing to draw */
1385  if (this->company == INVALID_COMPANY) return;
1386 
1388  if (this->IsWidgetDisabled(widget)) return;
1389  CompanyID cid = (CompanyID)(widget - WID_PRD_COMPANY_FIRST);
1390  int offset = (cid == this->company) ? 1 : 0;
1391  Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
1392  DrawCompanyIcon(cid, (r.left + r.right - sprite_size.width) / 2 + offset, (r.top + r.bottom - sprite_size.height) / 2 + offset);
1393  return;
1394  }
1395 
1396  if (!IsInsideMM(widget, WID_PRD_SCORE_FIRST, WID_PRD_SCORE_LAST + 1)) return;
1397 
1398  ScoreID score_type = (ScoreID)(widget - WID_PRD_SCORE_FIRST);
1399 
1400  /* The colours used to show how the progress is going */
1401  int colour_done = _colour_gradient[COLOUR_GREEN][4];
1402  int colour_notdone = _colour_gradient[COLOUR_RED][4];
1403 
1404  /* Draw all the score parts */
1405  int64 val = _score_part[company][score_type];
1406  int64 needed = _score_info[score_type].needed;
1407  int score = _score_info[score_type].score;
1408 
1409  /* SCORE_TOTAL has its own rules ;) */
1410  if (score_type == SCORE_TOTAL) {
1411  for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) score += _score_info[i].score;
1412  needed = SCORE_MAX;
1413  }
1414 
1415  uint bar_top = r.top + WD_MATRIX_TOP;
1416  uint text_top = bar_top + 2;
1417 
1418  DrawString(this->score_info_left, this->score_info_right, text_top, STR_PERFORMANCE_DETAIL_VEHICLES + score_type);
1419 
1420  /* Draw the score */
1421  SetDParam(0, score);
1422  DrawString(this->score_info_left, this->score_info_right, text_top, STR_BLACK_COMMA, TC_FROMSTRING, SA_RIGHT);
1423 
1424  /* Calculate the %-bar */
1425  uint x = Clamp<int64>(val, 0, needed) * this->bar_width / needed;
1426  bool rtl = _current_text_dir == TD_RTL;
1427  if (rtl) {
1428  x = this->bar_right - x;
1429  } else {
1430  x = this->bar_left + x;
1431  }
1432 
1433  /* Draw the bar */
1434  if (x != this->bar_left) GfxFillRect(this->bar_left, bar_top, x, bar_top + this->bar_height, rtl ? colour_notdone : colour_done);
1435  if (x != this->bar_right) GfxFillRect(x, bar_top, this->bar_right, bar_top + this->bar_height, rtl ? colour_done : colour_notdone);
1436 
1437  /* Draw it */
1438  SetDParam(0, Clamp<int64>(val, 0, needed) * 100 / needed);
1439  DrawString(this->bar_left, this->bar_right, text_top, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING, SA_HOR_CENTER);
1440 
1441  /* SCORE_LOAN is inversed */
1442  if (score_type == SCORE_LOAN) val = needed - val;
1443 
1444  /* Draw the amount we have against what is needed
1445  * For some of them it is in currency format */
1446  SetDParam(0, val);
1447  SetDParam(1, needed);
1448  switch (score_type) {
1449  case SCORE_MIN_PROFIT:
1450  case SCORE_MIN_INCOME:
1451  case SCORE_MAX_INCOME:
1452  case SCORE_MONEY:
1453  case SCORE_LOAN:
1454  DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY);
1455  break;
1456  default:
1457  DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_INT);
1458  }
1459  }
1460 
1461  void OnClick(Point pt, int widget, int click_count) override
1462  {
1463  /* Check which button is clicked */
1465  /* Is it no on disable? */
1466  if (!this->IsWidgetDisabled(widget)) {
1467  this->RaiseWidget(this->company + WID_PRD_COMPANY_FIRST);
1468  this->company = (CompanyID)(widget - WID_PRD_COMPANY_FIRST);
1469  this->LowerWidget(this->company + WID_PRD_COMPANY_FIRST);
1470  this->SetDirty();
1471  }
1472  }
1473  }
1474 
1475  void OnGameTick() override
1476  {
1477  /* Update the company score every 5 days */
1478  if (--this->timeout == 0) {
1479  this->UpdateCompanyStats();
1480  this->SetDirty();
1481  }
1482  }
1483 
1489  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1490  {
1491  if (!gui_scope) return;
1492  /* Disable the companies who are not active */
1493  for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
1495  }
1496 
1497  /* Check if the currently selected company is still active. */
1498  if (this->company != INVALID_COMPANY && !Company::IsValidID(this->company)) {
1499  /* Raise the widget for the previous selection. */
1500  this->RaiseWidget(this->company + WID_PRD_COMPANY_FIRST);
1501  this->company = INVALID_COMPANY;
1502  }
1503 
1504  if (this->company == INVALID_COMPANY) {
1505  for (const Company *c : Company::Iterate()) {
1506  this->company = c->index;
1507  break;
1508  }
1509  }
1510 
1511  /* Make sure the widget is lowered */
1512  this->LowerWidget(this->company + WID_PRD_COMPANY_FIRST);
1513  }
1514 };
1515 
1516 CompanyID PerformanceRatingDetailWindow::company = INVALID_COMPANY;
1517 
1524 static NWidgetBase *MakePerformanceDetailPanels(int *biggest_index)
1525 {
1526  const StringID performance_tips[] = {
1527  STR_PERFORMANCE_DETAIL_VEHICLES_TOOLTIP,
1528  STR_PERFORMANCE_DETAIL_STATIONS_TOOLTIP,
1529  STR_PERFORMANCE_DETAIL_MIN_PROFIT_TOOLTIP,
1530  STR_PERFORMANCE_DETAIL_MIN_INCOME_TOOLTIP,
1531  STR_PERFORMANCE_DETAIL_MAX_INCOME_TOOLTIP,
1532  STR_PERFORMANCE_DETAIL_DELIVERED_TOOLTIP,
1533  STR_PERFORMANCE_DETAIL_CARGO_TOOLTIP,
1534  STR_PERFORMANCE_DETAIL_MONEY_TOOLTIP,
1535  STR_PERFORMANCE_DETAIL_LOAN_TOOLTIP,
1536  STR_PERFORMANCE_DETAIL_TOTAL_TOOLTIP,
1537  };
1538 
1539  static_assert(lengthof(performance_tips) == SCORE_END - SCORE_BEGIN);
1540 
1542  for (int widnum = WID_PRD_SCORE_FIRST; widnum <= WID_PRD_SCORE_LAST; widnum++) {
1543  NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_BROWN, widnum);
1544  panel->SetFill(1, 1);
1545  panel->SetDataTip(0x0, performance_tips[widnum - WID_PRD_SCORE_FIRST]);
1546  vert->Add(panel);
1547  }
1548  *biggest_index = WID_PRD_SCORE_LAST;
1549  return vert;
1550 }
1551 
1554 {
1555  return MakeCompanyButtonRows(biggest_index, WID_PRD_COMPANY_FIRST, WID_PRD_COMPANY_LAST, COLOUR_BROWN, 8, STR_PERFORMANCE_DETAIL_SELECT_COMPANY_TOOLTIP);
1556 }
1557 
1558 static const NWidgetPart _nested_performance_rating_detail_widgets[] = {
1560  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1561  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_PERFORMANCE_DETAIL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1562  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1563  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1564  EndContainer(),
1565  NWidget(WWT_PANEL, COLOUR_BROWN),
1567  EndContainer(),
1569 };
1570 
1571 static WindowDesc _performance_rating_detail_desc(
1572  WDP_AUTO, "league_details", 0, 0,
1574  0,
1575  _nested_performance_rating_detail_widgets, lengthof(_nested_performance_rating_detail_widgets)
1576 );
1577 
1578 void ShowPerformanceRatingDetail()
1579 {
1580  AllocateWindowDescFront<PerformanceRatingDetailWindow>(&_performance_rating_detail_desc, 0);
1581 }
1582 
1583 void InitializeGraphGui()
1584 {
1585  _legend_excluded_companies = 0;
1586  _legend_excluded_cargo = 0;
1587 }
MakeCompanyButtonRows
NWidgetBase * MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, Colours button_colour, int max_length, StringID button_tooltip)
Make a number of rows with button-like graphics, for enabling/disabling each company.
Definition: widget.cpp:3128
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
PaymentRatesGraphWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: graph_gui.cpp:915
PaymentRatesGraphWindow::legend_width
uint legend_width
Width of legend 'blob'.
Definition: graph_gui.cpp:877
CargoArray::GetSum
const T GetSum() const
Get the sum of all cargo amounts.
Definition: cargo_type.h:122
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:3234
IsInsideMM
static 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:204
PaymentRatesGraphWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: graph_gui.cpp:937
CompanyEconomyEntry::company_value
Money company_value
The value of the company.
Definition: company_base.h:28
NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1241
WID_PHG_KEY
@ WID_PHG_KEY
Key button.
Definition: graph_widget.h:34
CompanyLeagueWindow::line_height
int line_height
Height of the text lines.
Definition: graph_gui.cpp:1136
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3136
GraphLegendWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: graph_gui.cpp:58
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1190
WID_CV_KEY_BUTTON
@ WID_CV_KEY_BUTTON
Key button.
Definition: graph_widget.h:26
WID_CPR_RESIZE
@ WID_CPR_RESIZE
Resize button.
Definition: graph_widget.h:46
ScaleFontTrad
static int ScaleFontTrad(int value)
Scale traditional pixel dimensions to Font zoom level.
Definition: zoom_func.h:127
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:664
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1141
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:247
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:320
FindLastBit
uint8 FindLastBit(uint64 x)
Search the last set bit in a 64 bit variable.
Definition: bitmath_func.cpp:66
SCORE_TOTAL
@ SCORE_TOTAL
This must always be the last entry.
Definition: economy_type.h:56
company_base.h
_cur_year
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
NWidgetContainer::Add
void Add(NWidgetBase *wid)
Append widget wid to container.
Definition: widget.cpp:1047
WD_MATRIX_TOP
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
Definition: window_gui.h:80
GUISettings::graph_line_thickness
uint8 graph_line_thickness
the thickness of the lines in the various graph guis
Definition: settings_type.h:169
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
PerformanceRatingDetailWindow
Definition: graph_gui.cpp:1292
company_gui.h
currency.h
GUIList< const Company * >
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
NWidgetResizeBase::SetMinimalTextLines
void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
Set minimal text lines for the widget.
Definition: widget.cpp:892
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1760
CompanyLeagueWindow
Definition: graph_gui.cpp:1130
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
CompanyLeagueWindow::BuildCompanyList
void BuildCompanyList()
(Re)Build the company league list
Definition: graph_gui.cpp:1141
WID_GL_FIRST_COMPANY
@ WID_GL_FIRST_COMPANY
First company in the legend.
Definition: graph_widget.h:20
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:57
WC_PERFORMANCE_HISTORY
@ WC_PERFORMANCE_HISTORY
Performance history graph; Window numbers:
Definition: window_type.h:538
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:712
PerformanceHistoryGraphWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: graph_gui.cpp:781
WID_PHG_DETAILED_PERFORMANCE
@ WID_PHG_DETAILED_PERFORMANCE
Detailed performance.
Definition: graph_widget.h:35
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:18
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:995
zoom_func.h
PerformanceRatingDetailWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: graph_gui.cpp:1382
MakeCompanyButtonRowsGraphGUI
NWidgetBase * MakeCompanyButtonRowsGraphGUI(int *biggest_index)
Make a number of rows with buttons for each company for the performance rating detail window.
Definition: graph_gui.cpp:1553
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:645
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:57
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
FR_LOWERED
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
Definition: window_gui.h:31
economy_func.h
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:330
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2138
ValuesInterval::highest
OverflowSafeInt64 highest
Highest value of this interval. Must be zero or greater.
Definition: graph_gui.cpp:155
NWidgetBase::SetPadding
void SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Set additional space (padding) around the widget.
Definition: widget_type.h:150
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:631
WID_CV_BACKGROUND
@ WID_CV_BACKGROUND
Background of the window.
Definition: graph_widget.h:27
WC_COMPANY_LEAGUE
@ WC_COMPANY_LEAGUE
Company league window; Window numbers:
Definition: window_type.h:550
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:55
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1799
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1109
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:891
BaseGraphWindow
Definition: graph_gui.cpp:163
WID_PHG_RESIZE
@ WID_PHG_RESIZE
Resize button.
Definition: graph_widget.h:38
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:790
PaymentRatesGraphWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: graph_gui.cpp:975
PaymentRatesGraphWindow
Definition: graph_gui.cpp:874
WC_DELIVERED_CARGO
@ WC_DELIVERED_CARGO
Delivered cargo graph; Window numbers:
Definition: window_type.h:532
WID_CV_RESIZE
@ WID_CV_RESIZE
Resize button.
Definition: graph_widget.h:29
gfx_func.h
ScoreInfo::score
int score
How much score it will give.
Definition: economy_type.h:67
WindowDesc
High level window description.
Definition: window_gui.h:168
COMPANY_FIRST
@ COMPANY_FIRST
First company, same as owner.
Definition: company_type.h:22
WC_GRAPH_LEGEND
@ WC_GRAPH_LEGEND
Legend for graphs; Window numbers:
Definition: window_type.h:508
window_gui.h
WID_PHG_GRAPH
@ WID_PHG_GRAPH
Graph itself.
Definition: graph_widget.h:37
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:464
MakePerformanceDetailPanels
static NWidgetBase * MakePerformanceDetailPanels(int *biggest_index)
Make a vertical list of panels for outputting score details.
Definition: graph_gui.cpp:1524
BaseGraphWindow::GetValuesInterval
ValuesInterval GetValuesInterval(int num_hori_lines) const
Get the interval that contains the graph's data.
Definition: graph_gui.cpp:204
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:156
WID_CPR_MATRIX_SCROLLBAR
@ WID_CPR_MATRIX_SCROLLBAR
Cargo list scrollbar.
Definition: graph_widget.h:51
CompanyProperties::colour
byte colour
Company colour.
Definition: company_base.h:71
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
CompanyEconomyEntry::performance_history
int32 performance_history
Company score (scale 0-1000)
Definition: company_base.h:27
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:655
WID_PRD_COMPANY_LAST
@ WID_PRD_COMPANY_LAST
Last company.
Definition: graph_widget.h:65
CompanyProperties::num_valid_stat_ent
byte num_valid_stat_ent
Number of valid statistical entries in old_economy.
Definition: company_base.h:101
WID_GL_BACKGROUND
@ WID_GL_BACKGROUND
Background of the window.
Definition: graph_widget.h:18
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:207
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1789
GraphLegendWindow
Definition: graph_gui.cpp:46
PaymentRatesGraphWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: graph_gui.cpp:898
SCORE_END
@ SCORE_END
How many scores are there..
Definition: economy_type.h:57
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:315
PaymentRatesGraphWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: graph_gui.cpp:1029
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:993
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:208
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
BaseGraphWindow::GRAPH_AXIS_LABEL_COLOUR
static const TextColour GRAPH_AXIS_LABEL_COLOUR
colour of the graph axis label.
Definition: graph_gui.cpp:173
BaseGraphWindow::UpdateStatistics
void UpdateStatistics(bool initialize)
Update the statistics.
Definition: graph_gui.cpp:566
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
PaymentRatesGraphWindow::line_height
uint line_height
Pixel height of each cargo type row.
Definition: graph_gui.cpp:875
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
SetMatrixDataTip
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1127
WID_CPR_ENABLE_CARGOES
@ WID_CPR_ENABLE_CARGOES
Enable cargoes button.
Definition: graph_widget.h:48
BaseGraphWindow::excluded_data
uint64 excluded_data
bitmask of the datasets that shouldn't be displayed.
Definition: graph_gui.cpp:178
WID_CPR_GRAPH
@ WID_CPR_GRAPH
Graph itself.
Definition: graph_widget.h:45
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:386
WID_PRD_COMPANY_FIRST
@ WID_PRD_COMPANY_FIRST
First company.
Definition: graph_widget.h:64
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
CompanyLeagueWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: graph_gui.cpp:1255
BaseGraphWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: graph_gui.cpp:540
CompanyLeagueWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: graph_gui.cpp:1205
safeguards.h
sortlist_type.h
WID_PRD_SCORE_LAST
@ WID_PRD_SCORE_LAST
Last entry in the score list.
Definition: graph_widget.h:62
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:312
ValuesInterval::lowest
OverflowSafeInt64 lowest
Lowest value of this interval. Must be zero or less.
Definition: graph_gui.cpp:156
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:170
BaseGraphWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: graph_gui.cpp:556
CompanyLeagueWindow::PerformanceSorter
static bool PerformanceSorter(const Company *const &c1, const Company *const &c2)
Sort the company league by performance history.
Definition: graph_gui.cpp:1156
CompanyLeagueWindow::text_width
uint text_width
The width of the actual text.
Definition: graph_gui.cpp:1134
sprites.h
PaymentRatesGraphWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: graph_gui.cpp:1019
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
PerformanceHistoryGraphWindow
Definition: graph_gui.cpp:769
date_func.h
WC_INCOME_GRAPH
@ WC_INCOME_GRAPH
Income graph; Window numbers:
Definition: window_type.h:520
stdafx.h
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:204
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
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:119
GUIList::NeedResort
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
Definition: sortlist_type.h:199
SCORE_MAX
@ SCORE_MAX
The max score that can be in the performance history.
Definition: economy_type.h:59
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:37
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:329
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
NWidgetResizeBase::SetFill
void SetFill(uint fill_x, uint fill_y)
Set the filling of the widget from initial size.
Definition: widget.cpp:905
WID_CPR_FOOTER
@ WID_CPR_FOOTER
Footer.
Definition: graph_widget.h:47
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:165
CompanyEconomyEntry::delivered_cargo
CargoArray delivered_cargo
The amount of delivered cargo.
Definition: company_base.h:26
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:144
BaseGraphWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: graph_gui.cpp:492
BaseGraphWindow::DrawGraph
void DrawGraph(Rect r) const
Actually draw the graph.
Definition: graph_gui.cpp:287
PerformanceRatingDetailWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: graph_gui.cpp:1324
WC_PAYMENT_RATES
@ WC_PAYMENT_RATES
Payment rates graph; Window numbers:
Definition: window_type.h:556
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:979
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
ValuesInterval
Contains the interval of a graph's data.
Definition: graph_gui.cpp:154
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
WC_COMPANY_VALUE
@ WC_COMPANY_VALUE
Company value graph; Window numbers:
Definition: window_type.h:544
CompanyEconomyEntry::expenses
Money expenses
The amount of expenses.
Definition: company_base.h:25
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1094
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:386
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
_sorted_standard_cargo_specs
span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:153
graph_gui.h
NWidgetCore::SetDataTip
void SetDataTip(uint32 widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:962
WC_PERFORMANCE_DETAIL
@ WC_PERFORMANCE_DETAIL
Performance detail window; Window numbers:
Definition: window_type.h:562
WID_CPR_MATRIX
@ WID_CPR_MATRIX
Cargo list.
Definition: graph_widget.h:50
IncomeGraphWindow
Definition: graph_gui.cpp:671
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:168
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:107
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1209
geometry_func.hpp
WID_PRD_SCORE_FIRST
@ WID_PRD_SCORE_FIRST
First entry in the score list.
Definition: graph_widget.h:61
SetDParamMaxValue
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:94
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1012
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
BaseGraphWindow::MIN_GRID_PIXEL_SIZE
static const int MIN_GRID_PIXEL_SIZE
Minimum distance between graph lines.
Definition: graph_gui.cpp:176
WID_CPR_BACKGROUND
@ WID_CPR_BACKGROUND
Background of the window.
Definition: graph_widget.h:43
BaseGraphWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: graph_gui.cpp:528
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
NWidgetVertical
Vertical container.
Definition: widget_type.h:518
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:673
cargotype.h
ScoreInfo::needed
int needed
How much you need to get the perfect score.
Definition: economy_type.h:66
GraphLegendWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: graph_gui.cpp:95
WD_RESIZEBOX_WIDTH
@ WD_RESIZEBOX_WIDTH
Width of a resize box widget.
Definition: window_gui.h:112
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1776
BaseGraphWindow::GetYLabelWidth
uint GetYLabelWidth(ValuesInterval current_interval, int num_hori_lines) const
Get width for Y labels.
Definition: graph_gui.cpp:263
CompanyValueGraphWindow
Definition: graph_gui.cpp:825
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
PerformanceRatingDetailWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: graph_gui.cpp:1461
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:175
WID_CL_BACKGROUND
@ WID_CL_BACKGROUND
Background of the window.
Definition: graph_widget.h:56
WID_GL_LAST_COMPANY
@ WID_GL_LAST_COMPANY
Last company in the legend.
Definition: graph_widget.h:21
CompanyLeagueWindow::icon_width
uint icon_width
The width of the company icon.
Definition: graph_gui.cpp:1135
CompanyLeagueWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: graph_gui.cpp:1169
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:213
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:21
CompanyLeagueWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: graph_gui.cpp:1243
WID_CPR_HEADER
@ WID_CPR_HEADER
Header.
Definition: graph_widget.h:44
ScoreID
ScoreID
Score categories in the detailed performance rating.
Definition: economy_type.h:45
CompanyEconomyEntry::income
Money income
The amount of income.
Definition: company_base.h:24
BaseGraphWindow::cost
OverflowSafeInt64 cost[GRAPH_MAX_DATASETS][GRAPH_NUM_MONTHS]
Stored costs for the last GRAPH_NUM_MONTHS months.
Definition: graph_gui.cpp:196
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:328
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:209
CompanyLeagueWindow::ordinal_width
uint ordinal_width
The width of the ordinal number.
Definition: graph_gui.cpp:1133
PaymentRatesGraphWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: graph_gui.cpp:1014
window_func.h
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
CenterBounds
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:140
ToggleBit
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
Definition: bitmath_func.hpp:181
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:457
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:57
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
graph_widget.h
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2212
OverflowSafeInt< int64 >
BaseGraphWindow::GRAPH_NUM_MONTHS
static const int GRAPH_NUM_MONTHS
Number of months displayed in the graph.
Definition: graph_gui.cpp:171
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1078
PaymentRatesGraphWindow::OnHundredthTick
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
Definition: graph_gui.cpp:1035
DeliveredCargoGraphWindow
Definition: graph_gui.cpp:720
GREY_SCALE
#define GREY_SCALE(level)
Return the colour for a particular greyscale level.
Definition: gfx_func.h:202
PaymentRatesGraphWindow::vscroll
Scrollbar * vscroll
Cargo list scrollbar.
Definition: graph_gui.cpp:876
Window
Data structure for an opened window.
Definition: window_gui.h:279
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
WID_CV_GRAPH
@ WID_CV_GRAPH
Graph itself.
Definition: graph_widget.h:28
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:326
Window::RaiseWidget
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:477
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:636
ZOOM_LVL_OUT_4X
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
Definition: zoom_type.h:26
NWidgetBackground
Nested widget with a child.
Definition: widget_type.h:586
BaseGraphWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: graph_gui.cpp:546
PerformanceRatingDetailWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: graph_gui.cpp:1475
MakeNWidgetCompanyLines
static NWidgetBase * MakeNWidgetCompanyLines(int *biggest_index)
Construct a vertical list of buttons, one for each company.
Definition: graph_gui.cpp:111
WID_CPR_DISABLE_CARGOES
@ WID_CPR_DISABLE_CARGOES
Disable cargoes button.
Definition: graph_widget.h:49
WC_OPERATING_PROFIT
@ WC_OPERATING_PROFIT
Operating profit graph; Window numbers:
Definition: window_type.h:526
Window::IsWidgetDisabled
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:415
CompanyLeagueWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: graph_gui.cpp:1177
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:468
Company
Definition: company_base.h:117
_cur_month
Month _cur_month
Current month (0..11)
Definition: date.cpp:27
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:100
PerformanceRatingDetailWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: graph_gui.cpp:1489
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:866
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
DAY_TICKS
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Definition: date_type.h:28
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
OperatingProfitGraphWindow
Definition: graph_gui.cpp:620
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:598
WID_PHG_BACKGROUND
@ WID_PHG_BACKGROUND
Background of the window.
Definition: graph_widget.h:36
SetMinimalTextLines
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1030
_score_info
const ScoreInfo _score_info[]
Score info, values used for computing the detailed performance rating.
Definition: economy.cpp:86
GraphLegendWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: graph_gui.cpp:76
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62