src/graph_gui.cpp
author peter1138
Tue, 22 Jan 2008 07:27:06 +0000
changeset 8374 7a1b6c89cb89
parent 8264 b1e85998c7d3
child 8409 de295d5e2bb4
permissions -rw-r--r--
(svn r11940) -Codechange: Store short filename once per open file instead of once per sprite cache entry. Not all file types need this, but most of the time no sprite cache entry needed it either.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
     3
/** @file graph_gui.cpp */
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1575
diff changeset
     6
#include "openttd.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "gui.h"
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
     8
#include "window_gui.h"
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8224
diff changeset
     9
#include "player_base.h"
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8224
diff changeset
    10
#include "player_gui.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    11
#include "economy_func.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2135
diff changeset
    12
#include "variables.h"
6091
c8827d9ae04a (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 5946
diff changeset
    13
#include "cargotype.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8107
diff changeset
    14
#include "strings_func.h"
8130
d2eb7d04f6e1 (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8121
diff changeset
    15
#include "core/alloc_func.hpp"
8131
160939e24ed3 (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
parents: 8130
diff changeset
    16
#include "window_func.h"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8131
diff changeset
    17
#include "date_func.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8179
diff changeset
    18
#include "gfx_func.h"
5291
0bd449fe7fe5 (svn r7444) -Codechange: Use one (global) cargo-colours array for drawing cargo-colours. Change Food
Darkvater
parents: 5247
diff changeset
    19
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    20
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    21
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    22
5806
b35dcabd2e23 (svn r8368) -Cleanup: [Graphs] Rename the variables relating to whether datasets should be drawn, and use HASBIT for testing against them.
maedhros
parents: 5805
diff changeset
    23
/* Bitmasks of player and cargo indices that shouldn't be drawn. */
b35dcabd2e23 (svn r8368) -Cleanup: [Graphs] Rename the variables relating to whether datasets should be drawn, and use HASBIT for testing against them.
maedhros
parents: 5805
diff changeset
    24
static uint _legend_excluded_players;
b35dcabd2e23 (svn r8368) -Cleanup: [Graphs] Rename the variables relating to whether datasets should be drawn, and use HASBIT for testing against them.
maedhros
parents: 5805
diff changeset
    25
static uint _legend_excluded_cargo;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
/************************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
/* GENERIC GRAPH DRAWER */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
/************************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
5768
dded34549c8c (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 5766
diff changeset
    31
enum {
6463
e986fe39dfe7 (svn r9638) -Feature: Increase cargo types from 12 to 32 and enable newcargo flag in NewGRF loader.
peter1138
parents: 6372
diff changeset
    32
	GRAPH_MAX_DATASETS = 32,
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
    33
	GRAPH_AXIS_LABEL_COLOUR = TC_BLACK,
5768
dded34549c8c (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 5766
diff changeset
    34
	GRAPH_AXIS_LINE_COLOUR  = 215,
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    35
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
    36
	GRAPH_X_POSITION_BEGINNING  = 44,  ///< Start the graph 44 pixels from gw->left
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
    37
	GRAPH_X_POSITION_SEPARATION = 22,  ///< There are 22 pixels between each X value
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    38
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
    39
	GRAPH_NUM_LINES_Y = 9, ///< How many horizontal lines to draw.
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
    40
	/* 9 is convenient as that means the distance between them is the height of the graph / 8,
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
    41
	 * which is the same
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    42
	 * as height >> 3. */
5768
dded34549c8c (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 5766
diff changeset
    43
};
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 222
diff changeset
    44
5805
1e6230a16f9b (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
parents: 5804
diff changeset
    45
/* Apparently these don't play well with enums. */
7763
342e5357b592 (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
parents: 7520
diff changeset
    46
static const OverflowSafeInt64 INVALID_DATAPOINT = INT64_MAX; // Value used for a datapoint that shouldn't be drawn.
342e5357b592 (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
parents: 7520
diff changeset
    47
static const uint INVALID_DATAPOINT_POS = UINT_MAX;  // Used to determine if the previous point was drawn.
5805
1e6230a16f9b (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
parents: 5804
diff changeset
    48
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    49
struct GraphDrawer {
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
    50
	uint excluded_data; ///< bitmask of the datasets that shouldn't be displayed.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
	byte num_dataset;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	byte num_on_x_axis;
5807
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
    53
	bool has_negative_values;
5771
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
    54
	byte num_vert_lines;
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
    55
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
    56
	/* The starting month and year that values are plotted against. If month is
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
    57
	 * 0xFF, use x_values_start and x_values_increment below instead. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	byte month;
4293
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4286
diff changeset
    59
	Year year;
5771
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
    60
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
    61
	/* These values are used if the graph is being plotted against values
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
    62
	 * rather than the dates specified by month and year. */
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
    63
	uint16 x_values_start;
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
    64
	uint16 x_values_increment;
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
    65
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
    66
	int left, top;  ///< Where to start drawing the graph, in pixels.
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
    67
	uint height;    ///< The height of the graph in pixels.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
	StringID format_str_y_axis;
5768
dded34549c8c (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 5766
diff changeset
    69
	byte colors[GRAPH_MAX_DATASETS];
8000
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
    70
	OverflowSafeInt64 cost[GRAPH_MAX_DATASETS][24]; ///< last 2 years
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    71
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2261
diff changeset
    73
static void DrawGraph(const GraphDrawer *gw)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
{
7763
342e5357b592 (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
parents: 7520
diff changeset
    75
	uint x, y;                       ///< Reused whenever x and y coordinates are needed.
342e5357b592 (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
parents: 7520
diff changeset
    76
	OverflowSafeInt64 highest_value; ///< Highest value to be drawn.
342e5357b592 (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
parents: 7520
diff changeset
    77
	int x_axis_offset;               ///< Distance from the top of the graph to the x axis.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
240
f1efbac04112 (svn r241) -Fix: Trailing spaces :O
darkvater
parents: 236
diff changeset
    79
	/* the colors and cost array of GraphDrawer must accomodate
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 222
diff changeset
    80
	 * both values for cargo and players. So if any are higher, quit */
5768
dded34549c8c (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 5766
diff changeset
    81
	assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_PLAYERS);
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    82
	assert(gw->num_vert_lines > 0);
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    83
5766
1980eef57c7d (svn r8317) -Codechange: Remove GraphDrawer::bg_line_color since it was the same everywhere it was set.
maedhros
parents: 5761
diff changeset
    84
	byte grid_colour = _colour_gradient[14][4];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
5807
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
    86
	/* The coordinates of the opposite edges of the graph. */
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    87
	int bottom = gw->top + gw->height - 1;
5807
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
    88
	int right  = gw->left + GRAPH_X_POSITION_BEGINNING + gw->num_vert_lines * GRAPH_X_POSITION_SEPARATION - 1;
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    89
5807
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
    90
	/* Draw the vertical grid lines. */
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    91
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    92
	/* Don't draw the first line, as that's where the axis will be. */
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    93
	x = gw->left + GRAPH_X_POSITION_BEGINNING + GRAPH_X_POSITION_SEPARATION;
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    94
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    95
	for (int i = 0; i < gw->num_vert_lines; i++) {
5766
1980eef57c7d (svn r8317) -Codechange: Remove GraphDrawer::bg_line_color since it was the same everywhere it was set.
maedhros
parents: 5761
diff changeset
    96
		GfxFillRect(x, gw->top, x, bottom, grid_colour);
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    97
		x += GRAPH_X_POSITION_SEPARATION;
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
    98
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    99
5807
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
   100
	/* Draw the horizontal grid lines. */
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   101
	x = gw->left + GRAPH_X_POSITION_BEGINNING;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	y = gw->height + gw->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   104
	for (int i = 0; i < GRAPH_NUM_LINES_Y; i++) {
5766
1980eef57c7d (svn r8317) -Codechange: Remove GraphDrawer::bg_line_color since it was the same everywhere it was set.
maedhros
parents: 5761
diff changeset
   105
		GfxFillRect(x, y, right, y, grid_colour);
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   106
		y -= (gw->height / (GRAPH_NUM_LINES_Y - 1));
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   107
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
5807
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
   109
	/* Draw the y axis. */
5768
dded34549c8c (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 5766
diff changeset
   110
	GfxFillRect(x, gw->top, x, bottom, GRAPH_AXIS_LINE_COLOUR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
5807
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
   112
	/* Find the distance from the top of the graph to the x axis. */
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
   113
	x_axis_offset = gw->height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
5807
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
   115
	/* The graph is currently symmetrical about the x axis. */
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
   116
	if (gw->has_negative_values) x_axis_offset /= 2;
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
   117
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
   118
	/* Draw the x axis. */
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
   119
	y = x_axis_offset + gw->top;
5768
dded34549c8c (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 5766
diff changeset
   120
	GfxFillRect(x, y, right, y, GRAPH_AXIS_LINE_COLOUR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
5807
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
   122
	/* Find the largest value that will be drawn. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
	if (gw->num_on_x_axis == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   126
	assert(gw->num_on_x_axis > 0);
5778
94301697f913 (svn r8330) -Codechange: Remove num_x and num_dataset from DrawGraph.
maedhros
parents: 5777
diff changeset
   127
	assert(gw->num_dataset > 0);
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 222
diff changeset
   128
5804
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   129
	/* Start of with a value of twice the height of the graph in pixels. It's a
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   130
	 * bit arbitrary, but it makes the cargo payment graph look a little nicer,
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   131
	 * and prevents division by zero when calculating where the datapoint
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   132
	 * should be drawn. */
5807
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
   133
	highest_value = x_axis_offset * 2;
5796
3e1a1281a9dc (svn r8356) -Codechange: [Graphs] Rename mx to highest_value, and fix the scaling for negative values.
maedhros
parents: 5793
diff changeset
   134
5778
94301697f913 (svn r8330) -Codechange: Remove num_x and num_dataset from DrawGraph.
maedhros
parents: 5777
diff changeset
   135
	for (int i = 0; i < gw->num_dataset; i++) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7923
diff changeset
   136
		if (!HasBit(gw->excluded_data, i)) {
5791
7b2a5160ee31 (svn r8347) -Codechange: [Graphs] Make some more variables local to the loops they're used in, and remove some assumptions about the size of an array.
maedhros
parents: 5778
diff changeset
   137
			for (int j = 0; j < gw->num_on_x_axis; j++) {
8000
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   138
				OverflowSafeInt64 datapoint = gw->cost[i][j];
5791
7b2a5160ee31 (svn r8347) -Codechange: [Graphs] Make some more variables local to the loops they're used in, and remove some assumptions about the size of an array.
maedhros
parents: 5778
diff changeset
   139
5805
1e6230a16f9b (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
parents: 5804
diff changeset
   140
				if (datapoint != INVALID_DATAPOINT) {
5796
3e1a1281a9dc (svn r8356) -Codechange: [Graphs] Rename mx to highest_value, and fix the scaling for negative values.
maedhros
parents: 5793
diff changeset
   141
					/* For now, if the graph has negative values the scaling is
3e1a1281a9dc (svn r8356) -Codechange: [Graphs] Rename mx to highest_value, and fix the scaling for negative values.
maedhros
parents: 5793
diff changeset
   142
					 * symmetrical about the x axis, so take the absolute value
3e1a1281a9dc (svn r8356) -Codechange: [Graphs] Rename mx to highest_value, and fix the scaling for negative values.
maedhros
parents: 5793
diff changeset
   143
					 * of each data point. */
7923
91982bd3c549 (svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
skidd13
parents: 7922
diff changeset
   144
					highest_value = max(highest_value, abs(datapoint));
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 222
diff changeset
   145
				}
5778
94301697f913 (svn r8330) -Codechange: Remove num_x and num_dataset from DrawGraph.
maedhros
parents: 5777
diff changeset
   146
			}
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 222
diff changeset
   147
		}
5778
94301697f913 (svn r8330) -Codechange: Remove num_x and num_dataset from DrawGraph.
maedhros
parents: 5777
diff changeset
   148
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   149
5804
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   150
	/* Round up highest_value so that it will divide cleanly into the number of
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   151
	 * axis labels used. */
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   152
	int round_val = highest_value % (GRAPH_NUM_LINES_Y - 1);
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   153
	if (round_val != 0) highest_value += (GRAPH_NUM_LINES_Y - 1 - round_val);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
	/* draw text strings on the y axis */
5804
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   156
	int64 y_label = highest_value;
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   157
	int64 y_label_separation = highest_value / (GRAPH_NUM_LINES_Y - 1);
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   158
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   159
	/* If there are negative values, the graph goes from highest_value to
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   160
	 * -highest_value, not highest_value to 0. */
5807
2723bba6f958 (svn r8369) -Cleanup: [Graphs] Rename include_neg and adj_height to more descriptive names, and add some more comments.
maedhros
parents: 5806
diff changeset
   161
	if (gw->has_negative_values) y_label_separation *= 2;
5804
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   162
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   163
	x = gw->left + GRAPH_X_POSITION_BEGINNING + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	y = gw->top - 3;
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   165
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   166
	for (int i = 0; i < GRAPH_NUM_LINES_Y; i++) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 519
diff changeset
   167
		SetDParam(0, gw->format_str_y_axis);
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6991
diff changeset
   168
		SetDParam(1, y_label);
5768
dded34549c8c (svn r8319) -Codechange: Remove the remaining colours from GraphDrawer as they're also the same everywhere.
maedhros
parents: 5766
diff changeset
   169
		DrawStringRightAligned(x, y, STR_0170, GRAPH_AXIS_LABEL_COLOUR);
5804
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   170
e5cd74217104 (svn r8366) -Codechange: [Graphs] Make the scaling code less cryptic, and fix two longstanding bugs.
maedhros
parents: 5796
diff changeset
   171
		y_label -= y_label_separation;
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   172
		y += (gw->height / (GRAPH_NUM_LINES_Y - 1));
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   173
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
	/* draw strings on the x axis */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
	if (gw->month != 0xFF) {
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   177
		x = gw->left + GRAPH_X_POSITION_BEGINNING;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
		y = gw->top + gw->height + 1;
5777
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   179
		byte month = gw->month;
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   180
		Year year  = gw->year;
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   181
		for (int i = 0; i < gw->num_on_x_axis; i++) {
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   182
			SetDParam(0, month + STR_0162_JAN);
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   183
			SetDParam(1, month + STR_0162_JAN + 2);
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   184
			SetDParam(2, year);
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   185
			DrawString(x, y, month == 0 ? STR_016F : STR_016E, GRAPH_AXIS_LABEL_COLOUR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
5777
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   187
			month += 3;
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   188
			if (month >= 12) {
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   189
				month = 0;
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   190
				year++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
			}
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   192
			x += GRAPH_X_POSITION_SEPARATION;
5777
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   193
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
	} else {
5793
01b18d4550e2 (svn r8350) -Codechange: [Graphs] Use DrawStringCentered instead of a hardcoded offset to make the string appear centred.
maedhros
parents: 5791
diff changeset
   195
		/* Draw the label under the data point rather than on the grid line. */
01b18d4550e2 (svn r8350) -Codechange: [Graphs] Use DrawStringCentered instead of a hardcoded offset to make the string appear centred.
maedhros
parents: 5791
diff changeset
   196
		x = gw->left + GRAPH_X_POSITION_BEGINNING + (GRAPH_X_POSITION_SEPARATION / 2) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
		y = gw->top + gw->height + 1;
5771
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
   198
		uint16 label = gw->x_values_start;
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
   199
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
   200
		for (int i = 0; i < gw->num_on_x_axis; i++) {
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
   201
			SetDParam(0, label);
5793
01b18d4550e2 (svn r8350) -Codechange: [Graphs] Use DrawStringCentered instead of a hardcoded offset to make the string appear centred.
maedhros
parents: 5791
diff changeset
   202
			DrawStringCentered(x, y, STR_01CB, GRAPH_AXIS_LABEL_COLOUR);
01b18d4550e2 (svn r8350) -Codechange: [Graphs] Use DrawStringCentered instead of a hardcoded offset to make the string appear centred.
maedhros
parents: 5791
diff changeset
   203
5771
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
   204
			label += gw->x_values_increment;
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   205
			x += GRAPH_X_POSITION_SEPARATION;
5771
1b62f1c3b266 (svn r8322) -Codechange: Rename unk61A and unk61C to something a little more descriptive.
maedhros
parents: 5768
diff changeset
   206
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
	/* draw lines and dots */
5777
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   210
	for (int i = 0; i < gw->num_dataset; i++) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7923
diff changeset
   211
		if (!HasBit(gw->excluded_data, i)) {
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   212
			/* Centre the dot between the grid lines. */
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   213
			x = gw->left + GRAPH_X_POSITION_BEGINNING + (GRAPH_X_POSITION_SEPARATION / 2);
5791
7b2a5160ee31 (svn r8347) -Codechange: [Graphs] Make some more variables local to the loops they're used in, and remove some assumptions about the size of an array.
maedhros
parents: 5778
diff changeset
   214
5805
1e6230a16f9b (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
parents: 5804
diff changeset
   215
			byte color  = gw->colors[i];
1e6230a16f9b (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
parents: 5804
diff changeset
   216
			uint prev_x = INVALID_DATAPOINT_POS;
1e6230a16f9b (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
parents: 5804
diff changeset
   217
			uint prev_y = INVALID_DATAPOINT_POS;
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   218
5791
7b2a5160ee31 (svn r8347) -Codechange: [Graphs] Make some more variables local to the loops they're used in, and remove some assumptions about the size of an array.
maedhros
parents: 5778
diff changeset
   219
			for (int j = 0; j < gw->num_on_x_axis; j++) {
8000
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   220
				OverflowSafeInt64 datapoint = gw->cost[i][j];
5791
7b2a5160ee31 (svn r8347) -Codechange: [Graphs] Make some more variables local to the loops they're used in, and remove some assumptions about the size of an array.
maedhros
parents: 5778
diff changeset
   221
5805
1e6230a16f9b (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
parents: 5804
diff changeset
   222
				if (datapoint != INVALID_DATAPOINT) {
8000
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   223
					/*
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   224
					 * Check whether we need to reduce the 'accuracy' of the
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   225
					 * datapoint value and the highest value to splut overflows.
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   226
					 * And when 'drawing' 'one million' or 'one million and one'
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   227
					 * there is no significant difference, so the least
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   228
					 * significant bits can just be removed.
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   229
					 *
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   230
					 * If there are more bits needed than would fit in a 32 bits
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   231
					 * integer, so at about 31 bits because of the sign bit, the
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   232
					 * least significant bits are removed.
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   233
					 */
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   234
					int mult_range = FindLastBit(x_axis_offset) + FindLastBit(abs(datapoint));
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   235
					int reduce_range = max(mult_range - 31, 0);
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   236
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   237
					/* Handle negative values differently (don't shift sign) */
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   238
					if (datapoint < 0) {
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   239
						datapoint = -(abs(datapoint) >> reduce_range);
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   240
					} else {
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   241
						datapoint >>= reduce_range;
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   242
					}
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   243
2ba28bc428f1 (svn r11559) -Fix [FS#1505]: overflow when drawing graphics with high company values.
rubidium
parents: 7997
diff changeset
   244
					y = gw->top + x_axis_offset - (x_axis_offset * datapoint) / (highest_value >> reduce_range);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
5805
1e6230a16f9b (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
parents: 5804
diff changeset
   246
					/* Draw the point. */
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6463
diff changeset
   247
					GfxFillRect(x - 1, y - 1, x + 1, y + 1, color);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
5805
1e6230a16f9b (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
parents: 5804
diff changeset
   249
					/* Draw the line connected to the previous point. */
1e6230a16f9b (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
parents: 5804
diff changeset
   250
					if (prev_x != INVALID_DATAPOINT_POS) GfxDrawLine(prev_x, prev_y, x, y, color);
1e6230a16f9b (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
parents: 5804
diff changeset
   251
1e6230a16f9b (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
parents: 5804
diff changeset
   252
					prev_x = x;
1e6230a16f9b (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
parents: 5804
diff changeset
   253
					prev_y = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
				} else {
5805
1e6230a16f9b (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
parents: 5804
diff changeset
   255
					prev_x = INVALID_DATAPOINT_POS;
1e6230a16f9b (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
parents: 5804
diff changeset
   256
					prev_y = INVALID_DATAPOINT_POS;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
				}
5805
1e6230a16f9b (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
parents: 5804
diff changeset
   258
5776
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   259
				x += GRAPH_X_POSITION_SEPARATION;
d36a554d7ccd (svn r8328) -Codechange: Remove some magic numbers in the graph drawing code.
maedhros
parents: 5771
diff changeset
   260
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
		}
5777
6a780a23cb59 (svn r8329) -Codechange: Remove the the horribly abused j and k variables completely, and make i local to each loop it's used in.
maedhros
parents: 5776
diff changeset
   262
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
/****************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
/* GRAPH LEGEND */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
/****************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
static void GraphLegendWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
{
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   271
	switch (e->event) {
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   272
		case WE_CREATE:
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   273
			for (uint i = 3; i < w->widget_count; i++) {
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   274
				if (!HasBit(_legend_excluded_players, i - 3)) w->LowerWidget(i);
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   275
			}
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   276
			break;
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   277
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   278
		case WE_PAINT: {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   279
			const Player *p;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   280
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   281
			FOR_ALL_PLAYERS(p) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   282
				if (p->is_active) continue;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   283
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   284
				SetBit(_legend_excluded_players, p->index);
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   285
				w->RaiseWidget(p->index + 3);
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   286
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   288
			DrawWindowWidgets(w);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   289
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   290
			FOR_ALL_PLAYERS(p) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   291
				if (!p->is_active) continue;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   292
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6463
diff changeset
   293
				DrawPlayerIcon(p->index, 4, 18 + p->index * 12);
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   294
7058
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7002
diff changeset
   295
				SetDParam(0, p->index);
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7002
diff changeset
   296
				SetDParam(1, p->index);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7923
diff changeset
   297
				DrawString(21, 17 + p->index * 12, STR_7021, HasBit(_legend_excluded_players, p->index) ? TC_BLACK : TC_WHITE);
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   298
			}
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   299
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   302
		case WE_CLICK:
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7932
diff changeset
   303
			if (!IsInsideMM(e->we.click.widget, 3, 11)) return;
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   304
7932
6c3d71e8a129 (svn r11485) -Codechange: Remove the doubled function ToggleBitT and rename the remaining to fit with the naming style
skidd13
parents: 7931
diff changeset
   305
			ToggleBit(_legend_excluded_players, e->we.click.widget - 3);
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   306
			w->ToggleWidgetLoweredState(e->we.click.widget);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
			InvalidateWindow(WC_INCOME_GRAPH, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
			InvalidateWindow(WC_OPERATING_PROFIT, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
			InvalidateWindow(WC_DELIVERED_CARGO, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
			InvalidateWindow(WC_PERFORMANCE_HISTORY, 0);
140
b00ce8503044 (svn r141) -Fix: Company-value was not updated immediatly if legend was changed
truelight
parents: 116
diff changeset
   312
			InvalidateWindow(WC_COMPANY_VALUE, 0);
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   313
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
static const Widget _graph_legend_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   318
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                       STR_018B_CLOSE_WINDOW},
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 534
diff changeset
   319
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   249,     0,    13, STR_704E_KEY_TO_COMPANY_GRAPHS, STR_018C_WINDOW_TITLE_DRAG_THIS},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   320
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   249,    14,   113, 0x0,                            STR_NULL},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   321
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    16,    27, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   322
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    28,    39, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   323
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    40,    51, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   324
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    52,    63, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   325
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    64,    75, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   326
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    76,    87, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   327
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,    88,    99, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   328
{      WWT_PANEL,   RESIZE_NONE,    14,     2,   247,   100,   111, 0x0,                            STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 165
diff changeset
   329
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
static const WindowDesc _graph_legend_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   333
	WDP_AUTO, WDP_AUTO, 250, 114, 250, 114,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5812
diff changeset
   334
	WC_GRAPH_LEGEND, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
	_graph_legend_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
	GraphLegendWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6203
diff changeset
   340
static void ShowGraphLegend()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
	AllocateWindowDescFront(&_graph_legend_desc, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
/********************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
/* OPERATING PROFIT */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
/********************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
static void SetupGraphDrawerForPlayers(GraphDrawer *gd)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
{
2475
efdcc705cb61 (svn r3001) s/Player*/const Player*/
tron
parents: 2458
diff changeset
   351
	const Player* p;
5806
b35dcabd2e23 (svn r8368) -Cleanup: [Graphs] Rename the variables relating to whether datasets should be drawn, and use HASBIT for testing against them.
maedhros
parents: 5805
diff changeset
   352
	uint excluded_players = _legend_excluded_players;
5601
d58f82901b2f (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5587
diff changeset
   353
	byte nums;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6463
diff changeset
   354
	int mo, yr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   356
	/* Exclude the players which aren't valid */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
	FOR_ALL_PLAYERS(p) {
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   358
		if (!p->is_active) SetBit(excluded_players, p->index);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   359
	}
5806
b35dcabd2e23 (svn r8368) -Cleanup: [Graphs] Rename the variables relating to whether datasets should be drawn, and use HASBIT for testing against them.
maedhros
parents: 5805
diff changeset
   360
	gd->excluded_data = excluded_players;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
	gd->num_vert_lines = 24;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
	nums = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
	FOR_ALL_PLAYERS(p) {
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   365
		if (p->is_active) nums = max(nums, p->num_valid_stat_ent);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
	}
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   367
	gd->num_on_x_axis = min(nums, 24);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   369
	mo = (_cur_month / 3 - nums) * 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
	yr = _cur_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
	while (mo < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
		yr--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
		mo += 12;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
	gd->year = yr;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
	gd->month = mo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
static void OperatingProfitWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
{
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   382
	switch (e->event) {
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   383
		case WE_PAINT: {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   384
			GraphDrawer gd;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   385
			const Player* p;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   386
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   387
			DrawWindowWidgets(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   389
			gd.left = 2;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   390
			gd.top = 18;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   391
			gd.height = 136;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   392
			gd.has_negative_values = true;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   393
			gd.format_str_y_axis = STR_CURRCOMPACT;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   394
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   395
			SetupGraphDrawerForPlayers(&gd);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   396
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   397
			int numd = 0;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   398
			FOR_ALL_PLAYERS(p) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   399
				if (p->is_active) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   400
					gd.colors[numd] = _colour_gradient[p->player_color][6];
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   401
					for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   402
						gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : (p->old_economy[j].income + p->old_economy[j].expenses);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   403
						i++;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   404
					}
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   405
				}
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   406
				numd++;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   407
			}
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   408
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   409
			gd.num_dataset = numd;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   410
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   411
			DrawGraph(&gd);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   412
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
		}
1085
56facccb1f3d (svn r1586) Fix: [ 1107340 ] Graphs don't show comapany info for company #8
dominik
parents: 1079
diff changeset
   414
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   415
		case WE_CLICK:
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   416
			/* Clicked on legend? */
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   417
			if (e->we.click.widget == 2) ShowGraphLegend();
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   418
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
static const Widget _operating_profit_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   423
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                        STR_018B_CLOSE_WINDOW},
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 534
diff changeset
   424
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   525,     0,    13, STR_7025_OPERATING_PROFIT_GRAPH, STR_018C_WINDOW_TITLE_DRAG_THIS},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   425
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   526,   575,     0,    13, STR_704C_KEY,                    STR_704D_SHOW_KEY_TO_GRAPHS},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   426
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   575,    14,   173, 0x0,                             STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 165
diff changeset
   427
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
static const WindowDesc _operating_profit_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   431
	WDP_AUTO, WDP_AUTO, 576, 174, 576, 174,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5812
diff changeset
   432
	WC_OPERATING_PROFIT, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
	_operating_profit_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
	OperatingProfitWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6203
diff changeset
   439
void ShowOperatingProfitGraph()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	if (AllocateWindowDescFront(&_operating_profit_desc, 0)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
		InvalidateWindow(WC_GRAPH_LEGEND, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
/****************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
/* INCOME GRAPH */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
/****************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
static void IncomeGraphWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
{
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   453
	switch (e->event) {
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   454
		case WE_PAINT: {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   455
			GraphDrawer gd;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   456
			const Player* p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   458
			DrawWindowWidgets(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   460
			gd.left = 2;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   461
			gd.top = 18;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   462
			gd.height = 104;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   463
			gd.has_negative_values = false;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   464
			gd.format_str_y_axis = STR_CURRCOMPACT;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   465
			SetupGraphDrawerForPlayers(&gd);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   466
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   467
			int numd = 0;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   468
			FOR_ALL_PLAYERS(p) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   469
				if (p->is_active) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   470
					gd.colors[numd] = _colour_gradient[p->player_color][6];
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   471
					for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   472
						gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : p->old_economy[j].income;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   473
						i++;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   474
					}
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   475
				}
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   476
				numd++;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   477
			}
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   478
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   479
			gd.num_dataset = numd;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   480
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   481
			DrawGraph(&gd);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   482
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   485
		case WE_CLICK:
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   486
			if (e->we.click.widget == 2) ShowGraphLegend();
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   487
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
static const Widget _income_graph_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   492
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 534
diff changeset
   493
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   525,     0,    13, STR_7022_INCOME_GRAPH, STR_018C_WINDOW_TITLE_DRAG_THIS},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   494
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   526,   575,     0,    13, STR_704C_KEY,          STR_704D_SHOW_KEY_TO_GRAPHS},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   495
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   575,    14,   141, 0x0,                   STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 165
diff changeset
   496
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
static const WindowDesc _income_graph_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   500
	WDP_AUTO, WDP_AUTO, 576, 142, 576, 142,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5812
diff changeset
   501
	WC_INCOME_GRAPH, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
	_income_graph_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
	IncomeGraphWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6203
diff changeset
   507
void ShowIncomeGraph()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
	if (AllocateWindowDescFront(&_income_graph_desc, 0)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
		InvalidateWindow(WC_GRAPH_LEGEND, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
/*******************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
/* DELIVERED CARGO */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
/*******************/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
static void DeliveredCargoGraphWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
{
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   520
	switch (e->event) {
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   521
		case WE_PAINT: {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   522
			GraphDrawer gd;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   523
			const Player* p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   525
			DrawWindowWidgets(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   527
			gd.left = 2;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   528
			gd.top = 18;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   529
			gd.height = 104;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   530
			gd.has_negative_values = false;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   531
			gd.format_str_y_axis = STR_7024;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   532
			SetupGraphDrawerForPlayers(&gd);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   533
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   534
			int numd = 0;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   535
			FOR_ALL_PLAYERS(p) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   536
				if (p->is_active) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   537
					gd.colors[numd] = _colour_gradient[p->player_color][6];
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   538
					for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) {
7763
342e5357b592 (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
parents: 7520
diff changeset
   539
						gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : (OverflowSafeInt64)p->old_economy[j].delivered_cargo;
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   540
						i++;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   541
					}
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   542
				}
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   543
				numd++;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   544
			}
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   545
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   546
			gd.num_dataset = numd;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   547
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   548
			DrawGraph(&gd);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   549
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   552
		case WE_CLICK:
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   553
			if (e->we.click.widget == 2) ShowGraphLegend();
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   554
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
static const Widget _delivered_cargo_graph_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   559
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                          STR_018B_CLOSE_WINDOW},
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 534
diff changeset
   560
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   525,     0,    13, STR_7050_UNITS_OF_CARGO_DELIVERED, STR_018C_WINDOW_TITLE_DRAG_THIS},
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   561
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   526,   575,     0,    13, STR_704C_KEY,                      STR_704D_SHOW_KEY_TO_GRAPHS},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   562
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   575,    14,   141, 0x0,                               STR_NULL},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 165
diff changeset
   563
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
static const WindowDesc _delivered_cargo_graph_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   567
	WDP_AUTO, WDP_AUTO, 576, 142, 576, 142,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5812
diff changeset
   568
	WC_DELIVERED_CARGO, WC_NONE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
	_delivered_cargo_graph_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
	DeliveredCargoGraphWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6203
diff changeset
   574
void ShowDeliveredCargoGraph()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
	if (AllocateWindowDescFront(&_delivered_cargo_graph_desc, 0)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
		InvalidateWindow(WC_GRAPH_LEGEND, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
	}
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   579
}
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   580
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   581
/***********************/
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   582
/* PERFORMANCE HISTORY */
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   583
/***********************/
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   584
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   585
static void PerformanceHistoryWndProc(Window *w, WindowEvent *e)
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   586
{
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   587
	switch (e->event) {
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   588
		case WE_PAINT: {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   589
			GraphDrawer gd;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   590
			const Player* p;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   591
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   592
			DrawWindowWidgets(w);
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   593
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   594
			gd.left = 2;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   595
			gd.top = 18;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   596
			gd.height = 200;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   597
			gd.has_negative_values = false;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   598
			gd.format_str_y_axis = STR_7024;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   599
			SetupGraphDrawerForPlayers(&gd);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   600
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   601
			int numd = 0;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   602
			FOR_ALL_PLAYERS(p) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   603
				if (p->is_active) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   604
					gd.colors[numd] = _colour_gradient[p->player_color][6];
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   605
					for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) {
7763
342e5357b592 (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
parents: 7520
diff changeset
   606
						gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : (OverflowSafeInt64)p->old_economy[j].performance_history;
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   607
						i++;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   608
					}
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   609
				}
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   610
				numd++;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   611
			}
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   612
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   613
			gd.num_dataset = numd;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   614
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   615
			DrawGraph(&gd);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   616
			break;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   617
		}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   618
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   619
		case WE_CLICK:
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   620
			if (e->we.click.widget == 2) ShowGraphLegend();
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   621
			if (e->we.click.widget == 3) ShowPerformanceRatingDetail();
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   622
			break;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   623
	}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   624
}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   625
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   626
static const Widget _performance_history_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   627
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                             STR_018B_CLOSE_WINDOW},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   628
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   475,     0,    13, STR_7051_COMPANY_PERFORMANCE_RATINGS, STR_018C_WINDOW_TITLE_DRAG_THIS},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   629
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   526,   575,     0,    13, STR_704C_KEY,                         STR_704D_SHOW_KEY_TO_GRAPHS},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   630
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   476,   525,     0,    13, STR_PERFORMANCE_DETAIL_KEY,           STR_704D_SHOW_KEY_TO_GRAPHS},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   631
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   575,    14,   237, 0x0,                                  STR_NULL},
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   632
{   WIDGETS_END},
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   633
};
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   634
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   635
static const WindowDesc _performance_history_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   636
	WDP_AUTO, WDP_AUTO, 576, 238, 576, 238,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5812
diff changeset
   637
	WC_PERFORMANCE_HISTORY, WC_NONE,
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   638
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   639
	_performance_history_widgets,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   640
	PerformanceHistoryWndProc
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   641
};
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   642
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6203
diff changeset
   643
void ShowPerformanceHistoryGraph()
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   644
{
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   645
	if (AllocateWindowDescFront(&_performance_history_desc, 0)) {
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   646
		InvalidateWindow(WC_GRAPH_LEGEND, 0);
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   647
	}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   648
}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   649
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   650
/*****************/
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   651
/* COMPANY VALUE */
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   652
/*****************/
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   653
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   654
static void CompanyValueGraphWndProc(Window *w, WindowEvent *e)
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   655
{
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   656
	switch (e->event) {
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   657
		case WE_PAINT: {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   658
			GraphDrawer gd;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   659
			const Player* p;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   660
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   661
			DrawWindowWidgets(w);
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   662
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   663
			gd.left = 2;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   664
			gd.top = 18;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   665
			gd.height = 200;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   666
			gd.has_negative_values = false;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   667
			gd.format_str_y_axis = STR_CURRCOMPACT;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   668
			SetupGraphDrawerForPlayers(&gd);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   669
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   670
			int numd = 0;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   671
			FOR_ALL_PLAYERS(p) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   672
				if (p->is_active) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   673
					gd.colors[numd] = _colour_gradient[p->player_color][6];
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   674
					for (int j = gd.num_on_x_axis, i = 0; --j >= 0;) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   675
						gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : p->old_economy[j].company_value;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   676
						i++;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   677
					}
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   678
				}
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   679
				numd++;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   680
			}
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   681
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   682
			gd.num_dataset = numd;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   683
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   684
			DrawGraph(&gd);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   685
			break;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   686
		}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   687
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   688
		case WE_CLICK:
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   689
			if (e->we.click.widget == 2) ShowGraphLegend();
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   690
			break;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   691
	}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   692
}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   693
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   694
static const Widget _company_value_graph_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   695
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   696
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   525,     0,    13, STR_7052_COMPANY_VALUES, STR_018C_WINDOW_TITLE_DRAG_THIS},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   697
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   526,   575,     0,    13, STR_704C_KEY,            STR_704D_SHOW_KEY_TO_GRAPHS},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   698
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   575,    14,   237, 0x0,                     STR_NULL},
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   699
{   WIDGETS_END},
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   700
};
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   701
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   702
static const WindowDesc _company_value_graph_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   703
	WDP_AUTO, WDP_AUTO, 576, 238, 576, 238,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5812
diff changeset
   704
	WC_COMPANY_VALUE, WC_NONE,
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   705
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   706
	_company_value_graph_widgets,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   707
	CompanyValueGraphWndProc
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   708
};
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   709
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6203
diff changeset
   710
void ShowCompanyValueGraph()
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   711
{
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   712
	if (AllocateWindowDescFront(&_company_value_graph_desc, 0)) {
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   713
		InvalidateWindow(WC_GRAPH_LEGEND, 0);
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   714
	}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   715
}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   716
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   717
/*****************/
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   718
/* PAYMENT RATES */
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   719
/*****************/
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   720
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   721
static void CargoPaymentRatesWndProc(Window *w, WindowEvent *e)
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   722
{
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   723
	switch (e->event) {
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   724
		case WE_PAINT: {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   725
			GraphDrawer gd;
4851
40e5c97799de (svn r6777) -GuiChange: When painting a lowered button on CargoPaymentsRates, displace the content of one pixel to the right and to the bottom. This will make it look like a normal button
belugas
parents: 4760
diff changeset
   726
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   727
			DrawWindowWidgets(w);
6192
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   728
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   729
			int x = 495;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   730
			int y = 24;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   731
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   732
			gd.excluded_data = _legend_excluded_cargo;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   733
			gd.left = 2;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   734
			gd.top = 24;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   735
			gd.height = w->height - 38;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   736
			gd.has_negative_values = false;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   737
			gd.format_str_y_axis = STR_CURRCOMPACT;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   738
			gd.num_on_x_axis = 20;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   739
			gd.num_vert_lines = 20;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   740
			gd.month = 0xFF;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   741
			gd.x_values_start     = 10;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   742
			gd.x_values_increment = 10;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   743
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   744
			uint i = 0;
6350
04b19f551aec (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6270
diff changeset
   745
			for (CargoID c = 0; c < NUM_CARGO; c++) {
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   746
				const CargoSpec *cs = GetCargo(c);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   747
				if (!cs->IsValid()) continue;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   748
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   749
				/* Only draw labels for widgets that exist. If the widget doesn't
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   750
				 * exist then the local player has used the climate cheat or
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   751
				 * changed the NewGRF configuration with this window open. */
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   752
				if (i + 3 < w->widget_count) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   753
					/* Since the buttons have no text, no images,
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   754
					 * both the text and the colored box have to be manually painted.
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   755
					 * clk_dif will move one pixel down and one pixel to the right
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   756
					 * when the button is clicked */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   757
					byte clk_dif = w->IsWidgetLowered(i + 3) ? 1 : 0;
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   758
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   759
					GfxFillRect(x + clk_dif, y + clk_dif, x + 8 + clk_dif, y + 5 + clk_dif, 0);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   760
					GfxFillRect(x + 1 + clk_dif, y + 1 + clk_dif, x + 7 + clk_dif, y + 4 + clk_dif, cs->legend_colour);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   761
					SetDParam(0, cs->name);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   762
					DrawString(x + 14 + clk_dif, y + clk_dif, STR_7065, TC_FROMSTRING);
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   763
					y += 8;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   764
				}
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   765
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   766
				gd.colors[i] = cs->legend_colour;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   767
				for (uint j = 0; j != 20; j++) {
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   768
					gd.cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 6 + 6, c);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   769
				}
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   770
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   771
				i++;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   772
			}
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   773
			gd.num_dataset = i;
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   774
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   775
			DrawGraph(&gd);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   776
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   777
			DrawString(2 + 46, 24 + gd.height + 7, STR_7062_DAYS_IN_TRANSIT, TC_FROMSTRING);
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   778
			DrawString(2 + 84, 24 - 9, STR_7063_PAYMENT_FOR_DELIVERING, TC_FROMSTRING);
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   779
			break;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   780
		}
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   781
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   782
		case WE_CLICK:
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   783
			if (e->we.click.widget >= 3) {
7932
6c3d71e8a129 (svn r11485) -Codechange: Remove the doubled function ToggleBitT and rename the remaining to fit with the naming style
skidd13
parents: 7931
diff changeset
   784
				ToggleBit(_legend_excluded_cargo, e->we.click.widget - 3);
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   785
				w->ToggleWidgetLoweredState(e->we.click.widget);
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   786
				SetWindowDirty(w);
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   787
			}
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   788
			break;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   789
	}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   790
}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   791
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   792
static const Widget _cargo_payment_rates_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   793
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                     STR_018B_CLOSE_WINDOW},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
   794
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   567,     0,    13, STR_7061_CARGO_PAYMENT_RATES, STR_018C_WINDOW_TITLE_DRAG_THIS},
6192
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   795
{      WWT_PANEL, RESIZE_BOTTOM,    14,     0,   567,    14,    45, 0x0,                          STR_NULL},
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   796
{   WIDGETS_END},
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   797
};
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   798
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   799
static const WindowDesc _cargo_payment_rates_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   800
	WDP_AUTO, WDP_AUTO, 568, 46, 568, 46,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5812
diff changeset
   801
	WC_PAYMENT_RATES, WC_NONE,
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   802
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   803
	_cargo_payment_rates_widgets,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   804
	CargoPaymentRatesWndProc
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   805
};
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   806
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   807
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6203
diff changeset
   808
void ShowCargoPaymentRates()
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   809
{
6192
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   810
	Window *w = AllocateWindowDescFront(&_cargo_payment_rates_desc, 0);
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   811
	if (w == NULL) return;
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   812
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   813
	/* Count the number of active cargo types */
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   814
	uint num_active = 0;
6350
04b19f551aec (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6270
diff changeset
   815
	for (CargoID c = 0; c < NUM_CARGO; c++) {
6192
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   816
		if (GetCargo(c)->IsValid()) num_active++;
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   817
	}
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   818
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   819
	/* Resize the window to fit the cargo types */
6372
dfc17fea6961 (svn r9435) -Fix (r8972): ensure the cargo payment graph is at least 12 "items" high
peter1138
parents: 6350
diff changeset
   820
	ResizeWindow(w, 0, max(num_active, 12U) * 8);
6192
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   821
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   822
	/* Add widgets for each cargo type */
6270
fc677cae1786 (svn r9079) -Codechange: add WWT_LAST widget when dynamically building cargo payment graph
peter1138
parents: 6248
diff changeset
   823
	w->widget_count += num_active;
fc677cae1786 (svn r9079) -Codechange: add WWT_LAST widget when dynamically building cargo payment graph
peter1138
parents: 6248
diff changeset
   824
	w->widget = ReallocT(w->widget, w->widget_count + 1);
fc677cae1786 (svn r9079) -Codechange: add WWT_LAST widget when dynamically building cargo payment graph
peter1138
parents: 6248
diff changeset
   825
	w->widget[w->widget_count].type = WWT_LAST;
6192
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   826
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   827
	/* Set the properties of each widget */
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   828
	for (uint i = 0; i != num_active; i++) {
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   829
		Widget *wi = &w->widget[3 + i];
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   830
		wi->type     = WWT_PANEL;
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   831
		wi->display_flags = RESIZE_NONE;
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   832
		wi->color    = 12;
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   833
		wi->left     = 493;
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   834
		wi->right    = 562;
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   835
		wi->top      = 24 + i * 8;
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   836
		wi->bottom   = wi->top + 7;
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   837
		wi->data     = 0;
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   838
		wi->tooltips = STR_7064_TOGGLE_GRAPH_FOR_CARGO;
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   839
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   840
		if (!HasBit(_legend_excluded_cargo, i)) w->LowerWidget(i + 3);
6192
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   841
	}
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   842
99324280e2ad (svn r8972) -Codechange: Dynamically add buttons on the cargo payment graph. This lets us remove the gaps and allow more than 12 cargo types later.
peter1138
parents: 6179
diff changeset
   843
	SetWindowDirty(w);
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   844
}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   845
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   846
/************************/
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   847
/* COMPANY LEAGUE TABLE */
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   848
/************************/
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   849
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   850
static const StringID _performance_titles[] = {
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   851
	STR_7066_ENGINEER,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   852
	STR_7066_ENGINEER,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   853
	STR_7067_TRAFFIC_MANAGER,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   854
	STR_7067_TRAFFIC_MANAGER,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   855
	STR_7068_TRANSPORT_COORDINATOR,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   856
	STR_7068_TRANSPORT_COORDINATOR,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   857
	STR_7069_ROUTE_SUPERVISOR,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   858
	STR_7069_ROUTE_SUPERVISOR,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   859
	STR_706A_DIRECTOR,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   860
	STR_706A_DIRECTOR,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   861
	STR_706B_CHIEF_EXECUTIVE,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   862
	STR_706B_CHIEF_EXECUTIVE,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   863
	STR_706C_CHAIRMAN,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   864
	STR_706C_CHAIRMAN,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   865
	STR_706D_PRESIDENT,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   866
	STR_706E_TYCOON,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   867
};
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   868
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   869
static inline StringID GetPerformanceTitleFromValue(uint value)
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   870
{
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   871
	return _performance_titles[minu(value, 1000) >> 6];
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   872
}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   873
2656
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   874
static int CDECL PerfHistComp(const void* elem1, const void* elem2)
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   875
{
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   876
	const Player* p1 = *(const Player* const*)elem1;
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   877
	const Player* p2 = *(const Player* const*)elem2;
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   878
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   879
	return p2->old_economy[1].performance_history - p1->old_economy[1].performance_history;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   880
}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   881
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   882
static void CompanyLeagueWndProc(Window *w, WindowEvent *e)
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   883
{
2482
374f6395847d (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2475
diff changeset
   884
	switch (e->event) {
2656
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   885
		case WE_PAINT: {
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   886
			const Player* plist[MAX_PLAYERS];
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   887
			const Player* p;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   888
2656
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   889
			DrawWindowWidgets(w);
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   890
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   891
			uint pl_num = 0;
2656
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   892
			FOR_ALL_PLAYERS(p) if (p->is_active) plist[pl_num++] = p;
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   893
2673
ff22d984097d (svn r3215) - Fix: warning on VS.NET 2003 complaining about constness reintroduced by revision 3192
Darkvater
parents: 2656
diff changeset
   894
			qsort((void*)plist, pl_num, sizeof(*plist), PerfHistComp);
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   895
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
   896
			for (uint i = 0; i != pl_num; i++) {
2656
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   897
				p = plist[i];
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   898
				SetDParam(0, i + STR_01AC_1ST);
7058
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7002
diff changeset
   899
				SetDParam(1, p->index);
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7002
diff changeset
   900
				SetDParam(2, p->index);
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7002
diff changeset
   901
				SetDParam(3, GetPerformanceTitleFromValue(p->old_economy[1].performance_history));
2656
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   902
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
   903
				DrawString(2, 15 + i * 10, i == 0 ? STR_7054 : STR_7055, TC_FROMSTRING);
2656
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   904
				DrawPlayerIcon(p->index, 27, 16 + i * 10);
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   905
			}
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   906
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   907
			break;
a27063f732cc (svn r3198) Rewrite the company league drawing routine for better readability
tron
parents: 2639
diff changeset
   908
		}
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   909
	}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   910
}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   911
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   912
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   913
static const Widget _company_league_widgets[] = {
2869
c5ed60d34909 (svn r3417) - Make company league table window pinnable.
peter1138
parents: 2725
diff changeset
   914
{   WWT_CLOSEBOX, RESIZE_NONE, 14,   0,  10,  0, 13, STR_00C5,                      STR_018B_CLOSE_WINDOW},
c5ed60d34909 (svn r3417) - Make company league table window pinnable.
peter1138
parents: 2725
diff changeset
   915
{    WWT_CAPTION, RESIZE_NONE, 14,  11, 387,  0, 13, STR_7053_COMPANY_LEAGUE_TABLE, STR_018C_WINDOW_TITLE_DRAG_THIS},
c5ed60d34909 (svn r3417) - Make company league table window pinnable.
peter1138
parents: 2725
diff changeset
   916
{  WWT_STICKYBOX, RESIZE_NONE, 14, 388, 399,  0, 13, STR_NULL,                      STR_STICKY_BUTTON},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   917
{      WWT_PANEL, RESIZE_NONE, 14,   0, 399, 14, 96, 0x0,                           STR_NULL},
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   918
{   WIDGETS_END},
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   919
};
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   920
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   921
static const WindowDesc _company_league_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
   922
	WDP_AUTO, WDP_AUTO, 400, 97, 400, 97,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5812
diff changeset
   923
	WC_COMPANY_LEAGUE, WC_NONE,
2869
c5ed60d34909 (svn r3417) - Make company league table window pinnable.
peter1138
parents: 2725
diff changeset
   924
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   925
	_company_league_widgets,
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   926
	CompanyLeagueWndProc
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   927
};
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   928
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6203
diff changeset
   929
void ShowCompanyLeagueTable()
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   930
{
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6463
diff changeset
   931
	AllocateWindowDescFront(&_company_league_desc, 0);
1086
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   932
}
adbaa5bda683 (svn r1587) -CodeChange: fixed up the graph loop a little..numd now shows the exact amount, no +1 needed
darkvater
parents: 1085
diff changeset
   933
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   934
/*****************************/
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   935
/* PERFORMANCE RATING DETAIL */
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   936
/*****************************/
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   937
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   938
static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
   939
{
5946
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   940
	static PlayerID _performance_rating_detail_player = INVALID_PLAYER;
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   941
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2869
diff changeset
   942
	switch (e->event) {
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   943
		case WE_PAINT: {
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
   944
			byte x;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
   945
			uint16 y = 14;
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   946
			int total_score = 0;
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   947
			int color_done, color_notdone;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   948
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   949
			/* Draw standard stuff */
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   950
			DrawWindowWidgets(w);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   951
5946
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   952
			/* Check if the currently selected player is still active. */
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   953
			if (_performance_rating_detail_player == INVALID_PLAYER || !GetPlayer(_performance_rating_detail_player)->is_active) {
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   954
				if (_performance_rating_detail_player != INVALID_PLAYER) {
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   955
					/* Raise and disable the widget for the previous selection. */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   956
					w->RaiseWidget(_performance_rating_detail_player + 13);
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   957
					w->DisableWidget(_performance_rating_detail_player + 13);
5946
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   958
					SetWindowDirty(w);
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   959
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   960
					_performance_rating_detail_player = INVALID_PLAYER;
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   961
				}
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   962
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   963
				for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   964
					if (GetPlayer(i)->is_active) {
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   965
						/* Lower the widget corresponding to this player. */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   966
						w->LowerWidget(i + 13);
5946
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   967
						SetWindowDirty(w);
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   968
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   969
						_performance_rating_detail_player = i;
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   970
						break;
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   971
					}
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   972
				}
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   973
			}
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   974
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   975
			/* If there are no active players, don't display anything else. */
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   976
			if (_performance_rating_detail_player == INVALID_PLAYER) break;
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   977
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   978
			/* Paint the player icons */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   979
			for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   980
				if (!GetPlayer(i)->is_active) {
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   981
					/* Check if we have the player as an active player */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   982
					if (!w->IsWidgetDisabled(i + 13)) {
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   983
						/* Bah, player gone :( */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   984
						w->DisableWidget(i + 13);
5946
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   985
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   986
						/* We need a repaint */
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   987
						SetWindowDirty(w);
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   988
					}
5946
ae3b1567b5d5 (svn r8612) -Fix (r117) [FS#582]: When the currently selected player in the performance
maedhros
parents: 5893
diff changeset
   989
					continue;
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   990
				}
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   991
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   992
				/* Check if we have the player marked as inactive */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   993
				if (w->IsWidgetDisabled(i + 13)) {
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   994
					/* New player! Yippie :p */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
   995
					w->EnableWidget(i + 13);
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
   996
					/* We need a repaint */
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   997
					SetWindowDirty(w);
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   998
				}
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
   999
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
  1000
				x = (i == _performance_rating_detail_player) ? 1 : 0;
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1001
				DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x);
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1002
			}
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1003
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1004
			/* The colors used to show how the progress is going */
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4365
diff changeset
  1005
			color_done = _colour_gradient[COLOUR_GREEN][4];
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4365
diff changeset
  1006
			color_notdone = _colour_gradient[COLOUR_RED][4];
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1007
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1008
			/* Draw all the score parts */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1009
			for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) {
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
  1010
				int val    = _score_part[_performance_rating_detail_player][i];
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1011
				int needed = _score_info[i].needed;
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1012
				int score  = _score_info[i].score;
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1013
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1014
				y += 20;
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1015
				/* SCORE_TOTAL has his own rulez ;) */
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1016
				if (i == SCORE_TOTAL) {
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1017
					needed = total_score;
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1018
					score = SCORE_MAX;
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1019
				} else {
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1020
					total_score += score;
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1021
				}
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1022
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
  1023
				DrawString(7, y, STR_PERFORMANCE_DETAIL_VEHICLES + i, TC_FROMSTRING);
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1024
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1025
				/* Draw the score */
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1026
				SetDParam(0, score);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
  1027
				DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, TC_FROMSTRING);
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1028
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1029
				/* Calculate the %-bar */
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7824
diff changeset
  1030
				x = Clamp(val, 0, needed) * 50 / needed;
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1031
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1032
				/* SCORE_LOAN is inversed */
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1033
				if (val < 0 && i == SCORE_LOAN) x = 0;
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1034
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1035
				/* Draw the bar */
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1036
				if (x !=  0) GfxFillRect(112,     y - 2, 112 + x,  y + 10, color_done);
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1037
				if (x != 50) GfxFillRect(112 + x, y - 2, 112 + 50, y + 10, color_notdone);
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1038
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1039
				/* Calculate the % */
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7824
diff changeset
  1040
				x = Clamp(val, 0, needed) * 100 / needed;
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1041
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1042
				/* SCORE_LOAN is inversed */
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1043
				if (val < 0 && i == SCORE_LOAN) x = 0;
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1044
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1045
				/* Draw it */
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1046
				SetDParam(0, x);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
  1047
				DrawStringCentered(137, y, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING);
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1048
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1049
				/* SCORE_LOAN is inversed */
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1050
				if (i == SCORE_LOAN) val = needed - val;
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1051
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1052
				/* Draw the amount we have against what is needed
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1053
				 * For some of them it is in currency format */
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1054
				SetDParam(0, val);
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1055
				SetDParam(1, needed);
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1056
				switch (i) {
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1057
					case SCORE_MIN_PROFIT:
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1058
					case SCORE_MIN_INCOME:
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1059
					case SCORE_MAX_INCOME:
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1060
					case SCORE_MONEY:
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1061
					case SCORE_LOAN:
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
  1062
						DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY, TC_FROMSTRING);
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1063
						break;
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1064
					default:
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7763
diff changeset
  1065
						DrawString(167, y, STR_PERFORMANCE_DETAIL_AMOUNT_INT, TC_FROMSTRING);
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1066
				}
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1067
			}
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1068
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1069
			break;
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1070
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1071
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1072
		case WE_CLICK:
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1073
			/* Check which button is clicked */
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7932
diff changeset
  1074
			if (IsInsideMM(e->we.click.widget, 13, 21)) {
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1075
				/* Is it no on disable? */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
  1076
				if (!w->IsWidgetDisabled(e->we.click.widget)) {
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
  1077
					w->RaiseWidget(_performance_rating_detail_player + 13);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1078
					_performance_rating_detail_player = (PlayerID)(e->we.click.widget - 13);
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
  1079
					w->LowerWidget(_performance_rating_detail_player + 13);
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1080
					SetWindowDirty(w);
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1081
				}
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1082
			}
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1083
			break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
  1084
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1085
		case WE_CREATE: {
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1086
			Player *p2;
4702
c79e9d9f27b3 (svn r6612) -Codechange: Use accessors for hidden_state.
belugas
parents: 4634
diff changeset
  1087
4709
a81ab800c25b (svn r6619) -Codechange: Use accessors for disabled_state.
belugas
parents: 4702
diff changeset
  1088
			/* Disable the players who are not active */
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
  1089
			for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
  1090
				w->SetWidgetDisabledState(i + 13, !GetPlayer(i)->is_active);
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1091
			}
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
  1092
			/* Update all player stats with the current data
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4709
diff changeset
  1093
			 * (this is because _score_info is not saved to a savegame) */
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1094
			FOR_ALL_PLAYERS(p2) {
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1095
				if (p2->is_active) UpdateCompanyRatingAndValue(p2, false);
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1096
			}
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1097
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1098
			w->custom[0] = DAY_TICKS;
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1099
			w->custom[1] = 5;
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1100
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7954
diff changeset
  1101
			if (_performance_rating_detail_player != INVALID_PLAYER) w->LowerWidget(_performance_rating_detail_player + 13);
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1102
			SetWindowDirty(w);
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1103
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1104
			break;
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1105
		}
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1106
6203
861336d3e289 (svn r8989) -Fix: more indenting and variable scoping
peter1138
parents: 6192
diff changeset
  1107
		case WE_TICK:
8179
60c4282e6de6 (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
parents: 8140
diff changeset
  1108
			if (_pause_game != 0) break;
60c4282e6de6 (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
parents: 8140
diff changeset
  1109
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1110
			/* Update the player score every 5 days */
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1111
			if (--w->custom[0] == 0) {
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1112
				w->custom[0] = DAY_TICKS;
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1113
				if (--w->custom[1] == 0) {
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1114
					Player *p2;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1115
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1116
					w->custom[1] = 5;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1117
					FOR_ALL_PLAYERS(p2) {
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6091
diff changeset
  1118
						/* Skip if player is not active */
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1119
						if (p2->is_active) UpdateCompanyRatingAndValue(p2, false);
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3027
diff changeset
  1120
					}
3027
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1121
					SetWindowDirty(w);
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1122
				}
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1123
			}
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1124
d2ebfd04bb77 (svn r3607) - Fix indenting of PerformanceRatingDetailWndProc()
peter1138
parents: 2952
diff changeset
  1125
			break;
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1126
	}
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1127
}
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1128
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1129
static const Widget _performance_rating_detail_widgets[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
  1130
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4293
diff changeset
  1131
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   298,     0,    13, STR_PERFORMANCE_DETAIL, STR_018C_WINDOW_TITLE_DRAG_THIS},
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1132
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,    14,    27, 0x0,                    STR_NULL},
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1133
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1134
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,    28,    47, 0x0,                    STR_PERFORMANCE_DETAIL_VEHICLES_TIP},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1135
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,    48,    67, 0x0,                    STR_PERFORMANCE_DETAIL_STATIONS_TIP},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1136
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,    68,    87, 0x0,                    STR_PERFORMANCE_DETAIL_MIN_PROFIT_TIP},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1137
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,    88,   107, 0x0,                    STR_PERFORMANCE_DETAIL_MIN_INCOME_TIP},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1138
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,   108,   127, 0x0,                    STR_PERFORMANCE_DETAIL_MAX_INCOME_TIP},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1139
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,   128,   147, 0x0,                    STR_PERFORMANCE_DETAIL_DELIVERED_TIP},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1140
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,   148,   167, 0x0,                    STR_PERFORMANCE_DETAIL_CARGO_TIP},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1141
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,   168,   187, 0x0,                    STR_PERFORMANCE_DETAIL_MONEY_TIP},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1142
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,   188,   207, 0x0,                    STR_PERFORMANCE_DETAIL_LOAN_TIP},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1143
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   298,   208,   227, 0x0,                    STR_PERFORMANCE_DETAIL_TOTAL_TIP},
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1144
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1145
{      WWT_PANEL,   RESIZE_NONE,    14,     2,    38,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1146
{      WWT_PANEL,   RESIZE_NONE,    14,    39,    75,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1147
{      WWT_PANEL,   RESIZE_NONE,    14,    76,   112,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1148
{      WWT_PANEL,   RESIZE_NONE,    14,   113,   149,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1149
{      WWT_PANEL,   RESIZE_NONE,    14,   150,   186,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1150
{      WWT_PANEL,   RESIZE_NONE,    14,   187,   223,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1151
{      WWT_PANEL,   RESIZE_NONE,    14,   224,   260,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
  1152
{      WWT_PANEL,   RESIZE_NONE,    14,   261,   297,    14,    26, 0x0,                    STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 165
diff changeset
  1153
{   WIDGETS_END},
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1154
};
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1155
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1156
static const WindowDesc _performance_rating_detail_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7266
diff changeset
  1157
	WDP_AUTO, WDP_AUTO, 299, 228, 299, 228,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5812
diff changeset
  1158
	WC_PERFORMANCE_DETAIL, WC_NONE,
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1159
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1160
	_performance_rating_detail_widgets,
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1161
	PerformanceRatingDetailWndProc
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1162
};
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1163
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6203
diff changeset
  1164
void ShowPerformanceRatingDetail()
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1165
{
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1166
	AllocateWindowDescFront(&_performance_rating_detail_desc, 0);
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 57
diff changeset
  1167
}