1 /* 2 * Copyright (C) 2010-2020 by the Widelands Development Team 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 * 18 */ 19 20 #ifndef WL_GRAPHIC_MINIMAP_RENDERER_H 21 #define WL_GRAPHIC_MINIMAP_RENDERER_H 22 23 #include <memory> 24 25 #include "base/rect.h" 26 #include "base/vector.h" 27 #include "graphic/texture.h" 28 #include "logic/editor_game_base.h" 29 #include "logic/map.h" 30 #include "logic/player.h" 31 32 // Layers for selecting what do display on the minimap. 33 enum class MiniMapLayer { 34 Terrain = 1, 35 Owner = 2, 36 Flag = 4, 37 Road = 8, 38 Building = 16, 39 Zoom2 = 32, 40 ViewWindow = 64, 41 }; 42 43 // A bunch of operators that turn MiniMapLayer into a bitwise combinable flag class. 44 inline MiniMapLayer operator|(MiniMapLayer left, MiniMapLayer right) { 45 return MiniMapLayer(static_cast<int>(left) | static_cast<int>(right)); 46 } 47 inline int operator&(MiniMapLayer left, MiniMapLayer right) { 48 return static_cast<int>(left) & static_cast<int>(right); 49 } 50 inline MiniMapLayer operator^(MiniMapLayer left, MiniMapLayer right) { 51 return MiniMapLayer(static_cast<int>(left) ^ static_cast<int>(right)); 52 } 53 54 enum class MiniMapType { 55 // Keep the view window always in the center of the minimap and pan the underlying map. 56 kStaticViewWindow, 57 58 // Always align the map at (0, 0) and move the view window instead. 59 kStaticMap, 60 }; 61 62 // Converts between minimap pixel and map pixel. 63 // Remember to call 'normalize_pix' after applying the transformation. 64 Vector2f minimap_pixel_to_mappixel(const Widelands::Map& map, 65 const Vector2i& minimap_pixel, 66 const Rectf& view_area, 67 MiniMapType minimap_type, 68 const bool zoom); 69 70 // Render the minimap. If player is not nullptr, it renders from that player's 71 // point of view. The 'view_area' designates the currently visible area in the 72 // main view in map pixel coordinates and is used to draw the wire frame view 73 // window. The 'view_point' is map pixel that will be drawn as the top-left 74 // point in the resulting minimap. 75 std::unique_ptr<Texture> draw_minimap(const Widelands::EditorGameBase& egbase, 76 const Widelands::Player* player, 77 const Rectf& view_area, 78 const MiniMapType& map_draw_type, 79 MiniMapLayer layers); 80 81 // Find an even multiplier to fit the map into 300px 82 int scale_map(const Widelands::Map& map, bool zoom); 83 84 #endif // end of include guard: WL_GRAPHIC_MINIMAP_RENDERER_H 85