From a0291d05231bc50fcae02542a74f558a11175328 Mon Sep 17 00:00:00 2001 From: Klemen Plestenjak Date: Fri, 22 Dec 2023 08:28:15 +0100 Subject: [PATCH] Add text shadow, fix font issues --- engine/breeze/ui/ui.c | 13 +++++++++++-- engine/breeze/ui/ui.h | 37 +++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/engine/breeze/ui/ui.c b/engine/breeze/ui/ui.c index 55ee4d9..b7281f1 100644 --- a/engine/breeze/ui/ui.c +++ b/engine/breeze/ui/ui.c @@ -133,7 +133,7 @@ static void calculateAxisSizePreorder(const BzUIAxis axis, BzUINode *node) { break; case BZ_UI_SIZE_FIT: BZ_ASSERT(node->string); - Vector2 size = MeasureTextEx(GetFontDefault(), node->string, node->style.fontSize, 2); + Vector2 size = MeasureTextEx(node->style.font, node->string, node->style.fontSize, node->style.fontSpacing); compSize = (axis == BZ_UI_AXIS_X) ? size.x : size.y; break; case BZ_UI_SIZE_PARENT_PERCENT: @@ -357,11 +357,20 @@ static void renderNode(BzUI *ui, BzUINode *node) { if (inter->down) color = style->borderActiveColor; DrawRectangleRoundedLines(rect, style->roundness, 0, style->borderThickness, color); } + if (node->flags & BZ_UI_DRAW_TEXT_SHADOW) { + Color color = style->textShadowColor; + if (inter->hovering) color = style->textShadowHoverColor; + if (inter->down) color = style->textShadowActiveColor; + DrawTextEx(style->font, node->string, (Vector2){ + drawRect.x + style->shadowOffset[BZ_UI_AXIS_X], + drawRect.y + style->shadowOffset[BZ_UI_AXIS_Y] + }, style->fontSize, style->fontSpacing, color); + } if (node->flags & BZ_UI_DRAW_TEXT) { Color color = style->textColor; if (inter->hovering) color = style->textHoverColor; if (inter->down) color = style->textActiveColor; - DrawTextEx(GetFontDefault(), node->string, (Vector2){drawRect.x, drawRect.y}, style->fontSize, 1, color); + DrawTextEx(style->font, node->string, (Vector2){drawRect.x, drawRect.y}, style->fontSize, style->fontSpacing, color); } node->changed = false; diff --git a/engine/breeze/ui/ui.h b/engine/breeze/ui/ui.h index 012610c..dae5da2 100644 --- a/engine/breeze/ui/ui.h +++ b/engine/breeze/ui/ui.h @@ -54,15 +54,26 @@ typedef struct BzUILayout { BzUIFlags flags; } BzUILayout; +typedef enum BzUIAxis { + BZ_UI_AXIS_X, + BZ_UI_AXIS_Y, + BZ_UI_AXIS_COUNT, +} BzUIAxis; + + typedef struct BzUIStyle { Font font; f32 fontSize; f32 fontSpacing; f32 borderThickness; f32 roundness; + f32 shadowOffset[BZ_UI_AXIS_COUNT]; Color textColor; Color textHoverColor; Color textActiveColor; + Color textShadowColor; + Color textShadowHoverColor; + Color textShadowActiveColor; Color bgColor; Color bgHoverColor; Color bgActiveColor; @@ -72,26 +83,20 @@ typedef struct BzUIStyle { } BzUIStyle; - -typedef enum BzUIAxis { - BZ_UI_AXIS_X, - BZ_UI_AXIS_Y, - BZ_UI_AXIS_COUNT, -} BzUIAxis; - enum { BZ_UI_NONE = 0, BZ_UI_CLICKABLE = (1 << 0), BZ_UI_DRAW_TEXT = (1 << 1), - BZ_UI_DRAW_BORDER = (1 << 2), - BZ_UI_DRAW_BACKGROUND = (1 << 3), - //BZ_UI_DRAW_SPRITE = (1 << 4), - BZ_UI_ALIGN_HORIZ_START = (1 << 5), - BZ_UI_ALIGN_HORIZ_CENTER = (1 << 6), - BZ_UI_ALIGN_HORIZ_END = (1 << 7), - BZ_UI_ALIGN_VERT_START = (1 << 8), - BZ_UI_ALIGN_VERT_CENTER = (1 << 9), - BZ_UI_ALIGN_VERT_END = (1 << 10), + BZ_UI_DRAW_TEXT_SHADOW = (1 << 2), + BZ_UI_DRAW_BORDER = (1 << 3), + BZ_UI_DRAW_BACKGROUND = (1 << 4), + //BZ_UI_DRAW_SPRITE = (1 << 5), + BZ_UI_ALIGN_HORIZ_START = (1 << 6), + BZ_UI_ALIGN_HORIZ_CENTER = (1 << 7), + BZ_UI_ALIGN_HORIZ_END = (1 << 8), + BZ_UI_ALIGN_VERT_START = (1 << 9), + BZ_UI_ALIGN_VERT_CENTER = (1 << 10), + BZ_UI_ALIGN_VERT_END = (1 << 11), BZ_UI_ALIGN_CENTER = BZ_UI_ALIGN_HORIZ_CENTER | BZ_UI_ALIGN_VERT_CENTER, };