Changeset - r12334:57fa457522c9
[Not reviewed]
master
0 13 0
rubidium - 15 years ago 2009-07-08 08:30:35
rubidium@openttd.org
(svn r16764) -Codechange: unify the way viewport signs are marked dirty
13 files changed with 38 insertions and 80 deletions:
0 comments (0 inline, 0 general)
src/functions.h
Show inline comments
 
@@ -29,18 +29,12 @@ void InitializeLandscapeVariables(bool o
 
 * Mark a tile given by its index dirty for repaint.
 
 *
 
 * @ingroup dirty
 
 */
 
void MarkTileDirtyByTile(TileIndex tile);
 

	
 
/**
 
 * Mark all viewports dirty for repaint.
 
 *
 
 * @ingroup dirty
 
 */
 
void MarkAllViewportsDirty(int left, int top, int right, int bottom);
 
void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost);
 
void ShowFeederIncomeAnimation(int x, int y, int z, Money cost);
 

	
 
void AskExitGame();
 
void AskExitToGameMenu();
 

	
src/lang/unfinished/vietnamese.txt
Show inline comments
 
##name Vietnamese (VI)
 
##ownname Vietnamese (VI)
 
##name Vietnamese
 
##ownname Vietnamese
 
##isocode vi_VN
 
##winlangid 0x042a
 
##grflangid 0x54
 
##plural 0
 

	
 
#
src/signs.cpp
Show inline comments
 
@@ -51,32 +51,12 @@ void UpdateAllSignVirtCoords()
 
	Sign *si;
 

	
 
	FOR_ALL_SIGNS(si) UpdateSignVirtCoords(si);
 
}
 

	
 
/**
 
 * Marks the region of a sign as dirty.
 
 *
 
 * This function marks the sign in all viewports as dirty for repaint.
 
 *
 
 * @param si Pointer to the Sign
 
 * @ingroup dirty
 
 */
 
void MarkSignDirty(Sign *si)
 
{
 
	/* 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(
 
		si->sign.left - 6,
 
		si->sign.top  - 3,
 
		si->sign.left + ScaleByZoom(si->sign.width_1 + 12, ZOOM_LVL_MAX),
 
		si->sign.top  + ScaleByZoom(12, ZOOM_LVL_MAX));
 
}
 

	
 
/**
 
 *
 
 * Initialize the signs
 
 *
 
 */
 
void InitializeSigns()
 
{
src/signs_cmd.cpp
Show inline comments
 
@@ -44,13 +44,13 @@ CommandCost CmdPlaceSign(TileIndex tile,
 
		si->y = y;
 
		si->z = GetSlopeZ(x, y);
 
		if (!StrEmpty(text)) {
 
			si->name = strdup(text);
 
		}
 
		UpdateSignVirtCoords(si);
 
		MarkSignDirty(si);
 
		si->sign.MarkDirty();
 
		InvalidateWindowData(WC_SIGN_LIST, 0, 0);
 
		_new_sign_id = si->index;
 
	}
 

	
 
	return CommandCost();
 
}
 
@@ -77,21 +77,21 @@ CommandCost CmdRenameSign(TileIndex tile
 
			/* Delete the old name */
 
			free(si->name);
 
			/* Assign the new one */
 
			si->name = strdup(text);
 
			si->owner = _current_company;
 

	
 
			/* Update; mark sign dirty twice, because it can either becom longer, or shorter */
 
			MarkSignDirty(si);
 
			/* Update; mark sign dirty twice, because it can either become longer, or shorter */
 
			si->sign.MarkDirty();
 
			UpdateSignVirtCoords(si);
 
			MarkSignDirty(si);
 
			si->sign.MarkDirty();
 
			InvalidateWindowData(WC_SIGN_LIST, 0, 1);
 
		}
 
	} else { // Delete sign
 
		if (flags & DC_EXEC) {
 
			MarkSignDirty(si);
 
			si->sign.MarkDirty();
 
			delete si;
 

	
 
			InvalidateWindowData(WC_SIGN_LIST, 0, 0);
 
		}
 
	}
 

	
src/signs_func.h
Show inline comments
 
@@ -8,13 +8,12 @@
 
#include "signs_type.h"
 

	
 
extern SignID _new_sign_id;
 

	
 
