summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2007-05-15 16:08:46 +0000
committertruelight <truelight@openttd.org>2007-05-15 16:08:46 +0000
commit765c466b8d5f9a534f785a14b4c41e36e07ae014 (patch)
tree839525ed601a24ac844e1fb9f64be11f2890b982
parentd4963476cb0226490143e9843df897f792feacb2 (diff)
downloadopenttd-765c466b8d5f9a534f785a14b4c41e36e07ae014.tar.xz
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
-Codechange: introduced ZOOM_LVL_DETAIL to show/remove details -Codechange: changed << and >> operator with ZoomLevel to a simple wrapper (that in theory also allows zoom-in besides the current zoom-out) -Fix r9845: missed some int -> ZoomLevel
-rw-r--r--src/gfx.cpp22
-rw-r--r--src/main_gui.cpp6
-rw-r--r--src/misc_gui.cpp8
-rw-r--r--src/openttd.cpp8
-rw-r--r--src/road_cmd.cpp2
-rw-r--r--src/screenshot.cpp8
-rw-r--r--src/smallmap_gui.cpp4
-rw-r--r--src/sound.cpp2
-rw-r--r--src/texteff.cpp4
-rw-r--r--src/vehicle.cpp4
-rw-r--r--src/viewport.cpp42
-rw-r--r--src/window.cpp12
-rw-r--r--src/zoom.hpp17
13 files changed, 79 insertions, 60 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 02974d155..84cfe2830 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -1426,7 +1426,7 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode)
const DrawPixelInfo *dpi = _cur_dpi;
int start_x, start_y;
BlitterParams bp;
- int zoom_mask = ~((1 << dpi->zoom) - 1);
+ int zoom_mask = ~(ScaleByZoom(1, dpi->zoom) - 1);
/* decode sprite header */
x += sprite->x_offs;
@@ -1458,7 +1458,7 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode)
start_y -= y;
y = 0;
} else {
- bp.dst += bp.pitch * (y >> dpi->zoom);
+ bp.dst += bp.pitch * UnScaleByZoom(y, dpi->zoom);
}
bp.start_y = start_y;
@@ -1476,7 +1476,7 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode)
x = 0;
}
bp.start_x = start_x;
- bp.dst += x >> dpi->zoom;
+ bp.dst += UnScaleByZoom(x, dpi->zoom);
if ( (x = x + bp.width - dpi->width) > 0) {
bp.width -= x;
@@ -1485,9 +1485,9 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode)
switch (dpi->zoom) {
default: NOT_REACHED();
- case 0: GfxBlitTileZoomIn(&bp); break;
- case 1: GfxBlitTileZoomMedium(&bp); break;
- case 2: GfxBlitTileZoomOut(&bp); break;
+ case ZOOM_LVL_NORMAL: GfxBlitTileZoomIn(&bp); break;
+ case ZOOM_LVL_OUT_2X: GfxBlitTileZoomMedium(&bp); break;
+ case ZOOM_LVL_OUT_4X: GfxBlitTileZoomOut(&bp); break;
}
} else {
bp.sprite += bp.width * (bp.height & ~zoom_mask);
@@ -1502,7 +1502,7 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode)
bp.sprite -= bp.width * y;
y = 0;
} else {
- bp.dst += bp.pitch * (y >> dpi->zoom);
+ bp.dst += bp.pitch * UnScaleByZoom(y, dpi->zoom);
}
if (bp.height > dpi->height - y) {
@@ -1518,7 +1518,7 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode)
bp.sprite -= x;
x = 0;
}
- bp.dst += x >> dpi->zoom;
+ bp.dst += UnScaleByZoom(x, dpi->zoom);
if (bp.width > dpi->width - x) {
bp.width = dpi->width - x;
@@ -1527,9 +1527,9 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode)
switch (dpi->zoom) {
default: NOT_REACHED();
- case 0: GfxBlitZoomInUncomp(&bp); break;
- case 1: GfxBlitZoomMediumUncomp(&bp); break;
- case 2: GfxBlitZoomOutUncomp(&bp); break;
+ case ZOOM_LVL_NORMAL: GfxBlitZoomInUncomp(&bp); break;
+ case ZOOM_LVL_OUT_2X: GfxBlitZoomMediumUncomp(&bp); break;
+ case ZOOM_LVL_OUT_4X: GfxBlitZoomOutUncomp(&bp); break;
}
}
}
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index b090e69df..5fc4b3f97 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -880,7 +880,7 @@ bool DoZoomInOutWindow(int how, Window *w)
switch (how) {
case ZOOM_IN:
- if (vp->zoom == ZOOM_LVL_NORMAL) return false;
+ if (vp->zoom == ZOOM_LVL_MIN) return false;
vp->zoom = (ZoomLevel)((byte)vp->zoom - 1);
vp->virtual_width >>= 1;
vp->virtual_height >>= 1;
@@ -889,7 +889,7 @@ bool DoZoomInOutWindow(int how, Window *w)
WP(w,vp_d).scrollpos_y += vp->virtual_height >> 1;
break;
case ZOOM_OUT:
- if (vp->zoom == ZOOM_LVL_OUT_4X) return false;
+ if (vp->zoom == ZOOM_LVL_MAX) return false;
vp->zoom = (ZoomLevel)((byte)vp->zoom + 1);
WP(w,vp_d).scrollpos_x -= vp->virtual_width >> 1;
@@ -1049,7 +1049,7 @@ void ZoomInOrOutToCursorWindow(bool in, Window *w)
vp = w->viewport;
if (_game_mode != GM_MENU) {
- if ((in && vp->zoom == ZOOM_LVL_NORMAL) || (!in && vp->zoom == ZOOM_LVL_OUT_4X))
+ if ((in && vp->zoom == ZOOM_LVL_MIN) || (!in && vp->zoom == ZOOM_LVL_MAX))
return;
pt = GetTileZoomCenterWindow(in,w);
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index c63e3d6bd..2336d5332 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -579,11 +579,11 @@ void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
/* move x pos to opposite corner */
- pt.x = ((pt.x - vp->virtual_left) >> vp->zoom) + vp->left;
+ pt.x = UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left;
pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - 260 : 20;
/* move y pos to opposite corner */
- pt.y = ((pt.y - vp->virtual_top) >> vp->zoom) + vp->top;
+ pt.y = UnScaleByZoom(pt.y - vp->virtual_top, vp->zoom) + vp->top;
pt.y = (pt.y < (_screen.height >> 1)) ? _screen.height - 80 : 100;
} else {
@@ -595,8 +595,8 @@ void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
if ( (x|y) != 0) {
pt = RemapCoords2(x, y);
vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
- pt.x = clamp(((pt.x - vp->virtual_left) >> vp->zoom) + vp->left - (334/2), 0, _screen.width - 334);
- pt.y = clamp(((pt.y - vp->virtual_top) >> vp->zoom) + vp->top - (137/2), 22, _screen.height - 137);
+ pt.x = clamp(UnScaleByZoom(pt.x - vp->virtual_left, vp->zoom) + vp->left - (334/2), 0, _screen.width - 334);
+ pt.y = clamp(UnScaleByZoom(pt.y - vp->virtual_top, vp->zoom) + vp->top - (137/2), 22, _screen.height - 137);
} else {
pt.x = (_screen.width - 334) >> 1;
pt.y = (_screen.height - 137) >> 1;
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 0cd1d5b49..088d9fce5 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -986,8 +986,8 @@ static void ScrollMainViewport(int x, int y)
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
assert(w);
- WP(w,vp_d).scrollpos_x += x << w->viewport->zoom;
- WP(w,vp_d).scrollpos_y += y << w->viewport->zoom;
+ WP(w,vp_d).scrollpos_x += ScaleByZoom(x, w->viewport->zoom);
+ WP(w,vp_d).scrollpos_y += ScaleByZoom(y, w->viewport->zoom);
}
}
@@ -1282,8 +1282,8 @@ bool AfterLoadGame()
vp = w->viewport;
vp->zoom = _saved_scrollpos_zoom;
- vp->virtual_width = vp->width << vp->zoom;
- vp->virtual_height = vp->height << vp->zoom;
+ vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
+ vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
/* in version 4.1 of the savegame, is_active was introduced to determine
* if a player does exist, rather then checking name_1 */
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 2b6881887..1ad5ce9e7 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -725,7 +725,7 @@ static void DrawRoadBits(TileInfo* ti)
}
/* Return if full detail is disabled, or we are zoomed fully out. */
- if (!HASBIT(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom == ZOOM_LVL_OUT_4X) return;
+ if (!HASBIT(_display_opt, DO_FULL_DETAIL) || _cur_dpi->zoom > ZOOM_LVL_DETAIL) return;
/* Draw extra details. */
for (drts = _road_display_table[roadside][road]; drts->image != 0; drts++) {
diff --git a/src/screenshot.cpp b/src/screenshot.cpp
index a6d3153c0..5948f29d3 100644
--- a/src/screenshot.cpp
+++ b/src/screenshot.cpp
@@ -479,10 +479,10 @@ static void LargeWorldCallback(void *userdata, Pixel *buf, uint y, uint pitch, u
left += wx;
ViewportDoDraw(vp,
- ((left - wx - vp->left) << vp->zoom) + vp->virtual_left,
- ((y - vp->top) << vp->zoom) + vp->virtual_top,
- ((left - vp->left) << vp->zoom) + vp->virtual_left,
- (((y + n) - vp->top) << vp->zoom) + vp->virtual_top
+ ScaleByZoom(left - wx - vp->left, vp->zoom) + vp->virtual_left,
+ ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top,
+ ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
+ ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top
);
}
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index 2b1868288..2035a8a96 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -1016,8 +1016,8 @@ static void ExtraViewPortWndProc(Window *w, WindowEvent *e)
_scrolling_viewport = false;
}
- WP(w, vp_d).scrollpos_x += e->we.scroll.delta.x << vp->zoom;
- WP(w, vp_d).scrollpos_y += e->we.scroll.delta.y << vp->zoom;
+ WP(w, vp_d).scrollpos_x += ScaleByZoom(e->we.scroll.delta.x, vp->zoom);
+ WP(w, vp_d).scrollpos_y += ScaleByZoom(e->we.scroll.delta.y, vp->zoom);
} break;
case WE_MOUSEWHEEL:
diff --git a/src/sound.cpp b/src/sound.cpp
index 5700125d0..2245e8c0e 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -152,7 +152,7 @@ static void StartSound(uint sound, int panning, uint volume)
}
-static const byte _vol_factor_by_zoom[] = {255, 190, 134};
+static const byte _vol_factor_by_zoom[ZOOM_LVL_END] = {255, 190, 134};
static const byte _sound_base_vol[] = {
128, 90, 128, 128, 128, 128, 128, 128,
diff --git a/src/texteff.cpp b/src/texteff.cpp
index 692641be5..bb187ac15 100644
--- a/src/texteff.cpp
+++ b/src/texteff.cpp
@@ -351,8 +351,10 @@ void DrawTextEffects(DrawPixelInfo *dpi)
}
break;
- default:
+ case ZOOM_LVL_OUT_4X:
break;
+
+ default: NOT_REACHED();
}
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 724cd3428..1b5b720b9 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1425,8 +1425,8 @@ Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y)
(uint)(y -= vp->top) >= (uint)vp->height)
return NULL;
- x = (x << vp->zoom) + vp->virtual_left;
- y = (y << vp->zoom) + vp->virtual_top;
+ x = ScaleByZoom(x, vp->zoom) + vp->virtual_left;
+ y = ScaleByZoom(y, vp->zoom) + vp->virtual_top;
FOR_ALL_VEHICLES(v) {
if ((v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0 &&
diff --git a/src/viewport.cpp b/src/viewport.cpp
index e5f6279cf..3320519bb 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -269,10 +269,10 @@ static void SetViewportPosition(Window *w, int x, int y)
vp->virtual_left = x;
vp->virtual_top = y;
- old_left >>= vp->zoom;
- old_top >>= vp->zoom;
- x >>= vp->zoom;
- y >>= vp->zoom;
+ old_left = UnScaleByZoom(old_left, vp->zoom);
+ old_top = UnScaleByZoom(old_top, vp->zoom);
+ x = UnScaleByZoom(x, vp->zoom);
+ y = UnScaleByZoom(y, vp->zoom);
old_left -= x;
old_top -= y;
@@ -333,8 +333,8 @@ static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y)
return pt;
}
- x = ((x << vp->zoom) + vp->virtual_left) >> 2;
- y = ((y << vp->zoom) + vp->virtual_top) >> 1;
+ x = (ScaleByZoom(x, vp->zoom) + vp->virtual_left) >> 2;
+ y = (ScaleByZoom(y, vp->zoom) + vp->virtual_top) >> 1;
a = y-x;
b = y+x;
@@ -406,10 +406,10 @@ Point GetTileZoomCenterWindow(bool in, Window * w)
* @param widget_zoom_out widget index for window with zoom-out button */
void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out)
{
- SetWindowWidgetDisabledState(w, widget_zoom_in, vp->zoom == ZOOM_LVL_NORMAL);
+ SetWindowWidgetDisabledState(w, widget_zoom_in, vp->zoom == ZOOM_LVL_MIN);
InvalidateWidget(w, widget_zoom_in);
- SetWindowWidgetDisabledState(w, widget_zoom_out, vp->zoom == ZOOM_LVL_OUT_4X);
+ SetWindowWidgetDisabledState(w, widget_zoom_out, vp->zoom == ZOOM_LVL_MAX);
InvalidateWidget(w, widget_zoom_out);
}
@@ -671,7 +671,7 @@ static void DrawTileSelection(const TileInfo *ti)
z += TILE_HEIGHT;
if (ti->tileh == SLOPE_STEEP_N) z += TILE_HEIGHT;
}
- DrawGroundSpriteAt(_cur_dpi->zoom != ZOOM_LVL_OUT_4X ? SPR_DOT : SPR_DOT_SMALL, PAL_NONE, ti->x, ti->y, z);
+ DrawGroundSpriteAt(_cur_dpi->zoom <= ZOOM_LVL_DETAIL ? SPR_DOT : SPR_DOT_SMALL, PAL_NONE, ti->x, ti->y, z);
} else if (_thd.drawstyle & HT_RAIL /*&& _thd.place_mode == VHM_RAIL*/) {
/* autorail highlight piece under cursor */
uint type = _thd.drawstyle & 0xF;
@@ -1241,7 +1241,7 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom
_cur_dpi = &vd.dpi;
vd.dpi.zoom = vp->zoom;
- mask = (-1) << vp->zoom;
+ mask = ScaleByZoom(-1, vp->zoom);
vd.combine_sprites = 0;
@@ -1251,8 +1251,8 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom
vd.dpi.top = top & mask;
vd.dpi.pitch = old_dpi->pitch;
- x = ((vd.dpi.left - (vp->virtual_left&mask)) >> vp->zoom) + vp->left;
- y = ((vd.dpi.top - (vp->virtual_top&mask)) >> vp->zoom) + vp->top;
+ x = UnScaleByZoom(vd.dpi.left - (vp->virtual_left & mask), vp->zoom) + vp->left;
+ y = UnScaleByZoom(vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top;
vd.dpi.dst_ptr = old_dpi->dst_ptr + x - old_dpi->left + (y - old_dpi->top) * old_dpi->pitch;
@@ -1295,7 +1295,7 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom
* If we do, the sprite memory will overflow. */
static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, int bottom)
{
- if (((bottom - top) * (right - left) << (2 * vp->zoom)) > 180000) {
+ if (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > 180000) {
if ((bottom - top) > (right - left)) {
int t = (top + bottom) >> 1;
ViewportDrawChk(vp, left, top, right, t);
@@ -1307,10 +1307,10 @@ static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, in
}
} else {
ViewportDoDraw(vp,
- ((left - vp->left) << vp->zoom) + vp->virtual_left,
- ((top - vp->top) << vp->zoom) + vp->virtual_top,
- ((right - vp->left) << vp->zoom) + vp->virtual_left,
- ((bottom - vp->top) << vp->zoom) + vp->virtual_top
+ ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
+ ScaleByZoom(top - vp->top, vp->zoom) + vp->virtual_top,
+ ScaleByZoom(right - vp->left, vp->zoom) + vp->virtual_left,
+ ScaleByZoom(bottom - vp->top, vp->zoom) + vp->virtual_top
);
}
}
@@ -1398,10 +1398,10 @@ static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right,
if (top >= vp->virtual_height) return;
SetDirtyBlocks(
- (left >> vp->zoom) + vp->left,
- (top >> vp->zoom) + vp->top,
- (right >> vp->zoom) + vp->left,
- (bottom >> vp->zoom) + vp->top
+ UnScaleByZoom(left, vp->zoom) + vp->left,
+ UnScaleByZoom(top, vp->zoom) + vp->top,
+ UnScaleByZoom(right, vp->zoom) + vp->left,
+ UnScaleByZoom(bottom, vp->zoom) + vp->top
);
}
diff --git a/src/window.cpp b/src/window.cpp
index 34ccb70aa..f4309971a 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1618,14 +1618,14 @@ static void HandleAutoscroll()
/* here allows scrolling in both x and y axis */
#define scrollspeed 3
if (x - 15 < 0) {
- WP(w, vp_d).scrollpos_x += (x - 15) * scrollspeed << vp->zoom;
+ WP(w, vp_d).scrollpos_x += ScaleByZoom((x - 15) * scrollspeed, vp->zoom);
} else if (15 - (vp->width - x) > 0) {
- WP(w, vp_d).scrollpos_x += (15 - (vp->width - x)) * scrollspeed << vp->zoom;
+ WP(w, vp_d).scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * scrollspeed, vp->zoom);
}
if (y - 15 < 0) {
- WP(w, vp_d).scrollpos_y += (y - 15) * scrollspeed << vp->zoom;
+ WP(w, vp_d).scrollpos_y += ScaleByZoom((y - 15) * scrollspeed, vp->zoom);
} else if (15 - (vp->height - y) > 0) {
- WP(w,vp_d).scrollpos_y += (15 - (vp->height - y)) * scrollspeed << vp->zoom;
+ WP(w,vp_d).scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * scrollspeed, vp->zoom);
}
#undef scrollspeed
}
@@ -1970,8 +1970,8 @@ void RelocateAllWindows(int neww, int newh)
ViewPort *vp = w->viewport;
vp->width = w->width = neww;
vp->height = w->height = newh;
- vp->virtual_width = neww << vp->zoom;
- vp->virtual_height = newh << vp->zoom;
+ vp->virtual_width = ScaleByZoom(neww, vp->zoom);
+ vp->virtual_height = ScaleByZoom(newh, vp->zoom);
continue; // don't modify top,left
}
diff --git a/src/zoom.hpp b/src/zoom.hpp
index 64a2a1397..fc57b0139 100644
--- a/src/zoom.hpp
+++ b/src/zoom.hpp
@@ -22,8 +22,25 @@ enum ZoomLevel {
ZOOM_LVL_TRAIN = ZOOM_LVL_NORMAL,
ZOOM_LVL_ROADVEH = ZOOM_LVL_NORMAL,
ZOOM_LVL_WORLD_SCREENSHOT = ZOOM_LVL_NORMAL,
+
+ ZOOM_LVL_DETAIL = ZOOM_LVL_OUT_2X, //! All zoomlevels below or equal to this, will result in details on the screen, like road-work, ...
+
+ ZOOM_LVL_MIN = ZOOM_LVL_NORMAL,
+ ZOOM_LVL_MAX = ZOOM_LVL_OUT_4X,
};
extern ZoomLevel _saved_scrollpos_zoom;
+static inline int ScaleByZoom(int value, ZoomLevel zoom)
+{
+ int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL;
+ return (zoom > ZOOM_LVL_NORMAL) ? value >> izoom : value << izoom;
+}
+
+static inline int UnScaleByZoom(int value, ZoomLevel zoom)
+{
+ int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL;
+ return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : value >> izoom;
+}
+
#endif /* ZOOM_HPP */