summaryrefslogtreecommitdiff
path: root/gfx-iso/include/isogfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx-iso/include/isogfx')
-rw-r--r--gfx-iso/include/isogfx/isogfx.h63
1 files changed, 48 insertions, 15 deletions
diff --git a/gfx-iso/include/isogfx/isogfx.h b/gfx-iso/include/isogfx/isogfx.h
index a5f7770..22c8fd5 100644
--- a/gfx-iso/include/isogfx/isogfx.h
+++ b/gfx-iso/include/isogfx/isogfx.h
@@ -3,64 +3,97 @@
3 */ 3 */
4#pragma once 4#pragma once
5 5
6#include <stdbool.h>
6#include <stdint.h> 7#include <stdint.h>
7 8
8typedef struct IsoGfx IsoGfx; 9typedef struct IsoGfx IsoGfx;
9 10
10typedef uint8_t Tile; 11/// Tile handle.
12typedef uint16_t Tile;
13
14/// Colour channel.
11typedef uint8_t Channel; 15typedef uint8_t Channel;
12 16
13typedef struct Pixel { 17typedef struct Pixel {
14 Channel r, g, b; 18 Channel r, g, b, a;
15} Pixel; 19} Pixel;
16 20
17typedef enum TileDescType { 21typedef enum TileDescType {
18 TileFromColour, 22 TileFromColour,
19 TileFromFile, 23 TileFromFile,
20 TileFromMemory 24 TileFromMemory,
21} TileDescType; 25} TileDescType;
22 26
23typedef struct TileDesc { 27typedef struct TileDesc {
24 TileDescType type; 28 TileDescType type;
29 int width; /// Tile width in pixels.
30 int height; /// Tile height in pixels.
25 union { 31 union {
26 Pixel colour; 32 Pixel colour; /// Constant colour tile.
27 struct { 33 struct {
28 const char* path; 34 const char* path;
29 } file; 35 } file;
30 struct { 36 struct {
31 const void* data; 37 const uint8_t* data; /// sizeof(Pixel) * width * height
32 } mem; 38 } mem;
33 }; 39 };
34} TileDesc; 40} TileDesc;
35 41
42typedef struct WorldDesc {
43 int tile_width; /// Base tile width in pixels.
44 int tile_height; /// Base tile height in pixels.
45 int world_width; /// World width in tiles.
46 int world_height; /// World height in tiles.
47 int max_num_tiles; /// 0 for an implementation-defined default.
48} WorldDesc;
49
36typedef struct IsoGfxDesc { 50typedef struct IsoGfxDesc {
37 int screen_width; 51 int screen_width; /// Screen width in pixels.
38 int screen_height; 52 int screen_height; /// Screen height in pixels.
39 int tile_width;
40 int tile_height;
41 int world_width;
42 int world_height;
43 int max_num_tiles; // 0 for an implementation-defined default.
44} IsoGfxDesc; 53} IsoGfxDesc;
45 54
55/// Create a new isometric graphics engine.
46IsoGfx* isogfx_new(const IsoGfxDesc*); 56IsoGfx* isogfx_new(const IsoGfxDesc*);
47 57
58/// Destroy the isometric graphics engine.
48void isogfx_del(IsoGfx**); 59void isogfx_del(IsoGfx**);
49 60
61/// Create an empty world.
62bool isogfx_make_world(IsoGfx*, const WorldDesc*);
63
64/// Load a world from a tile map (.TM) file.
65bool isogfx_load_world(IsoGfx*, const char* filepath);
66
67/// Return the world's width.
68int isogfx_world_width(const IsoGfx*);
69
70/// Return the world's height.
71int isogfx_world_height(const IsoGfx*);
72
73/// Create a new tile.
50Tile isogfx_make_tile(IsoGfx*, const TileDesc*); 74Tile isogfx_make_tile(IsoGfx*, const TileDesc*);
51 75
76/// Set the tile at position (x,y).
52void isogfx_set_tile(IsoGfx*, int x, int y, Tile); 77void isogfx_set_tile(IsoGfx*, int x, int y, Tile);
53 78
79/// Set the tiles in positions in the range (x0,y0) - (x1,y1).
54void isogfx_set_tiles(IsoGfx*, int x0, int y0, int x1, int y1, Tile); 80void isogfx_set_tiles(IsoGfx*, int x0, int y0, int x1, int y1, Tile);
55 81
82/// Translate Cartesian to isometric coordinates.
56void isogfx_pick_tile( 83void isogfx_pick_tile(
57 const IsoGfx*, double xcart, double ycart, int* xiso, int* yiso); 84 const IsoGfx*, double xcart, double ycart, int* xiso, int* yiso);
58 85
86/// Render the world.
59void isogfx_render(IsoGfx*); 87void isogfx_render(IsoGfx*);
60 88
89/// Draw/overlay a tile at position (x,y).
90///
91/// This function just renders a tile at position (x,y) and should be called
92/// after isogfx_render() to obtain the correct result. To set the tile at
93/// position (x,y) instead, use isogfx_set_tile().
61void isogfx_draw_tile(IsoGfx*, int x, int y, Tile); 94void isogfx_draw_tile(IsoGfx*, int x, int y, Tile);
62 95
96/// Return a pointer to the internal colour buffer.
97///
98/// Call after each call to isogfx_render() to retrieve the render output.
63const Pixel* isogfx_get_screen_buffer(const IsoGfx*); 99const Pixel* isogfx_get_screen_buffer(const IsoGfx*);
64
65int isogfx_world_width(const IsoGfx*);
66int isogfx_world_height(const IsoGfx*);