OpenTTD
zoom_func.h
Go to the documentation of this file.
1 /* $Id: zoom_func.h 27417 2015-10-29 19:23:21Z frosch $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #ifndef ZOOM_FUNC_H
13 #define ZOOM_FUNC_H
14 
15 #include "zoom_type.h"
16 
24 static inline int ScaleByZoom(int value, ZoomLevel zoom)
25 {
26  assert(zoom >= 0);
27  return value << zoom;
28 }
29 
37 static inline int UnScaleByZoom(int value, ZoomLevel zoom)
38 {
39  assert(zoom >= 0);
40  return (value + (1 << zoom) - 1) >> zoom;
41 }
42 
49 static inline int ScaleByZoomLower(int value, ZoomLevel zoom)
50 {
51  assert(zoom >= 0);
52  return value << zoom;
53 }
54 
61 static inline int UnScaleByZoomLower(int value, ZoomLevel zoom)
62 {
63  assert(zoom >= 0);
64  return value >> zoom;
65 }
66 
72 static inline int UnScaleGUI(int value)
73 {
74  return UnScaleByZoom(value, ZOOM_LVL_GUI);
75 }
76 
82 static inline int ScaleGUITrad(int value)
83 {
84  return UnScaleGUI(value * ZOOM_LVL_BASE);
85 }
86 
87 #endif /* ZOOM_FUNC_H */
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:72
static int UnScaleByZoomLower(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
Definition: zoom_func.h:61
static int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) When shifting right...
Definition: zoom_func.h:37
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:82
static int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right...
Definition: zoom_func.h:24
static int ScaleByZoomLower(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL)
Definition: zoom_func.h:49
Types related to zooming in and out.
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:21