author | Tero Marttila <terom@fixme.fi> |
Fri, 18 Jul 2008 21:28:42 +0300 | |
changeset 11175 | 020c61e39c94 |
parent 10429 | 1b99254f9607 |
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 |
|
10429
1b99254f9607
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
10255
diff
changeset
|
3 |
/** @file zoom_func.h Functions related to zooming. */ |
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
4 |
|
8619
c2434269c3eb
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8608
diff
changeset
|
5 |
#ifndef ZOOM_FUNC_H |
c2434269c3eb
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8608
diff
changeset
|
6 |
#define ZOOM_FUNC_H |
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
7 |
|
8619
c2434269c3eb
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8608
diff
changeset
|
8 |
#include "zoom_type.h" |
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
9 |
|
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
10 |
extern ZoomLevel _saved_scrollpos_zoom; |
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
diff
changeset
|
11 |
|
8401
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
12 |
/** |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
13 |
* 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
|
14 |
* 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
|
15 |
* @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
|
16 |
* @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
|
17 |
* @return shifted value |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
18 |
*/ |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
19 |
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
|
20 |
{ |
7149
ba2798e551a3
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
7124
diff
changeset
|
21 |
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
|
22 |
int izoom = zoom - ZOOM_LVL_NORMAL; |
7329 | 23 |
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
|
24 |
} |
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
25 |
|
8401
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
26 |
/** |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
27 |
* 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
|
28 |
* 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
|
29 |
* @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
|
30 |
* @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
|
31 |
* @return shifted value |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
32 |
*/ |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
33 |
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
|
34 |
{ |
7149
ba2798e551a3
(svn r9884) -Feature: 2 new zoom-out levels: 8 times and 16 times
truelight
parents:
7124
diff
changeset
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
} |
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
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 |
* @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
|
43 |
* @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
|
44 |
* @return shifted value |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
45 |
*/ |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
46 |
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
|
47 |
{ |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
} |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
52 |
|
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
53 |
/** |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
54 |
* 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
|
55 |
* @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
|
56 |
* @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
|
57 |
* @return shifted value |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
58 |
*/ |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
59 |
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
|
60 |
{ |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
} |
3b1db2134a9e
(svn r11456) -Fix [FS#1412] (r10070): Viewport is bound to its top-left corner
smatz
parents:
7349
diff
changeset
|
65 |
|
8619
c2434269c3eb
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8608
diff
changeset
|
66 |
#endif /* ZOOM_FUNC_H */ |