1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "2D/BsSpriteManager.h"
4#include "2D/BsSpriteMaterials.h"
5
6namespace bs
7{
8 SpriteManager::SpriteManager()
9 {
10 SpriteMaterial* imageTransparentMat = registerMaterial<SpriteImageMaterial>(true, false);
11 SpriteMaterial* imageOpaqueMat = registerMaterial<SpriteImageMaterial>(false, false);
12 SpriteMaterial* imageTransparentAnimMat = registerMaterial<SpriteImageMaterial>(true, true);
13 SpriteMaterial* imageOpaqueAnimMat = registerMaterial<SpriteImageMaterial>(false, true);
14 SpriteMaterial* textMat = registerMaterial<SpriteTextMaterial>();
15 SpriteMaterial* lineMat = registerMaterial<SpriteLineMaterial>();
16
17 builtinMaterialIds[(UINT32)BuiltinSpriteMaterialType::ImageTransparent] = imageTransparentMat->getId();
18 builtinMaterialIds[(UINT32)BuiltinSpriteMaterialType::ImageOpaque] = imageOpaqueMat->getId();
19 builtinMaterialIds[(UINT32)BuiltinSpriteMaterialType::ImageTransparentAnimated] = imageTransparentAnimMat->getId();
20 builtinMaterialIds[(UINT32)BuiltinSpriteMaterialType::ImageOpaqueAnimated] = imageOpaqueAnimMat->getId();
21 builtinMaterialIds[(UINT32)BuiltinSpriteMaterialType::Text] = textMat->getId();
22 builtinMaterialIds[(UINT32)BuiltinSpriteMaterialType::Line] = lineMat->getId();
23 }
24
25 SpriteManager::~SpriteManager()
26 {
27 for(auto& entry : mMaterials)
28 bs_delete(entry.second);
29 }
30
31 SpriteMaterial* SpriteManager::getMaterial(UINT32 id) const
32 {
33 auto iterFind = mMaterials.find(id);
34 if (iterFind != mMaterials.end())
35 return iterFind->second;
36
37 return nullptr;
38 }
39}