summaryrefslogtreecommitdiff
path: root/src/ui/text.h
blob: b689582eb0e72db400fd5b0998ab424ba966a969 (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
51
52
#pragma once

#include <the_Foundation/rect.h>
#include <the_Foundation/string.h>

#include <SDL_render.h>

enum iFontId {
    default_FontId,
    uiShortcuts_FontId,
    uiInput_FontId,
    /* Document fonts: */
    paragraph_FontId,
    firstParagraph_FontId,
    preformatted_FontId,
    quote_FontId,
    header1_FontId,
    header2_FontId,
    header3_FontId,
    max_FontId
};

#define specialSymbol_Text  0x10

enum iSpecialSymbol {
    silence_SpecialSymbol,
};

void    init_Text           (SDL_Renderer *);
void    deinit_Text         (void);

int     lineHeight_Text     (int font);
iInt2   measure_Text        (int font, const char *text);
iInt2   advance_Text        (int font, const char *text);
iInt2   advanceN_Text       (int font, const char *text, size_t n);

void    draw_Text           (int font, iInt2 pos, int color, const char *text, ...); /* negative pos to switch alignment */
void    drawCentered_Text   (int font, iRect rect, int color, const char *text, ...);

SDL_Texture *   glyphCache_Text     (void);

/*-----------------------------------------------------------------------------------------------*/

iDeclareType(TextBuf)
iDeclareTypeConstructionArgs(TextBuf, int font, const char *text)

struct Impl_TextBuf {
    SDL_Texture *texture;
    iInt2        size;
};

void    draw_TextBuf        (const iTextBuf *, iInt2 pos, int color);