trmnl_sdl/sdl_helpers.h

34 lines
963 B
C++

#ifndef SDL_HELPERS_H_
#define SDL_HELPERS_H_
#include <SDL2/SDL_ttf.h>
#include <iostream>
#include <string>
#include "json.hpp"
// Call this before everything
// Prints its messages
bool init_sdl();
// Call this at the end only if init has passed
void clean_sdl();
// A simple way to get a font pointer to use
// Can return NULL
TTF_Font* get_font(const std::string& filename, int size);
// Reads the file and tries to parse a JSON file with comments
// cfg - output json struct
// filename - filepath to open and read
// log - output errors to this ostream, silent if NULL
bool read_config_json(nlohmann::json& cfg, const std::string& filename, std::ostream* log = &std::cout);
// JSON Extractors - They do not override already set values if key is not present
void json_extract(const nlohmann::json& j, const std::string& key, std::string& out);
void json_extract(const nlohmann::json& j, const std::string& key, int& out);
#endif // SDL_HELPERS_H_