Fix cc39fa9: New orders are non-stop by default (#8689)
[openttd-github.git] / src / zoom_func.h
blob485284a06cd7eaab3128d8ffe713fc1abdd7c2a0
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file zoom_func.h Functions related to zooming. */
10 #ifndef ZOOM_FUNC_H
11 #define ZOOM_FUNC_H
13 #include "zoom_type.h"
15 /**
16 * Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL)
17 * When shifting right, value is rounded up
18 * @param value value to shift
19 * @param zoom zoom level to shift to
20 * @return shifted value
22 static inline int ScaleByZoom(int value, ZoomLevel zoom)
24 return value << zoom;
27 /**
28 * Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
29 * When shifting right, value is rounded up
30 * @param value value to shift
31 * @param zoom zoom level to shift to
32 * @return shifted value
34 static inline int UnScaleByZoom(int value, ZoomLevel zoom)
36 return (value + (1 << zoom) - 1) >> zoom;
39 /**
40 * Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL)
41 * @param value value to shift
42 * @param zoom zoom level to shift to
43 * @return shifted value
45 static inline int ScaleByZoomLower(int value, ZoomLevel zoom)
47 return value << zoom;
50 /**
51 * Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
52 * @param value value to shift
53 * @param zoom zoom level to shift to
54 * @return shifted value
56 static inline int UnScaleByZoomLower(int value, ZoomLevel zoom)
58 return value >> zoom;
61 /**
62 * Short-hand to apply GUI zoom level.
63 * @param value Pixel amount at #ZOOM_LVL_BEGIN (full zoom in).
64 * @return Pixel amount at #ZOOM_LVL_GUI (current interface size).
66 static inline int UnScaleGUI(int value)
68 return UnScaleByZoom(value, ZOOM_LVL_GUI);
71 /**
72 * Scale traditional pixel dimensions to GUI zoom level.
73 * @param value Pixel amount at #ZOOM_LVL_BASE (traditional "normal" interface size).
74 * @return Pixel amount at #ZOOM_LVL_GUI (current interface size).
76 static inline int ScaleGUITrad(int value)
78 return UnScaleGUI(value * ZOOM_LVL_BASE);
81 /**
82 * Short-hand to apply font zoom level.
83 * @param value Pixel amount at #ZOOM_LVL_BEGIN (full zoom in).
84 * @return Pixel amount at #ZOOM_LVL_FONT (current interface size).
86 static inline int UnScaleFont(int value)
88 return UnScaleByZoom(value, ZOOM_LVL_FONT);
91 /**
92 * Scale traditional pixel dimensions to Font zoom level.
93 * @param value Pixel amount at #ZOOM_LVL_BASE (traditional "normal" interface size).
94 * @return Pixel amount at #ZOOM_LVL_FONT (current interface size).
96 static inline int ScaleFontTrad(int value)
98 return UnScaleFont(value * ZOOM_LVL_BASE);
101 #endif /* ZOOM_FUNC_H */