changeset 451:90a097b1aa0f

core: font -> mlk_font
author David Demelier <markand@malikania.fr>
date Sat, 18 Feb 2023 20:40:01 +0100
parents b26dd49f69ff
children f89147faf8cf
files libmlk-core/mlk/core/font.c libmlk-core/mlk/core/font.h libmlk-rpg/mlk/rpg/battle-bar-default.c libmlk-rpg/mlk/rpg/battle-indicator.c libmlk-rpg/mlk/rpg/message.c libmlk-rpg/mlk/rpg/message.h libmlk-ui/mlk/ui/debug.c libmlk-ui/mlk/ui/label.c libmlk-ui/mlk/ui/notify.c libmlk-ui/mlk/ui/theme.c libmlk-ui/mlk/ui/theme.h
diffstat 11 files changed, 46 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/libmlk-core/mlk/core/font.c	Sat Feb 18 13:37:11 2023 +0100
+++ b/libmlk-core/mlk/core/font.c	Sat Feb 18 20:40:01 2023 +0100
@@ -29,7 +29,7 @@
 #include "util.h"
 
 int
-font_open(struct font *font, const char *path, unsigned int size)
+mlk_font_open(struct mlk_font *font, const char *path, unsigned int size)
 {
 	assert(font);
 	assert(path);
@@ -41,7 +41,7 @@
 }
 
 int
-font_openmem(struct font *font, const void *buffer, size_t buflen, unsigned int size)
+mlk_font_openmem(struct mlk_font *font, const void *buffer, size_t buflen, unsigned int size)
 {
 	assert(font);
 	assert(buffer);
@@ -56,15 +56,15 @@
 }
 
 int
-font_ok(const struct font *font)
+mlk_font_ok(const struct mlk_font *font)
 {
 	return font && font->handle;
 }
 
 int
