author | skidd13 |
Tue, 20 Nov 2007 14:11:19 +0000 | |
changeset 8428 | f8300c908bd9 |
parent 8401 | 3b1db2134a9e |
child 8591 | 46eca2eb57ba |
permissions | -rw-r--r-- |
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
1 |
/* $Id$ */ |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
2 |
|
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
3 |
/** @file zoom.hpp */ |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
4 |
|
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
5 |
#ifndef ZOOM_HPP |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
6 |
#define ZOOM_HPP |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
7 |
|
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
8 |
enum ZoomLevel { |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
9 |
/* Our possible zoom-levels */ |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
10 |
ZOOM_LVL_NORMAL = 0, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
11 |
ZOOM_LVL_OUT_2X, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
12 |
ZOOM_LVL_OUT_4X, |
7149
ba2798e551a3
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
7124
diff
changeset
|
13 |
ZOOM_LVL_OUT_8X, |
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
14 |
ZOOM_LVL_END, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
15 |
|
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
16 |
/* Here we define in which zoom viewports are */ |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
17 |
ZOOM_LVL_VIEWPORT = ZOOM_LVL_NORMAL, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
18 |
ZOOM_LVL_NEWS = ZOOM_LVL_NORMAL, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
19 |
ZOOM_LVL_INDUSTRY = ZOOM_LVL_OUT_2X, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
20 |
ZOOM_LVL_TOWN = ZOOM_LVL_OUT_2X, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
21 |
ZOOM_LVL_AIRCRAFT = ZOOM_LVL_NORMAL, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
22 |
ZOOM_LVL_SHIP = ZOOM_LVL_NORMAL, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
23 |
ZOOM_LVL_TRAIN = ZOOM_LVL_NORMAL, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
24 |
ZOOM_LVL_ROADVEH = ZOOM_LVL_NORMAL, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
25 |
ZOOM_LVL_WORLD_SCREENSHOT = ZOOM_LVL_NORMAL, |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
26 |
|
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7329
diff
changeset
|
27 |
ZOOM_LVL_DETAIL = ZOOM_LVL_OUT_2X, ///< All zoomlevels below or equal to this, will result in details on the screen, like road-work, ... |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
28 |
|
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
29 |
ZOOM_LVL_MIN = ZOOM_LVL_NORMAL, |
7349
2ebfdf726932
(svn r10093) -Revert: removed 16x zoom-out as it is broken beyond repair
truelight
parents:
7348
diff
changeset
|
30 |
ZOOM_LVL_MAX = ZOOM_LVL_OUT_8X, |
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
31 |
}; |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
32 |
|
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
33 |
extern ZoomLevel _saved_scrollpos_zoom; |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
34 |
|
8401
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
35 |
/** |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
36 |
* Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
37 |
* When shifting right, value is rounded up |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
38 |
* @param value value to shift |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
39 |
* @param zoom zoom level to shift to |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
40 |
* @return shifted value |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
41 |
*/ |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
42 |
static inline int ScaleByZoom(int value, ZoomLevel zoom) |
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
43 |
{ |
7149
ba2798e551a3
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
7124
diff
changeset
|
44 |
if (zoom == ZOOM_LVL_NORMAL) return value; |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
45 |
int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL; |
7329 | 46 |
return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : (value + (1 << -izoom) - 1) >> -izoom; |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
47 |
} |
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
48 |
|
8401
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
49 |
/** |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
50 |
* Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
51 |
* When shifting right, value is rounded up |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
52 |
* @param value value to shift |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
53 |
* @param zoom zoom level to shift to |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
54 |
* @return shifted value |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
55 |
*/ |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
56 |
static inline int UnScaleByZoom(int value, ZoomLevel zoom) |
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
57 |
{ |
7149
ba2798e551a3
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
7124
diff
changeset
|
58 |
if (zoom == ZOOM_LVL_NORMAL) return value; |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
59 |
int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL; |
7327
fa2e72e31f59
(svn r10070) -Fix: fix the rounding problem of zoom-levels in zoom.hpp, so it is global for every call
truelight
parents:
7200
diff
changeset
|
60 |
return (zoom > ZOOM_LVL_NORMAL) ? (value + (1 << izoom) - 1) >> izoom : value << -izoom; |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
61 |
} |
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
62 |
|
8401
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
63 |
/** |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
64 |
* Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
65 |
* @param value value to shift |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
66 |
* @param zoom zoom level to shift to |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
67 |
* @return shifted value |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
68 |
*/ |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
69 |
static inline int ScaleByZoomLower(int value, ZoomLevel zoom) |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
70 |
{ |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
71 |
if (zoom == ZOOM_LVL_NORMAL) return value; |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
72 |
int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL; |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
73 |
return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : value >> -izoom; |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
74 |
} |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
75 |
|
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
76 |
/** |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
77 |
* Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
78 |
* @param value value to shift |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
79 |
* @param zoom zoom level to shift to |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
80 |
* @return shifted value |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
81 |
*/ |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
82 |
static inline int UnScaleByZoomLower(int value, ZoomLevel zoom) |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
83 |
{ |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
84 |
if (zoom == ZOOM_LVL_NORMAL) return value; |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
85 |
int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL; |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
86 |
return (zoom > ZOOM_LVL_NORMAL) ? value >> izoom : value << -izoom; |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
87 |
} |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
88 |
|
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
89 |
#endif /* ZOOM_HPP */ |