summaryrefslogtreecommitdiff
path: root/src/viewport.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2011-11-24 12:38:48 +0000
committerpeter1138 <peter1138@openttd.org>2011-11-24 12:38:48 +0000
commit81598273e9b6bb2ee20ebdd82f3d4646a02999ba (patch)
tree2d13cc93dc84f2d99cff6fc2bb02214d4453f033 /src/viewport.cpp
parent15d0a22aac6b90a2055e68d019cab4350376a8fd (diff)
downloadopenttd-81598273e9b6bb2ee20ebdd82f3d4646a02999ba.tar.xz
(svn r23316) -Feature: Add ability to zoom in to 2x and 4x level.
Diffstat (limited to 'src/viewport.cpp')
-rw-r--r--src/viewport.cpp60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/viewport.cpp b/src/viewport.cpp
index b42acfdfc..56b2941aa 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -377,8 +377,8 @@ static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y)
return pt;
}
- x = (ScaleByZoom(x, vp->zoom) + vp->virtual_left) >> 2;
- y = (ScaleByZoom(y, vp->zoom) + vp->virtual_top) >> 1;
+ x = (ScaleByZoom(x, vp->zoom) + vp->virtual_left) >> (2 + ZOOM_LVL_SHIFT);
+ y = (ScaleByZoom(y, vp->zoom) + vp->virtual_top) >> (1 + ZOOM_LVL_SHIFT);
a = y - x;
b = y + x;
@@ -539,9 +539,9 @@ void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32 x, int32 y, int z,
if (_vd.foundation[_vd.foundation_part] != -1) {
Point pt = RemapCoords(x, y, z);
- AddChildSpriteToFoundation(image, pal, sub, _vd.foundation_part, pt.x + extra_offs_x, pt.y + extra_offs_y);
+ AddChildSpriteToFoundation(image, pal, sub, _vd.foundation_part, pt.x + extra_offs_x * ZOOM_LVL_BASE, pt.y + extra_offs_y * ZOOM_LVL_BASE);
} else {
- AddTileSpriteToDraw(image, pal, _cur_ti->x + x, _cur_ti->y + y, _cur_ti->z + z, sub, extra_offs_x, extra_offs_y);
+ AddTileSpriteToDraw(image, pal, _cur_ti->x + x, _cur_ti->y + y, _cur_ti->z + z, sub, extra_offs_x * ZOOM_LVL_BASE, extra_offs_y * ZOOM_LVL_BASE);
}
}
@@ -583,8 +583,8 @@ void OffsetGroundSprite(int x, int y)
/* _vd.last_child == NULL if foundation sprite was clipped by the viewport bounds */
if (_vd.last_child != NULL) _vd.foundation[_vd.foundation_part] = _vd.parent_sprites_to_draw.Length() - 1;
- _vd.foundation_offset[_vd.foundation_part].x = x;
- _vd.foundation_offset[_vd.foundation_part].y = y;
+ _vd.foundation_offset[_vd.foundation_part].x = x * ZOOM_LVL_BASE;
+ _vd.foundation_offset[_vd.foundation_part].y = y * ZOOM_LVL_BASE;
_vd.last_foundation_child[_vd.foundation_part] = _vd.last_child;
}
@@ -858,7 +858,7 @@ static void DrawSelectionSprite(SpriteID image, PaletteID pal, const TileInfo *t
AddTileSpriteToDraw(image, pal, ti->x, ti->y, ti->z + z_offset);
} else {
/* draw on top of foundation */
- AddChildSpriteToFoundation(image, pal, NULL, foundation_part, 0, -z_offset);
+ AddChildSpriteToFoundation(image, pal, NULL, foundation_part, 0, -z_offset * ZOOM_LVL_BASE);
}
}
@@ -1040,14 +1040,14 @@ static void ViewportAddLandscape()
_cur_ti = &ti;
/* Transform into tile coordinates and round to closest full tile */
- x = ((_vd.dpi.top >> 1) - (_vd.dpi.left >> 2)) & ~TILE_UNIT_MASK;
- y = ((_vd.dpi.top >> 1) + (_vd.dpi.left >> 2) - TILE_SIZE) & ~TILE_UNIT_MASK;
+ x = ((_vd.dpi.top >> (1 + ZOOM_LVL_SHIFT)) - (_vd.dpi.left >> (2 + ZOOM_LVL_SHIFT))) & ~TILE_UNIT_MASK;
+ y = ((_vd.dpi.top >> (1 + ZOOM_LVL_SHIFT)) + (_vd.dpi.left >> (2 + ZOOM_LVL_SHIFT)) - TILE_SIZE) & ~TILE_UNIT_MASK;
/* determine size of area */
{
Point pt = RemapCoords(x, y, 241);
- width = (_vd.dpi.left + _vd.dpi.width - pt.x + 95) >> 6;
- height = (_vd.dpi.top + _vd.dpi.height - pt.y) >> 5 << 1;
+ width = (_vd.dpi.left + _vd.dpi.width - pt.x + 95 * ZOOM_LVL_BASE) >> (6 + ZOOM_LVL_SHIFT);
+ height = (_vd.dpi.top + _vd.dpi.height - pt.y) >> (5 + ZOOM_LVL_SHIFT) << 1;
}
assert(width > 0);
@@ -1166,7 +1166,7 @@ static void ViewportAddTownNames(DrawPixelInfo *dpi)
const Town *t;
FOR_ALL_TOWNS(t) {
- ViewportAddString(dpi, ZOOM_LVL_OUT_4X, &t->sign,
+ ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &t->sign,
_settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_VIEWPORT_TOWN,
STR_VIEWPORT_TOWN_TINY_WHITE, STR_VIEWPORT_TOWN_TINY_BLACK,
t->index, t->population);
@@ -1189,7 +1189,7 @@ static void ViewportAddStationNames(DrawPixelInfo *dpi)
/* Don't draw if station is owned by another company and competitor station names are hidden. Stations owned by none are never ignored. */
if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && _local_company != st->owner && st->owner != OWNER_NONE) continue;
- ViewportAddString(dpi, ZOOM_LVL_OUT_4X, &st->sign,
+ ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &st->sign,
is_station ? STR_VIEWPORT_STATION : STR_VIEWPORT_WAYPOINT,
(is_station ? STR_VIEWPORT_STATION : STR_VIEWPORT_WAYPOINT) + 1, STR_NULL,
st->index, st->facilities, (st->owner == OWNER_NONE || !st->IsInUse()) ? COLOUR_GREY : _company_colours[st->owner]);
@@ -1209,7 +1209,7 @@ static void ViewportAddSigns(DrawPixelInfo *dpi)
* companies can leave OWNER_NONE signs after them. */
if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && _local_company != si->owner) continue;
- ViewportAddString(dpi, ZOOM_LVL_OUT_4X, &si->sign,
+ ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &si->sign,
STR_WHITE_SIGN,
IsTransparencySet(TO_SIGNS) ? STR_VIEWPORT_SIGN_SMALL_WHITE : STR_VIEWPORT_SIGN_SMALL_BLACK, STR_NULL,
si->index, 0, (si->owner == OWNER_NONE) ? COLOUR_GREY : _company_colours[si->owner]);
@@ -1262,7 +1262,7 @@ 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);
+ DrawSpriteViewport(ts->image, ts->pal, ts->x, ts->y, ts->sub);
}
}
@@ -1329,13 +1329,13 @@ static void ViewportDrawParentSprites(const ParentSpriteToSortVector *psd, const
const ParentSpriteToDraw * const *psd_end = psd->End();
for (const ParentSpriteToDraw * const *it = psd->Begin(); it != psd_end; it++) {
const ParentSpriteToDraw *ps = *it;
- if (ps->image != SPR_EMPTY_BOUNDING_BOX) DrawSprite(ps->image, ps->pal, ps->x, ps->y, ps->sub);
+ if (ps->image != SPR_EMPTY_BOUNDING_BOX) DrawSpriteViewport(ps->image, ps->pal, ps->x, ps->y, ps->sub);
int child_idx = ps->first_child;
while (child_idx >= 0) {
const ChildScreenSpriteToDraw *cs = csstdv->Get(child_idx);
child_idx = cs->next;
- DrawSprite(cs->image, cs->pal, ps->left + cs->x, ps->top + cs->y, cs->sub);
+ DrawSpriteViewport(cs->image, cs->pal, ps->left + cs->x, ps->top + cs->y, cs->sub);
}
}
}
@@ -1475,7 +1475,7 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom
*/
static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, int bottom)
{
- if (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > 180000) {
+ if (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > 180000 * ZOOM_LVL_BASE * ZOOM_LVL_BASE) {
if ((bottom - top) > (right - left)) {
int t = (top + bottom) >> 1;
ViewportDrawChk(vp, left, top, right, t);
@@ -1540,8 +1540,8 @@ static inline void ClampViewportToMap(const ViewPort *vp, int &x, int &y)
int vy = x + y * 2;
/* clamp to size of map */
- vx = Clamp(vx, 0, MapMaxX() * TILE_SIZE * 4);
- vy = Clamp(vy, 0, MapMaxY() * TILE_SIZE * 4);
+ vx = Clamp(vx, 0, MapMaxX() * TILE_SIZE * 4 * ZOOM_LVL_BASE);
+ vy = Clamp(vy, 0, MapMaxY() * TILE_SIZE * 4 * ZOOM_LVL_BASE);
/* Convert map coordinates to viewport coordinates */
x = (-vx + vy) / 2;
@@ -1576,7 +1576,7 @@ void UpdateViewportPosition(Window *w)
if (delta_x != 0 || delta_y != 0) {
if (_settings_client.gui.smooth_scroll) {
- int max_scroll = ScaleByMapSize1D(512);
+ int max_scroll = ScaleByMapSize1D(512 * ZOOM_LVL_BASE);
/* Not at our desired position yet... */
w->viewport->scrollpos_x += Clamp(delta_x / 4, -max_scroll, max_scroll);
w->viewport->scrollpos_y += Clamp(delta_y / 4, -max_scroll, max_scroll);
@@ -1668,10 +1668,10 @@ void MarkTileDirtyByTile(TileIndex tile)
{
Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, GetTilePixelZ(tile));
MarkAllViewportsDirty(
- pt.x - 31,
- pt.y - 122,
- pt.x - 31 + 67,
- pt.y - 122 + 154
+ pt.x - 31 * ZOOM_LVL_BASE,
+ pt.y - 122 * ZOOM_LVL_BASE,
+ pt.x - 31 * ZOOM_LVL_BASE + 67 * ZOOM_LVL_BASE,
+ pt.y - 122 * ZOOM_LVL_BASE + 154 * ZOOM_LVL_BASE
);
}
@@ -1748,15 +1748,15 @@ static void SetSelectionTilesDirty()
/* the 'x' coordinate of 'top' and 'bot' is the same (and always in the same distance from tile middle),
* tile height/slope affects only the 'y' on-screen coordinate! */
- int l = top.x - (TILE_PIXELS - 2); // 'x' coordinate of left side of dirty rectangle
+ int l = top.x - (TILE_PIXELS - 2) * ZOOM_LVL_BASE; // 'x' coordinate of left side of dirty rectangle
int t = top.y; // 'y' coordinate of top side -//-
- int r = top.x + (TILE_PIXELS - 2); // right side of dirty rectangle
+ int r = top.x + (TILE_PIXELS - 2) * ZOOM_LVL_BASE; // right side of dirty rectangle
int b = bot.y; // bottom -//-
- static const int OVERLAY_WIDTH = 4; // part of selection sprites is drawn outside the selected area
+ static const int OVERLAY_WIDTH = 4 * ZOOM_LVL_BASE; // part of selection sprites is drawn outside the selected area
/* For halftile foundations on SLOPE_STEEP_S the sprite extents some more towards the top */
- MarkAllViewportsDirty(l - OVERLAY_WIDTH, t - OVERLAY_WIDTH - TILE_HEIGHT, r + OVERLAY_WIDTH, b + OVERLAY_WIDTH);
+ MarkAllViewportsDirty(l - OVERLAY_WIDTH, t - OVERLAY_WIDTH - TILE_HEIGHT * ZOOM_LVL_BASE, r + OVERLAY_WIDTH, b + OVERLAY_WIDTH * ZOOM_LVL_BASE);
/* haven't we reached the topmost tile yet? */
if (top_x != x_start) {
@@ -1809,7 +1809,7 @@ void SetSelectionRed(bool b)
*/
static bool CheckClickOnViewportSign(const ViewPort *vp, int x, int y, const ViewportSign *sign)
{
- bool small = (vp->zoom >= ZOOM_LVL_OUT_4X);
+ bool small = (vp->zoom >= ZOOM_LVL_OUT_16X);
int sign_half_width = ScaleByZoom((small ? sign->width_small : sign->width_normal) / 2, vp->zoom);
int sign_height = ScaleByZoom(VPSM_TOP + (small ? FONT_HEIGHT_SMALL : FONT_HEIGHT_NORMAL) + VPSM_BOTTOM, vp->zoom);