void UpdateAllSignVirtCoords();
 
void PlaceProc_Sign(TileIndex tile);
 
void MarkSignDirty(Sign *si);
 
void UpdateSignVirtCoords(Sign *si);
 

	
 
/* signs_gui.cpp */
 
void ShowRenameSignWindow(const Sign *si);
 
void HandleClickOnSign(const Sign *si);
 
void DeleteRenameSignWindow(SignID sign);
src/station.cpp
Show inline comments
 
@@ -152,21 +152,13 @@ void Station::AddFacility(StationFacilit
 
}
 

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

	
 
		/* 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->sign.left - 6,
 
			this->sign.top,
 
			this->sign.left + ScaleByZoom(this->sign.width_1 + 12, ZOOM_LVL_MAX),
 
			this->sign.top + ScaleByZoom(12, ZOOM_LVL_MAX));
 
		this->sign.MarkDirty();
 
	}
 
}
 

	
 
void Station::MarkTilesDirty(bool cargo_change) const
 
{
 
	TileIndex tile = this->train_tile;
src/town_cmd.cpp
Show inline comments
 
@@ -319,43 +319,25 @@ static bool IsCloseToTown(TileIndex tile
 
		if (DistanceManhattan(tile, t->xy) < dist) return true;
 
	}
 
	return false;
 
}
 

	
 
/**
 
 * Marks the town sign as needing a repaint.
 
 *
 
 * This function marks the area of the sign of a town as dirty for repaint.
 
 *
 
 * @param t Town requesting town sign for repaint
 
 * @ingroup dirty
 
 */
 
static void MarkTownSignDirty(Town *t)
 
{
 
	MarkAllViewportsDirty(
 
		t->sign.left - 6,
 
		t->sign.top - 3,
 
		t->sign.left + t->sign.width_1 * 4 + 12,
 
		t->sign.top + 45
 
	);
 
}
 

	
 
/**
 
 * Resize the sign(label) of the town after changes in
 
 * population (creation or growth or else)
 
 * @param t Town to update
 
 */
 
void UpdateTownVirtCoord(Town *t)
 
{
 
	MarkTownSignDirty(t);
 
	t->sign.MarkDirty();
 
	Point pt = RemapCoords2(TileX(t->xy) * TILE_SIZE, TileY(t->xy) * TILE_SIZE);
 
	SetDParam(0, t->index);
 
	SetDParam(1, t->population);
 
	t->sign.UpdatePosition(pt.x, pt.y - 24,
 
		_settings_client.gui.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL);
 
	MarkTownSignDirty(t);
 
	t->sign.MarkDirty();
 
}
 

	
 
/** Update the virtual coords needed to draw the town sign for all towns. */
 
void UpdateAllTownVirtCoords()
 
{
 
	Town *t;
src/viewport.cpp
Show inline comments
 
@@ -1298,12 +1298,28 @@ void ViewportSign::UpdatePosition(int ce
 
	/* zoomed out version */
 
	_cur_fontsize = FS_SMALL;
 
	this->width_2 = 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->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);
src/viewport_func.h
Show inline comments
 
@@ -16,12 +16,19 @@ void SetSelectionRed(bool);
 
void DeleteWindowViewport(Window *w);
 
void InitializeWindowViewport(Window *w, int x, int y, int width, int height, uint32 follow_flags, ZoomLevel zoom);
 
ViewPort *IsPtInWindowViewport(const Window *w, int x, int y);
 
Point GetTileBelowCursor();
 
void UpdateViewportPosition(Window *w);
 

	
 
/**
 
 * Mark all viewports dirty for repaint.
 
 *
 
 * @ingroup dirty
 
 */
 
void MarkAllViewportsDirty(int left, int top, int right, int bottom);
 

	
 
bool DoZoomInOutWindow(int how, Window *w);
 
void ZoomInOrOutToCursorWindow(bool in, Window * w);
 
Point GetTileZoomCenterWindow(bool in, Window * w);
 
void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out);
 

	
 
static inline void MaxZoomInOut(int how, Window *w)
src/viewport_type.h
Show inline comments
 
