From d6c787f1a7280593ffaec8eed9ed239784299182 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Wed, 8 Oct 2025 17:24:42 +0000 Subject: [PATCH] better font api git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@229 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Mw/Draw.h | 3 ++- src/draw.c | 10 ++++++++-- src/widget/button.c | 2 +- src/widget/label.c | 2 +- src/widget/menu.c | 7 +++---- src/widget/submenu.c | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/Mw/Draw.h b/include/Mw/Draw.h index ccb4856..a37701e 100644 --- a/include/Mw/Draw.h +++ b/include/Mw/Draw.h @@ -77,9 +77,10 @@ MWDECL void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int in * %param point Center point of the text * %param text Text * %param bold Bold + * %param align Align * %param color Color */ -MWDECL void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, MwLLColor color); +MWDECL void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color); /*! * %brief Creates a pixmap from image diff --git a/src/draw.c b/src/draw.c index d5e68f1..76f7942 100644 --- a/src/draw.c +++ b/src/draw.c @@ -359,13 +359,19 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert, MwLLFreeColor(darker); } -void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, MwLLColor color) { +void MwDrawText(MwWidget handle, MwPoint* point, const char* text, int bold, int align, MwLLColor color) { int i, x, y, sx, sy; MwRect r; - sx = point->x - strlen(text) * FontWidth * FontScale / 2; + sx = point->x; sy = point->y - FontHeight * FontScale / 2; + if(align == MwALIGNMENT_CENTER) { + sx -= strlen(text) * FontWidth * FontScale / 2; + } else if(align == MwALIGNMENT_END) { + sx -= strlen(text) * FontWidth * FontScale; + } + for(i = 0; text[i] != 0; i++) { for(y = 0; y < FontHeight; y++) { for(x = 0; x < FontWidth; x++) { diff --git a/src/widget/button.c b/src/widget/button.c index 4b0d5bd..89d7127 100644 --- a/src/widget/button.c +++ b/src/widget/button.c @@ -50,7 +50,7 @@ static void draw(MwWidget handle) { point.x = r.x + r.width / 2; point.y = r.x + r.height / 2; - MwDrawText(handle, &point, str, 0, text); + MwDrawText(handle, &point, str, 0, MwALIGNMENT_CENTER, text); } MwLLFreeColor(text); diff --git a/src/widget/label.c b/src/widget/label.c index 40db38d..f5a828d 100644 --- a/src/widget/label.c +++ b/src/widget/label.c @@ -34,7 +34,7 @@ static void draw(MwWidget handle) { p.x = r.width - MwTextWidth(handle, str) / 2; } p.y = r.height / 2; - MwDrawText(handle, &p, str, 0, text); + MwDrawText(handle, &p, str, 0, MwALIGNMENT_CENTER, text); MwLLFreeColor(text); MwLLFreeColor(base); diff --git a/src/widget/menu.c b/src/widget/menu.c index c9d178b..f1533a1 100644 --- a/src/widget/menu.c +++ b/src/widget/menu.c @@ -83,10 +83,9 @@ static void destroy(MwWidget handle) { if(incr) { \ p.x = MwGetInteger(handle, MwNwidth) - tw - 10; \ } \ - p.x += tw / 2; \ \ - r.x = p.x - tw / 2 - 5; \ - r.y = p.y - th / 2 - 5; \ + r.x = p.x - 5; \ + r.y = p.y - 5; \ r.width = tw + 10; \ r.height = th + 10; \ \ @@ -112,7 +111,7 @@ static void draw(MwWidget handle) { MwDrawFrame(handle, &r, base, 0); } - MwDrawText(handle, &p, m->sub[i]->name + incr, 1, text); + MwDrawText(handle, &p, m->sub[i]->name + incr, 1, MwALIGNMENT_BEGINNING, text); END_MENU_LOOP; MwLLFreeColor(text); diff --git a/src/widget/submenu.c b/src/widget/submenu.c index 97717fb..78a485a 100644 --- a/src/widget/submenu.c +++ b/src/widget/submenu.c @@ -62,7 +62,7 @@ static void draw(MwWidget handle) { p.x = 5 + tw / 2; p.y += th / 2; - MwDrawText(handle, &p, menu->sub[i]->name, 1, text); + MwDrawText(handle, &p, menu->sub[i]->name, 1, MwALIGNMENT_CENTER, text); if(arrlen(menu->sub[i]->sub) > 0) { MwRect tr;