(svn r16761) -Codechange: make UpdateViewportSignPos(ition) a class function of ViewportSign

pull/155/head
rubidium 15 years ago
parent 52abc92d1f
commit 4989b4afb9

@ -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 */

@ -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. */

@ -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);
}

@ -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;
}

@ -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);

@ -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 {

@ -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);
}
/**

Loading…
Cancel
Save