annotate src/graph_gui.cpp @ 15183:43a5d37b45c4 draft

(svn r19812) -Codechange: give some unnamed enums a name or, in case they consisted of unrelated values use static const (u)int
author rubidium <rubidium@openttd.org>
date Thu, 13 May 2010 09:44:44 +0000
parents bd4b62132aed
children 821c26b30fd9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1 /* $Id$ */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12671
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12671
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12671
diff changeset
5 * 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.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12671
diff changeset
6 * 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.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12671
diff changeset
7 * 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/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12671
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12671
diff changeset
9
9111
d48433370037 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents: 8409
diff changeset
10 /** @file graph_gui.cpp GUI that shows performance graphs. */
6179
e3e61b92574b (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6091
diff changeset
11
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
12 #include "stdafx.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
13 #include "openttd.h"
14505
69522d847103 (svn r19076) -Codechange: Move graph functions to their own header.
terkhen <terkhen@openttd.org>
parents: 14409
diff changeset
14 #include "graph_gui.h"
8107
f65cf2bc3255 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium <rubidium@openttd.org>
parents: 8106
diff changeset
15 #include "window_gui.h"
10208
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
16 #include "company_base.h"
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
17 #include "company_gui.h"
8116
9cc845deddfe (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents: 8114
diff changeset
18 #include "economy_func.h"
6091
17ebeb5a2c37 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138 <peter1138@openttd.org>
parents: 5946
diff changeset
19 #include "cargotype.h"
8114
2d6af5d7a142 (svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents: 8107
diff changeset
20 #include "strings_func.h"
8131
e300ac8001ae (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents: 8130
diff changeset
21 #include "window_func.h"
8140
fb8a05d579da (svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents: 8131
diff changeset
22 #include "date_func.h"
8224
c45446125bf0 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents: 8179
diff changeset
23 #include "gfx_func.h"
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
24 #include "sortlist_type.h"
14258
a899d4e5ee1a (svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents: 14214
diff changeset
25 #include "core/geometry_func.hpp"
15103
bd4b62132aed (svn r19729) -Fix [FS#3793]: The company value graph crashed the game when displaying companies with a huge amount of money.
terkhen <terkhen@openttd.org>
parents: 15053
diff changeset
26 #include "math.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
27
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
28 #include "table/strings.h"
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
29 #include "table/sprites.h"
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8254
diff changeset
30
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
31 /* Bitmasks of company and cargo indices that shouldn't be drawn. */
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
32 static uint _legend_excluded_companies;
5806
4f5e2ea123e8 (svn r8368) -Cleanup: [Graphs] Rename the variables relating to whether datasets should be drawn, and use HASBIT for testing against them.
maedhros <maedhros@openttd.org>
parents: 5805
diff changeset
33 static uint _legend_excluded_cargo;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
34
5805
b7c3a94ff74e (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros <maedhros@openttd.org>
parents: 5804
diff changeset
35 /* Apparently these don't play well with enums. */
8409
7c5e4180e2b1 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium <rubidium@openttd.org>
parents: 8264
diff changeset
36 static const OverflowSafeInt64 INVALID_DATAPOINT(INT64_MAX); // Value used for a datapoint that shouldn't be drawn.
7763
b66a3cb83e69 (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium <rubidium@openttd.org>
parents: 7520
diff changeset
37 static const uint INVALID_DATAPOINT_POS = UINT_MAX; // Used to determine if the previous point was drawn.
5805
b7c3a94ff74e (svn r8367) -Fix: [Graphs] Don't try to use the same value to mean something is invalid for both an int64 and a uint.
maedhros <maedhros@openttd.org>
parents: 5804
diff changeset
38
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
39 /****************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
40 /* GRAPH LEGEND */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
41 /****************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
42
11623
7f91f3d79f90 (svn r16003) -Codechange: Replaced magic widget number constant with enumerated value in graph legend window.
alberth <alberth@openttd.org>
parents: 11622
diff changeset
43 /** Widget numbers of the graph legend window. */
7f91f3d79f90 (svn r16003) -Codechange: Replaced magic widget number constant with enumerated value in graph legend window.
alberth <alberth@openttd.org>
parents: 11622
diff changeset
44 enum GraphLegendWidgetNumbers {
7f91f3d79f90 (svn r16003) -Codechange: Replaced magic widget number constant with enumerated value in graph legend window.
alberth <alberth@openttd.org>
parents: 11622
diff changeset
45 GLW_BACKGROUND,
7f91f3d79f90 (svn r16003) -Codechange: Replaced magic widget number constant with enumerated value in graph legend window.
alberth <alberth@openttd.org>
parents: 11622
diff changeset
46
7f91f3d79f90 (svn r16003) -Codechange: Replaced magic widget number constant with enumerated value in graph legend window.
alberth <alberth@openttd.org>
parents: 11622
diff changeset
47 GLW_FIRST_COMPANY,
11749
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
48 GLW_LAST_COMPANY = GLW_FIRST_COMPANY + MAX_COMPANIES - 1,
11623
7f91f3d79f90 (svn r16003) -Codechange: Replaced magic widget number constant with enumerated value in graph legend window.
alberth <alberth@openttd.org>
parents: 11622
diff changeset
49 };
7f91f3d79f90 (svn r16003) -Codechange: Replaced magic widget number constant with enumerated value in graph legend window.
alberth <alberth@openttd.org>
parents: 11622
diff changeset
50
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
51 struct GraphLegendWindow : Window {
12608
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
52 GraphLegendWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
53 {
12608
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
54 this->InitNested(desc, window_number);
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
55
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
56 for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
57 if (!HasBit(_legend_excluded_companies, c)) this->LowerWidget(c + GLW_FIRST_COMPANY);
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
58
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
59 this->OnInvalidateData(c);
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
60 }
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
61 }
6203
60d5fce9d6b0 (svn r8989) -Fix: more indenting and variable scoping
peter1138 <peter1138@openttd.org>
parents: 6192
diff changeset
62
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
63 virtual void OnPaint()
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
64 {
12608
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
65 this->DrawWidgets();
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
66 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
67
12608
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
68 virtual void DrawWidget(const Rect &r, int widget) const
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
69 {
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
70 if (!IsInsideMM(widget, GLW_FIRST_COMPANY, MAX_COMPANIES + GLW_FIRST_COMPANY)) return;
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
71
12608
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
72 CompanyID cid = (CompanyID)(widget - GLW_FIRST_COMPANY);
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
73
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
74 if (!Company::IsValidID(cid)) return;
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
75
13643
a790e57124b2 (svn r18167) -Change: make the graph legend, cargo payment graph and company league windows RTL aware
rubidium <rubidium@openttd.org>
parents: 13636
diff changeset
76 bool rtl = _dynlang.text_dir == TD_RTL;
a790e57124b2 (svn r18167) -Change: make the graph legend, cargo payment graph and company league windows RTL aware
rubidium <rubidium@openttd.org>
parents: 13636
diff changeset
77
13725
a1342a520bb0 (svn r18250) -Codechange: make the graph legend big font aware
rubidium <rubidium@openttd.org>
parents: 13705
diff changeset
78 DrawCompanyIcon(cid, rtl ? r.right - 16 : r.left + 2, r.top + 2 + (FONT_HEIGHT_NORMAL - 10) / 2);
12608
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
79
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
80 SetDParam(0, cid);
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
81 SetDParam(1, cid);
13725
a1342a520bb0 (svn r18250) -Codechange: make the graph legend big font aware
rubidium <rubidium@openttd.org>
parents: 13705
diff changeset
82 DrawString(r.left + (rtl ? WD_FRAMERECT_LEFT : 19), r.right - (rtl ? 19 : WD_FRAMERECT_RIGHT), r.top + WD_FRAMERECT_TOP, STR_COMPANY_NAME_COMPANY_NUM, HasBit(_legend_excluded_companies, cid) ? TC_BLACK : TC_WHITE);
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
83 }
6203
60d5fce9d6b0 (svn r8989) -Fix: more indenting and variable scoping
peter1138 <peter1138@openttd.org>
parents: 6192
diff changeset
84
14409
1eaefde497fd (svn r18966) -Codechange: Remove Window::OnDoubleClick() in favour of a parameter for OnClick().
frosch <frosch@openttd.org>
parents: 14258
diff changeset
85 virtual void OnClick(Point pt, int widget, int click_count)
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
86 {
11623
7f91f3d79f90 (svn r16003) -Codechange: Replaced magic widget number constant with enumerated value in graph legend window.
alberth <alberth@openttd.org>
parents: 11622
diff changeset
87 if (!IsInsideMM(widget, GLW_FIRST_COMPANY, MAX_COMPANIES + GLW_FIRST_COMPANY)) return;
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
88
11623
7f91f3d79f90 (svn r16003) -Codechange: Replaced magic widget number constant with enumerated value in graph legend window.
alberth <alberth@openttd.org>
parents: 11622
diff changeset
89 ToggleBit(_legend_excluded_companies, widget - GLW_FIRST_COMPANY);
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
90 this->ToggleWidgetLoweredState(widget);
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
91 this->SetDirty();
14966
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
92 InvalidateWindowData(WC_INCOME_GRAPH, 0);
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
93 InvalidateWindowData(WC_OPERATING_PROFIT, 0);
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
94 InvalidateWindowData(WC_DELIVERED_CARGO, 0);
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
95 InvalidateWindowData(WC_PERFORMANCE_HISTORY, 0);
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
96 InvalidateWindowData(WC_COMPANY_VALUE, 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
97 }
12608
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
98
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
99 virtual void OnInvalidateData(int data)
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
100 {
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
101 if (Company::IsValidID(data)) return;
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
102
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
103 SetBit(_legend_excluded_companies, data);
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
104 this->RaiseWidget(data + GLW_FIRST_COMPANY);
e260c3e0576e (svn r17051) -Codechange: make the graph legend window use nested widgets
rubidium <rubidium@openttd.org>
parents: 12598
diff changeset
105 }
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
106 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
107
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
108 /**
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
109 * Construct a vertical list of buttons, one for each company.
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
110 * @param biggest_index Storage for collecting the biggest index used in the returned tree.
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
111 * @return Panel with company buttons.
13954
79b889a3a0cd (svn r18490) -Doc: Fixed syntax of a few doxygen pre and post coditions.
alberth <alberth@openttd.org>
parents: 13916
diff changeset
112 * @post \c *biggest_index contains the largest used index in the tree.
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
113 */
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
114 static NWidgetBase *MakeNWidgetCompanyLines(int *biggest_index)
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
115 {
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
116 NWidgetVertical *vert = new NWidgetVertical();
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
117
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
118 for (int widnum = GLW_FIRST_COMPANY; widnum <= GLW_LAST_COMPANY; widnum++) {
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
119 NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
13725
a1342a520bb0 (svn r18250) -Codechange: make the graph legend big font aware
rubidium <rubidium@openttd.org>
parents: 13705
diff changeset
120 panel->SetMinimalSize(246, FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
a1342a520bb0 (svn r18250) -Codechange: make the graph legend big font aware
rubidium <rubidium@openttd.org>
parents: 13705
diff changeset
121 panel->SetFill(1, 0);
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
122 panel->SetDataTip(0x0, STR_GRAPH_KEY_COMPANY_SELECTION_TOOLTIP);
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
123 vert->Add(panel);
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
124 }
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
125 *biggest_index = GLW_LAST_COMPANY;
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
126 return vert;
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
127 }
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
128
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
129 static const NWidgetPart _nested_graph_legend_widgets[] = {
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
130 NWidget(NWID_HORIZONTAL),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
131 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
132 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_KEY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
14045
68fabdc82f5b (svn r18588) -Feature [FS#2943]: Add shading and unshading of windows.
alberth <alberth@openttd.org>
parents: 13954
diff changeset
133 NWidget(WWT_SHADEBOX, COLOUR_GREY),
13916
32bb7763b24a (svn r18447) -Change: make some more windows (e.g. graphs, company view) stickyable
rubidium <rubidium@openttd.org>
parents: 13798
diff changeset
134 NWidget(WWT_STICKYBOX, COLOUR_GREY),
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
135 EndContainer(),
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
136 NWidget(WWT_PANEL, COLOUR_GREY, GLW_BACKGROUND),
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
137 NWidget(NWID_SPACER), SetMinimalSize(0, 2),
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
138 NWidget(NWID_HORIZONTAL),
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
139 NWidget(NWID_SPACER), SetMinimalSize(2, 0),
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
140 NWidgetFunction(MakeNWidgetCompanyLines),
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
141 NWidget(NWID_SPACER), SetMinimalSize(2, 0),
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
142 EndContainer(),
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
143 EndContainer(),
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
144 };
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
145
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
146 static const WindowDesc _graph_legend_desc(
13798
6f820ae12bb3 (svn r18324) -Codechange: there's no need for a default size when the window isn't resizable
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
147 WDP_AUTO, 0, 0,
5893
8547517ef719 (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium <rubidium@openttd.org>
parents: 5812
diff changeset
148 WC_GRAPH_LEGEND, WC_NONE,
13749
fc3ab8256c95 (svn r18274) -Codechange: remove the unused WDF flags
rubidium <rubidium@openttd.org>
parents: 13739
diff changeset
149 0,
13564
bae287664b02 (svn r18086) -Codechange: remove 'widget' from WindowDesc
rubidium <rubidium@openttd.org>
parents: 13556
diff changeset
150 _nested_graph_legend_widgets, lengthof(_nested_graph_legend_widgets)
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
151 );
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
152
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6203
diff changeset
153 static void ShowGraphLegend()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
154 {
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
155 AllocateWindowDescFront<GraphLegendWindow>(&_graph_legend_desc, 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
156 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
157
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
158 /** Contains the interval of a graph's data. */
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
159 struct ValuesInterval {
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
160 OverflowSafeInt64 highest; ///< Highest value of this interval. Must be zero or greater.
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
161 OverflowSafeInt64 lowest; ///< Lowest value of this interval. Must be zero or less.
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
162 };
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
163
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
164 /******************/
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
165 /* BASE OF GRAPHS */
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
166 /*****************/
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
167
12079
0f1b20a70f70 (svn r16488) -Codechange [FS#2941]: Use widget numbers of base grap window and cargo payment window in the window handling code (erikjanp)
alberth <alberth@openttd.org>
parents: 11949
diff changeset
168 /** Widget numbers of a base graph window. */
0f1b20a70f70 (svn r16488) -Codechange [FS#2941]: Use widget numbers of base grap window and cargo payment window in the window handling code (erikjanp)
alberth <alberth@openttd.org>
parents: 11949
diff changeset
169 enum CompanyValueWidgets {
0f1b20a70f70 (svn r16488) -Codechange [FS#2941]: Use widget numbers of base grap window and cargo payment window in the window handling code (erikjanp)
alberth <alberth@openttd.org>
parents: 11949
diff changeset
170 BGW_KEY_BUTTON,
0f1b20a70f70 (svn r16488) -Codechange [FS#2941]: Use widget numbers of base grap window and cargo payment window in the window handling code (erikjanp)
alberth <alberth@openttd.org>
parents: 11949
diff changeset
171 BGW_BACKGROUND,
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
172 BGW_GRAPH,
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
173 BGW_RESIZE,
12079
0f1b20a70f70 (svn r16488) -Codechange [FS#2941]: Use widget numbers of base grap window and cargo payment window in the window handling code (erikjanp)
alberth <alberth@openttd.org>
parents: 11949
diff changeset
174 };
0f1b20a70f70 (svn r16488) -Codechange [FS#2941]: Use widget numbers of base grap window and cargo payment window in the window handling code (erikjanp)
alberth <alberth@openttd.org>
parents: 11949
diff changeset
175
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
176 struct BaseGraphWindow : Window {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
177 protected:
15183
43a5d37b45c4 (svn r19812) -Codechange: give some unnamed enums a name or, in case they consisted of unrelated values use static const (u)int
rubidium <rubidium@openttd.org>
parents: 15103
diff changeset
178 static const int GRAPH_MAX_DATASETS = 32;
43a5d37b45c4 (svn r19812) -Codechange: give some unnamed enums a name or, in case they consisted of unrelated values use static const (u)int
rubidium <rubidium@openttd.org>
parents: 15103
diff changeset
179 static const int GRAPH_AXIS_LINE_COLOUR = 215;
43a5d37b45c4 (svn r19812) -Codechange: give some unnamed enums a name or, in case they consisted of unrelated values use static const (u)int
rubidium <rubidium@openttd.org>
parents: 15103
diff changeset
180 static const int GRAPH_NUM_MONTHS = 24; ///< Number of months displayed in the graph.
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
181
15183
43a5d37b45c4 (svn r19812) -Codechange: give some unnamed enums a name or, in case they consisted of unrelated values use static const (u)int
rubidium <rubidium@openttd.org>
parents: 15103
diff changeset
182 static const int MIN_GRAPH_NUM_LINES_Y = 9; ///< Minimal number of horizontal lines to draw.
43a5d37b45c4 (svn r19812) -Codechange: give some unnamed enums a name or, in case they consisted of unrelated values use static const (u)int
rubidium <rubidium@openttd.org>
parents: 15103
diff changeset
183 static const int MIN_GRID_PIXEL_SIZE = 20; ///< Minimum distance between graph lines.
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
184
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
185 uint excluded_data; ///< bitmask of the datasets that shouldn't be displayed.
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
186 byte num_dataset;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
187 byte num_on_x_axis;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
188 byte num_vert_lines;
9865
5aa8480f318a (svn r14011) -Codechange: not required to define an enum which was just the representation of another.
belugas <belugas@openttd.org>
parents: 9850
diff changeset
189 static const TextColour graph_axis_label_colour = TC_BLACK; ///< colour of the graph axis label.
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
190
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
191 /* The starting month and year that values are plotted against. If month is
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
192 * 0xFF, use x_values_start and x_values_increment below instead. */
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
193 byte month;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
194 Year year;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
195
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
196 /* These values are used if the graph is being plotted against values
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
197 * rather than the dates specified by month and year. */
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
198 uint16 x_values_start;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
199 uint16 x_values_increment;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
200
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
201 int graph_widget;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
202 StringID format_str_y_axis;
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 11080
diff changeset
203 byte colours[GRAPH_MAX_DATASETS];
12615
5f44b757d251 (svn r17058) -Codechange: magic numbers removal.
belugas <belugas@openttd.org>
parents: 12610
diff changeset
204 OverflowSafeInt64 cost[GRAPH_MAX_DATASETS][GRAPH_NUM_MONTHS]; ///< Stored costs for the last #GRAPH_NUM_MONTHS months
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
205
14940
f042e7eb7d0e (svn r19543) -Feature [FS#3726]: Scale the vertical axis of graphs depending on the graph's highest value.
terkhen <terkhen@openttd.org>
parents: 14939
diff changeset
206 /**
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
207 * Get the interval that contains the graph's data. Excluded data is ignored to show smaller values in
14947
cf7635945b3b (svn r19550) -Fix (r19543): Scale graphs without taking into account excluded data.
terkhen <terkhen@openttd.org>
parents: 14940
diff changeset
208 * better detail when disabling higher ones.
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
209 * @param num_hori_lines Number of horizontal lines to be drawn.
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
210 * @return Highest and lowest values of the graph (ignoring disabled data).
14940
f042e7eb7d0e (svn r19543) -Feature [FS#3726]: Scale the vertical axis of graphs depending on the graph's highest value.
terkhen <terkhen@openttd.org>
parents: 14939
diff changeset
211 */
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
212 ValuesInterval GetValuesInterval(int num_hori_lines) const
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
213 {
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
214 ValuesInterval current_interval;
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
215 current_interval.highest = INT64_MIN;
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
216 current_interval.lowest = INT64_MAX;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
217
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
218 for (int i = 0; i < this->num_dataset; i++) {
14947
cf7635945b3b (svn r19550) -Fix (r19543): Scale graphs without taking into account excluded data.
terkhen <terkhen@openttd.org>
parents: 14940
diff changeset
219 if (HasBit(this->excluded_data, i)) continue;
14940
f042e7eb7d0e (svn r19543) -Feature [FS#3726]: Scale the vertical axis of graphs depending on the graph's highest value.
terkhen <terkhen@openttd.org>
parents: 14939
diff changeset
220 for (int j = 0; j < this->num_on_x_axis; j++) {
f042e7eb7d0e (svn r19543) -Feature [FS#3726]: Scale the vertical axis of graphs depending on the graph's highest value.
terkhen <terkhen@openttd.org>
parents: 14939
diff changeset
221 OverflowSafeInt64 datapoint = this->cost[i][j];
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
222
14940
f042e7eb7d0e (svn r19543) -Feature [FS#3726]: Scale the vertical axis of graphs depending on the graph's highest value.
terkhen <terkhen@openttd.org>
parents: 14939
diff changeset
223 if (datapoint != INVALID_DATAPOINT) {
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
224 current_interval.highest = max(current_interval.highest, datapoint);
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
225 current_interval.lowest = min(current_interval.lowest, datapoint);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
226 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
227 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
228 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
229
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
230 /* Prevent showing values too close to the graph limits. */
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
231 current_interval.highest = (11 * current_interval.highest) / 10;
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
232 current_interval.lowest = (11 * current_interval.lowest) / 10;
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
233
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
234 /* Always include zero in the shown range. */
15103
bd4b62132aed (svn r19729) -Fix [FS#3793]: The company value graph crashed the game when displaying companies with a huge amount of money.
terkhen <terkhen@openttd.org>
parents: 15053
diff changeset
235 double abs_lower = (current_interval.lowest > 0) ? 0 : (double)abs(current_interval.lowest);
bd4b62132aed (svn r19729) -Fix [FS#3793]: The company value graph crashed the game when displaying companies with a huge amount of money.
terkhen <terkhen@openttd.org>
parents: 15053
diff changeset
236 double abs_higher = (current_interval.highest < 0) ? 0 : (double)current_interval.highest;
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
237
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
238 int num_pos_grids;
15103
bd4b62132aed (svn r19729) -Fix [FS#3793]: The company value graph crashed the game when displaying companies with a huge amount of money.
terkhen <terkhen@openttd.org>
parents: 15053
diff changeset
239 int64 grid_size;
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
240
15053
851a045406bc (svn r19673) -Codechange: Optimize calculation of graph grid size (method by Alberth).
terkhen <terkhen@openttd.org>
parents: 15045
diff changeset
241 if (abs_lower != 0 || abs_higher != 0) {
851a045406bc (svn r19673) -Codechange: Optimize calculation of graph grid size (method by Alberth).
terkhen <terkhen@openttd.org>
parents: 15045
diff changeset
242 /* The number of grids to reserve for the positive part is: */
15103
bd4b62132aed (svn r19729) -Fix [FS#3793]: The company value graph crashed the game when displaying companies with a huge amount of money.
terkhen <terkhen@openttd.org>
parents: 15053
diff changeset
243 num_pos_grids = (int)floor(0.5 + num_hori_lines * abs_higher / (abs_higher + abs_lower));
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
244
15053
851a045406bc (svn r19673) -Codechange: Optimize calculation of graph grid size (method by Alberth).
terkhen <terkhen@openttd.org>
parents: 15045
diff changeset
245 /* If there are any positive or negative values, force that they have at least one grid. */
851a045406bc (svn r19673) -Codechange: Optimize calculation of graph grid size (method by Alberth).
terkhen <terkhen@openttd.org>
parents: 15045
diff changeset
246 if (num_pos_grids == 0 && abs_higher != 0) num_pos_grids++;
851a045406bc (svn r19673) -Codechange: Optimize calculation of graph grid size (method by Alberth).
terkhen <terkhen@openttd.org>
parents: 15045
diff changeset
247 if (num_pos_grids == num_hori_lines && abs_lower != 0) num_pos_grids--;
851a045406bc (svn r19673) -Codechange: Optimize calculation of graph grid size (method by Alberth).
terkhen <terkhen@openttd.org>
parents: 15045
diff changeset
248
851a045406bc (svn r19673) -Codechange: Optimize calculation of graph grid size (method by Alberth).
terkhen <terkhen@openttd.org>
parents: 15045
diff changeset
249 /* Get the required grid size for each side and use the maximum one. */
15103
bd4b62132aed (svn r19729) -Fix [FS#3793]: The company value graph crashed the game when displaying companies with a huge amount of money.
terkhen <terkhen@openttd.org>
parents: 15053
diff changeset
250 int64 grid_size_higher = (abs_higher > 0) ? ((int64)abs_higher + num_pos_grids - 1) / num_pos_grids : 0;
bd4b62132aed (svn r19729) -Fix [FS#3793]: The company value graph crashed the game when displaying companies with a huge amount of money.
terkhen <terkhen@openttd.org>
parents: 15053
diff changeset
251 int64 grid_size_lower = (abs_lower > 0) ? ((int64)abs_lower + num_hori_lines - num_pos_grids - 1) / (num_hori_lines - num_pos_grids) : 0;
15053
851a045406bc (svn r19673) -Codechange: Optimize calculation of graph grid size (method by Alberth).
terkhen <terkhen@openttd.org>
parents: 15045
diff changeset
252 grid_size = max(grid_size_higher, grid_size_lower);
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
253 } else {
15053
851a045406bc (svn r19673) -Codechange: Optimize calculation of graph grid size (method by Alberth).
terkhen <terkhen@openttd.org>
parents: 15045
diff changeset
254 /* If both values are zero, show an empty graph. */
851a045406bc (svn r19673) -Codechange: Optimize calculation of graph grid size (method by Alberth).
terkhen <terkhen@openttd.org>
parents: 15045
diff changeset
255 num_pos_grids = num_hori_lines / 2;
851a045406bc (svn r19673) -Codechange: Optimize calculation of graph grid size (method by Alberth).
terkhen <terkhen@openttd.org>
parents: 15045
diff changeset
256 grid_size = 1;
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
257 }
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
258
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
259 current_interval.highest = num_pos_grids * grid_size;
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
260 current_interval.lowest = -(num_hori_lines - num_pos_grids) * grid_size;
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
261 return current_interval;
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
262 }
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
263
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
264 /** Get width for Y labels.
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
265 * @param current_interval Interval that contains all of the graph data.
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
266 * @param num_hori_lines Number of horizontal lines to be drawn.
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
267 */
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
268 uint GetYLabelWidth(ValuesInterval current_interval, int num_hori_lines) const
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
269 {
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
270 /* draw text strings on the y axis */
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
271 int64 y_label = current_interval.highest;
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
272 int64 y_label_separation = (current_interval.highest - current_interval.lowest) / num_hori_lines;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
273
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
274 uint max_width = 0;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
275
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
276 for (int i = 0; i < (num_hori_lines + 1); i++) {
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
277 SetDParam(0, this->format_str_y_axis);
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
278 SetDParam(1, y_label);
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
279 Dimension d = GetStringBoundingBox(STR_GRAPH_Y_LABEL);
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
280 if (d.width > max_width) max_width = d.width;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
281
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
282 y_label -= y_label_separation;
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
283 }
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
284
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
285 return max_width;
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
286 }
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
287
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
288 /**
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
289 * Actually draw the graph.
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
290 * @param r the rectangle of the data field of the graph
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
291 */
13734
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
292 void DrawGraph(Rect r) const
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
293 {
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
294 uint x, y; ///< Reused whenever x and y coordinates are needed.
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
295 ValuesInterval interval; ///< Interval that contains all of the graph data.
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
296 int x_axis_offset; ///< Distance from the top of the graph to the x axis.
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
297
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
298 /* the colours and cost array of GraphDrawer must accomodate
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
299 * both values for cargo and companies. So if any are higher, quit */
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
300 assert_compile(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_COMPANIES);
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
301 assert(this->num_vert_lines > 0);
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
302
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
303 byte grid_colour = _colour_gradient[COLOUR_GREY][4];
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
304
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
305 /* Rect r will be adjusted to contain just the graph, with labels being
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
306 * placed outside the area. */
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
307 r.top += 5 + GetCharacterHeight(FS_SMALL) / 2;
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
308 r.bottom -= (this->month == 0xFF ? 1 : 3) * GetCharacterHeight(FS_SMALL) + 4;
13636
eba941c66c5d (svn r18160) -Codechange: The hyphen character may not line up in all fonts, so draw
peter1138 <peter1138@openttd.org>
parents: 13635
diff changeset
309 r.left += 9;
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
310 r.right -= 5;
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
311
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
312 /* Initial number of horizontal lines. */
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
313 int num_hori_lines = 160 / MIN_GRID_PIXEL_SIZE;
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
314 /* For the rest of the height, the number of horizontal lines will increase more slowly. */
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
315 int resize = (r.bottom - r.top - 160) / (2 * MIN_GRID_PIXEL_SIZE);
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
316 if (resize > 0) num_hori_lines += resize;
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
317
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
318 interval = GetValuesInterval(num_hori_lines);
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
319
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
320 int label_width = GetYLabelWidth(interval, num_hori_lines);
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
321
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
322 r.left += label_width;
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
323
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
324 int x_sep = (r.right - r.left) / this->num_vert_lines;
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
325 int y_sep = (r.bottom - r.top) / num_hori_lines;
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
326
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
327 /* Redetermine right and bottom edge of graph to fit with the integer
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
328 * separation values. */
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
329 r.right = r.left + x_sep * this->num_vert_lines;
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
330 r.bottom = r.top + y_sep * num_hori_lines;
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
331
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
332 OverflowSafeInt64 interval_size = interval.highest + abs(interval.lowest);
15103
bd4b62132aed (svn r19729) -Fix [FS#3793]: The company value graph crashed the game when displaying companies with a huge amount of money.
terkhen <terkhen@openttd.org>
parents: 15053
diff changeset
333 /* Where to draw the X axis. Use floating point to avoid overflowing and results of zero. */
bd4b62132aed (svn r19729) -Fix [FS#3793]: The company value graph crashed the game when displaying companies with a huge amount of money.
terkhen <terkhen@openttd.org>
parents: 15053
diff changeset
334 x_axis_offset = (int)((r.bottom - r.top) * (double)interval.highest / (double)interval_size);
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
335
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
336 /* Draw the vertical grid lines. */
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
337
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
338 /* Don't draw the first line, as that's where the axis will be. */
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
339 x = r.left + x_sep;
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
340
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
341 for (int i = 0; i < this->num_vert_lines; i++) {
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
342 GfxFillRect(x, r.top, x, r.bottom, grid_colour);
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
343 x += x_sep;
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
344 }
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
345
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
346 /* Draw the horizontal grid lines. */
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
347 y = r.bottom;
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
348
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
349 for (int i = 0; i < (num_hori_lines + 1); i++) {
13636
eba941c66c5d (svn r18160) -Codechange: The hyphen character may not line up in all fonts, so draw
peter1138 <peter1138@openttd.org>
parents: 13635
diff changeset
350 GfxFillRect(r.left - 3, y, r.left - 1, y, GRAPH_AXIS_LINE_COLOUR);
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
351 GfxFillRect(r.left, y, r.right, y, grid_colour);
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
352 y -= y_sep;
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
353 }
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
354
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
355 /* Draw the y axis. */
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
356 GfxFillRect(r.left, r.top, r.left, r.bottom, GRAPH_AXIS_LINE_COLOUR);
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
357
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
358 /* Draw the x axis. */
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
359 y = x_axis_offset + r.top;
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
360 GfxFillRect(r.left, y, r.right, y, GRAPH_AXIS_LINE_COLOUR);
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
361
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
362 /* Find the largest value that will be drawn. */
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
363 if (this->num_on_x_axis == 0)
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
364 return;
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
365
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
366 assert(this->num_on_x_axis > 0);
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
367 assert(this->num_dataset > 0);
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
368
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
369 /* draw text strings on the y axis */
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
370 int64 y_label = interval.highest;
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
371 int64 y_label_separation = abs(interval.highest - interval.lowest) / num_hori_lines;
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
372
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
373 y = r.top - GetCharacterHeight(FS_SMALL) / 2;
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
374
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
375 for (int i = 0; i < (num_hori_lines + 1); i++) {
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
376 SetDParam(0, this->format_str_y_axis);
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
377 SetDParam(1, y_label);
13636
eba941c66c5d (svn r18160) -Codechange: The hyphen character may not line up in all fonts, so draw
peter1138 <peter1138@openttd.org>
parents: 13635
diff changeset
378 DrawString(r.left - label_width - 4, r.left - 4, y, STR_GRAPH_Y_LABEL, graph_axis_label_colour, SA_RIGHT);
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
379
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
380 y_label -= y_label_separation;
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
381 y += y_sep;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
382 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
383
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
384 /* draw strings on the x axis */
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
385 if (this->month != 0xFF) {
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
386 x = r.left;
12610
0f2da83ae71c (svn r17053) -Codechange: pass a Rect to DrawGraph so it knows where to draw
rubidium <rubidium@openttd.org>
parents: 12609
diff changeset
387 y = r.bottom + 2;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
388 byte month = this->month;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
389 Year year = this->year;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
390 for (int i = 0; i < this->num_on_x_axis; i++) {
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
391 SetDParam(0, month + STR_MONTH_ABBREV_JAN);
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
392 SetDParam(1, month + STR_MONTH_ABBREV_JAN + 2);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
393 SetDParam(2, year);
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
394 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);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
395
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
396 month += 3;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
397 if (month >= 12) {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
398 month = 0;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
399 year++;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
400 }
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
401 x += x_sep;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
402 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
403 } else {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
404 /* Draw the label under the data point rather than on the grid line. */
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
405 x = r.left;
12610
0f2da83ae71c (svn r17053) -Codechange: pass a Rect to DrawGraph so it knows where to draw
rubidium <rubidium@openttd.org>
parents: 12609
diff changeset
406 y = r.bottom + 2;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
407 uint16 label = this->x_values_start;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
408
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
409 for (int i = 0; i < this->num_on_x_axis; i++) {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
410 SetDParam(0, label);
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
411 DrawString(x + 1, x + x_sep - 1, y, STR_GRAPH_Y_LABEL_NUMBER, graph_axis_label_colour, SA_CENTER);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
412
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
413 label += this->x_values_increment;
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
414 x += x_sep;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
415 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
416 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
417
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
418 /* draw lines and dots */
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
419 for (int i = 0; i < this->num_dataset; i++) {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
420 if (!HasBit(this->excluded_data, i)) {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
421 /* Centre the dot between the grid lines. */
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
422 x = r.left + (x_sep / 2);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
423
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 11080
diff changeset
424 byte colour = this->colours[i];
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
425 uint prev_x = INVALID_DATAPOINT_POS;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
426 uint prev_y = INVALID_DATAPOINT_POS;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
427
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
428 for (int j = 0; j < this->num_on_x_axis; j++) {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
429 OverflowSafeInt64 datapoint = this->cost[i][j];
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
430
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
431 if (datapoint != INVALID_DATAPOINT) {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
432 /*
11361
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11111
diff changeset
433 * Check whether we need to reduce the 'accuracy' of the
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11111
diff changeset
434 * datapoint value and the highest value to splut overflows.
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11111
diff changeset
435 * And when 'drawing' 'one million' or 'one million and one'
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11111
diff changeset
436 * there is no significant difference, so the least
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11111
diff changeset
437 * significant bits can just be removed.
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11111
diff changeset
438 *
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11111
diff changeset
439 * If there are more bits needed than would fit in a 32 bits
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11111
diff changeset
440 * integer, so at about 31 bits because of the sign bit, the
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11111
diff changeset
441 * least significant bits are removed.
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11111
diff changeset
442 */
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
443 int mult_range = FindLastBit(x_axis_offset) + FindLastBit(abs(datapoint));
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
444 int reduce_range = max(mult_range - 31, 0);
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
445
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
446 /* Handle negative values differently (don't shift sign) */
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
447 if (datapoint < 0) {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
448 datapoint = -(abs(datapoint) >> reduce_range);
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
449 } else {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
450 datapoint >>= reduce_range;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
451 }
15016
0df61c282687 (svn r19631) -Feature: Graphs with negative values are no longer forced to have the zero axis in the middle (grid size calculation by Alberth).
terkhen <terkhen@openttd.org>
parents: 15003
diff changeset
452 y = r.top + x_axis_offset - ((r.bottom - r.top) * datapoint) / (interval_size >> reduce_range);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
453
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
454 /* Draw the point. */
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 11080
diff changeset
455 GfxFillRect(x - 1, y - 1, x + 1, y + 1, colour);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
456
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
457 /* Draw the line connected to the previous point. */
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 11080
diff changeset
458 if (prev_x != INVALID_DATAPOINT_POS) GfxDrawLine(prev_x, prev_y, x, y, colour);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
459
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
460 prev_x = x;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
461 prev_y = y;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
462 } else {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
463 prev_x = INVALID_DATAPOINT_POS;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
464 prev_y = INVALID_DATAPOINT_POS;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
465 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
466
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
467 x += x_sep;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
468 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
469 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
470 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
471 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
472
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
473
15017
b7446f6e1b69 (svn r19632) -Cleanup: has_negative_values is no longer used.
terkhen <terkhen@openttd.org>
parents: 15016
diff changeset
474 BaseGraphWindow(int widget, StringID format_str_y_axis) :
b7446f6e1b69 (svn r19632) -Cleanup: has_negative_values is no longer used.
terkhen <terkhen@openttd.org>
parents: 15016
diff changeset
475 Window(),
12610
0f2da83ae71c (svn r17053) -Codechange: pass a Rect to DrawGraph so it knows where to draw
rubidium <rubidium@openttd.org>
parents: 12609
diff changeset
476 format_str_y_axis(format_str_y_axis)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
477 {
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 12979
diff changeset
478 SetWindowDirty(WC_GRAPH_LEGEND, 0);
12609
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
479 this->num_vert_lines = 24;
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
480 this->graph_widget = widget;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
481 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
482
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
483 void InitializeWindow(const WindowDesc *desc, WindowNumber number)
12671
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
484 {
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
485 /* Initialise the dataset */
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
486 this->UpdateStatistics(true);
13734
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
487
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
488 this->InitNested(desc, number);
12671
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
489 }
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
490
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
491 public:
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
492 virtual void OnPaint()
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
493 {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
494 this->DrawWidgets();
13734
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
495 }
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
496
13734
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
497 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
498 {
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
499 if (widget != this->graph_widget) return;
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
500
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
501 uint x_label_width = 0;
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
502
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
503 if (this->month != 0xFF) {
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
504 byte month = this->month;
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
505 Year year = this->year;
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
506 for (int i = 0; i < this->num_on_x_axis; i++) {
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
507 SetDParam(0, month + STR_MONTH_ABBREV_JAN);
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
508 SetDParam(1, month + STR_MONTH_ABBREV_JAN + 2);
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
509 SetDParam(2, year);
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
510 x_label_width = max(x_label_width, GetStringBoundingBox(month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH).width);
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
511
13734
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
512 month += 3;
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
513 if (month >= 12) {
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
514 month = 0;
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
515 year++;
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
516 }
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
517 }
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
518 } else {
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
519 /* Draw the label under the data point rather than on the grid line. */
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
520 SetDParam(0, this->x_values_start + this->num_on_x_axis * this->x_values_increment);
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
521 x_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL_NUMBER).width;
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
522 }
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
523
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
524 SetDParam(0, this->format_str_y_axis);
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
525 SetDParam(1, INT64_MAX);
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
526 uint y_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL).width;
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
527
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
528 size->width = max<uint>(size->width, 5 + y_label_width + this->num_on_x_axis * (x_label_width + 5) + 9);
15044
7dc598210fb7 (svn r19661) -Codechange: Base the number of vertical grids of a graph on its size.
terkhen <terkhen@openttd.org>
parents: 15017
diff changeset
529 size->height = max<uint>(size->height, 5 + (1 + MIN_GRAPH_NUM_LINES_Y * 2 + (this->month != 0xFF ? 3 : 1)) * FONT_HEIGHT_SMALL + 4);
13734
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
530 size->height = max<uint>(size->height, size->width / 3);
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
531 }
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
532
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
533 virtual void DrawWidget(const Rect &r, int widget) const
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
534 {
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
535 if (widget != this->graph_widget) return;
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
536
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
537 DrawGraph(r);
12609
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
538 }
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
539
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
540 virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
541 {
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
542 return INVALID_DATAPOINT;
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
543 }
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
544
14409
1eaefde497fd (svn r18966) -Codechange: Remove Window::OnDoubleClick() in favour of a parameter for OnClick().
frosch <frosch@openttd.org>
parents: 14258
diff changeset
545 virtual void OnClick(Point pt, int widget, int click_count)
12609
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
546 {
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
547 /* Clicked on legend? */
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
548 if (widget == BGW_KEY_BUTTON) ShowGraphLegend();
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
549 }
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
550
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
551 virtual void OnTick()
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
552 {
12671
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
553 this->UpdateStatistics(false);
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
554 }
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
555
14966
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
556 virtual void OnInvalidateData(int data)
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
557 {
15003
895f760ad105 (svn r19615) -Fix [FS#3763]: Company related graphs weren't updated correctly after changing the company colour.
terkhen <terkhen@openttd.org>
parents: 14971
diff changeset
558 this->UpdateStatistics(true);
14966
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
559 }
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
560
12671
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
561 /**
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
562 * Update the statistics.
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
563 * @param initialize Initialize the data structure.
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
564 */
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
565 void UpdateStatistics(bool initialize)
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
566 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
567 uint excluded_companies = _legend_excluded_companies;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
568
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
569 /* Exclude the companies which aren't valid */
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
570 for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
11924
fccc9cea27a7 (svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents: 11922
diff changeset
571 if (!Company::IsValidID(c)) SetBit(excluded_companies, c);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
572 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
573
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
574 byte nums = 0;
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
575 const Company *c;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
576 FOR_ALL_COMPANIES(c) {
12609
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
577 nums = min(this->num_vert_lines, max(nums, c->num_valid_stat_ent));
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
578 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
579
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
580 int mo = (_cur_month / 3 - nums) * 3;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
581 int yr = _cur_year;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
582 while (mo < 0) {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
583 yr--;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
584 mo += 12;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
585 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
586
12671
34de19198186 (svn r17126) -Fix [FS#3096]: Initialize graph data from the constructor of the derived class.
alberth <alberth@openttd.org>
parents: 12632
diff changeset
587 if (!initialize && this->excluded_data == excluded_companies && this->num_on_x_axis == nums &&
12609
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
588 this->year == yr && this->month == mo) {
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
589 /* There's no reason to get new stats */
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
590 return;
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
591 }
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
592
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
593 this->excluded_data = excluded_companies;
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
594 this->num_on_x_axis = nums;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
595 this->year = yr;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
596 this->month = mo;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
597
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
598 int numd = 0;
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
599 for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) {
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
600 c = Company::GetIfValid(k);
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
601 if (c != NULL) {
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 11080
diff changeset
602 this->colours[numd] = _colour_gradient[c->colour][6];
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
603 for (int j = this->num_on_x_axis, i = 0; --j >= 0;) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
604 this->cost[numd][i] = (j >= c->num_valid_stat_ent) ? INVALID_DATAPOINT : GetGraphData(c, j);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
605 i++;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
606 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
607 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
608 numd++;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
609 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
610
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
611 this->num_dataset = numd;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
612 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
613 };
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
614
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
615
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
616 /********************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
617 /* OPERATING PROFIT */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
618 /********************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
619
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
620 struct OperatingProfitGraphWindow : BaseGraphWindow {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
621 OperatingProfitGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
622 BaseGraphWindow(BGW_GRAPH, STR_JUST_CURRCOMPACT)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
623 {
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
624 this->InitializeWindow(desc, window_number);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
625 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
626
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
627 virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
628 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
629 return c->old_economy[j].income + c->old_economy[j].expenses;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
630 }
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
631 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
632
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
633 static const NWidgetPart _nested_operating_profit_widgets[] = {
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
634 NWidget(NWID_HORIZONTAL),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
635 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
636 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_OPERATING_PROFIT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
13629
de84b51f7506 (svn r18153) -Codechange: Correct height for 'key' button on graph windows.
peter1138 <peter1138@openttd.org>
parents: 13628
diff changeset
637 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, BGW_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
14045
68fabdc82f5b (svn r18588) -Feature [FS#2943]: Add shading and unshading of windows.
alberth <alberth@openttd.org>
parents: 13954
diff changeset
638 NWidget(WWT_SHADEBOX, COLOUR_GREY),
13916
32bb7763b24a (svn r18447) -Change: make some more windows (e.g. graphs, company view) stickyable
rubidium <rubidium@openttd.org>
parents: 13798
diff changeset
639 NWidget(WWT_STICKYBOX, COLOUR_GREY),
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
640 EndContainer(),
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
641 NWidget(WWT_PANEL, COLOUR_GREY, BGW_BACKGROUND),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
642 NWidget(NWID_HORIZONTAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
643 NWidget(WWT_EMPTY, COLOUR_GREY, BGW_GRAPH), SetMinimalSize(576, 160), SetFill(1, 1), SetResize(1, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
644 NWidget(NWID_VERTICAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
645 NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
646 NWidget(WWT_RESIZEBOX, COLOUR_GREY, BGW_RESIZE),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
647 EndContainer(),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
648 EndContainer(),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
649 EndContainer(),
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
650 };
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
651
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
652 static const WindowDesc _operating_profit_desc(
13798
6f820ae12bb3 (svn r18324) -Codechange: there's no need for a default size when the window isn't resizable
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
653 WDP_AUTO, 0, 0,
5893
8547517ef719 (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium <rubidium@openttd.org>
parents: 5812
diff changeset
654 WC_OPERATING_PROFIT, WC_NONE,
13749
fc3ab8256c95 (svn r18274) -Codechange: remove the unused WDF flags
rubidium <rubidium@openttd.org>
parents: 13739
diff changeset
655 WDF_UNCLICK_BUTTONS,
13564
bae287664b02 (svn r18086) -Codechange: remove 'widget' from WindowDesc
rubidium <rubidium@openttd.org>
parents: 13556
diff changeset
656 _nested_operating_profit_widgets, lengthof(_nested_operating_profit_widgets)
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
657 );
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
658
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
659
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6203
diff changeset
660 void ShowOperatingProfitGraph()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
661 {
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
662 AllocateWindowDescFront<OperatingProfitGraphWindow>(&_operating_profit_desc, 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
663 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
664
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
665
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
666 /****************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
667 /* INCOME GRAPH */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
668 /****************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
669
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
670 struct IncomeGraphWindow : BaseGraphWindow {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
671 IncomeGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
672 BaseGraphWindow(BGW_GRAPH, STR_JUST_CURRCOMPACT)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
673 {
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
674 this->InitializeWindow(desc, window_number);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
675 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
676
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
677 virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
678 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
679 return c->old_economy[j].income;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
680 }
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
681 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
682
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
683 static const NWidgetPart _nested_income_graph_widgets[] = {
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
684 NWidget(NWID_HORIZONTAL),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
685 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
686 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_INCOME_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
13629
de84b51f7506 (svn r18153) -Codechange: Correct height for 'key' button on graph windows.
peter1138 <peter1138@openttd.org>
parents: 13628
diff changeset
687 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, BGW_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
14045
68fabdc82f5b (svn r18588) -Feature [FS#2943]: Add shading and unshading of windows.
alberth <alberth@openttd.org>
parents: 13954
diff changeset
688 NWidget(WWT_SHADEBOX, COLOUR_GREY),
13916
32bb7763b24a (svn r18447) -Change: make some more windows (e.g. graphs, company view) stickyable
rubidium <rubidium@openttd.org>
parents: 13798
diff changeset
689 NWidget(WWT_STICKYBOX, COLOUR_GREY),
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
690 EndContainer(),
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
691 NWidget(WWT_PANEL, COLOUR_GREY, BGW_BACKGROUND),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
692 NWidget(NWID_HORIZONTAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
693 NWidget(WWT_EMPTY, COLOUR_GREY, BGW_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
694 NWidget(NWID_VERTICAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
695 NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
696 NWidget(WWT_RESIZEBOX, COLOUR_GREY, BGW_RESIZE),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
697 EndContainer(),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
698 EndContainer(),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
699 EndContainer(),
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
700 };
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
701
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
702
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
703 static const WindowDesc _income_graph_desc(
13798
6f820ae12bb3 (svn r18324) -Codechange: there's no need for a default size when the window isn't resizable
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
704 WDP_AUTO, 0, 0,
5893
8547517ef719 (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium <rubidium@openttd.org>
parents: 5812
diff changeset
705 WC_INCOME_GRAPH, WC_NONE,
13749
fc3ab8256c95 (svn r18274) -Codechange: remove the unused WDF flags
rubidium <rubidium@openttd.org>
parents: 13739
diff changeset
706 WDF_UNCLICK_BUTTONS,
13564
bae287664b02 (svn r18086) -Codechange: remove 'widget' from WindowDesc
rubidium <rubidium@openttd.org>
parents: 13556
diff changeset
707 _nested_income_graph_widgets, lengthof(_nested_income_graph_widgets)
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
708 );
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
709
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6203
diff changeset
710 void ShowIncomeGraph()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
711 {
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
712 AllocateWindowDescFront<IncomeGraphWindow>(&_income_graph_desc, 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
713 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
714
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
715 /*******************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
716 /* DELIVERED CARGO */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
717 /*******************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
718
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
719 struct DeliveredCargoGraphWindow : BaseGraphWindow {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
720 DeliveredCargoGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
721 BaseGraphWindow(BGW_GRAPH, STR_JUST_COMMA)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
722 {
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
723 this->InitializeWindow(desc, window_number);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
724 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
725
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
726 virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
727 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
728 return c->old_economy[j].delivered_cargo;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
729 }
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
730 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
731
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
732 static const NWidgetPart _nested_delivered_cargo_graph_widgets[] = {
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
733 NWidget(NWID_HORIZONTAL),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
734 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
735 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_CARGO_DELIVERED_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
13629
de84b51f7506 (svn r18153) -Codechange: Correct height for 'key' button on graph windows.
peter1138 <peter1138@openttd.org>
parents: 13628
diff changeset
736 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, BGW_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
14045
68fabdc82f5b (svn r18588) -Feature [FS#2943]: Add shading and unshading of windows.
alberth <alberth@openttd.org>
parents: 13954
diff changeset
737 NWidget(WWT_SHADEBOX, COLOUR_GREY),
13916
32bb7763b24a (svn r18447) -Change: make some more windows (e.g. graphs, company view) stickyable
rubidium <rubidium@openttd.org>
parents: 13798
diff changeset
738 NWidget(WWT_STICKYBOX, COLOUR_GREY),
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
739 EndContainer(),
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
740 NWidget(WWT_PANEL, COLOUR_GREY, BGW_BACKGROUND),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
741 NWidget(NWID_HORIZONTAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
742 NWidget(WWT_EMPTY, COLOUR_GREY, BGW_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
743 NWidget(NWID_VERTICAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
744 NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
745 NWidget(WWT_RESIZEBOX, COLOUR_GREY, BGW_RESIZE),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
746 EndContainer(),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
747 EndContainer(),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
748 EndContainer(),
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
749 };
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
750
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
751 static const WindowDesc _delivered_cargo_graph_desc(
13798
6f820ae12bb3 (svn r18324) -Codechange: there's no need for a default size when the window isn't resizable
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
752 WDP_AUTO, 0, 0,
5893
8547517ef719 (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium <rubidium@openttd.org>
parents: 5812
diff changeset
753 WC_DELIVERED_CARGO, WC_NONE,
13749
fc3ab8256c95 (svn r18274) -Codechange: remove the unused WDF flags
rubidium <rubidium@openttd.org>
parents: 13739
diff changeset
754 WDF_UNCLICK_BUTTONS,
13564
bae287664b02 (svn r18086) -Codechange: remove 'widget' from WindowDesc
rubidium <rubidium@openttd.org>
parents: 13556
diff changeset
755 _nested_delivered_cargo_graph_widgets, lengthof(_nested_delivered_cargo_graph_widgets)
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
756 );
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
757
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6203
diff changeset
758 void ShowDeliveredCargoGraph()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
759 {
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
760 AllocateWindowDescFront<DeliveredCargoGraphWindow>(&_delivered_cargo_graph_desc, 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
761 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
762
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
763 /***********************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
764 /* PERFORMANCE HISTORY */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
765 /***********************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
766
11749
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
767 /** Widget numbers of the performance history window. */
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
768 enum PerformanceHistoryGraphWidgets {
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
769 PHW_KEY,
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
770 PHW_DETAILED_PERFORMANCE,
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
771 PHW_BACKGROUND,
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
772 PHW_GRAPH,
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
773 PHW_RESIZE,
11749
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
774 };
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
775
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
776 struct PerformanceHistoryGraphWindow : BaseGraphWindow {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
777 PerformanceHistoryGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
778 BaseGraphWindow(PHW_GRAPH, STR_JUST_COMMA)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
779 {
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
780 this->InitializeWindow(desc, window_number);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
781 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
782
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
783 virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
784 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
785 return c->old_economy[j].performance_history;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
786 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
787
14409
1eaefde497fd (svn r18966) -Codechange: Remove Window::OnDoubleClick() in favour of a parameter for OnClick().
frosch <frosch@openttd.org>
parents: 14258
diff changeset
788 virtual void OnClick(Point pt, int widget, int click_count)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
789 {
11749
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
790 if (widget == PHW_DETAILED_PERFORMANCE) ShowPerformanceRatingDetail();
14409
1eaefde497fd (svn r18966) -Codechange: Remove Window::OnDoubleClick() in favour of a parameter for OnClick().
frosch <frosch@openttd.org>
parents: 14258
diff changeset
791 this->BaseGraphWindow::OnClick(pt, widget, click_count);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
792 }
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
793 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
794
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
795 static const NWidgetPart _nested_performance_history_widgets[] = {
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
796 NWidget(NWID_HORIZONTAL),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
797 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
798 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_COMPANY_PERFORMANCE_RATINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
13629
de84b51f7506 (svn r18153) -Codechange: Correct height for 'key' button on graph windows.
peter1138 <peter1138@openttd.org>
parents: 13628
diff changeset
799 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, PHW_DETAILED_PERFORMANCE), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_PERFORMANCE_DETAIL_KEY, STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP),
de84b51f7506 (svn r18153) -Codechange: Correct height for 'key' button on graph windows.
peter1138 <peter1138@openttd.org>
parents: 13628
diff changeset
800 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, PHW_KEY), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
14045
68fabdc82f5b (svn r18588) -Feature [FS#2943]: Add shading and unshading of windows.
alberth <alberth@openttd.org>
parents: 13954
diff changeset
801 NWidget(WWT_SHADEBOX, COLOUR_GREY),
13916
32bb7763b24a (svn r18447) -Change: make some more windows (e.g. graphs, company view) stickyable
rubidium <rubidium@openttd.org>
parents: 13798
diff changeset
802 NWidget(WWT_STICKYBOX, COLOUR_GREY),
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
803 EndContainer(),
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
804 NWidget(WWT_PANEL, COLOUR_GREY, PHW_BACKGROUND),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
805 NWidget(NWID_HORIZONTAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
806 NWidget(WWT_EMPTY, COLOUR_GREY, PHW_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
807 NWidget(NWID_VERTICAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
808 NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
809 NWidget(WWT_RESIZEBOX, COLOUR_GREY, PHW_RESIZE),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
810 EndContainer(),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
811 EndContainer(),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
812 EndContainer(),
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
813 };
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
814
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
815 static const WindowDesc _performance_history_desc(
13798
6f820ae12bb3 (svn r18324) -Codechange: there's no need for a default size when the window isn't resizable
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
816 WDP_AUTO, 0, 0,
5893
8547517ef719 (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium <rubidium@openttd.org>
parents: 5812
diff changeset
817 WC_PERFORMANCE_HISTORY, WC_NONE,
13749
fc3ab8256c95 (svn r18274) -Codechange: remove the unused WDF flags
rubidium <rubidium@openttd.org>
parents: 13739
diff changeset
818 WDF_UNCLICK_BUTTONS,
13564
bae287664b02 (svn r18086) -Codechange: remove 'widget' from WindowDesc
rubidium <rubidium@openttd.org>
parents: 13556
diff changeset
819 _nested_performance_history_widgets, lengthof(_nested_performance_history_widgets)
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
820 );
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
821
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6203
diff changeset
822 void ShowPerformanceHistoryGraph()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
823 {
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
824 AllocateWindowDescFront<PerformanceHistoryGraphWindow>(&_performance_history_desc, 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
825 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
826
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
827 /*****************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
828 /* COMPANY VALUE */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
829 /*****************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
830
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
831 struct CompanyValueGraphWindow : BaseGraphWindow {
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
832 CompanyValueGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
833 BaseGraphWindow(BGW_GRAPH, STR_JUST_CURRCOMPACT)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
834 {
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
835 this->InitializeWindow(desc, window_number);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
836 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
837
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
838 virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
839 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
840 return c->old_economy[j].company_value;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
841 }
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
842 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
843
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
844 static const NWidgetPart _nested_company_value_graph_widgets[] = {
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
845 NWidget(NWID_HORIZONTAL),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
846 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
847 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_COMPANY_VALUES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
13629
de84b51f7506 (svn r18153) -Codechange: Correct height for 'key' button on graph windows.
peter1138 <peter1138@openttd.org>
parents: 13628
diff changeset
848 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, BGW_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
14045
68fabdc82f5b (svn r18588) -Feature [FS#2943]: Add shading and unshading of windows.
alberth <alberth@openttd.org>
parents: 13954
diff changeset
849 NWidget(WWT_SHADEBOX, COLOUR_GREY),
13916
32bb7763b24a (svn r18447) -Change: make some more windows (e.g. graphs, company view) stickyable
rubidium <rubidium@openttd.org>
parents: 13798
diff changeset
850 NWidget(WWT_STICKYBOX, COLOUR_GREY),
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
851 EndContainer(),
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
852 NWidget(WWT_PANEL, COLOUR_GREY, BGW_BACKGROUND),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
853 NWidget(NWID_HORIZONTAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
854 NWidget(WWT_EMPTY, COLOUR_GREY, BGW_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
855 NWidget(NWID_VERTICAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
856 NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
857 NWidget(WWT_RESIZEBOX, COLOUR_GREY, BGW_RESIZE),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
858 EndContainer(),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
859 EndContainer(),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
860 EndContainer(),
11582
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
861 };
a72797507693 (svn r15952) -Codechange: Added nested widgets to operating profit, income, delivered cargo, and company value windows.
alberth <alberth@openttd.org>
parents: 11574
diff changeset
862
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
863 static const WindowDesc _company_value_graph_desc(
13798
6f820ae12bb3 (svn r18324) -Codechange: there's no need for a default size when the window isn't resizable
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
864 WDP_AUTO, 0, 0,
5893
8547517ef719 (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium <rubidium@openttd.org>
parents: 5812
diff changeset
865 WC_COMPANY_VALUE, WC_NONE,
13749
fc3ab8256c95 (svn r18274) -Codechange: remove the unused WDF flags
rubidium <rubidium@openttd.org>
parents: 13739
diff changeset
866 WDF_UNCLICK_BUTTONS,
13564
bae287664b02 (svn r18086) -Codechange: remove 'widget' from WindowDesc
rubidium <rubidium@openttd.org>
parents: 13556
diff changeset
867 _nested_company_value_graph_widgets, lengthof(_nested_company_value_graph_widgets)
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
868 );
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
869
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6203
diff changeset
870 void ShowCompanyValueGraph()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
871 {
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
872 AllocateWindowDescFront<CompanyValueGraphWindow>(&_company_value_graph_desc, 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
873 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
874
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
875 /*****************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
876 /* PAYMENT RATES */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
877 /*****************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
878
12079
0f1b20a70f70 (svn r16488) -Codechange [FS#2941]: Use widget numbers of base grap window and cargo payment window in the window handling code (erikjanp)
alberth <alberth@openttd.org>
parents: 11949
diff changeset
879 /** Widget numbers of the cargo payment rates. */
0f1b20a70f70 (svn r16488) -Codechange [FS#2941]: Use widget numbers of base grap window and cargo payment window in the window handling code (erikjanp)
alberth <alberth@openttd.org>
parents: 11949
diff changeset
880 enum CargoPaymentRatesWidgets {
0f1b20a70f70 (svn r16488) -Codechange [FS#2941]: Use widget numbers of base grap window and cargo payment window in the window handling code (erikjanp)
alberth <alberth@openttd.org>
parents: 11949
diff changeset
881 CPW_BACKGROUND,
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
882 CPW_HEADER,
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
883 CPW_GRAPH,
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
884 CPW_RESIZE,
13635
ff4e7183cd2a (svn r18159) -Codechange: Rework graphs to scale to the widget they are in, instead of using absolute pixel placement. X-axis labels still need work for large fonts.
peter1138 <peter1138@openttd.org>
parents: 13629
diff changeset
885 CPW_FOOTER,
14939
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
886 CPW_ENABLE_CARGOS,
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
887 CPW_DISABLE_CARGOS,
12079
0f1b20a70f70 (svn r16488) -Codechange [FS#2941]: Use widget numbers of base grap window and cargo payment window in the window handling code (erikjanp)
alberth <alberth@openttd.org>
parents: 11949
diff changeset
888 CPW_CARGO_FIRST,
0f1b20a70f70 (svn r16488) -Codechange [FS#2941]: Use widget numbers of base grap window and cargo payment window in the window handling code (erikjanp)
alberth <alberth@openttd.org>
parents: 11949
diff changeset
889 };
0f1b20a70f70 (svn r16488) -Codechange [FS#2941]: Use widget numbers of base grap window and cargo payment window in the window handling code (erikjanp)
alberth <alberth@openttd.org>
parents: 11949
diff changeset
890
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
891 struct PaymentRatesGraphWindow : BaseGraphWindow {
14933
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
892 bool first_init; ///< This value is true until the first initialization of the window has finished.
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
893 PaymentRatesGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
15017
b7446f6e1b69 (svn r19632) -Cleanup: has_negative_values is no longer used.
terkhen <terkhen@openttd.org>
parents: 15016
diff changeset
894 BaseGraphWindow(CPW_GRAPH, STR_JUST_CURRCOMPACT)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
895 {
14933
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
896 this->first_init = true;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
897 this->num_on_x_axis = 20;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
898 this->num_vert_lines = 20;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
899 this->month = 0xFF;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
900 this->x_values_start = 10;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
901 this->x_values_increment = 10;
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
902
12609
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
903 /* Initialise the dataset */
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
904 this->OnHundredthTick();
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
905
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
906 this->InitNested(desc, window_number);
14199
e4aab18f4d6c (svn r18750) -Fix [FS#3492]: the cargo payment button states weren't properly set on opening the window
rubidium <rubidium@openttd.org>
parents: 14097
diff changeset
907
14933
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
908 this->UpdateLoweredWidgets();
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
909 }
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
910
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
911 virtual void OnInit()
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
912 {
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
913 /* UpdateLoweredWidgets needs to be called after a language or NewGRF change, but it can't be called before
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
914 * InitNested is done. On the first init these functions are called in the correct order by the constructor. */
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
915 if (!this->first_init) {
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
916 /* Initialise the dataset */
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
917 this->OnHundredthTick();
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
918 this->UpdateLoweredWidgets();
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
919 }
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
920 this->first_init = false;
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
921 }
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
922
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
923 void UpdateExcludedData()
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
924 {
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
925 this->excluded_data = 0;
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
926
14936
58044b15c59e (svn r19539) -Codechange: Use a macro to loop through the list of sorted cargo specifications.
terkhen <terkhen@openttd.org>
parents: 14933
diff changeset
927 int i = 0;
58044b15c59e (svn r19539) -Codechange: Use a macro to loop through the list of sorted cargo specifications.
terkhen <terkhen@openttd.org>
parents: 14933
diff changeset
928 const CargoSpec *cs;
14965
8616df9ca587 (svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents: 14947
diff changeset
929 FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
14936
58044b15c59e (svn r19539) -Codechange: Use a macro to loop through the list of sorted cargo specifications.
terkhen <terkhen@openttd.org>
parents: 14933
diff changeset
930 if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i);
58044b15c59e (svn r19539) -Codechange: Use a macro to loop through the list of sorted cargo specifications.
terkhen <terkhen@openttd.org>
parents: 14933
diff changeset
931 i++;
14933
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
932 }
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
933 }
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
934
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
935 void UpdateLoweredWidgets()
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
936 {
14965
8616df9ca587 (svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents: 14947
diff changeset
937 for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
14933
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
938 this->SetWidgetLoweredState(CPW_CARGO_FIRST + i, !HasBit(this->excluded_data, i));
14199
e4aab18f4d6c (svn r18750) -Fix [FS#3492]: the cargo payment button states weren't properly set on opening the window
rubidium <rubidium@openttd.org>
parents: 14097
diff changeset
939 }
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
940 }
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
941
13705
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
942 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
943 {
13734
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
944 if (widget < CPW_CARGO_FIRST) {
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
945 BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
946 return;
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
947 }
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
948
14933
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
949 const CargoSpec *cs = _sorted_cargo_specs[widget - CPW_CARGO_FIRST];
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
950 SetDParam(0, cs->name);
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
951 Dimension d = GetStringBoundingBox(STR_GRAPH_CARGO_PAYMENT_CARGO);
14519
3c95cfb7a679 (svn r19090) -Codechange: some comment coding style fixes
rubidium <rubidium@openttd.org>
parents: 14505
diff changeset
952 d.width += 14; // colour field
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
953 d.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
954 d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
955 *size = maxdim(d, *size);
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
956 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
957
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
958 virtual void DrawWidget(const Rect &r, int widget) const
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
959 {
13734
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
960 if (widget < CPW_CARGO_FIRST) {
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
961 BaseGraphWindow::DrawWidget(r, widget);
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
962 return;
f41a11f073f6 (svn r18259) -Codechange: make the graphs big font aware
rubidium <rubidium@openttd.org>
parents: 13725
diff changeset
963 }
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
964
14933
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
965 const CargoSpec *cs = _sorted_cargo_specs[widget - CPW_CARGO_FIRST];
13643
a790e57124b2 (svn r18167) -Change: make the graph legend, cargo payment graph and company league windows RTL aware
rubidium <rubidium@openttd.org>
parents: 13636
diff changeset
966 bool rtl = _dynlang.text_dir == TD_RTL;
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
967
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
968 /* Since the buttons have no text, no images,
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
969 * both the text and the coloured box have to be manually painted.
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
970 * clk_dif will move one pixel down and one pixel to the right
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
971 * when the button is clicked */
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
972 byte clk_dif = this->IsWidgetLowered(widget) ? 1 : 0;
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
973 int x = r.left + WD_FRAMERECT_LEFT;
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
974 int y = r.top;
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
975
13643
a790e57124b2 (svn r18167) -Change: make the graph legend, cargo payment graph and company league windows RTL aware
rubidium <rubidium@openttd.org>
parents: 13636
diff changeset
976 int rect_x = clk_dif + (rtl ? r.right - 12 : r.left + WD_FRAMERECT_LEFT);
a790e57124b2 (svn r18167) -Change: make the graph legend, cargo payment graph and company league windows RTL aware
rubidium <rubidium@openttd.org>
parents: 13636
diff changeset
977
a790e57124b2 (svn r18167) -Change: make the graph legend, cargo payment graph and company league windows RTL aware
rubidium <rubidium@openttd.org>
parents: 13636
diff changeset
978 GfxFillRect(rect_x, y + clk_dif, rect_x + 8, y + 5 + clk_dif, 0);
a790e57124b2 (svn r18167) -Change: make the graph legend, cargo payment graph and company league windows RTL aware
rubidium <rubidium@openttd.org>
parents: 13636
diff changeset
979 GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
980 SetDParam(0, cs->name);
13643
a790e57124b2 (svn r18167) -Change: make the graph legend, cargo payment graph and company league windows RTL aware
rubidium <rubidium@openttd.org>
parents: 13636
diff changeset
981 DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
982 }
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
983
14409
1eaefde497fd (svn r18966) -Codechange: Remove Window::OnDoubleClick() in favour of a parameter for OnClick().
frosch <frosch@openttd.org>
parents: 14258
diff changeset
984 virtual void OnClick(Point pt, int widget, int click_count)
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
985 {
14939
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
986 switch (widget) {
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
987 case CPW_ENABLE_CARGOS:
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
988 /* Remove all cargos from the excluded lists. */
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
989 _legend_excluded_cargo = 0;
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
990 this->excluded_data = 0;
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
991 this->UpdateLoweredWidgets();
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
992 this->SetDirty();
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
993 break;
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
994
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
995 case CPW_DISABLE_CARGOS: {
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
996 /* Add all cargos to the excluded lists. */
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
997 int i = 0;
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
998 const CargoSpec *cs;
14965
8616df9ca587 (svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents: 14947
diff changeset
999 FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
14939
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1000 SetBit(_legend_excluded_cargo, cs->Index());
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1001 SetBit(this->excluded_data, i);
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1002 i++;
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1003 }
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1004 this->UpdateLoweredWidgets();
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1005 this->SetDirty();
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1006 } break;
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1007
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1008 default:
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1009 if (widget >= CPW_CARGO_FIRST) {
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1010 int i = widget - CPW_CARGO_FIRST;
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1011 ToggleBit(_legend_excluded_cargo, _sorted_cargo_specs[i]->Index());
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1012 this->ToggleWidgetLoweredState(widget);
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1013 this->UpdateExcludedData();
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1014 this->SetDirty();
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1015 }
d5e618321973 (svn r19542) -Feature: Add buttons to enable / disable all cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14936
diff changeset
1016 break;
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
1017 }
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
1018 }
12609
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1019
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1020 virtual void OnTick()
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1021 {
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1022 /* Override default OnTick */
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1023 }
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1024
14966
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
1025 virtual void OnInvalidateData(int data)
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
1026 {
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
1027 this->OnHundredthTick();
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
1028 }
c2e2c495370e (svn r19574) -Fix: graphs were not properly updated when going toggling keys (i.e. companies)
rubidium <rubidium@openttd.org>
parents: 14965
diff changeset
1029
12609
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1030 virtual void OnHundredthTick()
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1031 {
14933
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
1032 this->UpdateExcludedData();
12609
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1033
14936
58044b15c59e (svn r19539) -Codechange: Use a macro to loop through the list of sorted cargo specifications.
terkhen <terkhen@openttd.org>
parents: 14933
diff changeset
1034 int i = 0;
58044b15c59e (svn r19539) -Codechange: Use a macro to loop through the list of sorted cargo specifications.
terkhen <terkhen@openttd.org>
parents: 14933
diff changeset
1035 const CargoSpec *cs;
14965
8616df9ca587 (svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents: 14947
diff changeset
1036 FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
14936
58044b15c59e (svn r19539) -Codechange: Use a macro to loop through the list of sorted cargo specifications.
terkhen <terkhen@openttd.org>
parents: 14933
diff changeset
1037 this->colours[i] = cs->legend_colour;
12609
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1038 for (uint j = 0; j != 20; j++) {
14936
58044b15c59e (svn r19539) -Codechange: Use a macro to loop through the list of sorted cargo specifications.
terkhen <terkhen@openttd.org>
parents: 14933
diff changeset
1039 this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
12609
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1040 }
14936
58044b15c59e (svn r19539) -Codechange: Use a macro to loop through the list of sorted cargo specifications.
terkhen <terkhen@openttd.org>
parents: 14933
diff changeset
1041 i++;
12609
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1042 }
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1043 this->num_dataset = i;
6324d0461e0c (svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
rubidium <rubidium@openttd.org>
parents: 12608
diff changeset
1044 }
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
1045 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1046
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1047 /** Construct the row containing the digit keys. */
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1048 static NWidgetBase *MakeCargoButtons(int *biggest_index)
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1049 {
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1050 NWidgetVertical *ver = new NWidgetVertical;
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1051
14965
8616df9ca587 (svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents: 14947
diff changeset
1052 for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
14933
7127e155ed79 (svn r19535) -Feature: Sort cargos at the cargo payment rates graph.
terkhen <terkhen@openttd.org>
parents: 14519
diff changeset
1053 NWidgetBackground *leaf = new NWidgetBackground(WWT_PANEL, COLOUR_ORANGE, CPW_CARGO_FIRST + i, NULL);
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1054 leaf->tool_tip = STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO;
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13695
diff changeset
1055 leaf->SetFill(1, 0);
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1056 leaf->SetLowered(true);
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1057 ver->Add(leaf);
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1058 }
14965
8616df9ca587 (svn r19573) -Fix (r19541): Special cargos did not appear at the refit list.
terkhen <terkhen@openttd.org>
parents: 14947
diff changeset
1059 *biggest_index = CPW_CARGO_FIRST + _sorted_standard_cargo_specs_size - 1;
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1060 return ver;
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1061 }
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1062
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1063
11621
cee8c1f807ea (svn r16001) -Codechange: Added nested widgets to cargo payment rates window
alberth <alberth@openttd.org>
parents: 11582
diff changeset
1064 static const NWidgetPart _nested_cargo_payment_rates_widgets[] = {
cee8c1f807ea (svn r16001) -Codechange: Added nested widgets to cargo payment rates window
alberth <alberth@openttd.org>
parents: 11582
diff changeset
1065 NWidget(NWID_HORIZONTAL),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
1066 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
1067 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
14045
68fabdc82f5b (svn r18588) -Feature [FS#2943]: Add shading and unshading of windows.
alberth <alberth@openttd.org>
parents: 13954
diff changeset
1068 NWidget(WWT_SHADEBOX, COLOUR_GREY),
13916
32bb7763b24a (svn r18447) -Change: make some more windows (e.g. graphs, company view) stickyable
rubidium <rubidium@openttd.org>
parents: 13798
diff changeset
1069 NWidget(WWT_STICKYBOX, COLOUR_GREY),
11621
cee8c1f807ea (svn r16001) -Codechange: Added nested widgets to cargo payment rates window
alberth <alberth@openttd.org>
parents: 11582
diff changeset
1070 EndContainer(),
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1071 NWidget(WWT_PANEL, COLOUR_GREY, CPW_BACKGROUND), SetMinimalSize(568, 128),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1072 NWidget(NWID_HORIZONTAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1073 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1074 NWidget(WWT_TEXT, COLOUR_GREY, CPW_HEADER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE, STR_NULL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1075 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1076 EndContainer(),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1077 NWidget(NWID_HORIZONTAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1078 NWidget(WWT_EMPTY, COLOUR_GREY, CPW_GRAPH), SetMinimalSize(495, 0), SetFill(1, 1), SetResize(1, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1079 NWidget(NWID_VERTICAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1080 NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 0), SetResize(0, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1081 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, CPW_ENABLE_CARGOS), SetDataTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1082 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, CPW_DISABLE_CARGOS), SetDataTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL), SetFill(1, 0),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1083 NWidget(NWID_SPACER), SetMinimalSize(0, 4),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1084 NWidgetFunction(MakeCargoButtons),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1085 NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1), SetResize(0, 1),
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1086 EndContainer(),
15045
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1087 NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1088 EndContainer(),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1089 NWidget(NWID_HORIZONTAL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1090 NWidget(NWID_SPACER), SetMinimalSize(WD_RESIZEBOX_WIDTH, 0), SetFill(1, 0), SetResize(1, 0),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1091 NWidget(WWT_TEXT, COLOUR_GREY, CPW_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL, STR_NULL),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1092 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
a23bdec8ddcb (svn r19662) -Feature: Resizable graphs.
terkhen <terkhen@openttd.org>
parents: 15044
diff changeset
1093 NWidget(WWT_RESIZEBOX, COLOUR_GREY, CPW_RESIZE),
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1094 EndContainer(),
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1095 EndContainer(),
11621
cee8c1f807ea (svn r16001) -Codechange: Added nested widgets to cargo payment rates window
alberth <alberth@openttd.org>
parents: 11582
diff changeset
1096 };
cee8c1f807ea (svn r16001) -Codechange: Added nested widgets to cargo payment rates window
alberth <alberth@openttd.org>
parents: 11582
diff changeset
1097
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
1098 static const WindowDesc _cargo_payment_rates_desc(
13798
6f820ae12bb3 (svn r18324) -Codechange: there's no need for a default size when the window isn't resizable
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
1099 WDP_AUTO, 0, 0,
5893
8547517ef719 (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium <rubidium@openttd.org>
parents: 5812
diff changeset
1100 WC_PAYMENT_RATES, WC_NONE,
14971
34548761af22 (svn r19579) -Codechange: auto-raise 'Enable/Disable all' buttons in the Cargo payment rates window
smatz <smatz@openttd.org>
parents: 14966
diff changeset
1101 WDF_UNCLICK_BUTTONS,
13564
bae287664b02 (svn r18086) -Codechange: remove 'widget' from WindowDesc
rubidium <rubidium@openttd.org>
parents: 13556
diff changeset
1102 _nested_cargo_payment_rates_widgets, lengthof(_nested_cargo_payment_rates_widgets)
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
1103 );
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1104
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1105
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6203
diff changeset
1106 void ShowCargoPaymentRates()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1107 {
9290
8d0747f9b5af (svn r13156) -Codechange: make classes of the GraphWindows.
rubidium <rubidium@openttd.org>
parents: 9289
diff changeset
1108 AllocateWindowDescFront<PaymentRatesGraphWindow>(&_cargo_payment_rates_desc, 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1109 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1110
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1111 /************************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1112 /* COMPANY LEAGUE TABLE */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1113 /************************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1114
13615
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1115 /** Widget numbers for the company league window. */
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1116 enum CompanyLeagueWidgets {
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1117 CLW_BACKGROUND,
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1118 };
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1119
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1120 static const StringID _performance_titles[] = {
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1121 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1122 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1123 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1124 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1125 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1126 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1127 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1128 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1129 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1130 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1131 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1132 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1133 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1134 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1135 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_PRESIDENT,
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11623
diff changeset
1136 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TYCOON,
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1137 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1138
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1139 static inline StringID GetPerformanceTitleFromValue(uint value)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1140 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1141 return _performance_titles[minu(value, 1000) >> 6];
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1142 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1143
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1144 class CompanyLeagueWindow : public Window {
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1145 private:
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1146 GUIList<const Company*> companies;
13739
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1147 uint ordinal_width; ///< The width of the ordinal number
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1148 uint text_width; ///< The width of the actual text
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1149
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1150 /**
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1151 * (Re)Build the company league list
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1152 */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1153 void BuildCompanyList()
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1154 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1155 if (!this->companies.NeedRebuild()) return;
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1156
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1157 this->companies.Clear();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1158
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1159 const Company *c;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1160 FOR_ALL_COMPANIES(c) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1161 *this->companies.Append() = c;
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1162 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1163
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1164 this->companies.Compact();
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1165 this->companies.RebuildDone();
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1166 }
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1167
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1168 /** Sort the company league by performance history */
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10480
diff changeset
1169 static int CDECL PerformanceSorter(const Company * const *c1, const Company * const *c2)
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1170 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1171 return (*c2)->old_economy[1].performance_history - (*c1)->old_economy[1].performance_history;
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1172 }
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1173
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1174 public:
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1175 CompanyLeagueWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
1176 {
13357
5ff3fc9fc1dc (svn r17866) -Codechange: make the remaining graph windows nested
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1177 this->InitNested(desc, window_number);
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1178 this->companies.ForceRebuild();
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1179 this->companies.NeedResort();
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
1180 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1181
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
1182 virtual void OnPaint()
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
1183 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1184 this->BuildCompanyList();
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1185 this->companies.Sort(&PerformanceSorter);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1186
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
1187 this->DrawWidgets();
13615
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1188 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1189
13615
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1190 virtual void DrawWidget(const Rect &r, int widget) const
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1191 {
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1192 if (widget != CLW_BACKGROUND) return;
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1193
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1194 uint y = r.top + WD_FRAMERECT_TOP;
13739
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1195 int icon_y_offset = 1 + (FONT_HEIGHT_NORMAL - 10) / 2;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1196
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1197 bool rtl = _dynlang.text_dir == TD_RTL;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1198 uint ordinal_left = rtl ? r.right - WD_FRAMERECT_LEFT - this->ordinal_width : r.left + WD_FRAMERECT_LEFT;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1199 uint ordinal_right = rtl ? r.right - WD_FRAMERECT_LEFT : r.left + WD_FRAMERECT_LEFT + this->ordinal_width;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1200 uint icon_left = r.left + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + (rtl ? this->text_width : this->ordinal_width);
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1201 uint text_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.right - WD_FRAMERECT_LEFT - this->text_width;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1202 uint text_right = rtl ? r.left + WD_FRAMERECT_LEFT + this->text_width : r.right - WD_FRAMERECT_LEFT;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1203
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1204 for (uint i = 0; i != this->companies.Length(); i++) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1205 const Company *c = this->companies[i];
13739
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1206 DrawString(ordinal_left, ordinal_right, y, i + STR_ORDINAL_NUMBER_1ST, i == 0 ? TC_WHITE : TC_YELLOW);
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1207
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1208 DrawCompanyIcon(c->index, icon_left, y + icon_y_offset);
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1209
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1210 SetDParam(0, c->index);
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1211 SetDParam(1, c->index);
13739
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1212 SetDParam(2, GetPerformanceTitleFromValue(c->old_economy[1].performance_history));
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1213 DrawString(text_left, text_right, y, STR_COMPANY_LEAGUE_COMPANY_NAME);
13615
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1214 y += FONT_HEIGHT_NORMAL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1215 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1216 }
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1217
13739
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1218 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1219 {
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1220 if (widget != CLW_BACKGROUND) return;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1221
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1222 this->ordinal_width = 0;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1223 for (uint i = 0; i < MAX_COMPANIES; i++) {
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1224 this->ordinal_width = max(this->ordinal_width, GetStringBoundingBox(STR_ORDINAL_NUMBER_1ST + i).width);
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1225 }
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1226 this->ordinal_width += 5; // Keep some extra spacing
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1227
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1228 uint widest_width = 0;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1229 uint widest_title = 0;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1230 for (uint i = 0; i < lengthof(_performance_titles); i++) {
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1231 uint width = GetStringBoundingBox(_performance_titles[i]).width;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1232 if (width > widest_width) {
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1233 widest_title = i;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1234 widest_width = width;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1235 }
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1236 }
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1237
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1238 const Company *c;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1239 FOR_ALL_COMPANIES(c) {
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1240 SetDParam(0, c->index);
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1241 SetDParam(1, c->index);
14097
e3c772e8163d (svn r18644) -Fix [FS#3434]: company league window was too narrow
rubidium <rubidium@openttd.org>
parents: 14045
diff changeset
1242 SetDParam(2, _performance_titles[widest_title]);
13739
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1243 widest_width = max(widest_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_NAME).width);
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1244 }
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1245
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1246 this->text_width = widest_width + 30; // Keep some extra spacing
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1247
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1248 size->width = WD_FRAMERECT_LEFT + this->ordinal_width + WD_FRAMERECT_RIGHT + 16 + WD_FRAMERECT_LEFT + this->text_width + WD_FRAMERECT_RIGHT;
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1249 }
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1250
49a2ea927978 (svn r18264) -Codechange: make the company league window big font aware
rubidium <rubidium@openttd.org>
parents: 13734
diff changeset
1251
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1252 virtual void OnTick()
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1253 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1254 if (this->companies.NeedResort()) {
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1255 this->SetDirty();
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1256 }
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1257 }
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1258
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1259 virtual void OnInvalidateData(int data)
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1260 {
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1261 if (data == 0) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1262 this->companies.ForceRebuild();
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1263 } else {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1264 this->companies.ForceResort();
9525
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1265 }
939a335c63b9 (svn r13521) -Codechange: Use GUIList sorting instead of poll & sort for CompanyLeagueWindow
skidd13 <skidd13@openttd.org>
parents: 9333
diff changeset
1266 }
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
1267 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1268
11622
6782ab076a1e (svn r16002) -Codechange: Added nested widgets for company league window
alberth <alberth@openttd.org>
parents: 11621
diff changeset
1269 static const NWidgetPart _nested_company_league_widgets[] = {
6782ab076a1e (svn r16002) -Codechange: Added nested widgets for company league window
alberth <alberth@openttd.org>
parents: 11621
diff changeset
1270 NWidget(NWID_HORIZONTAL),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
1271 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
1272 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_COMPANY_LEAGUE_TABLE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
14045
68fabdc82f5b (svn r18588) -Feature [FS#2943]: Add shading and unshading of windows.
alberth <alberth@openttd.org>
parents: 13954
diff changeset
1273 NWidget(WWT_SHADEBOX, COLOUR_GREY),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
1274 NWidget(WWT_STICKYBOX, COLOUR_GREY),
11622
6782ab076a1e (svn r16002) -Codechange: Added nested widgets for company league window
alberth <alberth@openttd.org>
parents: 11621
diff changeset
1275 EndContainer(),
13615
469d32611e74 (svn r18139) -Codechange: Scale company league table for font height.
peter1138 <peter1138@openttd.org>
parents: 13564
diff changeset
1276 NWidget(WWT_PANEL, COLOUR_GREY, CLW_BACKGROUND), SetMinimalSize(400, 0), SetMinimalTextLines(15, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM),
11622
6782ab076a1e (svn r16002) -Codechange: Added nested widgets for company league window
alberth <alberth@openttd.org>
parents: 11621
diff changeset
1277 };
6782ab076a1e (svn r16002) -Codechange: Added nested widgets for company league window
alberth <alberth@openttd.org>
parents: 11621
diff changeset
1278
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
1279 static const WindowDesc _company_league_desc(
13798
6f820ae12bb3 (svn r18324) -Codechange: there's no need for a default size when the window isn't resizable
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
1280 WDP_AUTO, 0, 0,
5893
8547517ef719 (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium <rubidium@openttd.org>
parents: 5812
diff changeset
1281 WC_COMPANY_LEAGUE, WC_NONE,
13749
fc3ab8256c95 (svn r18274) -Codechange: remove the unused WDF flags
rubidium <rubidium@openttd.org>
parents: 13739
diff changeset
1282 0,
13564
bae287664b02 (svn r18086) -Codechange: remove 'widget' from WindowDesc
rubidium <rubidium@openttd.org>
parents: 13556
diff changeset
1283 _nested_company_league_widgets, lengthof(_nested_company_league_widgets)
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
1284 );
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1285
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6203
diff changeset
1286 void ShowCompanyLeagueTable()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1287 {
9289
c052caf473db (svn r13155) -Codechange: make a window class of the company league and graph legenda windows.
rubidium <rubidium@openttd.org>
parents: 9273
diff changeset
1288 AllocateWindowDescFront<CompanyLeagueWindow>(&_company_league_desc, 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1289 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1290
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1291 /*****************************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1292 /* PERFORMANCE RATING DETAIL */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1293 /*****************************/
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1294
11749
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
1295 /** Widget numbers of the performance rating details window. */
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
1296 enum PerformanceRatingDetailsWidgets {
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
1297 PRW_SCORE_FIRST,
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
1298 PRW_SCORE_LAST = PRW_SCORE_FIRST + (SCORE_END - SCORE_BEGIN) - 1,
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
1299
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
1300 PRW_COMPANY_FIRST,
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
1301 PRW_COMPANY_LAST = PRW_COMPANY_FIRST + MAX_COMPANIES - 1,
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
1302 };
31fe7c0637e4 (svn r16139) -Codechange: Adding/completing widget number enums of several graph windows.
alberth <alberth@openttd.org>
parents: 11730
diff changeset
1303
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1304 struct PerformanceRatingDetailWindow : Window {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1305 static CompanyID company;
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1306 int timeout;
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1307
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1308 PerformanceRatingDetailWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1309 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1310 this->UpdateCompanyStats();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1311
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1312 this->InitNested(desc, window_number);
12912
6e3b759a3b58 (svn r17404) -Change (r17379): silence gcc warning caused by inlining of a virtual function
rubidium <rubidium@openttd.org>
parents: 12908
diff changeset
1313 this->OnInvalidateData(INVALID_COMPANY);
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1314 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1315
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1316 void UpdateCompanyStats()
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1317 {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1318 /* Update all company stats with the current data
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1319 * (this is because _score_info is not saved to a savegame) */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1320 Company *c;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1321 FOR_ALL_COMPANIES(c) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1322 UpdateCompanyRatingAndValue(c, false);
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1323 }
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1324
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1325 this->timeout = DAY_TICKS * 5;
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1326 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1327
13671
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1328 uint score_info_left;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1329 uint score_info_right;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1330 uint bar_left;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1331 uint bar_right;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1332 uint bar_width;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1333 uint bar_height;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1334 uint score_detail_left;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1335 uint score_detail_right;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1336
13705
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
1337 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
13671
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1338 {
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1339 switch (widget) {
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1340 case PRW_SCORE_FIRST:
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1341 this->bar_height = FONT_HEIGHT_NORMAL + 4;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1342 size->height = this->bar_height + 2 * WD_MATRIX_TOP;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1343
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1344 uint score_info_width = 0;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1345 for (uint i = SCORE_BEGIN; i < SCORE_END; i++) {
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1346 score_info_width = max(score_info_width, GetStringBoundingBox(STR_PERFORMANCE_DETAIL_VEHICLES + i).width);
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1347 }
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1348 SetDParam(0, 1000);
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1349 score_info_width += GetStringBoundingBox(STR_BLACK_COMMA).width + WD_FRAMERECT_LEFT;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1350
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1351 SetDParam(0, 100);
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1352 this->bar_width = GetStringBoundingBox(STR_PERFORMANCE_DETAIL_PERCENT).width + 20; // Wide bars!
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1353
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1354 /* At this number we are roughly at the max; it can become wider,
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1355 * but then you need at 1000 times more money. At that time you're
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1356 * not that interested anymore in the last few digits anyway. */
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1357 uint max = 999999999; // nine 9s
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1358 SetDParam(0, max);
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1359 SetDParam(1, max);
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1360 uint score_detail_width = GetStringBoundingBox(STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY).width;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1361
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1362 size->width = 7 + score_info_width + 5 + this->bar_width + 5 + score_detail_width + 7;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1363 uint left = 7;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1364 uint right = size->width - 7;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1365
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1366 bool rtl = _dynlang.text_dir == TD_RTL;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1367 this->score_info_left = rtl ? right - score_info_width : left;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1368 this->score_info_right = rtl ? right : left + score_info_width;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1369
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1370 this->score_detail_left = rtl ? left : right - score_detail_width;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1371 this->score_detail_right = rtl ? left + score_detail_width : right;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1372
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1373 this->bar_left = left + (rtl ? score_detail_width : score_info_width) + 5;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1374 this->bar_right = this->bar_left + this->bar_width;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1375 break;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1376 }
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1377 }
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1378
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1379 virtual void OnPaint()
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1380 {
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1381 /* Draw standard stuff */
9273
72a6d2e60834 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium <rubidium@openttd.org>
parents: 9255
diff changeset
1382 this->DrawWidgets();
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1383 }
8179
a0879dc1b54d (svn r11742) -Codechange [FS#1319]: Run window tick events when paused, so that news pop-ups and the about window still progress. For other windows the events are ignored when paused.
peter1138 <peter1138@openttd.org>
parents: 8140
diff changeset
1384
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1385 virtual void DrawWidget(const Rect &r, int widget) const
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1386 {
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1387 /* No need to draw when there's nothing to draw */
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1388 if (this->company == INVALID_COMPANY) return;
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1389
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1390 if (IsInsideMM(widget, PRW_COMPANY_FIRST, PRW_COMPANY_LAST + 1)) {
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1391 if (this->IsWidgetDisabled(widget)) return;
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1392 CompanyID cid = (CompanyID)(widget - PRW_COMPANY_FIRST);
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1393 int offset = (cid == this->company) ? 1 : 0;
13446
37fb6e7b7eb9 (svn r17955) -Codechange: s/SPR_PLAYER_ICON/SPR_COMPANY_ICON/
rubidium <rubidium@openttd.org>
parents: 13357
diff changeset
1394 Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1395 DrawCompanyIcon(cid, (r.left + r.right - sprite_size.width) / 2 + offset, (r.top + r.bottom - sprite_size.height) / 2 + offset);
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1396 return;
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1397 }
12888
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1398
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1399 if (!IsInsideMM(widget, PRW_SCORE_FIRST, PRW_SCORE_LAST + 1)) return;
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1400
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1401 ScoreID score_type = (ScoreID)(widget - PRW_SCORE_FIRST);
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1402
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1403 /* The colours used to show how the progress is going */
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1404 int colour_done = _colour_gradient[COLOUR_GREEN][4];
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1405 int colour_notdone = _colour_gradient[COLOUR_RED][4];
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1406
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1407 /* Draw all the score parts */
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1408 int val = _score_part[company][score_type];
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1409 int needed = _score_info[score_type].needed;
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1410 int score = _score_info[score_type].score;
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1411
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1412 /* SCORE_TOTAL has his own rules ;) */
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1413 if (score_type == SCORE_TOTAL) {
12908
730eacf8ad29 (svn r17400) -Fix [FS#3172] (r17380): total line of performance rating was calculated wrong
rubidium <rubidium@openttd.org>
parents: 12888
diff changeset
1414 for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) score += _score_info[i].score;
730eacf8ad29 (svn r17400) -Fix [FS#3172] (r17380): total line of performance rating was calculated wrong
rubidium <rubidium@openttd.org>
parents: 12888
diff changeset
1415 needed = SCORE_MAX;
12888
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1416 }
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1417
13671
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1418 uint bar_top = r.top + WD_MATRIX_TOP;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1419 uint text_top = bar_top + 2;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1420
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1421 DrawString(this->score_info_left, this->score_info_right, text_top, STR_PERFORMANCE_DETAIL_VEHICLES + score_type);
12888
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1422
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1423 /* Draw the score */
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1424 SetDParam(0, score);
13671
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1425 DrawString(this->score_info_left, this->score_info_right, text_top, STR_BLACK_COMMA, TC_FROMSTRING, SA_RIGHT);
12888
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1426
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1427 /* Calculate the %-bar */
13671
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1428 uint x = Clamp(val, 0, needed) * this->bar_width / needed;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1429 bool rtl = _dynlang.text_dir == TD_RTL;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1430 if (rtl) {
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1431 x = this->bar_right - x;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1432 } else {
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1433 x = this->bar_left + x;
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1434 }
12888
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1435
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1436 /* Draw the bar */
13671
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1437 if (x != this->bar_left) GfxFillRect(this->bar_left, bar_top, x, bar_top + this->bar_height, rtl ? colour_notdone : colour_done);
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1438 if (x != this->bar_right) GfxFillRect(x, bar_top, this->bar_right, bar_top + this->bar_height, rtl ? colour_done : colour_notdone);
12888
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1439
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1440 /* Draw it */
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1441 SetDParam(0, Clamp(val, 0, needed) * 100 / needed);
13671
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1442 DrawString(this->bar_left, this->bar_right, text_top, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING, SA_CENTER);
12888
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1443
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1444 /* SCORE_LOAN is inversed */
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1445 if (score_type == SCORE_LOAN) val = needed - val;
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1446
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1447 /* Draw the amount we have against what is needed
13454
24547db62b5c (svn r17963) -Codechange: some documentation style
rubidium <rubidium@openttd.org>
parents: 13446
diff changeset
1448 * For some of them it is in currency format */
12888
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1449 SetDParam(0, val);
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1450 SetDParam(1, needed);
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1451 switch (score_type) {
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1452 case SCORE_MIN_PROFIT:
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1453 case SCORE_MIN_INCOME:
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1454 case SCORE_MAX_INCOME:
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1455 case SCORE_MONEY:
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1456 case SCORE_LOAN:
13671
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1457 DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY);
12888
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1458 break;
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1459 default:
13671
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1460 DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_INT);
12888
a464f3bd54ed (svn r17380) -Codechange: move drawing the performance detail data to DrawWidget
rubidium <rubidium@openttd.org>
parents: 12887
diff changeset
1461 }
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1462 }
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1463
14409
1eaefde497fd (svn r18966) -Codechange: Remove Window::OnDoubleClick() in favour of a parameter for OnClick().
frosch <frosch@openttd.org>
parents: 14258
diff changeset
1464 virtual void OnClick(Point pt, int widget, int click_count)
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1465 {
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1466 /* Check which button is clicked */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1467 if (IsInsideMM(widget, PRW_COMPANY_FIRST, PRW_COMPANY_LAST + 1)) {
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1468 /* Is it no on disable? */
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1469 if (!this->IsWidgetDisabled(widget)) {
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1470 this->RaiseWidget(this->company + PRW_COMPANY_FIRST);
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1471 this->company = (CompanyID)(widget - PRW_COMPANY_FIRST);
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1472 this->LowerWidget(this->company + PRW_COMPANY_FIRST);
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1473 this->SetDirty();
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1474 }
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1475 }
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1476 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1477
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1478 virtual void OnTick()
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1479 {
11852
862dd1024fe7 (svn r16242) -Codechange: rework pausing
rubidium <rubidium@openttd.org>
parents: 11770
diff changeset
1480 if (_pause_mode != PM_UNPAUSED) return;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1481
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1482 /* Update the company score every 5 days */
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1483 if (--this->timeout == 0) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1484 this->UpdateCompanyStats();
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1485 this->SetDirty();
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1486 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1487 }
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1488
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1489 /**
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1490 * Invalidate the data of this window.
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1491 * @param data the company ID of the company that is going to be removed
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1492 */
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1493 virtual void OnInvalidateData(int data)
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1494 {
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1495 /* Disable the companies who are not active */
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1496 for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
12979
6266831f418a (svn r17473) -Codechange: use the post destructor for destroying companies too instead of complicating the graph GUI invalidate code.
rubidium <rubidium@openttd.org>
parents: 12927
diff changeset
1497 this->SetWidgetDisabledState(i + PRW_COMPANY_FIRST, !Company::IsValidID(i));
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1498 }
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1499
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1500 /* Check if the currently selected company is still active. */
12979
6266831f418a (svn r17473) -Codechange: use the post destructor for destroying companies too instead of complicating the graph GUI invalidate code.
rubidium <rubidium@openttd.org>
parents: 12927
diff changeset
1501 if (this->company != INVALID_COMPANY && !Company::IsValidID(this->company)) {
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1502 /* Raise the widget for the previous selection. */
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1503 this->RaiseWidget(this->company + PRW_COMPANY_FIRST);
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1504 this->company = INVALID_COMPANY;
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1505 }
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1506
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1507 if (this->company == INVALID_COMPANY) {
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1508 const Company *c;
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1509 FOR_ALL_COMPANIES(c) {
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1510 this->company = c->index;
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1511 break;
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1512 }
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1513 }
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1514
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1515 /* Make sure the widget is lowered */
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1516 this->LowerWidget(this->company + PRW_COMPANY_FIRST);
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1517 }
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1518 };
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1519
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10054
diff changeset
1520 CompanyID PerformanceRatingDetailWindow::company = INVALID_COMPANY;
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1521
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1522 /** Make a vertical list of panels for outputting score details.
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1523 * @param biggest_index Storage for collecting the biggest index used in the returned tree.
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1524 * @return Panel with performance details.
13954
79b889a3a0cd (svn r18490) -Doc: Fixed syntax of a few doxygen pre and post coditions.
alberth <alberth@openttd.org>
parents: 13916
diff changeset
1525 * @post \c *biggest_index contains the largest used index in the tree.
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1526 */
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1527 static NWidgetBase *MakePerformanceDetailPanels(int *biggest_index)
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1528 {
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1529 const StringID performance_tips[] = {
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1530 STR_PERFORMANCE_DETAIL_VEHICLES_TOOLTIP,
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1531 STR_PERFORMANCE_DETAIL_STATIONS_TOOLTIP,
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1532 STR_PERFORMANCE_DETAIL_MIN_PROFIT_TOOLTIP,
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1533 STR_PERFORMANCE_DETAIL_MIN_INCOME_TOOLTIP,
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1534 STR_PERFORMANCE_DETAIL_MAX_INCOME_TOOLTIP,
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1535 STR_PERFORMANCE_DETAIL_DELIVERED_TOOLTIP,
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1536 STR_PERFORMANCE_DETAIL_CARGO_TOOLTIP,
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1537 STR_PERFORMANCE_DETAIL_MONEY_TOOLTIP,
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1538 STR_PERFORMANCE_DETAIL_LOAN_TOOLTIP,
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1539 STR_PERFORMANCE_DETAIL_TOTAL_TOOLTIP,
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1540 };
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1541
12927
950767ea4ee5 (svn r17420) -Codechange: replace assert() by assert_compile() where possible
smatz <smatz@openttd.org>
parents: 12912
diff changeset
1542 assert_compile(lengthof(performance_tips) == SCORE_END - SCORE_BEGIN);
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1543
13671
e411d2d97fc1 (svn r18196) -Codechange: make the performance rating details window big font and RTL aware
rubidium <rubidium@openttd.org>
parents: 13643
diff changeset
1544 NWidgetVertical *vert = new NWidgetVertical(NC_EQUALSIZE);
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1545 for (int widnum = PRW_SCORE_FIRST; widnum <= PRW_SCORE_LAST; widnum++) {
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1546 NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13695
diff changeset
1547 panel->SetFill(1, 1);
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1548 panel->SetDataTip(0x0, performance_tips[widnum - PRW_SCORE_FIRST]);
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1549 vert->Add(panel);
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1550 }
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1551 *biggest_index = PRW_SCORE_LAST;
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1552 return vert;
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1553 }
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1554
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1555 /**
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1556 * Make a number of rows with button-like graphics, for enabling/disabling each company.
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1557 * @param biggest_index Storage for collecting the biggest index used in the returned tree.
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1558 * @return Panel with rows of company buttons.
13954
79b889a3a0cd (svn r18490) -Doc: Fixed syntax of a few doxygen pre and post coditions.
alberth <alberth@openttd.org>
parents: 13916
diff changeset
1559 * @post \c *biggest_index contains the largest used index in the tree.
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1560 */
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1561 static NWidgetBase *MakeCompanyButtonRows(int *biggest_index)
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1562 {
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1563 static const int MAX_LENGTH = 8; // Maximal number of company buttons in one row.
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1564 NWidgetVertical *vert = NULL; // Storage for all rows.
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1565 NWidgetHorizontal *hor = NULL; // Storage for buttons in one row.
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1566 int hor_length = 0;
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1567
13446
37fb6e7b7eb9 (svn r17955) -Codechange: s/SPR_PLAYER_ICON/SPR_COMPANY_ICON/
rubidium <rubidium@openttd.org>
parents: 13357
diff changeset
1568 Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1569 sprite_size.width += WD_MATRIX_LEFT + WD_MATRIX_RIGHT;
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1570 sprite_size.height += WD_MATRIX_TOP + WD_MATRIX_BOTTOM + 1; // 1 for the 'offset' of being pressed
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1571
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1572 for (int widnum = PRW_COMPANY_FIRST; widnum <= PRW_COMPANY_LAST; widnum++) {
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1573 /* Ensure there is room in 'hor' for another button. */
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1574 if (hor_length == MAX_LENGTH) {
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1575 if (vert == NULL) vert = new NWidgetVertical();
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1576 vert->Add(hor);
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1577 hor = NULL;
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1578 hor_length = 0;
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1579 }
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1580 if (hor == NULL) {
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1581 hor = new NWidgetHorizontal();
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1582 hor_length = 0;
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1583 }
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1584
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1585 NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1586 panel->SetMinimalSize(sprite_size.width, sprite_size.height);
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13695
diff changeset
1587 panel->SetFill(1, 0);
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12615
diff changeset
1588 panel->SetDataTip(0x0, STR_GRAPH_KEY_COMPANY_SELECTION_TOOLTIP);
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1589 hor->Add(panel);
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1590 hor_length++;
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1591 }
12403
0024ba6bb40e (svn r16837) -Codechange: Collect largest used index while constructing nested widget tree.
alberth <alberth@openttd.org>
parents: 12079
diff changeset
1592 *biggest_index = PRW_COMPANY_LAST;
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1593 if (vert == NULL) return hor; // All buttons fit in a single row.
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1594
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1595 if (hor_length > 0 && hor_length < MAX_LENGTH) {
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1596 /* Last row is partial, add a spacer at the end to force all buttons to the left. */
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1597 NWidgetSpacer *spc = new NWidgetSpacer(0, 0);
12887
bda0d7a566ac (svn r17379) -Codechange: make the performance rating window nested, although it still needs some improvements
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
1598 spc->SetMinimalSize(sprite_size.width, sprite_size.height);
13704
af90d4bf0785 (svn r18229) -Codechange: Make fill_x, fill_y a number instead of a bool.
alberth <alberth@openttd.org>
parents: 13695
diff changeset
1599 spc->SetFill(1, 0);
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1600 hor->Add(spc);
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1601 }
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1602 if (hor != NULL) vert->Add(hor);
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1603 return vert;
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1604 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1605
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1606 static const NWidgetPart _nested_performance_rating_detail_widgets[] = {
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1607 NWidget(NWID_HORIZONTAL),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
1608 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
1609 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_PERFORMANCE_DETAIL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
14045
68fabdc82f5b (svn r18588) -Feature [FS#2943]: Add shading and unshading of windows.
alberth <alberth@openttd.org>
parents: 13954
diff changeset
1610 NWidget(WWT_SHADEBOX, COLOUR_GREY),
13916
32bb7763b24a (svn r18447) -Change: make some more windows (e.g. graphs, company view) stickyable
rubidium <rubidium@openttd.org>
parents: 13798
diff changeset
1611 NWidget(WWT_STICKYBOX, COLOUR_GREY),
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1612 EndContainer(),
13755
bf8a4ced15fe (svn r18280) -Codechange: remove widget indices that are not needed for custom drawing/handling input
rubidium <rubidium@openttd.org>
parents: 13752
diff changeset
1613 NWidget(WWT_PANEL, COLOUR_GREY),
11751
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1614 NWidgetFunction(MakeCompanyButtonRows), SetPadding(0, 1, 1, 2),
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1615 EndContainer(),
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1616 NWidgetFunction(MakePerformanceDetailPanels),
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1617 };
090ef9105d01 (svn r16141) -Codechange: Adding nested widgets to remaining graph windows.
alberth <alberth@openttd.org>
parents: 11749
diff changeset
1618
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
1619 static const WindowDesc _performance_rating_detail_desc(
13798
6f820ae12bb3 (svn r18324) -Codechange: there's no need for a default size when the window isn't resizable
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
1620 WDP_AUTO, 0, 0,
5893
8547517ef719 (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium <rubidium@openttd.org>
parents: 5812
diff changeset
1621 WC_PERFORMANCE_DETAIL, WC_NONE,
13749
fc3ab8256c95 (svn r18274) -Codechange: remove the unused WDF flags
rubidium <rubidium@openttd.org>
parents: 13739
diff changeset
1622 0,
13564
bae287664b02 (svn r18086) -Codechange: remove 'widget' from WindowDesc
rubidium <rubidium@openttd.org>
parents: 13556
diff changeset
1623 _nested_performance_rating_detail_widgets, lengthof(_nested_performance_rating_detail_widgets)
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11361
diff changeset
1624 );
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1625
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6203
diff changeset
1626 void ShowPerformanceRatingDetail()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1627 {
9255
e12e58b72aa0 (svn r13121) -Codechange: make a class of the PerformanceRatingDetailWindow.
rubidium <rubidium@openttd.org>
parents: 9143
diff changeset
1628 AllocateWindowDescFront<PerformanceRatingDetailWindow>(&_performance_rating_detail_desc, 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1629 }