From 3086383cdc7087b46ebcd9320c300ea6ba67ec7a Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 7 Jul 2009 16:51:20 +0000 Subject: (svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign --- src/signs.cpp | 2 +- src/station_cmd.cpp | 2 +- src/town_cmd.cpp | 2 +- src/viewport.cpp | 21 ++++++++++++--------- src/viewport_func.h | 2 -- src/viewport_type.h | 3 +++ src/waypoint_cmd.cpp | 2 +- 7 files changed, 19 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/signs.cpp b/src/signs.cpp index 3da538a71..3102d7973 100644 --- a/src/signs.cpp +++ b/src/signs.cpp @@ -42,7 +42,7 @@ void UpdateSignVirtCoords(Sign *si) { Point pt = RemapCoords(si->x, si->y, si->z); SetDParam(0, si->index); - UpdateViewportSignPos(&si->sign, pt.x, pt.y - 6, STR_SIGN_WHITE); + si->sign.UpdatePosition(pt.x, pt.y - 6, STR_SIGN_WHITE); } /** Update the coordinates of all signs */ diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 331de8856..cde7a4ee6 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -380,7 +380,7 @@ void Station::UpdateVirtCoord() SetDParam(0, this->index); SetDParam(1, this->facilities); - UpdateViewportSignPos(&this->sign, pt.x, pt.y, STR_STATION_SIGN); + this->sign.UpdatePosition(pt.x, pt.y, STR_STATION_SIGN); } /** Update the virtual coords needed to draw the station sign for all stations. */ diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index aaebfabaf..6a09c8a7e 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -350,7 +350,7 @@ void UpdateTownVirtCoord(Town *t) Point pt = RemapCoords2(TileX(t->xy) * TILE_SIZE, TileY(t->xy) * TILE_SIZE); SetDParam(0, t->index); SetDParam(1, t->population); - UpdateViewportSignPos(&t->sign, pt.x, pt.y - 24, + t->sign.UpdatePosition(pt.x, pt.y - 24, _settings_client.gui.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL); MarkTownSignDirty(t); } diff --git a/src/viewport.cpp b/src/viewport.cpp index bf3014bde..fa1f746a6 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1279,23 +1279,26 @@ static void ViewportAddWaypoints(DrawPixelInfo *dpi) } } -void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str) +/** + * 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) { - char buffer[256]; - uint w; + this->top = top; - sign->top = top; + char buffer[DRAW_STRING_BUFFER]; GetString(buffer, str, lastof(buffer)); - w = GetStringBoundingBox(buffer).width + 3; - sign->width_1 = w; - sign->left = left - w / 2; + this->width_1 = GetStringBoundingBox(buffer).width + 3; + this->left = center - this->width_1 / 2; /* zoomed out version */ _cur_fontsize = FS_SMALL; - w = GetStringBoundingBox(buffer).width + 3; + this->width_2 = GetStringBoundingBox(buffer).width + 3; _cur_fontsize = FS_NORMAL; - sign->width_2 = w; } diff --git a/src/viewport_func.h b/src/viewport_func.h index 601c5a574..bce5b002f 100644 --- a/src/viewport_func.h +++ b/src/viewport_func.h @@ -8,7 +8,6 @@ #include "gfx_type.h" #include "viewport_type.h" #include "vehicle_type.h" -#include "strings_type.h" #include "window_type.h" #include "tile_type.h" @@ -19,7 +18,6 @@ void InitializeWindowViewport(Window *w, int x, int y, int width, int height, ui ViewPort *IsPtInWindowViewport(const Window *w, int x, int y); Point GetTileBelowCursor(); void UpdateViewportPosition(Window *w); -void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str); bool DoZoomInOutWindow(int how, Window *w); void ZoomInOrOutToCursorWindow(bool in, Window * w); diff --git a/src/viewport_type.h b/src/viewport_type.h index 6822339cc..d00509eb5 100644 --- a/src/viewport_type.h +++ b/src/viewport_type.h @@ -6,6 +6,7 @@ #define VIEWPORT_TYPE_H #include "zoom_type.h" +#include "strings_type.h" /** * Data structure for viewport, display of a part of the world @@ -28,6 +29,8 @@ struct ViewportSign { int32 left; int32 top; uint16 width_1, width_2; + + void UpdatePosition(int center, int top, StringID str); }; enum { diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 8267bbd67..cb0129f43 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -32,7 +32,7 @@ void UpdateWaypointSign(Waypoint *wp) { Point pt = RemapCoords2(TileX(wp->xy) * TILE_SIZE, TileY(wp->xy) * TILE_SIZE); SetDParam(0, wp->index); - UpdateViewportSignPos(&wp->sign, pt.x, pt.y - 0x20, STR_WAYPOINT_VIEWPORT); + wp->sign.UpdatePosition(pt.x, pt.y - 0x20, STR_WAYPOINT_VIEWPORT); } /** -- cgit v1.2.3-70-g09d2