 |
Cytopia
0.3
A city building simulation game
|
Go to the documentation of this file.
10 #include <SDL_image.h>
29 const json uiDataJSON = json::parse(jsonFileContent,
nullptr,
false);
32 if (uiDataJSON.is_discarded())
35 for (
const auto &tileID : uiDataJSON.items())
37 for (
auto it = uiDataJSON[tileID.key()].begin(); it != uiDataJSON[tileID.key()].end(); ++it)
84 SDL_Surface *surface = IMG_Load(fName.c_str());
99 throw UIError(
TRACE_INFO "Texture could not be created! SDL Error: " +
string{SDL_GetError()});
106 SDL_FreeSurface(it.second);
112 SDL_DestroyTexture(it.second);
118 for (
const auto &ita : it.second)
120 SDL_DestroyTexture(ita.second);
128 SDL_Color Color{0, 0, 0, SDL_ALPHA_TRANSPARENT};
132 const int bpp = surface->format->BytesPerPixel;
133 Uint8 *p = &
static_cast<Uint8 *
>(surface->pixels)[y * surface->pitch + x * bpp];
134 const Uint32 pixel = *
reinterpret_cast<Uint32 *
>(p);
136 SDL_GetRGBA(pixel, surface->format, &Color.r, &Color.g, &Color.b, &Color.a);
SDL_Surface * getTileSurface(const std::string &id)
A UI-related error occured.
bool fileExists(const std::string &filePath)
Check if a file (or folder) exists.
SDL_Texture * getTileTexture(const std::string &id)
std::unordered_map< std::string, SDL_Texture * > m_tileTextureMap
SDL_Texture * getUITexture(const std::string &uiElement)
retrieves texture for a tileID
void loadUITexture()
Load Texture in to Texture Map, if an entry for this tile ID does not yet exist.
std::unordered_map< std::string, SDL_Surface * > m_surfaceMap
std::string readFileAsString(const std::string &fileName, bool binaryMode)
Read contents from a file as string.
std::string getBasePath()
Get base path (where Cytopia is being run)
SDL_Color getColorOfPixelInSurface(const std::string &tileID, int x, int y)
Get the Color Of Pixel In Surface object at a given coordinate.
void flush()
Delete everything. Should be called from the destuctor only.
SDL_Texture * createTextureFromSurface(SDL_Surface *surface)
void loadTexture(const std::string &id, const std::string &fileName)
static Settings & instance(void)
Get an instance of the singleton.
std::unordered_map< std::string, std::unordered_map< std::string, SDL_Texture * > > m_uiTextureMap
SDL_Surface * createSurfaceFromFile(const std::string &fileName)