# zoom_func.h

Go to the documentation of this file.

    00001 /* $Id: zoom_func.h 18351 2009-11-30 11:29:52Z 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   if (zoom == ZOOM_LVL_NORMAL) return value;
    00027   int izoom = zoom - ZOOM_LVL_NORMAL;
    00028   return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : (value + (1 << -izoom) - 1) >> -izoom;
    00029 }
    00030
    00038 static inline int UnScaleByZoom(int value, ZoomLevel zoom)
    00039 {
    00040   if (zoom == ZOOM_LVL_NORMAL) return value;
    00041   int izoom = zoom - ZOOM_LVL_NORMAL;
    00042   return (zoom > ZOOM_LVL_NORMAL) ? (value + (1 << izoom) - 1) >> izoom : value << -izoom;
    00043 }
    00044
    00051 static inline int ScaleByZoomLower(int value, ZoomLevel zoom)
    00052 {
    00053   if (zoom == ZOOM_LVL_NORMAL) return value;
    00054   int izoom = zoom - ZOOM_LVL_NORMAL;
    00055   return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : value >> -izoom;
    00056 }
    00057
    00064 static inline int UnScaleByZoomLower(int value, ZoomLevel zoom)
    00065 {
    00066   if (zoom == ZOOM_LVL_NORMAL) return value;
    00067   int izoom = zoom - ZOOM_LVL_NORMAL;
    00068   return (zoom > ZOOM_LVL_NORMAL) ? value >> izoom : value << -izoom;
    00069 }
    00070
    00071 #endif /* ZOOM_FUNC_H */