author | rubidium |
Fri, 21 Dec 2007 08:34:53 +0000 | |
changeset 8608 | 45d77f05d3a3 |
parent 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 |
|
8608
45d77f05d3a3
(svn r11673) -Codechange: move the overflow safe type to a separate file.
rubidium
parents:
8591
diff
changeset
|
8 |
#include "core/enum_type.hpp" |
8591
46eca2eb57ba
(svn r11656) -Codechange: add ZOOM_LVL_BEGIN and postfix operators so ZoomLevel can be used in some iterations
smatz
parents:
8401
diff
changeset
|
9 |
|
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
10 |
enum ZoomLevel { |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
11 |
/* Our possible zoom-levels */ |
8591
46eca2eb57ba
(svn r11656) -Codechange: add ZOOM_LVL_BEGIN and postfix operators so ZoomLevel can be used in some iterations
smatz
parents:
8401
diff
changeset
|
12 |
ZOOM_LVL_BEGIN = 0, |
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
13 |
ZOOM_LVL_NORMAL = 0, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
14 |
ZOOM_LVL_OUT_2X, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
15 |
ZOOM_LVL_OUT_4X, |
7149
ba2798e551a3
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
7124
diff
changeset
|
16 |
ZOOM_LVL_OUT_8X, |
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
17 |
ZOOM_LVL_END, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
18 |
|
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
19 |
/* Here we define in which zoom viewports are */ |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
20 |
ZOOM_LVL_VIEWPORT = ZOOM_LVL_NORMAL, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
21 |
ZOOM_LVL_NEWS = ZOOM_LVL_NORMAL, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
22 |
ZOOM_LVL_INDUSTRY = ZOOM_LVL_OUT_2X, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
23 |
ZOOM_LVL_TOWN = ZOOM_LVL_OUT_2X, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
24 |
ZOOM_LVL_AIRCRAFT = ZOOM_LVL_NORMAL, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
25 |
ZOOM_LVL_SHIP = ZOOM_LVL_NORMAL, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
26 |
ZOOM_LVL_TRAIN = ZOOM_LVL_NORMAL, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
27 |
ZOOM_LVL_ROADVEH = ZOOM_LVL_NORMAL, |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
28 |
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
|
29 |
|
7348
becce3f57dc7
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
7329
diff
changeset
|
30 |
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
|
31 |
|
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
32 |
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
|
33 |
ZOOM_LVL_MAX = ZOOM_LVL_OUT_8X, |
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
34 |
}; |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
35 |
|
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
36 |
extern ZoomLevel _saved_scrollpos_zoom; |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
37 |
|
8591
46eca2eb57ba
(svn r11656) -Codechange: add ZOOM_LVL_BEGIN and postfix operators so ZoomLevel can be used in some iterations
smatz
parents:
8401
diff
changeset
|
38 |
DECLARE_POSTFIX_INCREMENT(ZoomLevel) |
46eca2eb57ba
(svn r11656) -Codechange: add ZOOM_LVL_BEGIN and postfix operators so ZoomLevel can be used in some iterations
smatz
parents:
8401
diff
changeset
|
39 |
|
8401
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
40 |
/** |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
41 |
* 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
|
42 |
* 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
|
43 |
* @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
|
44 |
* @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
|
45 |
* @return shifted value |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
46 |
*/ |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
47 |
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
|
48 |
{ |
7149
ba2798e551a3
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
7124
diff
changeset
|
49 |
if (zoom == ZOOM_LVL_NORMAL) return value; |
8591
46eca2eb57ba
(svn r11656) -Codechange: add ZOOM_LVL_BEGIN and postfix operators so ZoomLevel can be used in some iterations
smatz
parents:
8401
diff
changeset
|
50 |
int izoom = zoom - ZOOM_LVL_NORMAL; |
7329 | 51 |
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
|
52 |
} |
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
53 |
|
8401
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
54 |
/** |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
55 |
* 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
|
56 |
* 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
|
57 |
* @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
|
58 |
* @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
|
59 |
* @return shifted value |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
60 |
*/ |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
61 |
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
|
62 |
{ |
7149
ba2798e551a3
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
7124
diff
changeset
|
63 |
if (zoom == ZOOM_LVL_NORMAL) return value; |
8591
46eca2eb57ba
(svn r11656) -Codechange: add ZOOM_LVL_BEGIN and postfix operators so ZoomLevel can be used in some iterations
smatz
parents:
8401
diff
changeset
|
64 |
int izoom = zoom - 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
|
65 |
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
|
66 |
} |
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
67 |
|
8401
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 |
* 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
|
70 |
* @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
|
71 |
* @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
|
72 |
* @return shifted value |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
73 |
*/ |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
74 |
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
|
75 |
{ |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
76 |
if (zoom == ZOOM_LVL_NORMAL) return value; |
8591
46eca2eb57ba
(svn r11656) -Codechange: add ZOOM_LVL_BEGIN and postfix operators so ZoomLevel can be used in some iterations
smatz
parents:
8401
diff
changeset
|
77 |
int izoom = zoom - ZOOM_LVL_NORMAL; |
8401
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
78 |
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
|
79 |
} |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
80 |
|
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 |
* 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
|
83 |
* @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
|
84 |
* @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
|
85 |
* @return shifted value |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
86 |
*/ |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
87 |
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
|
88 |
{ |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
89 |
if (zoom == ZOOM_LVL_NORMAL) return value; |
8591
46eca2eb57ba
(svn r11656) -Codechange: add ZOOM_LVL_BEGIN and postfix operators so ZoomLevel can be used in some iterations
smatz
parents:
8401
diff
changeset
|
90 |
int izoom = zoom - ZOOM_LVL_NORMAL; |
8401
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
91 |
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
|
92 |
} |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
93 |
|
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
94 |
#endif /* ZOOM_HPP */ |