dfhack/library/include/modules/Textures.h

83 lines
2.4 KiB
C

#pragma once
2023-08-11 12:40:41 -06:00
#include <string>
2023-08-12 07:11:42 -06:00
#include <vector>
2023-08-11 00:14:05 -06:00
#include "ColorText.h"
2023-08-12 07:11:42 -06:00
#include "Export.h"
2023-08-12 23:33:31 -06:00
struct SDL_Surface;
2023-08-11 00:14:05 -06:00
2023-08-13 11:09:12 -06:00
typedef uintptr_t TexposHandle;
2023-08-11 00:14:05 -06:00
namespace DFHack {
/**
* The Textures module - loads and provides access to DFHack textures
* \ingroup grp_modules
* \ingroup grp_textures
*/
namespace Textures {
2023-08-12 23:33:31 -06:00
const uint32_t TILE_WIDTH_PX = 8;
const uint32_t TILE_HEIGHT_PX = 12;
2023-08-11 00:14:05 -06:00
/**
* Load texture and get handle.
* Keep it to obtain valid texpos.
*/
2023-09-01 09:12:59 -06:00
DFHACK_EXPORT TexposHandle loadTexture(SDL_Surface* surface, bool reserved = false);
2023-08-11 00:14:05 -06:00
2023-08-11 12:40:41 -06:00
/**
* Load tileset from image file.
* Return vector of handles to obtain valid texposes.
*/
2023-08-12 23:33:31 -06:00
DFHACK_EXPORT std::vector<TexposHandle> loadTileset(const std::string& file,
int tile_px_w = TILE_WIDTH_PX,
2023-09-01 09:12:59 -06:00
int tile_px_h = TILE_HEIGHT_PX,
bool reserved = false);
2023-08-11 12:40:41 -06:00
2023-08-11 00:14:05 -06:00
/**
* Get texpos by handle.
2023-08-16 21:32:26 -06:00
* Always use this function, if you need to get valid texpos for your texture.
2023-08-11 00:14:05 -06:00
* Texpos can change on game textures reset, but handle will be the same.
*/
2023-08-11 12:40:41 -06:00
DFHACK_EXPORT long getTexposByHandle(TexposHandle handle);
2023-08-11 00:14:05 -06:00
2023-08-28 01:00:39 -06:00
/**
* Delete all info about texture by TexposHandle
*/
DFHACK_EXPORT void deleteHandle(TexposHandle handle);
/**
2023-08-29 22:38:21 -06:00
* Create new texture with RGBA32 format and pixels as data in row major order.
2023-08-28 01:00:39 -06:00
* Register this texture and return TexposHandle.
*/
DFHACK_EXPORT TexposHandle createTile(std::vector<uint32_t>& pixels, int tile_px_w = TILE_WIDTH_PX,
2023-09-01 09:12:59 -06:00
int tile_px_h = TILE_HEIGHT_PX, bool reserved = false);
2023-08-28 01:00:39 -06:00
/**
2023-08-29 22:38:21 -06:00
* Create new textures as tileset with RGBA32 format and pixels as data in row major order.
2023-08-28 01:00:39 -06:00
* Register this textures and return vector of TexposHandle.
*/
DFHACK_EXPORT std::vector<TexposHandle> createTileset(std::vector<uint32_t>& pixels,
int texture_px_w, int texture_px_h,
int tile_px_w = TILE_WIDTH_PX,
2023-09-01 09:12:59 -06:00
int tile_px_h = TILE_HEIGHT_PX,
bool reserved = false);
2023-08-28 01:00:39 -06:00
2023-08-11 12:40:41 -06:00
/**
2023-08-12 07:11:42 -06:00
* Call this on DFHack init just once to setup interposed handlers and
* init static assets.
2023-08-11 12:40:41 -06:00
*/
2023-08-12 07:11:42 -06:00
void init(DFHack::color_ostream& out);
/**
* Call this when DFHack is being unloaded.
*
*/
void cleanup();
2023-08-12 07:11:42 -06:00
} // namespace Textures
} // namespace DFHack