aboutsummaryrefslogtreecommitdiff
path: root/include/mgl/graphics/font_char_map.h
blob: 1daf4a297dbacec50279ce06d25e086b20297f7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef MGL_FONT_CHAR_MAP_H
#define MGL_FONT_CHAR_MAP_H

#include "font_glyph.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

typedef struct mgl_font_char_entry mgl_font_char_entry;
typedef struct mgl_font_char_map mgl_font_char_map;

struct mgl_font_char_entry {
    uint32_t key;
    mgl_font_glyph value;
    mgl_font_char_entry *next;
    /* TODO: Remove when fonts copy textures */
    mgl_vec2i render_offset;
    /* TODO: Remove when fonts copy textures */
    bool rendered;
};

typedef struct {
    mgl_font_char_map *char_map;
    size_t index;
    mgl_font_char_entry *value;
} mgl_font_char_iterator;

struct mgl_font_char_map {
    mgl_font_char_entry **entries;
    size_t size;
    size_t capacity;
};

void mgl_font_char_map_init(mgl_font_char_map *self);
void mgl_font_char_map_deinit(mgl_font_char_map *self);

/*
    |value| is copied.
    |inserted_entry| is the newly allocated and inserted entry. the entry wont ever reallocate. may be set to NULL to ignore it.
*/
int mgl_font_char_map_insert(mgl_font_char_map *self, uint32_t key, const mgl_font_glyph *value, mgl_font_char_entry **inserted_entry);
/* The returned value is only valid until the next insert */
mgl_font_char_entry* mgl_font_char_map_get(const mgl_font_char_map *self, uint32_t key);
void mgl_font_char_map_clear_rendered(mgl_font_char_map *self);

/* Iterator value is NULL when the end has been reached */
mgl_font_char_iterator mgl_font_char_map_begin(mgl_font_char_map *self);
void mgl_font_char_iterator_next(mgl_font_char_iterator *self);

#endif /* MGL_FONT_CHAR_MAP_H */