playground-sdk/gfx/draw.h

40 lines
1.3 KiB
C++

#pragma once
#include <SDL3/SDL.h>
#include <SDL3_ttf/SDL_ttf.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include "core/vfs.h"
namespace playground {
// Image cache and ordered 2D draw calls in the display's logical coordinate space.
class Draw {
public:
Draw(SDL_Renderer* renderer, const Vfs& assets);
~Draw();
Draw(const Draw&) = delete;
Draw& operator=(const Draw&) = delete;
SDL_Texture* load(const std::string& path);
bool image(const std::string& path, const SDL_FRect& destination);
bool image(const std::string& path, const SDL_FRect* source, const SDL_FRect& destination);
bool text(const std::string& utf8, float x, float y, SDL_Color color,
int pointSize = 16, float alignWidth = 0, bool center = false,
const std::string& fontName = "", int outlineSize = 0,
SDL_Color outlineColor = {0, 0, 0, 255});
void clear();
private:
SDL_Renderer* renderer_;
const Vfs& assets_;
std::unordered_map<std::string, SDL_Texture*> textures_;
std::unordered_map<std::string, SDL_Texture*> textTextures_;
std::unordered_map<std::string, Bytes> vectorFonts_;
std::unordered_map<std::string, TTF_Font*> sizedFonts_;
std::unordered_set<std::string> warnedVectorFonts_;
bool ttfReady_ = false;
};
} // namespace playground