v / vlib / sokol / sfons / sfons.c.v
42 lines · 36 sloc · 920 bytes · 227dbc7d4a3943fe8f1541f595b6ef9851bef552
Raw
1module sfons
2
3import fontstash
4import sokol.f as _
5import sokol.memory
6
7// create a new Context/font atlas, for rendering glyphs, given its dimensions `width` and `height`
8@[inline]
9pub fn create(width int, height int, flags int) &fontstash.Context {
10 assert is_power_of_two(width)
11 assert is_power_of_two(height)
12 allocator := C.sfons_allocator_t{
13 alloc_fn: memory.salloc
14 free_fn: memory.sfree
15 user_data: voidptr(0x100005f0)
16 }
17 desc := C.sfons_desc_t{
18 width: width
19 height: height
20 allocator: allocator
21 }
22 return C.sfons_create(&desc)
23}
24
25@[inline]
26pub fn destroy(ctx &fontstash.Context) {
27 C.sfons_destroy(ctx)
28}
29
30@[inline]
31pub fn rgba(r u8, g u8, b u8, a u8) u32 {
32 return C.sfons_rgba(r, g, b, a)
33}
34
35@[inline]
36pub fn flush(ctx &fontstash.Context) {
37 C.sfons_flush(ctx)
38}
39
40fn is_power_of_two(x int) bool {
41 return x in [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768]
42}
43