Remove second template parameter from class GUIList
[openttd/fttd.git] / src / zoom_func.h
blob35615ddd44c815f734ec7763cf5f9699bee494ca
1 /* $Id$ */
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 */
10 /** @file zoom_func.h Functions related to zooming. */
12 #ifndef ZOOM_FUNC_H
13 #define ZOOM_FUNC_H
15 #include "zoom_type.h"
17 /**
18 * Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL)
19 * When shifting right, value is rounded up
20 * @param value value to shift
21 * @param zoom zoom level to shift to
22 * @return shifted value
24 static inline int ScaleByZoom(int value, ZoomLevel zoom)
26 assert(zoom >= 0);
27 return value << zoom;
30 /**
31 * Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
32 * When shifting right, value is rounded up
33 * @param value value to shift
34 * @param zoom zoom level to shift to
35 * @return shifted value
37 static inline int UnScaleByZoom(int value, ZoomLevel zoom)
39 assert(zoom >= 0);
40 return (value + (1 << zoom) - 1) >> zoom;
43 /**
44 * Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
45 * @param value value to shift
46 * @param zoom zoom level to shift to
47 * @return shifted value
49 static inline int UnScaleByZoomLower(int value, ZoomLevel zoom)
51 assert(zoom >= 0);
52 return value >> zoom;
55 /**
56 * Short-hand to apply GUI zoom level.
57 * @param value Pixel amount at #ZOOM_LVL_BEGIN (full zoom in).
58 * @return Pixel amount at #ZOOM_LVL_GUI (current interface size).
60 static inline int UnScaleGUI(int value)
62 return UnScaleByZoom(value, ZOOM_LVL_GUI);
65 /**
66 * Scale traditional pixel dimensions to GUI zoom level.
67 * @param value Pixel amount at #ZOOM_LVL_BASE (traditional "normal" interface size).
68 * @return Pixel amount at #ZOOM_LVL_GUI (current interface size).
70 static inline int ScaleGUITrad(int value)
72 return UnScaleGUI(value * ZOOM_LVL_BASE);
75 #endif /* ZOOM_FUNC_H */