@@ -28,12 +28,13 @@ struct ViewPort {
 
struct ViewportSign {
 
	int32 left;
 
	int32 top;
 
	uint16 width_1, width_2;
 

	
 
	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
src/waypoint.cpp
Show inline comments
 
@@ -85,13 +85,13 @@ Waypoint::~Waypoint()
 
	free(this->name);
 

	
 
	if (CleaningPool()) return;
 
	DeleteWindowById(WC_WAYPOINT_VIEW, this->index);
 
	RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index);
 

	
 
	RedrawWaypointSign(this);
 
	this->sign.MarkDirty();
 
}
 

	
 
void InitializeWaypoints()
 
{
 
	_waypoint_pool.CleanPool();
 
}
src/waypoint.h
Show inline comments
 
@@ -57,9 +57,8 @@ static inline Waypoint *GetWaypointByTil
 
CommandCost RemoveTrainWaypoint(TileIndex tile, DoCommandFlag flags, bool justremove);
 
Station *ComposeWaypointStation(TileIndex tile);
 
void ShowWaypointWindow(const Waypoint *wp);
 
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype);
 
void UpdateAllWaypointSigns();
 
void UpdateWaypointSign(Waypoint *wp);
 
void RedrawWaypointSign(const Waypoint *wp);
 

	
 
#endif /* WAYPOINT_H */
src/waypoint_cmd.cpp
Show inline comments
 
@@ -33,24 +33,12 @@ void UpdateWaypointSign(Waypoint *wp)
 
	Point pt = RemapCoords2(TileX(wp->xy) * TILE_SIZE, TileY(wp->xy) * TILE_SIZE);
 
	SetDParam(0, wp->index);
 
	wp->sign.UpdatePosition(pt.x, pt.y - 0x20, STR_WAYPOINT_VIEWPORT);
 
}
 

	
 
/**
 
 * Redraw the sign of a waypoint
 
 * @param wp Waypoint to redraw sign */
 
void RedrawWaypointSign(const Waypoint *wp)
 
{
 
	MarkAllViewportsDirty(
 
		wp->sign.left - 6,
 
		wp->sign.top,
 
		wp->sign.left + (wp->sign.width_1 << 2) + 12,
 
		wp->sign.top + 48);
 
}
 

	
 
/**
 
 * Set the default name for a waypoint
 
 * @param wp Waypoint to work on
 
 */
 
static void MakeDefaultWaypointName(Waypoint *wp)
 
{
 
	uint32 used = 0; // bitmap of used waypoint numbers, sliding window with 'next' as base
 
@@ -189,13 +177,13 @@ CommandCost CmdBuildTrainWaypoint(TileIn
 
				if (v->First() == v && v->current_order.IsType(OT_GOTO_WAYPOINT) &&
 
						v->dest_tile == wp->xy) {
 
					v->dest_tile = tile;
 
				}
 
			}
 

	
 
			RedrawWaypointSign(wp);
 
			wp->sign.MarkDirty();
 
			wp->xy = tile;
 
			InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
 
		}
 
		wp->owner = owner;
 

	
 
		const StationSpec *statspec;
 
@@ -221,13 +209,13 @@ CommandCost CmdBuildTrainWaypoint(TileIn
 
		wp->deleted = 0;
 
		wp->build_date = _date;
 

	
 
		if (wp->town_index == INVALID_TOWN) MakeDefaultWaypointName(wp);
 

	
 
		UpdateWaypointSign(wp);
 
		RedrawWaypointSign(wp);
 
		wp->sign.MarkDirty();
 
		YapfNotifyTrackLayoutChange(tile, AxisToTrack(axis));
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_train_depot);
 
}
 

	
 
@@ -251,13 +239,13 @@ CommandCost RemoveTrainWaypoint(TileInde
 

	
 
	if (flags & DC_EXEC) {
 
		Track track = GetRailWaypointTrack(tile);
 
		wp = GetWaypointByTile(tile);
 

	
 
		wp->deleted = 30; // let it live for this many days before we do the actual deletion.
 
		RedrawWaypointSign(wp);
 
		wp->sign.MarkDirty();
 

	
 
		Train *v = NULL;
 
		if (justremove) {
 
			TrackBits tracks = GetRailWaypointBits(tile);
 
			bool reserved = GetDepotWaypointReservation(tile);
 
			MakeRailNormal(tile, wp->owner, tracks, GetRailType(tile));
0 comments (0 inline, 0 general)