Changeset - r12335:832893ebf982
[Not reviewed]
master
0 5 0
rubidium - 15 years ago 2009-07-08 08:50:20
rubidium@openttd.org
(svn r16765) -Codechange: give ViewportSign's width_1 and width_2 more self explaining names
5 files changed with 46 insertions and 48 deletions:
0 comments (0 inline, 0 general)
src/smallmap_gui.cpp
Show inline comments
 
@@ -782,35 +782,35 @@ public:
 
			}
 
		}
 

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

	
 
			FOR_ALL_TOWNS(t) {
 
				/* Remap the town coordinate */
 
				Point pt = RemapCoords(
 
						this->RemapX(TileX(t->xy)),
 
						this->RemapY(TileY(t->xy)),
 
						0);
 
				x = pt.x - this->subscroll + 3 - (t->sign.width_2 >> 1);
 
				x = pt.x - this->subscroll + 3 - (t->sign.width_small >> 1);
 
				y = pt.y;
 

	
 
				/* Check if the town sign is within bounds */
 
				if (x + t->sign.width_2 > dpi->left &&
 
				if (x + t->sign.width_small > dpi->left &&
 
						x < dpi->left + dpi->width &&
 
						y + 6 > dpi->top &&
 
						y < dpi->top + dpi->height) {
 
					/* And draw it. */
 
					SetDParam(0, t->index);
 
					DrawString(x, x + t->sign.width_2, y, STR_SMALLMAP_TOWN);
 
					DrawString(x, x + t->sign.width_small, y, STR_SMALLMAP_TOWN);
 
				}
 
			}
 
		}
 

	
 
		/* Find main viewport. */
 
		ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
 

	
 
		/* Draw map indicators */
 
		Point pt = RemapCoords(this->scroll_x, this->scroll_y, 0);
 

	
 
		x = vp->virtual_left - pt.x;
 
		y = vp->virtual_top - pt.y;
src/station.cpp
Show inline comments
 