-font_render(struct font *font, struct texture *tex, const char *text, unsigned long color)
+mlk_font_render(struct mlk_font *font, struct texture *tex, const char *text, unsigned long color)
 {
-	assert(font_ok(font));
+	assert(mlk_font_ok(font));
 	assert(text);
 
 	SDL_Color fg = {
@@ -77,7 +77,7 @@
 	SDL_Surface *(*func)(TTF_Font *, const char *, SDL_Color);
 
 	switch (font->style) {
-	case FONT_STYLE_ANTIALIASED:
+	case MLK_FONT_STYLE_ANTIALIASED:
 		func = TTF_RenderUTF8_Blended;
 		break;
 	default:
@@ -92,17 +92,17 @@
 }
 
 unsigned int
-font_height(const struct font *font)
+mlk_font_height(const struct mlk_font *font)
 {
-	assert(font_ok(font));
+	assert(mlk_font_ok(font));
 
 	return TTF_FontHeight(font->handle);
 }
 
 int
-font_query(const struct font *font, const char *text, unsigned int *w, unsigned int *h)
+mlk_font_query(const struct mlk_font *font, const char *text, unsigned int *w, unsigned int *h)
 {
-	assert(font_ok(font));
+	assert(mlk_font_ok(font));
 	assert(text);
 
 	if (w)
@@ -117,7 +117,7 @@
 }
 
 void
-font_finish(struct font *font)
+mlk_font_finish(struct mlk_font *font)
 {
 	assert(font);
 
--- a/libmlk-core/mlk/core/font.h	Sat Feb 18 13:37:11 2023 +0100
+++ b/libmlk-core/mlk/core/font.h	Sat Feb 18 20:40:01 2023 +0100
@@ -25,39 +25,39 @@
 
 struct texture;
 
-enum font_style {
-	FONT_STYLE_ANTIALIASED,
-	FONT_STYLE_NONE,
-	FONT_STYLE_LAST
+enum mlk_font_style {
+	MLK_FONT_STYLE_ANTIALIASED,
+	MLK_FONT_STYLE_NONE,
+	MLK_FONT_STYLE_LAST
 };
 
-struct font {
-	enum font_style style;
+struct mlk_font {
+	enum mlk_font_style style;
 	void *handle;
 };
 
 CORE_BEGIN_DECLS
 
 int
-font_open(struct font *, const char *, unsigned int);
+mlk_font_open(struct mlk_font *, const char *, unsigned int);
 
 int
-font_openmem(struct font *, const void *, size_t, unsigned int);
+mlk_font_openmem(struct mlk_font *, const void *, size_t, unsigned int);
 
 int
-font_ok(const struct font *);
+mlk_font_ok(const struct mlk_font *);
 
 int
-font_render(struct font *, struct texture *, const char *, unsigned long);
+mlk_font_render(struct mlk_font *, struct texture *, const char *, unsigned long);
 
 unsigned int
-font_height(const struct font *);
+mlk_font_height(const struct mlk_font *);
 
 int
-font_query(const struct font *, const char *, unsigned int *, unsigned int *);
+mlk_font_query(const struct mlk_font *, const char *, unsigned int *, unsigned int *);
 
 void
-font_finish(struct font *);
+mlk_font_finish(struct mlk_font *);
 
 CORE_END_DECLS
 
--- a/libmlk-rpg/mlk/rpg/battle-bar-default.c	Sat Feb 18 13:37:11 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/battle-bar-default.c	Sat Feb 18 20:40:01 2023 +0100
@@ -234,7 +234,7 @@
 	char line[64];
 
 	/* Compute spacing between elements. */
-	spacing = h - (font_height(theme->fonts[THEME_FONT_INTERFACE]) * 3);
+	spacing = h - (mlk_font_height(theme->fonts[THEME_FONT_INTERFACE]) * 3);
 	spacing /= 4;
 
 	/* Reuse the same label. */
--- a/libmlk-rpg/mlk/rpg/battle-indicator.c	Sat Feb 18 13:37:11 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/battle-indicator.c	Sat Feb 18 20:40:01 2023 +0100
@@ -62,8 +62,8 @@
 	bti->elapsed = 0;
 	bti->alpha = 250;
 
-	if (font_render(theme->fonts[THEME_FONT_INTERFACE], &bti->tex[0], buf, bti->cur) < 0||
-	    font_render(theme->fonts[THEME_FONT_INTERFACE], &bti->tex[1], buf, 0x000000ff) < 0)
+	if (mlk_font_render(theme->fonts[THEME_FONT_INTERFACE], &bti->tex[0], buf, bti->cur) < 0||
+	    mlk_font_render(theme->fonts[THEME_FONT_INTERFACE], &bti->tex[1], buf, 0x000000ff) < 0)
 		panic();
 }
 
--- a/libmlk-rpg/mlk/rpg/message.c	Sat Feb 18 13:37:11 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/message.c	Sat Feb 18 20:40:01 2023 +0100
@@ -88,7 +88,7 @@
 	for (size_t i = 0; i < msg->linesz; ++i) {
 		if (!msg->lines[i])
 			continue;
-		if (font_query(THEME(msg)->fonts[THEME_FONT_INTERFACE], msg->lines[i], &w, NULL) < 0)
+		if (mlk_font_query(THEME(msg)->fonts[THEME_FONT_INTERFACE], msg->lines[i], &w, NULL) < 0)
 			panic();
 		if (w > maxw)
 			maxw = w;
@@ -103,7 +103,7 @@
 	assert(msg);
 
 	const struct theme *th = THEME(msg);
-	const unsigned int lh  = font_height(th->fonts[THEME_FONT_INTERFACE]);
+	const unsigned int lh  = mlk_font_height(th->fonts[THEME_FONT_INTERFACE]);
 
 	return (th->padding * 2) + (msg->linesz * lh) + ((msg->linesz - 1) * msg->spacing);
 }
@@ -118,7 +118,7 @@
 	for (size_t i = 0; i < msg->linesz; ++i) {
 		if (!msg->lines[i])
 			continue;
-		if (font_query(theme->fonts[THEME_FONT_INTERFACE], msg->lines[i], &lw, &lh) < 0)
+		if (mlk_font_query(theme->fonts[THEME_FONT_INTERFACE], msg->lines[i], &lw, &lh) < 0)
 			panic();
 
 		label.theme = theme;
--- a/libmlk-rpg/mlk/rpg/message.h	Sat Feb 18 13:37:11 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/message.h	Sat Feb 18 20:40:01 2023 +0100
@@ -23,7 +23,7 @@
 #include <mlk/core/texture.h>
 
 struct mlk_action;
-struct font;
+struct mlk_font;
 struct theme;
 
 union mlk_event;
--- a/libmlk-ui/mlk/ui/debug.c	Sat Feb 18 13:37:11 2023 +0100
+++ b/libmlk-ui/mlk/ui/debug.c	Sat Feb 18 20:40:01 2023 +0100
@@ -57,7 +57,7 @@
 
 	char line[DEBUG_LINE_MAX];
 	const struct theme *theme;
-	struct font *font;
+	struct mlk_font *font;
 	struct texture tex;
 	int x, y;
 
@@ -66,7 +66,7 @@
 	theme = report->theme ? report->theme : theme_default();
 	font = theme->fonts[THEME_FONT_DEBUG];
 
-	if (font_render(font, &tex, line, theme->colors[THEME_COLOR_DEBUG]) < 0)
+	if (mlk_font_render(font, &tex, line, theme->colors[THEME_COLOR_DEBUG]) < 0)
 		return;
 
 	x = theme->padding;
--- a/libmlk-ui/mlk/ui/label.c	Sat Feb 18 13:37:11 2023 +0100
+++ b/libmlk-ui/mlk/ui/label.c	Sat Feb 18 20:40:01 2023 +0100
@@ -32,7 +32,7 @@
 	assert(t);
 	assert(label);
 
-	struct font *font;
+	struct mlk_font *font;
 	struct texture tex;
 	unsigned long color;
 
@@ -45,7 +45,7 @@
 
 	/* Shadow text, only if enabled. */
 	if (label->flags & LABEL_FLAGS_SHADOW) {
-		if (font_render(font, &tex, label->text, t->colors[THEME_COLOR_SHADOW]) < 0)
+		if (mlk_font_render(font, &tex, label->text, t->colors[THEME_COLOR_SHADOW]) < 0)
 			panic();
 
 		texture_draw(&tex, label->x + 1, label->y + 1);
@@ -53,7 +53,7 @@
 	}
 
 	/* Normal text. */
-	if (font_render(font, &tex, label->text, color) < 0)
+	if (mlk_font_render(font, &tex, label->text, color) < 0)
 		panic();
 
 	texture_draw(&tex, label->x, label->y);
@@ -73,11 +73,11 @@
 	assert(label->text);
 
 	const struct theme *t = label->theme ? label->theme : theme_default();
-	const struct font *f = label->flags & LABEL_FLAGS_IMPORTANT
+	const struct mlk_font *f = label->flags & LABEL_FLAGS_IMPORTANT
 		? t->fonts[THEME_FONT_IMPORTANT]
 		: t->fonts[THEME_FONT_INTERFACE];
 
-	if (font_query(f, label->text, w, h) < 0)
+	if (mlk_font_query(f, label->text, w, h) < 0)
 		panic();
 }
 
--- a/libmlk-ui/mlk/ui/notify.c	Sat Feb 18 13:37:11 2023 +0100
+++ b/libmlk-ui/mlk/ui/notify.c	Sat Feb 18 20:40:01 2023 +0100
@@ -91,12 +91,12 @@
 	/* Align title to the right of the icon at the same y coordinate. */
 	geo->title_x  = geo->icon_x + n->icon->w + geo->theme->padding;
 	geo->title_y  = geo->icon_y;
-	geo->title_y -= font_height(geo->theme->fonts[THEME_FONT_IMPORTANT]) / 2;
+	geo->title_y -= mlk_font_height(geo->theme->fonts[THEME_FONT_IMPORTANT]) / 2;
 
 	/* Align body so it ends at the end of the icon. */
 	geo->body_x  = geo->title_x;
 	geo->body_y  = geo->icon_y + n->icon->h;
-	geo->body_y -= font_height(geo->theme->fonts[THEME_FONT_INTERFACE]) / 2;
+	geo->body_y -= mlk_font_height(geo->theme->fonts[THEME_FONT_INTERFACE]) / 2;
 }
 
 static void
--- a/libmlk-ui/mlk/ui/theme.c	Sat Feb 18 13:37:11 2023 +0100
+++ b/libmlk-ui/mlk/ui/theme.c	Sat Feb 18 20:40:01 2023 +0100
@@ -63,8 +63,8 @@
 	const unsigned char *data;
 	const size_t datasz;
 	unsigned int size;
-	struct font **dest;
-	struct font font;
+	struct mlk_font **dest;
+	struct mlk_font font;
 } default_fonts[] = {
 	FONT(assets_fonts_opensans_light, 12, THEME_FONT_DEBUG),
 	FONT(assets_fonts_opensans_regular, 14, THEME_FONT_INTERFACE),
@@ -78,7 +78,7 @@
 	for (size_t i = 0; i < UTIL_SIZE(default_fonts); ++i) {
 		struct font_catalog *fc = &default_fonts[i];
 
-		if (font_openmem(&fc->font, fc->data, fc->datasz, fc->size) < 0)
+		if (mlk_font_openmem(&fc->font, fc->data, fc->datasz, fc->size) < 0)
 			goto failed;
 
 		/* Reference this font into the catalog. */
@@ -149,7 +149,7 @@
 theme_finish(void)
 {
 	for (size_t i = 0; i < UTIL_SIZE(default_fonts); ++i) {
-		font_finish(&default_fonts[i].font);
+		mlk_font_finish(&default_fonts[i].font);
 		*default_fonts[i].dest = NULL;
 	}
 }
--- a/libmlk-ui/mlk/ui/theme.h	Sat Feb 18 13:37:11 2023 +0100
+++ b/libmlk-ui/mlk/ui/theme.h	Sat Feb 18 20:40:01 2023 +0100
@@ -23,7 +23,7 @@
 
 struct button;
 struct checkbox;
-struct font;
+struct mlk_font;
 struct frame;
 struct label;
 struct sprite;
@@ -49,7 +49,7 @@
 };
 
 struct theme {
-	struct font *fonts[THEME_FONT_NUM];
+	struct mlk_font *fonts[THEME_FONT_NUM];
 	const struct sprite *sprites[THEME_SPRITE_NUM];
 	unsigned long colors[THEME_COLOR_NUM];
 	unsigned int padding;