1 /* 2 * Copyright (C) 2012 Me and My Shadow 3 * 4 * This file is part of Me and My Shadow. 5 * 6 * Me and My Shadow is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Me and My Shadow is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with Me and My Shadow. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef IMAGEMANAGER_H 21 #define IMAGEMANAGER_H 22 23 #include <SDL_render.h> 24 #include <string> 25 #include <map> 26 #include <memory> 27 28 using SharedTexture = std::shared_ptr<SDL_Texture>; 29 30 //Class for loading images. 31 class ImageManager{ 32 public: 33 //Constructor. ImageManager()34 ImageManager(){} 35 //Destructor. 36 ~ImageManager(); 37 38 //Loads an image. 39 //file: The image file to load. 40 //Returns: The SDL_Surface containing the image. 41 SDL_Surface* loadImage(const std::string& file); 42 //Load an image directly to a texture. Returns NULL on failure. 43 //This does not support color keyed textures. 44 //SDL_Texture* loadTexture(const std::string& file, SDL_Renderer& renderer); 45 //Load an image directly to a texture. Terminates on failure. 46 //This does not support color keyed textures. 47 SharedTexture loadTexture(const std::string& file, SDL_Renderer& renderer); 48 49 //Destroys the images 50 void destroy(); 51 private: 52 //Forbid copying 53 ImageManager(const ImageManager&) = delete; 54 ImageManager& operator=(ImageManager const&) = delete; 55 56 //Map containing the images. 57 //The key is the name of the image and the value is a pointer to the SDL_Surface. 58 std::map<std::string, SDL_Surface*> imageCollection; 59 std::map<std::string, SharedTexture> textureCollection; 60 }; 61 62 #endif 63