-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneko_ctx.c
51 lines (37 loc) · 1.43 KB
/
neko_ctx.c
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
//SPDX-License-Identifier: GPL-2.0-or-later
/*
Copyright (c) 2019-2024 Cyril Hrubis <[email protected]>
*/
#include <core/gp_core.h>
#include <backends/gp_backend.h>
#include "neko_ctx.h"
struct neko_ctx ctx;
static gp_text_style style = GP_DEFAULT_TEXT_STYLE;
static gp_text_style style_bold = GP_DEFAULT_TEXT_STYLE;
void neko_ctx_init(gp_backend *backend, int reverse, const char *font_family)
{
const gp_font_family *family = gp_font_family_lookup(font_family);
style.font = gp_font_family_face_lookup(family, GP_FONT_REGULAR);
if (!style.font)
style.font = gp_font_family_face_lookup(family, GP_FONT_MONO);
if (style.font)
ctx.font = &style;
style_bold.font = gp_font_family_face_lookup(family, GP_FONT_REGULAR | GP_FONT_BOLD);
if (!style_bold.font)
style_bold.font = gp_font_family_face_lookup(family, GP_FONT_MONO | GP_FONT_BOLD);
if (!style_bold.font) {
style_bold.font = gp_font_family_face_lookup(family, GP_FONT_MONO);
gp_text_style_embold(&style_bold, style.font, 1);
}
ctx.font_bold = &style_bold;
ctx.backend = backend;
ctx.padd = gp_text_descent(ctx.font)+1;
ctx.col_bg = gp_rgb_to_pixmap_pixel(0, 0, 0, backend->pixmap);
ctx.col_fg = gp_rgb_to_pixmap_pixel(0xff, 0xff, 0xff, backend->pixmap);
if (reverse)
GP_SWAP(ctx.col_bg, ctx.col_fg);
if (reverse)
ctx.col_sel = gp_rgb_to_pixmap_pixel(0xa0, 0xc0, 0xff, backend->pixmap);
else
ctx.col_sel = gp_rgb_to_pixmap_pixel(0, 0x20, 0x60, backend->pixmap);
}