-
Notifications
You must be signed in to change notification settings - Fork 0
/
fontdraw.h
69 lines (52 loc) · 1.99 KB
/
fontdraw.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include <stdint.h>
#include "bmpload.h"
struct font_descriptor_t {
uint16_t offset; // in atlas
int8_t xofs, yofs; // in pixels
uint8_t width, height;
uint8_t advance;
uint8_t reserved;
};
struct font_info_t {
int atlas_width, atlas_height;
int start_char;
font_descriptor_t *desc;
uint32_t *atlasData; // interleaved dwords pixels/mask
BITMAPV5HEADER bmphead;
};
// init font info
int font_load(font_info_t *info, font_descriptor_t *desc, const char *bitmapFile, int startChar);
// unload font
int font_free(font_info_t *info);
// get character descriptor
font_descriptor_t* font_get_char_info(font_info_t *info, int ch);
// get length of string
int font_get_length(font_info_t *font, const char *str);
// draw one char
int font_draw_char(uint8_t *dst, struct font_info_t *font, int ch, int x, int y, int dst_pitch, uint32_t colormask = 0xFFFFFFFF);
// draw string
int font_draw_string(uint8_t *dst, struct font_info_t *font, const char *str, int x, int y, int dst_pitch, uint32_t colormask = 0xFFFFFFFF);
// draw one char
int font_draw_char_add(uint8_t *dst, struct font_info_t *font, int ch, int x, int y, int dst_pitch, uint32_t colormask = 0xFFFFFFFF);
// draw string
int font_draw_string_add(uint8_t *dst, struct font_info_t *font, const char *str, int x, int y, int dst_pitch, uint32_t colormask = 0xFFFFFFFF);
void font_generate_mask(uint32_t* dst, uint8_t* src, int l);
// ------------------
// scroller!
struct scroller_t {
font_info_t *font;
const char *text;
// internals
const char *curtext;
int length;
int textofs; // in characters
int pixelpos; // in pixels
int glyphpos; // in pixels
};
// init scroller
void scroller_init(scroller_t *scroll);
// advance scroller
void scroller_advance(scroller_t *scroll, int dx);
// draw scroller from current position
void scroller_draw(scroller_t *scroll, uint8_t *dst, int x, int y, int width, int dst_pitch, uint32_t color = 0xFFFFFFFF);