Files
kichikuou_system3-sdl2/src/sys/cg.h
T
kichikuou bdb93bf7ed Add SDL3 support alongside SDL2
Centralize the differences between SDL2 and SDL3 behind compatibility
interfaces and select the appropriate implementations with the
SYSTEM3_SDL_VERSION CMake option. The default is SDL2 except on Android,
which supports only SDL3.
2026-09-15 15:21:22 +09:00

43 lines
947 B
C++

/*
ALICE SOFT SYSTEM 3 for Win32
[ CG ]
*/
#ifndef _CG_H_
#define _CG_H_
#include <memory>
#include "sdl_compat.h"
#include "common.h"
inline uint8_t* surface_line(SDL_Surface* surface, int y)
{
return static_cast<uint8*>(surface->pixels) + surface->pitch * y;
}
struct SurfaceDeleter {
void operator()(SDL_Surface* s) const noexcept {
if (s) sdl::DestroySurface(s);
}
};
struct CG {
std::unique_ptr<SDL_Surface, SurfaceDeleter> surface_;
int x;
int y;
CG() = default;
CG(int x, int y, int width, int height)
: surface_(sdl::CreateSurface(width, height, SDL_PIXELFORMAT_INDEX8)),
x(x), y(y) {}
explicit operator bool() const noexcept { return static_cast<bool>(surface_); }
SDL_Surface* surface() const { return surface_.get(); }
int width() const { return surface_->w; }
int height() const { return surface_->h; }
SDL_Palette* palette() const { return sdl::GetSurfacePalette(surface_.get()); }
};
#endif // _CG_H_