/* Copyright: (c) Kayne Ruse 2013-2016 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * * 3. This notice may not be removed or altered from any source * distribution. */ #pragma once #include "image.hpp" #include #include #include template class CompositeImage { public: CompositeImage() = default; ~CompositeImage() = default; void Load(SDL_Renderer* const, std::string spriteDir, std::list nameList); void SetTextures(std::map& templateImages); void Free(); void DrawTo(SDL_Renderer* const, Sint16 x, Sint16 y, double scaleX = 1.0, double scaleY = 1.0); //accessors & mutators T* Find(std::string name); bool Enable(std::string name); bool Disable(std::string name); void EnableAll(); void DisableAll(); std::map>* GetTemplateImages(); private: std::map> imageMap; }; template void CompositeImage::Load(SDL_Renderer* const renderer, std::string spriteDir, std::list nameList) { for (auto& it : nameList) { imageMap[it].first = true; imageMap[it].second.Load(renderer, spriteDir + it); } } template void CompositeImage::SetTextures(std::map& templateImages) { for (auto& it : templateImages) { imageMap[it.first].first = true; imageMap[it.first].second.SetTexture(it.second.GetTexture()); } } template void CompositeImage::Free() { imageMap.clear(); } template void CompositeImage::DrawTo(SDL_Renderer* const dest, Sint16 x, Sint16 y, double scaleX, double scaleY) { //draw all members, regardless of internal ordering for (auto& it : imageMap) { if (it.second.first) { it.second.second.DrawTo(dest, x, y, scaleX, scaleY); } } } //------------------------- //accessors & mutators //------------------------- template T* CompositeImage::Find(std::string name) { auto it = imageMap.find(name); if (it == imageMap.end()) { return nullptr; } else { return &it->second.second; } } template bool CompositeImage::Enable(std::string name) { auto it = imageMap.find(name); if (it == imageMap.end()) { return false; } else { imageMap[name].first = true; return true; } } template bool CompositeImage::Disable(std::string name) { auto it = imageMap.find(name); if (it == imageMap.end()) { return false; } else { imageMap[name].first = false; return true; } } template void CompositeImage::EnableAll() { for (auto& it : imageMap) { it.second.first = true; } } template void CompositeImage::DisableAll() { for (auto& it : imageMap) { it.second.first = false; } } template std::map>* CompositeImage::GetTemplateImages() { return &imageMap; }