Changeset - r19602:15640881b58e
[Not reviewed]
master
0 1 0
frosch - 12 years ago 2012-09-19 22:10:48
frosch@openttd.org
(svn r24533) -Codechange: Move position determination on minimap legend to separate function.
1 file changed with 24 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/smallmap_gui.cpp
Show inline comments
 
@@ -1252,12 +1252,33 @@ public:
 

	
 
		this->SetupWidgetData();
 

	
 
		this->SetDirty();
 
	}
 

	
 
	/**
 
	 * Determines the mouse position on the legend.
 
	 * @param pt Mouse position.
 
	 * @return Legend item under the mouse.
 
	 */
 
	int GetPositionOnLegend(Point pt)
 
	{
 
		const NWidgetBase *wi = this->GetWidget<NWidgetBase>(WID_SM_LEGEND);
 
		uint line = (pt.y - wi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_SMALL;
 
		uint columns = this->GetNumberColumnsLegend(wi->current_x);
 
		uint number_of_rows = max(CeilDiv(max(_smallmap_company_count, _smallmap_industry_count), columns), this->min_number_of_fixed_rows);
 
		if (line >= number_of_rows) return -1;
 

	
 
		bool rtl = _current_text_dir == TD_RTL;
 
		int x = pt.x - wi->pos_x;
 
		if (rtl) x = wi->current_x - x;
 
		uint column = (x - WD_FRAMERECT_LEFT) / this->column_width;
 

	
 
		return (column * number_of_rows) + line;
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		/* User clicked something, notify the industry chain window to stop sending newly selected industries. */
 
		InvalidateWindowClassesData(WC_INDUSTRY_CARGOES, NUM_INDUSTRYTYPES);
 

	
 
		switch (widget) {
 
@@ -1319,28 +1340,17 @@ public:
 
				this->SetDirty();
 
				SndPlayFx(SND_15_BEEP);
 
				break;
 

	
 
			case WID_SM_LEGEND: // Legend
 
				if (this->map_type == SMT_INDUSTRY || this->map_type == SMT_OWNER) {
 
					const NWidgetBase *wi = this->GetWidget<NWidgetBase>(WID_SM_LEGEND); // Label panel
 
					uint line = (pt.y - wi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_SMALL;
 
					uint columns = this->GetNumberColumnsLegend(wi->current_x);
 
					uint number_of_rows = max(CeilDiv(max(_smallmap_company_count, _smallmap_industry_count), columns), this->min_number_of_fixed_rows);
 
					if (line >= number_of_rows) break;
 

	
 
					bool rtl = _current_text_dir == TD_RTL;
 
					int x = pt.x - wi->pos_x;
 
					if (rtl) x = wi->current_x - x;
 
					uint column = (x - WD_FRAMERECT_LEFT) / this->column_width;
 

	
 
					/* If industry type small map*/
 
					if (this->map_type == SMT_INDUSTRY) {
 
						/* If click on industries label, find right industry type and enable/disable it. */
 
						int industry_pos = (column * number_of_rows) + line;
 
						if (industry_pos < _smallmap_industry_count) {
 
						int industry_pos = GetPositionOnLegend(pt);
 
						if (industry_pos >= 0 && industry_pos < _smallmap_industry_count) {
 
							if (_ctrl_pressed) {
 
								/* Disable all, except the clicked one. */
 
								bool changes = false;
 
								for (int i = 0; i != _smallmap_industry_count; i++) {
 
									bool new_state = i == industry_pos;
 
									if (_legend_from_industries[i].show_on_map != new_state) {
 
@@ -1357,13 +1367,13 @@ public:
 
							} else {
 
								_legend_from_industries[industry_pos].show_on_map = !_legend_from_industries[industry_pos].show_on_map;
 
							}
 
						}
 
					} else if (this->map_type == SMT_OWNER) {
 
						/* If click on companies label, find right company and enable/disable it. */
 
						int company_pos = (column * number_of_rows) + line;
 
						int company_pos = GetPositionOnLegend(pt);
 
						if (company_pos < NUM_NO_COMPANY_ENTRIES) break;
 
						if (company_pos < _smallmap_company_count) {
 
							if (_ctrl_pressed) {
 
								/* Disable all, except the clicked one */
 
								bool changes = false;
 
								for (int i = NUM_NO_COMPANY_ENTRIES; i != _smallmap_company_count; i++) {
0 comments (0 inline, 0 general)