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/>.
10 /** @file zoom_func.h Functions related to zooming. */
15 #include "zoom_type.h"
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
)
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
)
40 return (value
+ (1 << zoom
) - 1) >> zoom
;
44 * Scale by zoom level, usually shift left (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 ScaleByZoomLower(int value
, ZoomLevel zoom
)
56 * Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
57 * @param value value to shift
58 * @param zoom zoom level to shift to
59 * @return shifted value
61 static inline int UnScaleByZoomLower(int value
, ZoomLevel zoom
)
67 #endif /* ZOOM_FUNC_H */