@@ -144,25 +144,25 @@ void Station::AddFacility(StationFacilit
 
{
 
	if (this->facilities == FACIL_NONE) {
 
		this->xy = facil_xy;
 
		this->random_bits = Random();
 
	}
 
	this->facilities |= new_facility_bit;
 
	this->owner = _current_company;
 
	this->build_date = _date;
 
}
 

	
 
void Station::MarkDirty() const
 
{
 
	if (this->sign.width_1 != 0) {
 
	if (this->sign.width_normal != 0) {
 
		InvalidateWindowWidget(WC_STATION_VIEW, index, SVW_CAPTION);
 
		this->sign.MarkDirty();
 
	}
 
}
 

	
 
void Station::MarkTilesDirty(bool cargo_change) const
 
{
 
	TileIndex tile = this->train_tile;
 
	int w, h;
 

	
 
	if (tile == INVALID_TILE) return;
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -1429,25 +1429,24 @@ CommandCost CmdBuildRoadStop(TileIndex t
 
		/* allocate and initialize new station */
 
		if (!Station::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
 

	
 
		if (flags & DC_EXEC) {
 
			st = new Station(tile);
 

	
 
			st->town = ClosestTownFromTile(tile, UINT_MAX);
 
			st->string_id = GenerateStationName(st, tile, STATIONNAMING_ROAD);
 

	
 
			if (Company::IsValidID(_current_company)) {
 
				SetBit(st->town->have_ratings, _current_company);
 
			}
 
			st->sign.width_1 = 0;
 
		}
 
	}
 

	
 
	cost.AddCost((type) ? _price.build_truck_station : _price.build_bus_station);
 

	
 
	if (flags & DC_EXEC) {
 
		RoadStop *road_stop = new RoadStop(tile);
 
		/* Insert into linked list of RoadStops */
 
		RoadStop **currstop = FindRoadStopSpot(type, st);
 
		*currstop = road_stop;
 

	
 
		/* initialize an empty station */
 
@@ -1786,25 +1785,24 @@ CommandCost CmdBuildAirport(TileIndex ti
 
		/* allocate and initialize new station */
 
		if (!Station::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
 

	
 
		if (flags & DC_EXEC) {
 
			st = new Station(tile);
 

	
 
			st->town = t;
 
			st->string_id = GenerateStationName(st, tile, !(afc->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_HELIPORT : STATIONNAMING_AIRPORT);
 

	
 
			if (Company::IsValidID(_current_company)) {
 
				SetBit(st->town->have_ratings, _current_company);
 
			}
 
			st->sign.width_1 = 0;
 
		}
 
	}
 

	
 
	cost.AddCost(_price.build_airport * w * h);
 

	
 
	if (flags & DC_EXEC) {
 
		/* Always add the noise, so there will be no need to recalculate when option toggles */
 
		nearest->noise_reached += newnoise_level;
 

	
 
		st->airport_tile = tile;
 
		st->AddFacility(FACIL_AIRPORT, tile);
 
		st->airport_type = (byte)p1;
 
@@ -1922,25 +1920,24 @@ CommandCost CmdBuildBuoy(TileIndex tile,
 
	/* allocate and initialize new station */
 
	if (!Station::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
 

	
 
	if (flags & DC_EXEC) {
 
		Station *st = new Station(tile);
 

	
 
		st->town = ClosestTownFromTile(tile, UINT_MAX);
 
		st->string_id = GenerateStationName(st, tile, STATIONNAMING_BUOY);
 

	
 
		if (Company::IsValidID(_current_company)) {
 
			SetBit(st->town->have_ratings, _current_company);
 
		}
 
		st->sign.width_1 = 0;
 
		st->dock_tile = tile;
 
		st->facilities |= FACIL_DOCK;
 
		/* Buoys are marked in the Station struct by this flag. Yes, it is this
 
		 * braindead.. */
 
		st->had_vehicle_of_type |= HVOT_BUOY;
 
		st->owner = OWNER_NONE;
 

	
 
		st->build_date = _date;
 

	
 
		MakeBuoy(tile, st->index, GetWaterClass(tile));
 

	
 
		UpdateStationVirtCoordDirty(st);
 
@@ -2938,25 +2935,24 @@ uint MoveGoodsToStation(TileIndex tile, 
 
	return moved;
 
}
 

	
 
void BuildOilRig(TileIndex tile)
 
{
 
	if (!Station::CanAllocateItem()) {
 
		DEBUG(misc, 0, "Can't allocate station for oilrig at 0x%X, reverting to oilrig only", tile);
 
		return;
 
	}
 

	
 
	Station *st = new Station(tile);
 
	st->town = ClosestTownFromTile(tile, UINT_MAX);
 
	st->sign.width_1 = 0;
 

	
 
	st->string_id = GenerateStationName(st, tile, STATIONNAMING_OILRIG);
 

	
 
	assert(IsTileType(tile, MP_INDUSTRY));
 
	DeleteAnimatedTile(tile);
 
	MakeOilrig(tile, st->index, GetWaterClass(tile));
 

	
 
	st->owner = OWNER_NONE;
 
	st->airport_flags = 0;
 
	st->airport_type = AT_OILRIG;
 
	st->xy = tile;
 
	st->bus_stops = NULL;
src/viewport.cpp
Show inline comments
 
@@ -1034,58 +1034,58 @@ static void ViewportAddTownNames(DrawPix
 

	
 
	left = dpi->left;
 
	top = dpi->top;
 
	right = left + dpi->width;
 
	bottom = top + dpi->height;
 

	
 
	switch (dpi->zoom) {
 
		case ZOOM_LVL_NORMAL:
 
			FOR_ALL_TOWNS(t) {
 
				if (bottom > t->sign.top &&
 
						top    < t->sign.top + 12 &&
 
						right  > t->sign.left &&
 
						left   < t->sign.left + t->sign.width_1) {
 
						left   < t->sign.left + t->sign.width_normal) {
 
					AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
 
						_settings_client.gui.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
 
						t->index, t->population);
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_2X:
 
			right += 2;
 
			bottom += 2;
 

	
 
			FOR_ALL_TOWNS(t) {
 
				if (bottom > t->sign.top &&
 
						top    < t->sign.top + 24 &&
 
						right  > t->sign.left &&
 
						left   < t->sign.left + t->sign.width_1 * 2) {
 
						left   < t->sign.left + t->sign.width_normal * 2) {
 
					AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
 
						_settings_client.gui.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
 
						t->index, t->population);
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_4X:
 
		case ZOOM_LVL_OUT_8X:
 
			right += ScaleByZoom(1, dpi->zoom);
 
			bottom += ScaleByZoom(1, dpi->zoom) + 1;
 

	
 
			FOR_ALL_TOWNS(t) {
 
				if (bottom > t->sign.top &&
 
						top    < t->sign.top + ScaleByZoom(12, dpi->zoom) &&
 
						right  > t->sign.left &&
 
						left   < t->sign.left + ScaleByZoom(t->sign.width_2, dpi->zoom)) {
 
						left   < t->sign.left + ScaleByZoom(t->sign.width_small, dpi->zoom)) {
 
					AddStringToDraw(t->sign.left + 5, t->sign.top + 1, STR_TOWN_LABEL_TINY_BLACK, t->index, 0);
 
					AddStringToDraw(t->sign.left + 1, t->sign.top - 3, STR_TOWN_LABEL_TINY_WHITE, t->index, 0);
 
				}
 
			}
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 

	
 
static void AddStation(const Station *st, StringID str, uint16 width)
 
@@ -1104,54 +1104,54 @@ static void ViewportAddStationNames(Draw
 

	
 
	left = dpi->left;
 
	top = dpi->top;
 
	right = left + dpi->width;
 
	bottom = top + dpi->height;
 

	
 
	switch (dpi->zoom) {
 
		case ZOOM_LVL_NORMAL:
 
			FOR_ALL_STATIONS(st) {
 
				if (bottom > st->sign.top &&
 
						top    < st->sign.top + 12 &&
 
						right  > st->sign.left &&
 
						left   < st->sign.left + st->sign.width_1) {
 
					AddStation(st, STR_STATION_SIGN, st->sign.width_1);
 
						left   < st->sign.left + st->sign.width_normal) {
 
					AddStation(st, STR_STATION_SIGN, st->sign.width_normal);
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_2X:
 
			right += 2;
 
			bottom += 2;
 
			FOR_ALL_STATIONS(st) {
 
				if (bottom > st->sign.top &&
 
						top    < st->sign.top + 24 &&
 
						right  > st->sign.left &&
 
						left   < st->sign.left + st->sign.width_1 * 2) {
 
					AddStation(st, STR_STATION_SIGN, st->sign.width_1);
 
						left   < st->sign.left + st->sign.width_normal * 2) {
 
					AddStation(st, STR_STATION_SIGN, st->sign.width_normal);
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_4X:
 
		case ZOOM_LVL_OUT_8X:
 
			right += ScaleByZoom(1, dpi->zoom);
 
			bottom += ScaleByZoom(1, dpi->zoom) + 1;
 

	
 
			FOR_ALL_STATIONS(st) {
 
				if (bottom > st->sign.top &&
 
						top    < st->sign.top + ScaleByZoom(12, dpi->zoom) &&
 
						right  > st->sign.left &&
 
						left   < st->sign.left + ScaleByZoom(st->sign.width_2, dpi->zoom)) {
 
					AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_2 | 0x8000);
 
						left   < st->sign.left + ScaleByZoom(st->sign.width_small, dpi->zoom)) {
 
					AddStation(st, STR_STATION_SIGN_TINY, st->sign.width_small | 0x8000);
 
				}
 
			}
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 

	
 
static void AddSign(const Sign *si, StringID str, uint16 width)
 
{
 
	AddStringToDraw(si->sign.left + 1, si->sign.top + 1, str, si->index, 0, (si->owner == OWNER_NONE) ? 14 : _company_colours[si->owner], width);
 
@@ -1168,54 +1168,54 @@ static void ViewportAddSigns(DrawPixelIn
 

	
 
	left = dpi->left;
 
	top = dpi->top;
 
	right = left + dpi->width;
 
	bottom = top + dpi->height;
 

	
 
	switch (dpi->zoom) {
 
		case ZOOM_LVL_NORMAL:
 
			FOR_ALL_SIGNS(si) {
 
				if (bottom > si->sign.top &&
 
						top    < si->sign.top + 12 &&
 
						right  > si->sign.left &&
 
						left   < si->sign.left + si->sign.width_1) {
 
					AddSign(si, STR_SIGN_WHITE, si->sign.width_1);
 
						left   < si->sign.left + si->sign.width_normal) {
 
					AddSign(si, STR_SIGN_WHITE, si->sign.width_normal);
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_2X:
 
			right += 2;
 
			bottom += 2;
 
			FOR_ALL_SIGNS(si) {
 
				if (bottom > si->sign.top &&
 
						top    < si->sign.top + 24 &&
 
						right  > si->sign.left &&
 
						left   < si->sign.left + si->sign.width_1 * 2) {
 
					AddSign(si, STR_SIGN_WHITE, si->sign.width_1);
 
						left   < si->sign.left + si->sign.width_normal * 2) {
 
					AddSign(si, STR_SIGN_WHITE, si->sign.width_normal);
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_4X:
 
		case ZOOM_LVL_OUT_8X:
 
			right += ScaleByZoom(1, dpi->zoom);
 
			bottom += ScaleByZoom(1, dpi->zoom) + 1;
 

	
 
			FOR_ALL_SIGNS(si) {
 
				if (bottom > si->sign.top &&
 
						top    < si->sign.top + ScaleByZoom(12, dpi->zoom) &&
 
						right  > si->sign.left &&
 
						left   < si->sign.left + ScaleByZoom(si->sign.width_2, dpi->zoom)) {
 
					AddSign(si, IsTransparencySet(TO_SIGNS) ? STR_SIGN_SMALL_WHITE : STR_SIGN_SMALL_BLACK, si->sign.width_2 | 0x8000);
 
						left   < si->sign.left + ScaleByZoom(si->sign.width_small, dpi->zoom)) {
 
					AddSign(si, IsTransparencySet(TO_SIGNS) ? STR_SIGN_SMALL_WHITE : STR_SIGN_SMALL_BLACK, si->sign.width_small | 0x8000);
 
				}
 
			}
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 

	
 
static void AddWaypoint(const Waypoint *wp, StringID str, uint16 width)
 
{
 
	AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, str, wp->index, 0, (wp->deleted ? 0xE : _company_colours[wp->owner]), width);
 
@@ -1232,98 +1232,98 @@ static void ViewportAddWaypoints(DrawPix
 

	
 
	left = dpi->left;
 
	top = dpi->top;
 
	right = left + dpi->width;
 
	bottom = top + dpi->height;
 

	
 
	switch (dpi->zoom) {
 
		case ZOOM_LVL_NORMAL:
 
			FOR_ALL_WAYPOINTS(wp) {
 
				if (bottom > wp->sign.top &&
 
						top    < wp->sign.top + 12 &&
 
						right  > wp->sign.left &&
 
						left   < wp->sign.left + wp->sign.width_1) {
 
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
 
						left   < wp->sign.left + wp->sign.width_normal) {
 
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_normal);
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_2X:
 
			right += 2;
 
			bottom += 2;
 
			FOR_ALL_WAYPOINTS(wp) {
 
				if (bottom > wp->sign.top &&
 
						top    < wp->sign.top + 24 &&
 
						right  > wp->sign.left &&
 
						left   < wp->sign.left + wp->sign.width_1 * 2) {
 
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_1);
 
						left   < wp->sign.left + wp->sign.width_normal * 2) {
 
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT, wp->sign.width_normal);
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_4X:
 
		case ZOOM_LVL_OUT_8X:
 
			right += ScaleByZoom(1, dpi->zoom);
 
			bottom += ScaleByZoom(1, dpi->zoom) + 1;
 

	
 
			FOR_ALL_WAYPOINTS(wp) {
 
				if (bottom > wp->sign.top &&
 
						top    < wp->sign.top + ScaleByZoom(12, dpi->zoom) &&
 
						right  > wp->sign.left &&
 
						left   < wp->sign.left + ScaleByZoom(wp->sign.width_2, dpi->zoom)) {
 
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_2 | 0x8000);
 
						left   < wp->sign.left + ScaleByZoom(wp->sign.width_small, dpi->zoom)) {
 
					AddWaypoint(wp, STR_WAYPOINT_VIEWPORT_TINY, wp->sign.width_small | 0x8000);
 
				}
 
			}
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/**
 
 * Update the position of the viewport sign.
 
 * @param center the (preferred) center of the viewport sign
 
 * @param top    the new top of the sign
 
 * @param str    the string to show in the sign
 
 */
 
void ViewportSign::UpdatePosition(int center, int top, StringID str)
 
{
 
	this->top = top;
 

	
 
	char buffer[DRAW_STRING_BUFFER];
 

	
 
	GetString(buffer, str, lastof(buffer));
 
	this->width_1 = GetStringBoundingBox(buffer).width + 3;
 
	this->left = center - this->width_1 / 2;
 
	this->width_normal = GetStringBoundingBox(buffer).width + 3;
 
	this->left = center - this->width_normal / 2;
 

	
 
	/* zoomed out version */
 
	_cur_fontsize = FS_SMALL;
 
	this->width_2 = GetStringBoundingBox(buffer).width + 3;
 
	this->width_small = GetStringBoundingBox(buffer).width + 3;
 
	_cur_fontsize = FS_NORMAL;
 
}
 

	
 
/**
 
 * Mark the sign dirty in all viewports.
 
 *
 
 * @ingroup dirty
 
 */
 
void ViewportSign::MarkDirty() const
 
{
 
	/* We use ZOOM_LVL_MAX here, as every viewport can have an other zoom,
 
	 *  and there is no way for us to know which is the biggest. So make the
 
	 *  biggest area dirty, and we are safe for sure. */
 
	MarkAllViewportsDirty(
 
		this->left - 6,
 
		this->top  - 3,
 
		this->left + ScaleByZoom(this->width_1 + 12, ZOOM_LVL_MAX),
 
		this->left + ScaleByZoom(this->width_normal + 12, ZOOM_LVL_MAX),
 
		this->top  + ScaleByZoom(12, ZOOM_LVL_MAX));
 
}
 

	
 
static void ViewportDrawTileSprites(const TileSpriteToDrawVector *tstdv)
 
{
 
	const TileSpriteToDraw *tsend = tstdv->End();
 
	for (const TileSpriteToDraw *ts = tstdv->Begin(); ts != tsend; ++ts) {
 
		DrawSprite(ts->image, ts->pal, ts->x, ts->y, ts->sub);
 
	}
 
}
 

	
 
/** Sort parent sprites pointer array */
 
@@ -1836,55 +1836,55 @@ static bool CheckClickOnTown(const ViewP
 
	const Town *t;
 

	
 
	if (!HasBit(_display_opt, DO_SHOW_TOWN_NAMES)) return false;
 

	
 
	switch (vp->zoom) {
 
		case ZOOM_LVL_NORMAL:
 
			x = x - vp->left + vp->virtual_left;
 
			y = y - vp->top  + vp->virtual_top;
 
			FOR_ALL_TOWNS(t) {
 
				if (y >= t->sign.top &&
 
						y < t->sign.top + 12 &&
 
						x >= t->sign.left &&
 
						x < t->sign.left + t->sign.width_1) {
 
						x < t->sign.left + t->sign.width_normal) {
 
					ShowTownViewWindow(t->index);
 
					return true;
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_2X:
 
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
 
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
 
			FOR_ALL_TOWNS(t) {
 
				if (y >= t->sign.top &&
 
						y < t->sign.top + 24 &&
 
						x >= t->sign.left &&
 
						x < t->sign.left + t->sign.width_1 * 2) {
 
						x < t->sign.left + t->sign.width_normal * 2) {
 
					ShowTownViewWindow(t->index);
 
					return true;
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_4X:
 
		case ZOOM_LVL_OUT_8X:
 
			x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left;
 
			y = ScaleByZoom(y - vp->top  + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top;
 

	
 
			FOR_ALL_TOWNS(t) {
 
				if (y >= t->sign.top &&
 
						y < t->sign.top + ScaleByZoom(12, vp->zoom) &&
 
						x >= t->sign.left &&
 
						x < t->sign.left + ScaleByZoom(t->sign.width_2, vp->zoom)) {
 
						x < t->sign.left + ScaleByZoom(t->sign.width_small, vp->zoom)) {
 
					ShowTownViewWindow(t->index);
 
					return true;
 
				}
 
			}
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 

	
 
	return false;
 
}
 

	
 
@@ -1894,55 +1894,55 @@ static bool CheckClickOnStation(const Vi
 
	const Station *st;
 

	
 
	if (!HasBit(_display_opt, DO_SHOW_STATION_NAMES) || IsInvisibilitySet(TO_SIGNS)) return false;
 

	
 
	switch (vp->zoom) {
 
		case ZOOM_LVL_NORMAL:
 
			x = x - vp->left + vp->virtual_left;
 
			y = y - vp->top  + vp->virtual_top;
 
			FOR_ALL_STATIONS(st) {
 
				if (y >= st->sign.top &&
 
						y < st->sign.top + 12 &&
 
						x >= st->sign.left &&
 
						x < st->sign.left + st->sign.width_1) {
 
						x < st->sign.left + st->sign.width_normal) {
 
					ShowStationViewWindow(st->index);
 
					return true;
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_2X:
 
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
 
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
 
			FOR_ALL_STATIONS(st) {
 
				if (y >= st->sign.top &&
 
						y < st->sign.top + 24 &&
 
						x >= st->sign.left &&
 
						x < st->sign.left + st->sign.width_1 * 2) {
 
						x < st->sign.left + st->sign.width_normal * 2) {
 
					ShowStationViewWindow(st->index);
 
					return true;
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_4X:
 
		case ZOOM_LVL_OUT_8X:
 
			x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left;
 
			y = ScaleByZoom(y - vp->top  + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top;
 

	
 
			FOR_ALL_STATIONS(st) {
 
				if (y >= st->sign.top &&
 
						y < st->sign.top + ScaleByZoom(12, vp->zoom) &&
 
						x >= st->sign.left &&
 
						x < st->sign.left + ScaleByZoom(st->sign.width_2, vp->zoom)) {
 
						x < st->sign.left + ScaleByZoom(st->sign.width_small, vp->zoom)) {
 
					ShowStationViewWindow(st->index);
 
					return true;
 
				}
 
			}
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 

	
 
	return false;
 
}
 

	
 
@@ -1953,55 +1953,55 @@ static bool CheckClickOnSign(const ViewP
 

	
 
	/* Signs are turned off, or they are transparent and invisibility is ON, or company is a spectator */
 
	if (!HasBit(_display_opt, DO_SHOW_SIGNS) || IsInvisibilitySet(TO_SIGNS) || _current_company == COMPANY_SPECTATOR) return false;
 

	
 
	switch (vp->zoom) {
 
		case ZOOM_LVL_NORMAL:
 
			x = x - vp->left + vp->virtual_left;
 
			y = y - vp->top  + vp->virtual_top;
 
			FOR_ALL_SIGNS(si) {
 
				if (y >= si->sign.top &&
 
						y <  si->sign.top + 12 &&
 
						x >= si->sign.left &&
 
						x <  si->sign.left + si->sign.width_1) {
 
						x <  si->sign.left + si->sign.width_normal) {
 
					HandleClickOnSign(si);
 
					return true;
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_2X:
 
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
 
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
 
			FOR_ALL_SIGNS(si) {
 
				if (y >= si->sign.top &&
 
						y <  si->sign.top + 24 &&
 
						x >= si->sign.left &&
 
						x <  si->sign.left + si->sign.width_1 * 2) {
 
						x <  si->sign.left + si->sign.width_normal * 2) {
 
					HandleClickOnSign(si);
 
					return true;
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_4X:
 
		case ZOOM_LVL_OUT_8X:
 
			x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left;
 
			y = ScaleByZoom(y - vp->top  + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top;
 

	
 
			FOR_ALL_SIGNS(si) {
 
				if (y >= si->sign.top &&
 
						y <  si->sign.top + ScaleByZoom(12, vp->zoom) &&
 
						x >= si->sign.left &&
 
						x <  si->sign.left + ScaleByZoom(si->sign.width_2, vp->zoom)) {
 
						x <  si->sign.left + ScaleByZoom(si->sign.width_small, vp->zoom)) {
 
					HandleClickOnSign(si);
 
					return true;
 
				}
 
			}
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 

	
 
	return false;
 
}
 

	
 
@@ -2011,55 +2011,55 @@ static bool CheckClickOnWaypoint(const V
 
	const Waypoint *wp;
 

	
 
	if (!HasBit(_display_opt, DO_WAYPOINTS) || IsInvisibilitySet(TO_SIGNS)) return false;
 

	
 
	switch (vp->zoom) {
 
		case ZOOM_LVL_NORMAL:
 
			x = x - vp->left + vp->virtual_left;
 
			y = y - vp->top  + vp->virtual_top;
 
			FOR_ALL_WAYPOINTS(wp) {
 
				if (y >= wp->sign.top &&
 
						y < wp->sign.top + 12 &&
 
						x >= wp->sign.left &&
 
						x < wp->sign.left + wp->sign.width_1) {
 
						x < wp->sign.left + wp->sign.width_normal) {
 
					ShowWaypointWindow(wp);
 
					return true;
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_2X:
 
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
 
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
 
			FOR_ALL_WAYPOINTS(wp) {
 
				if (y >= wp->sign.top &&
 
						y < wp->sign.top + 24 &&
 
						x >= wp->sign.left &&
 
						x < wp->sign.left + wp->sign.width_1 * 2) {
 
						x < wp->sign.left + wp->sign.width_normal * 2) {
 
					ShowWaypointWindow(wp);
 
					return true;
 
				}
 
			}
 
			break;
 

	
 
		case ZOOM_LVL_OUT_4X:
 
		case ZOOM_LVL_OUT_8X:
 
			x = ScaleByZoom(x - vp->left + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_left;
 
			y = ScaleByZoom(y - vp->top  + ScaleByZoom(1, vp->zoom) - 1, vp->zoom) + vp->virtual_top;
 

	
 
			FOR_ALL_WAYPOINTS(wp) {
 
				if (y >= wp->sign.top &&
 
						y < wp->sign.top + ScaleByZoom(12, vp->zoom) &&
 
						x >= wp->sign.left &&
 
						x < wp->sign.left + ScaleByZoom(wp->sign.width_2, vp->zoom)) {
 
						x < wp->sign.left + ScaleByZoom(wp->sign.width_small, vp->zoom)) {
 
					ShowWaypointWindow(wp);
 
					return true;
 
				}
 
			}
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 

	
 
	return false;
 
}
 

	
src/viewport_type.h
Show inline comments
 
@@ -16,28 +16,30 @@ struct ViewPort {
 
	int top;     ///< Screen coordinate top edge of the viewport
 
	int width;   ///< Screen width of the viewport
 
	int height;  ///< Screen height of the viewport
 

	
 
	int virtual_left;    ///< Virtual left coordinate
 
	int virtual_top;     ///< Virtual top coordinate
 
	int virtual_width;   ///< width << zoom
 
	int virtual_height;  ///< height << zoom
 

	
 
	ZoomLevel zoom;
 
};
 

	
 
/** Location information about a sign as seen on the viewport */
 
struct ViewportSign {
 
	int32 left;
 
	int32 top;
 
	uint16 width_1, width_2;
 
	int32 left; ///< The left most position of the sign
 
	int32 top;  ///< THe top of the sign
 
	uint16 width_normal; ///< The width when not zoomed out (normal font)
 
	uint16 width_small;  ///< The width when zoomed out (small font)
 

	
 
	void UpdatePosition(int center, int top, StringID str);
 
	void MarkDirty() const;
 
};
 

	
 
enum {
 
	ZOOM_IN   = 0,
 
	ZOOM_OUT  = 1,
 
	ZOOM_NONE = 2, // hack, used to update the button status
 
};
 

	
 
/**
0 comments (0 inline, 0 general)