aboutsummaryrefslogtreecommitdiffstats
path: root/renderer.c
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-02-16 21:13:58 -0500
committerSam Anthony <sam@samanthony.xyz>2025-02-16 21:13:58 -0500
commitac6ef66cc8f60ecc9d7ee8691bf7a73fcc24f4b7 (patch)
tree43228b509adf544468f4f35747bba8130e2ea133 /renderer.c
parent40b2fc59394a2bedd1097fde107ce54b5773d649 (diff)
downloadvolute-ac6ef66cc8f60ecc9d7ee8691bf7a73fcc24f4b7.zip
renderer: set font size functions on init
Diffstat (limited to 'renderer.c')
-rw-r--r--renderer.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/renderer.c b/renderer.c
index 4720ac0..5bbfbcb 100644
--- a/renderer.c
+++ b/renderer.c
@@ -12,6 +12,10 @@ enum window {
HEIGHT = 600,
};
+enum text {
+ TEXT_HEIGHT = 18,
+};
+
static const mu_Color COLOR_BG = {0, 0, 0, 255};
static const char button_map[256] = {
@@ -42,6 +46,27 @@ static int buf_idx;
static SDL_Window *window;
+static int text_width(mu_Font font, const char *text, int len) {
+ if (len < 0) {
+ len = strlen(text);
+ }
+
+ int res = 0;
+ for (const char *p = text; *p && len--; p++) {
+ if ((*p & 0xc0) == 0x80) { continue; }
+ int chr = mu_min((unsigned char) *p, 127);
+ res += atlas[ATLAS_FONT + chr].w;
+ }
+ return res;
+}
+
+
+static int
+text_height(mu_Font font) {
+ return TEXT_HEIGHT;
+}
+
+
static void flush(void) {
if (buf_idx == 0) { return; }
@@ -211,7 +236,7 @@ static void render_command(mu_Command *cmd) {
}
-void r_init(void) {
+void r_init(mu_Context *ctx) {
/* init SDL window */
SDL_Init(SDL_INIT_EVERYTHING);
window = SDL_CreateWindow(
@@ -239,6 +264,10 @@ void r_init(void) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
assert(glGetError() == 0);
+
+ /* init microui */
+ ctx->text_width = text_width;
+ ctx->text_height = text_height;
}
@@ -266,22 +295,6 @@ void r_present(void) {
}
-int r_get_text_width(const char *text, int len) {
- int res = 0;
- for (const char *p = text; *p && len--; p++) {
- if ((*p & 0xc0) == 0x80) { continue; }
- int chr = mu_min((unsigned char) *p, 127);
- res += atlas[ATLAS_FONT + chr].w;
- }
- return res;
-}
-
-
-int r_get_text_height(void) {
- return 18;
-}
-
-
void r_get_window_size(int *w, int *h) {
SDL_GetWindowSize(window, w, h);
}