# zoom_func.h

Go to the documentation of this file.

    00001 /* $Id: zoom_func.h 26202 2014-01-02 11:05:42Z rubidium $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef ZOOM_FUNC_H
    00013 #define ZOOM_FUNC_H
    00014
    00015 #include "zoom_type.h"
    00016
    00024 static inline int ScaleByZoom(int value, ZoomLevel zoom)
    00025 {
    00026   assert(zoom >= 0);
    00027   return value << zoom;
    00028 }
    00029
    00037 static inline int UnScaleByZoom(int value, ZoomLevel zoom)
    00038 {
    00039   assert(zoom >= 0);
    00040   return (value + (1 << zoom) - 1) >> zoom;
    00041 }
    00042
    00049 static inline int ScaleByZoomLower(int value, ZoomLevel zoom)
    00050 {
    00051   assert(zoom >= 0);
    00052   return value << zoom;
    00053 }
    00054
    00061 static inline int UnScaleByZoomLower(int value, ZoomLevel zoom)
    00062 {
    00063   assert(zoom >= 0);
    00064   return value >> zoom;
    00065 }
    00066
    00067 #endif /* ZOOM_FUNC_H */