Changeset - r9832:eff8cdc337fb
[Not reviewed]
master
0 1 0
peter1138 - 16 years ago 2008-08-03 14:58:26
peter1138@openttd.org
(svn r13975) -Codechange: Replace some globals used by the small map window with static members of the window.
1 file changed with 26 insertions and 22 deletions:
0 comments (0 inline, 0 general)
src/smallmap_gui.cpp
Show inline comments
 
@@ -52,14 +52,12 @@ static const Widget _smallmap_widgets[] 
 
{   WWT_TEXTBTN,     RESIZE_TB,  COLOUR_BROWN,     0,    99,   202,   213, STR_MESSAGES_ENABLE_ALL, STR_NULL},
 
{   WWT_TEXTBTN,     RESIZE_TB,  COLOUR_BROWN,   100,   201,   202,   213, STR_MESSAGES_DISABLE_ALL,STR_NULL},
 
{ WWT_RESIZEBOX,   RESIZE_LRTB,  COLOUR_BROWN,   338,   349,   202,   213, 0x0,                     STR_RESIZE_BUTTON},
 
{  WIDGETS_END},
 
};
 

	
 
static int _smallmap_type;
 
static bool _smallmap_show_towns = true;
 
/* number of used industries */
 
static int _smallmap_industry_count;
 
/* number of industries per column*/
 
static uint _industries_per_column;
 

	
 
/** Macro for ordinary entry of LegendAndColor */
 
@@ -568,12 +566,15 @@ class SmallMapWindow : public Window
 
	};
 

	
 
	enum {
 
		BASE_NB_PER_COLUMN = 6,
 
	};
 

	
 
	static SmallMapType map_type;
 
	static bool show_towns;
 

	
 
	int32 scroll_x;
 
	int32 scroll_y;
 
	int32 subscroll;
 
	uint8 refresh;
 

	
 
public:
 
