35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
#pragma once
|
|
#include "core/vfs.h"
|
|
#include <SDL3/SDL.h>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace playground {
|
|
|
|
struct CharacterFrame {
|
|
int x=0, y=0, w=0, h=0, regx=0, regy=0;
|
|
};
|
|
|
|
// Frame 0 is the full portrait; later frames are expressions aligned by regx/regy.
|
|
bool parseCharacterFrames(std::string_view xml, std::vector<CharacterFrame>& frames,
|
|
std::string* error=nullptr);
|
|
|
|
class CharacterAtlas {
|
|
public:
|
|
CharacterAtlas()=default;
|
|
~CharacterAtlas();
|
|
CharacterAtlas(const CharacterAtlas&)=delete;
|
|
CharacterAtlas& operator=(const CharacterAtlas&)=delete;
|
|
bool load(SDL_Renderer* renderer,const Vfs& assets,std::string_view name,
|
|
std::string* error=nullptr);
|
|
bool draw(SDL_Renderer* renderer,float x,float y,size_t expression=0,
|
|
Uint8 alpha=255) const;
|
|
const std::vector<CharacterFrame>& frames() const { return frames_; }
|
|
SDL_Texture* texture() const { return texture_; }
|
|
private:
|
|
SDL_Texture* texture_=nullptr;
|
|
std::vector<CharacterFrame> frames_;
|
|
};
|
|
|
|
} // namespace playground
|