Changeset - r7905:248f62044329
[Not reviewed]
master
0 2 0
smatz - 17 years ago 2007-11-18 13:13:59
smatz@openttd.org
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
2 files changed with 47 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/viewport.cpp
Show inline comments
 
@@ -296,10 +296,13 @@ static void SetViewportPosition(Window *
 
	vp->virtual_left = x;
 
	vp->virtual_top = y;
 

	
 
	old_left = UnScaleByZoom(old_left, vp->zoom);
 
	old_top = UnScaleByZoom(old_top, vp->zoom);
 
	x = UnScaleByZoom(x, vp->zoom);
 
	y = UnScaleByZoom(y, vp->zoom);
 
	/* viewport is bound to its left top corner, so it must be rounded down (UnScaleByZoomLower)
 
	 * else glitch described in FS#1412 will happen (offset by 1 pixel with zoom level > NORMAL)
 
	 */
 
	old_left = UnScaleByZoomLower(old_left, vp->zoom);
 
	old_top = UnScaleByZoomLower(old_top, vp->zoom);
 
	x = UnScaleByZoomLower(x, vp->zoom);
 
	y = UnScaleByZoomLower(y, vp->zoom);
 

	
 
	old_left -= x;
 
	old_top -= y;
src/zoom.hpp
Show inline comments
 
@@ -32,6 +32,13 @@ enum ZoomLevel {
 

	
 
extern ZoomLevel _saved_scrollpos_zoom;
 

	
 
/**
 
 * Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL)
 
 * When shifting right, value is rounded up
 
 * @param value value to shift
 
 * @param zoom  zoom level to shift to
 
 * @return shifted value
 
 */
 
static inline int ScaleByZoom(int value, ZoomLevel zoom)
 
{
 
	if (zoom == ZOOM_LVL_NORMAL) return value;
 
@@ -39,6 +46,13 @@ static inline int ScaleByZoom(int value,
 
	return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : (value + (1 << -izoom) - 1) >> -izoom;
 
}
 

	
 
/**
 
 * Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
 
 * When shifting right, value is rounded up
 
 * @param value value to shift
 
 * @param zoom  zoom level to shift to
 
 * @return shifted value
 
 */
 
static inline int UnScaleByZoom(int value, ZoomLevel zoom)
 
{
 
	if (zoom == ZOOM_LVL_NORMAL) return value;
 
@@ -46,4 +60,30 @@ static inline int UnScaleByZoom(int valu
 
	return (zoom > ZOOM_LVL_NORMAL) ? (value + (1 << izoom) - 1) >> izoom : value << -izoom;
 
}
 

	
 
/**
 
 * Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL)
 
 * @param value value to shift
 
 * @param zoom  zoom level to shift to
 
 * @return shifted value
 
 */
 
static inline int ScaleByZoomLower(int value, ZoomLevel zoom)
 
{
 
	if (zoom == ZOOM_LVL_NORMAL) return value;
 
	int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL;
 
	return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : value >> -izoom;
 
}
 

	
 
/**
 
 * Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
 
 * @param value value to shift
 
 * @param zoom  zoom level to shift to
 
 * @return shifted value
 
 */
 
static inline int UnScaleByZoomLower(int value, ZoomLevel zoom)
 
{
 
	if (zoom == ZOOM_LVL_NORMAL) return value;
 
	int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL;
 
	return (zoom > ZOOM_LVL_NORMAL) ? value >> izoom : value << -izoom;
 
}
 

	
 
#endif /* ZOOM_HPP */
0 comments (0 inline, 0 general)