Changeset - r12599:6b04ff4e5cf4
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-08-03 14:44:55
rubidium@openttd.org
(svn r17052) -Codechange: move state changes out of OnPaint for the graph windows
1 file changed with 55 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/graph_gui.cpp
Show inline comments
 
@@ -389,42 +389,67 @@ protected:
 
	BaseGraphWindow(const WindowDesc *desc, WindowNumber window_number, int left,
 
									int top, int height, bool has_negative_values, StringID format_str_y_axis) :
 
			Window(desc, window_number), has_negative_values(has_negative_values),
 
			gd_left(left), gd_top(top), gd_height(height), format_str_y_axis(format_str_y_axis)
 
	{
 
		InvalidateWindow(WC_GRAPH_LEGEND, 0);
 
		this->num_vert_lines = 24;
 

	
 
		/* Initialise the dataset */
 
		this->OnTick();
 
	}
 

	
 
public:
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 

	
 
		this->DrawGraph();
 
	}
 

	
 
	virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
 
	{
 
		return INVALID_DATAPOINT;
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		/* Clicked on legend? */
 
		if (widget == BGW_KEY_BUTTON) ShowGraphLegend();
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		uint excluded_companies = _legend_excluded_companies;
 

	
 
		/* Exclude the companies which aren't valid */
 
		for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
			if (!Company::IsValidID(c)) SetBit(excluded_companies, c);
 
		}
 
		this->excluded_data = excluded_companies;
 
		this->num_vert_lines = 24;
 

	
 
		byte nums = 0;
 
		const Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
			nums = max(nums, c->num_valid_stat_ent);
 
			nums = min(this->num_vert_lines, max(nums, c->num_valid_stat_ent));
 
		}
 
		this->num_on_x_axis = min(nums, 24);
 

	
 
		int mo = (_cur_month / 3 - nums) * 3;
 
		int yr = _cur_year;
 
		while (mo < 0) {
 
			yr--;
 
			mo += 12;
 
		}
 

	
 
		if (this->excluded_data == excluded_companies && this->num_on_x_axis == nums &&
 
				this->year == yr && this->month == mo) {
 
			/* There's no reason to get new stats */
 
			return;
 
		}
 

	
 
		this->excluded_data = excluded_companies;
 
		this->num_on_x_axis = nums;
 
		this->year = yr;
 
		this->month = mo;
 

	
 
		int numd = 0;
 
		for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) {
 
			c = Company::GetIfValid(k);
 
@@ -436,25 +461,12 @@ public:
 
				}
 
			}
 
			numd++;
 
		}
 

	
 
		this->num_dataset = numd;
 

	
 
		this->DrawGraph();
 
	}
 

	
 
	virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
 
	{
 
		return INVALID_DATAPOINT;
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		/* Clicked on legend? */
 
		if (widget == BGW_KEY_BUTTON) ShowGraphLegend();
 
	}
 
};
 

	
 

	
 
/********************/
 
/* OPERATING PROFIT */
 
@@ -758,21 +770,22 @@ struct PaymentRatesGraphWindow : BaseGra
 
		this->num_on_x_axis = 20;
 
		this->num_vert_lines = 20;
 
		this->month = 0xFF;
 
		this->x_values_start     = 10;
 
		this->x_values_increment = 10;
 

	
 
		/* Initialise the dataset */
 
		this->OnHundredthTick();
 

	
 
		this->FindWindowPlacementAndResize(desc);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 

	
 
		this->excluded_data = _legend_excluded_cargo;
 

	
 
		int x = 495;
 
		int y = 24;
 

	
 
		uint i = 0;
 

	
 
		const CargoSpec *cs;
 
@@ -790,36 +803,52 @@ struct PaymentRatesGraphWindow : BaseGra
 
				GfxFillRect(x + clk_dif, y + clk_dif, x + 8 + clk_dif, y + 5 + clk_dif, 0);
 
				GfxFillRect(x + 1 + clk_dif, y + 1 + clk_dif, x + 7 + clk_dif, y + 4 + clk_dif, cs->legend_colour);
 
				SetDParam(0, cs->name);
 
				DrawString(x + 14 + clk_dif, this->width, y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
 
				y += 8;
 
			}
 

	
 
			this->colours[i] = cs->legend_colour;
 
			for (uint j = 0; j != 20; j++) {
 
				this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
 
			}
 

	
 
			i++;
 
		}
 
		this->num_dataset = i;
 

	
 
		this->DrawGraph();
 

	
 
		DrawString(2 + 46, this->width, 24 + this->gd_height + 7, STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL);
 
		DrawString(2 + 84, this->width, 24 - 9, STR_GRAPH_CARGO_PAYMENT_RATES_TITLE);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		if (widget >= CPW_CARGO_FIRST) {
 
			ToggleBit(_legend_excluded_cargo, widget - CPW_CARGO_FIRST);
 
			this->ToggleWidgetLoweredState(widget);
 
			this->excluded_data = _legend_excluded_cargo;
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		/* Override default OnTick */
 
	}
 

	
 
	virtual void OnHundredthTick()
 
	{
 
		this->excluded_data = _legend_excluded_cargo;
 

	
 
		int i = 0;
 
		const CargoSpec *cs;
 
		FOR_ALL_CARGOSPECS(cs) {
 
			this->colours[i] = cs->legend_colour;
 
			for (uint j = 0; j != 20; j++) {
 
				this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
 
			}
 

	
 
			i++;
 
		}
 
		this->num_dataset = i;
 
	}
 
};
 

	
 
static const Widget _cargo_payment_rates_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_GREY,     0,    10,     0,    13, STR_BLACK_CROSS,                       STR_TOOLTIP_CLOSE_WINDOW},
 
{    WWT_CAPTION,   RESIZE_NONE,  COLOUR_GREY,    11,   567,     0,    13, STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS},
 
{      WWT_PANEL, RESIZE_BOTTOM,  COLOUR_GREY,     0,   567,    14,    45, 0x0,                                   STR_NULL},
0 comments (0 inline, 0 general)