97c8847eb0
Co-authored-by: Copilot <copilot@github.com>
39 lines
1.7 KiB
C++
39 lines
1.7 KiB
C++
#pragma once
|
|
/** @file Palette.hpp
|
|
* @brief HDK sdl video header only wrapper for SDL_Palette struct & related functions
|
|
*/
|
|
#include <SDL3/SDL_pixels.h>
|
|
#include <hdk/grid/SharedPtrWrapper.hpp>
|
|
namespace hdk::sdl {
|
|
/**
|
|
* @brief
|
|
* @note
|
|
*/
|
|
class Palette : public hdk::grid::SharedPtrWrapper<SDL_Palette> {
|
|
public:
|
|
/** Inherit constructors from SharedPtrWrapper */
|
|
using hdk::grid::SharedPtrWrapper<SDL_Palette>::SharedPtrWrapper;
|
|
/** @see https://wiki.libsdl.org/SDL3/SDL_CreatePalette
|
|
* @brief Create a palette with a specified number of colors.
|
|
* @param ncolors The number of colors in the palette.
|
|
* @return Palette The created palette. If the creation fails, returns an invalid palette.
|
|
*/
|
|
static Palette Create(int ncolors) {
|
|
return Palette(get_or_cache(SDL_CreatePalette(ncolors), SDL_DestroyPalette));
|
|
}
|
|
/** @see https://wiki.libsdl.org/SDL3/SDL_DestroyPalette
|
|
* @brief Destroy a palette and free its associated memory.
|
|
*/
|
|
void Destroy() const { SDL_DestroyPalette(*this); }
|
|
/** @see https://wiki.libsdl.org/SDL3/SDL_SetPaletteColors
|
|
* @brief Set a range of colors in a palette.
|
|
* @param colors An array of SDL_Color structures representing the colors to set in the palette.
|
|
* @param firstcolor The index of the first color to set in the palette.
|
|
* @param ncolors The number of colors to set in the palette.
|
|
* @return bool True on success, false on failure.
|
|
*/
|
|
bool SetColors(const SDL_Color* colors, int firstcolor, int ncolors) const {
|
|
return SDL_SetPaletteColors(*this, colors, firstcolor, ncolors);
|
|
}
|
|
};
|
|
} |