Changeset - r25336:6f4b1c1f8c7f
[Not reviewed]
master
0 1 0
Peter Nelson - 3 years ago 2021-04-25 12:48:00
peter1138@openttd.org
Fix: Cargo legend blob in cargo payment rate window did not rescale.
1 file changed with 14 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/graph_gui.cpp
Show inline comments
 
@@ -870,111 +870,120 @@ static WindowDesc _company_value_graph_d
 
void ShowCompanyValueGraph()
 
{
 
	AllocateWindowDescFront<CompanyValueGraphWindow>(&_company_value_graph_desc, 0);
 
}
 

	
 
/*****************/
 
/* PAYMENT RATES */
 
/*****************/
 

	
 
struct PaymentRatesGraphWindow : BaseGraphWindow {
 
	uint line_height;   ///< Pixel height of each cargo type row.
 
	Scrollbar *vscroll; ///< Cargo list scrollbar.
 
	uint legend_width;  ///< Width of legend 'blob'.
 

	
 
	PaymentRatesGraphWindow(WindowDesc *desc, WindowNumber window_number) :
 
			BaseGraphWindow(desc, WID_CPR_GRAPH, STR_JUST_CURRENCY_SHORT)
 
	{
 
		this->num_on_x_axis = 20;
 
		this->num_vert_lines = 20;
 
		this->month = 0xFF;
 
		this->x_values_start     = 10;
 
		this->x_values_increment = 10;
 

	
 
		this->CreateNestedTree();
 
		this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR);
 
		this->vscroll->SetCount(_sorted_standard_cargo_specs_size);
 

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

	
 
		this->FinishInitNested(window_number);
 
	}
 

	
 
	void OnInit() override
 
	{
 
		/* Width of the legend blob. */
 
		this->legend_width = (FONT_HEIGHT_SMALL - ScaleFontTrad(1)) * 8 / 5;
 
	}
 

	
 
	void UpdateExcludedData()
 
	{
 
		this->excluded_data = 0;
 

	
 
		int i = 0;
 
		const CargoSpec *cs;
 
		FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 
			if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i);
 
			i++;
 
		}
 
	}
 

	
 
	void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
 
	{
 
		if (widget != WID_CPR_MATRIX) {
 
			BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
 
			return;
 
		}
 

	
 
		const CargoSpec *cs;
 
		FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 
			SetDParam(0, cs->name);
 
			Dimension d = GetStringBoundingBox(STR_GRAPH_CARGO_PAYMENT_CARGO);
 
			d.width += 14; // colour field
 
			d.width += this->legend_width + 4; // colour field
 
			d.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
 
			d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
 
			*size = maxdim(d, *size);
 
		}
 

	
 
		this->line_height = size->height;
 
		size->height = this->line_height * 11; /* Default number of cargo types in most climates. */
 
		resize->width = 0;
 
		resize->height = this->line_height;
 
	}
 

	
 
	void DrawWidget(const Rect &r, int widget) const override
 
	{
 
		if (widget != WID_CPR_MATRIX) {
 
			BaseGraphWindow::DrawWidget(r, widget);
 
			return;
 
		}
 

	
 
		bool rtl = _current_text_dir == TD_RTL;
 

	
 
		int x = r.left + WD_FRAMERECT_LEFT;
 
		int y = r.top;
 
		uint row_height = FONT_HEIGHT_SMALL;
 
		int padding = ScaleFontTrad(1);
 

	
 
		int pos = this->vscroll->GetPosition();
 
		int max = pos + this->vscroll->GetCapacity();
 

	
 
		const CargoSpec *cs;
 
		FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
 
			if (pos-- > 0) continue;
 
			if (--max < 0) break;
 

	
 
			bool lowered = !HasBit(_legend_excluded_cargo, cs->Index());
 

	
 
			/* Redraw box if lowered */
 
			if (lowered) DrawFrameRect(r.left, y, r.right, y + this->line_height - 1, COLOUR_BROWN, lowered ? FR_LOWERED : FR_NONE);
 

	
 
			byte clk_dif = lowered ? 1 : 0;
 
			int rect_x = clk_dif + (rtl ? r.right - 12 : r.left + WD_FRAMERECT_LEFT);
 
			int rect_x = clk_dif + (rtl ? r.right - this->legend_width - WD_FRAMERECT_RIGHT : r.left + WD_FRAMERECT_LEFT);
 

	
 
			GfxFillRect(rect_x, y + clk_dif, rect_x + 8, y + 5 + clk_dif, PC_BLACK);
 
			GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
 
			GfxFillRect(rect_x, y + padding + clk_dif, rect_x + this->legend_width, y + row_height - 1 + clk_dif, PC_BLACK);
 
			GfxFillRect(rect_x + 1, y + padding + 1 + clk_dif, rect_x + this->legend_width - 1, y + row_height - 2 + clk_dif, cs->legend_colour);
 
			SetDParam(0, cs->name);
 
			DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
 
			DrawString(rtl ? r.left : x + this->legend_width + 4 + clk_dif, (rtl ? r.right - this->legend_width - 4 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
 

	
 
			y += this->line_height;
 
		}
 
	}
 

	
 
	void OnClick(Point pt, int widget, int click_count) override
 
	{
 
		switch (widget) {
 
			case WID_CPR_ENABLE_CARGOES:
 
				/* Remove all cargoes from the excluded lists. */
 
				_legend_excluded_cargo = 0;
 
				this->excluded_data = 0;
0 comments (0 inline, 0 general)