@@ -588,13 +589,13 @@ public:
 
	 *
 
	 * @param dpi pointer to pixel to write onto
 
	 * @param w pointer to Window struct
 
	 * @param type type of map requested (vegetation, owners, routes, etc)
 
	 * @param show_towns true if the town names should be displayed, false if not.
 
	 */
 
	void DrawSmallMap(DrawPixelInfo *dpi, int type, bool show_towns)
 
	void DrawSmallMap(DrawPixelInfo *dpi)
 
	{
 
		Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
		DrawPixelInfo *old_dpi;
 
		int dx,dy, x, y, x2, y2;
 
		void *ptr;
 
		int tile_x;
 
@@ -605,13 +606,13 @@ public:
 
		_cur_dpi = dpi;
 

	
 
		/* clear it */
 
		GfxFillRect(dpi->left, dpi->top, dpi->left + dpi->width - 1, dpi->top + dpi->height - 1, 0);
 

	
 
		/* setup owner table */
 
		if (type == SMT_OWNER) {
 
		if (this->map_type == SMT_OWNER) {
 
			const Player *p;
 

	
 
			/* fill with some special colors */
 
			_owner_colors[OWNER_TOWN] = MKCOLOR(0xB4B4B4B4);
 
			_owner_colors[OWNER_NONE] = MKCOLOR(0x54545454);
 
			_owner_colors[OWNER_WATER] = MKCOLOR(0xCACACACA);
 
@@ -670,13 +671,13 @@ public:
 
				mask &= _smallmap_mask_right[t - 1];
 
			}
 

	
 
			/* number of lines */
 
			reps = (dpi->height - y + 1) / 2;
 
			if (reps > 0) {
 
				DrawSmallMapStuff(ptr, tile_x, tile_y, dpi->pitch * 2, reps, mask, _smallmap_draw_procs[type]);
 
				DrawSmallMapStuff(ptr, tile_x, tile_y, dpi->pitch * 2, reps, mask, _smallmap_draw_procs[this->map_type]);
 
			}
 

	
 
	skip_column:
 
			if (y == 0) {
 
				tile_y++;
 
				y++;
 
@@ -688,13 +689,13 @@ public:
 
			}
 
			ptr = blitter->MoveTo(ptr, 2, 0);
 
			x += 2;
 
		}
 

	
 
		/* draw vehicles? */
 
		if (type == SMT_CONTOUR || type == SMT_VEHICLES) {
 
		if (this->map_type == SMT_CONTOUR || this->map_type == SMT_VEHICLES) {
 
			Vehicle *v;
 
			bool skip;
 
			byte color;
 

	
 
			FOR_ALL_VEHICLES(v) {
 
				if (v->type != VEH_EFFECT &&
 
@@ -726,22 +727,22 @@ public:
 
						/* Check if we're at the very right edge, and if so draw only a single pixel */
 
						if (x != dpi->width - 1) continue;
 
						skip = true;
 
					}
 

	
 
					/* Calculate pointer to pixel and the color */
 
					color = (type == SMT_VEHICLES) ? _vehicle_type_colors[v->type] : 0xF;
 
					color = (this->map_type == SMT_VEHICLES) ? _vehicle_type_colors[v->type] : 0xF;
 

	
 
					/* And draw either one or two pixels depending on clipping */
 
					blitter->SetPixel(dpi->dst_ptr, x, y, color);
 
					if (!skip) blitter->SetPixel(dpi->dst_ptr, x + 1, y, color);
 
				}
 
			}
 
		}
 

	
 
		if (show_towns) {
 
		if (this->show_towns) {
 
			const Town *t;
 

	
 
			FOR_ALL_TOWNS(t) {
 
				/* Remap the town coordinate */
 
				Point pt = RemapCoords(
 
					(int)(TileX(t->xy) * TILE_SIZE - this->scroll_x) / TILE_SIZE,
 
@@ -827,14 +828,14 @@ public:
 
				wi           = &this->widget[i];
 
				wi->top      = wi->top + diff;
 
				wi->bottom   = wi->bottom + diff;
 
			}
 
		}
 

	
 
		this->LowerWidget(_smallmap_type + SM_WIDGET_CONTOUR);
 
		this->SetWidgetLoweredState(SM_WIDGET_TOGGLETOWNNAME, _smallmap_show_towns);
 
		this->LowerWidget(this->map_type + SM_WIDGET_CONTOUR);
 
		this->SetWidgetLoweredState(SM_WIDGET_TOGGLETOWNNAME, this->show_towns);
 

	
 
		this->SmallMapCenterOnCurrentPos();
 
		this->FindWindowPlacementAndResize(desc);
 
	}
 

	
 
	virtual void OnPaint()
 
@@ -842,30 +843,30 @@ public:
 
		const LegendAndColour *tbl;
 
		int x, y, y_org;
 
		uint diff;
 
		DrawPixelInfo new_dpi;
 

	
 
		/* Hide Enable all/Disable all buttons if is not industry type small map*/
 
		this->SetWidgetHiddenState(SM_WIDGET_ENABLEINDUSTRIES, _smallmap_type != SMT_INDUSTRY);
 
		this->SetWidgetHiddenState(SM_WIDGET_DISABLEINDUSTRIES, _smallmap_type != SMT_INDUSTRY);
 
		this->SetWidgetHiddenState(SM_WIDGET_ENABLEINDUSTRIES, this->map_type != SMT_INDUSTRY);
 
		this->SetWidgetHiddenState(SM_WIDGET_DISABLEINDUSTRIES, this->map_type != SMT_INDUSTRY);
 

	
 
		/* draw the window */
 
		SetDParam(0, STR_00E5_CONTOURS + _smallmap_type);
 
		SetDParam(0, STR_00E5_CONTOURS + this->map_type);
 
		this->DrawWidgets();
 

	
 
		tbl = _legend_table[_smallmap_type];
 
		tbl = _legend_table[this->map_type];
 

	
 
		/* difference in window size */
 
		diff = (_industries_per_column > BASE_NB_PER_COLUMN) ? ((_industries_per_column - BASE_NB_PER_COLUMN) * BASE_NB_PER_COLUMN) + 1 : 0;
 

	
 
		x = 4;
 
		y_org = this->height - 44 - 11 - diff;
 
		y = y_org;
 

	
 
		for (;;) {
 
			if (_smallmap_type == SMT_INDUSTRY) {
 
			if (this->map_type == SMT_INDUSTRY) {
 
				/* Industry name must be formated, since it's not in tiny font in the specs.
 
				 * So, draw with a parameter and use the STR_SMALLMAP_INDUSTRY string, which is tiny font.*/
 
				SetDParam(0, tbl->legend);
 
				assert(tbl->type < NUM_INDUSTRYTYPES);
 
				SetDParam(1, _industry_counts[tbl->type]);
 
				if (!tbl->show_on_map) {
 
@@ -894,13 +895,13 @@ public:
 
				y = y_org;
 
			}
 
		}
 

	
 
		if (!FillDrawPixelInfo(&new_dpi, 3, 17, this->width - 28 + 22, this->height - 64 - 11 - diff)) return;
 

	
 
		this->DrawSmallMap(&new_dpi, _smallmap_type, _smallmap_show_towns);
 
		this->DrawSmallMap(&new_dpi);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case SM_WIDGET_MAP: { // Map window
 
@@ -925,15 +926,15 @@ public:
 
			case SM_WIDGET_CONTOUR:    // Show land contours
 
			case SM_WIDGET_VEHICLES:   // Show vehicles
 
			case SM_WIDGET_INDUSTRIES: // Show industries
 
			case SM_WIDGET_ROUTES:     // Show transport routes
 
			case SM_WIDGET_VEGETATION: // Show vegetation
 
			case SM_WIDGET_OWNERS:     // Show land owners
 
				this->RaiseWidget(_smallmap_type + SM_WIDGET_CONTOUR);
 
				_smallmap_type = widget - SM_WIDGET_CONTOUR;
 
				this->LowerWidget(_smallmap_type + SM_WIDGET_CONTOUR);
 
				this->RaiseWidget(this->map_type + SM_WIDGET_CONTOUR);
 
				this->map_type = (SmallMapType)(widget - SM_WIDGET_CONTOUR);
 
				this->LowerWidget(this->map_type + SM_WIDGET_CONTOUR);
 

	
 
				this->SetDirty();
 
				SndPlayFx(SND_15_BEEP);
 
				break;
 

	
 
			case SM_WIDGET_CENTERMAP: // Center the smallmap again
 
@@ -941,22 +942,22 @@ public:
 

	
 
				this->SetDirty();
 
				SndPlayFx(SND_15_BEEP);
 
				break;
 

	
 
			case SM_WIDGET_TOGGLETOWNNAME: // Toggle town names
 
				this->ToggleWidgetLoweredState(SM_WIDGET_TOGGLETOWNNAME);
 
				_smallmap_show_towns = this->IsWidgetLowered(SM_WIDGET_TOGGLETOWNNAME);
 
				this->show_towns = !this->show_towns;
 
				this->SetWidgetLoweredState(SM_WIDGET_TOGGLETOWNNAME, this->show_towns);
 

	
 
				this->SetDirty();
 
				SndPlayFx(SND_15_BEEP);
 
				break;
 

	
 
			case SM_WIDGET_LEGEND: // Legend
 
				/* if industry type small map*/
 
				if (_smallmap_type == SMT_INDUSTRY) {
 
				if (this->map_type == SMT_INDUSTRY) {
 
					/* if click on industries label, find right industry type and enable/disable it */
 
					Widget *wi = &this->widget[SM_WIDGET_LEGEND]; // label panel
 
					uint column = (pt.x - 4) / 123;
 
					uint line = (pt.y - wi->top - 2) / 6;
 
					uint free = _smallmap_industry_count % 3;
 

	
 
@@ -1073,12 +1074,15 @@ public:
 
		this->subscroll = sub;
 

	
 
		this->SetDirty();
 
	}
 
};
 

	
 
SmallMapWindow::SmallMapType SmallMapWindow::map_type = SMT_CONTOUR;
 
bool SmallMapWindow::show_towns = true;
 

	
 
static const WindowDesc _smallmap_desc = {
 
	WDP_AUTO, WDP_AUTO, 350, 214, 446, 314,
 
	WC_SMALLMAP, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
 
	_smallmap_widgets,
 
};
0 comments (0 inline, 0 general)