OpenTTD Source: src/zoom_func.h Source File

OpenTTD Source 13.1

zoom_func.h
Go to the documentation of this file.
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 */
7
10 #ifndef ZOOM_FUNC_H
11 #define ZOOM_FUNC_H
12
13 #include "zoom_type.h"
14
22 static inline int ScaleByZoom(int value, ZoomLevel zoom)
23 {
24 return value << zoom;
25 }
26
34 static inline int UnScaleByZoom(int value, ZoomLevel zoom)
35 {
36 return (value + (1 << zoom) - 1) >> zoom;
37 }
38
45 static inline int AdjustByZoom(int value, int zoom)
46 {
47 return zoom < 0 ? UnScaleByZoom(value, ZoomLevel(-zoom)) : ScaleByZoom(value, ZoomLevel(zoom));
48 }
49
56 static inline int ScaleByZoomLower(int value, ZoomLevel zoom)
57 {
58 return value << zoom;
59 }
60
67 static inline int UnScaleByZoomLower(int value, ZoomLevel zoom)
68 {
69 return value >> zoom;
70 }
71
77 static inline int UnScaleGUI(int value)
78 {
79 return UnScaleByZoom(value, ZOOM_LVL_GUI);
80 }
81
87 static inline ZoomLevel ScaleZoomGUI(ZoomLevel value)
88 {
89 return std::clamp(ZoomLevel(value + (ZOOM_LVL_GUI - ZOOM_LVL_OUT_4X)), ZOOM_LVL_MIN, ZOOM_LVL_MAX);
90 }
91
97 static inline ZoomLevel UnScaleZoomGUI(ZoomLevel value)
98 {
99 return std::clamp(ZoomLevel(value - (ZOOM_LVL_GUI - ZOOM_LVL_OUT_4X)), ZOOM_LVL_MIN, ZOOM_LVL_MAX);
100 }
101
107 static inline int ScaleSpriteTrad(int value)
108 {
109 return UnScaleGUI(value * ZOOM_LVL_BASE);
110 }
111
117 static inline int ScaleGUITrad(int value)
118 {
119 return value * _gui_scale / 100;
120 }
121
122 #endif /* ZOOM_FUNC_H */
UnScaleByZoomLower
static int UnScaleByZoomLower(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
Definition: zoom_func.h:67
ScaleByZoomLower
static int ScaleByZoomLower(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL)
Definition: zoom_func.h:56
UnScaleGUI
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:77
UnScaleZoomGUI
static ZoomLevel UnScaleZoomGUI(ZoomLevel value)
UnScale zoom level relative to GUI zoom.
Definition: zoom_func.h:97
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
ZOOM_LVL_MAX
@ ZOOM_LVL_MAX
Maximum zoom level.
Definition: zoom_type.h:46
_gui_scale
int _gui_scale
GUI scale, 100 is 100%.
Definition: gfx.cpp:65
ZOOM_LVL_MIN
@ ZOOM_LVL_MIN
Minimum zoom level.
Definition: zoom_type.h:45
ScaleSpriteTrad
static int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition: zoom_func.h:107
UnScaleByZoom
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:34
ScaleByZoom
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:22
AdjustByZoom
static int AdjustByZoom(int value, int zoom)
Adjust by zoom level; zoom < 0 shifts right, zoom >= 0 shifts left.
Definition: zoom_func.h:45
ScaleZoomGUI
static ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition: zoom_func.h:87
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
zoom_type.h
ZOOM_LVL_OUT_4X
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
Definition: zoom_type.h:24