summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-07-07 16:51:20 +0000
committerrubidium <rubidium@openttd.org>2009-07-07 16:51:20 +0000
commit3086383cdc7087b46ebcd9320c300ea6ba67ec7a (patch)
treea455fb825d1db26aaa259eaae03ac95b000f0fca /src
parentfbb2fb97206771cc3d54a3e2f43f6fc098f0c557 (diff)
downloadopenttd-3086383cdc7087b46ebcd9320c300ea6ba67ec7a.tar.xz
(svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign
Diffstat (limited to 'src')
-rw-r--r--src/signs.cpp2
-rw-r--r--src/station_cmd.cpp2
-rw-r--r--src/town_cmd.cpp2
-rw-r--r--src/viewport.cpp21
-rw-r--r--src/viewport_func.h2
-rw-r--r--src/viewport_type.h3
-rw-r--r--src/waypoint_cmd.cpp2
7 files changed, 19 insertions, 15 deletions
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);
}
/**