1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/* $Id$ */
/** @file zoom.hpp */
#ifndef ZOOM_HPP
#define ZOOM_HPP
enum ZoomLevel {
/* Our possible zoom-levels */
ZOOM_LVL_NORMAL = 0,
ZOOM_LVL_OUT_2X,
ZOOM_LVL_OUT_4X,
ZOOM_LVL_OUT_8X,
ZOOM_LVL_END,
/* Here we define in which zoom viewports are */
ZOOM_LVL_VIEWPORT = ZOOM_LVL_NORMAL,
ZOOM_LVL_NEWS = ZOOM_LVL_NORMAL,
ZOOM_LVL_INDUSTRY = ZOOM_LVL_OUT_2X,
ZOOM_LVL_TOWN = ZOOM_LVL_OUT_2X,
ZOOM_LVL_AIRCRAFT = ZOOM_LVL_NORMAL,
ZOOM_LVL_SHIP = ZOOM_LVL_NORMAL,
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_8X,
};
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;
int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL;
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;
int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL;
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 */
|