From 5ddfbd1f3929e756b4fbc18bd4a9e02bc89f38b2 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 29 Nov 2025 23:42:59 +0800 Subject: [PATCH] Added source alpha multiplier for text inline styling examples --- examples/text/text_inline_styling.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/text/text_inline_styling.c b/examples/text/text_inline_styling.c index aeebe0abc..f1ab2ad1c 100644 --- a/examples/text/text_inline_styling.c +++ b/examples/text/text_inline_styling.c @@ -81,12 +81,15 @@ int main(void) DrawTextStyled(GetFontDefault(), "This changes the [c00ff00ff][bff0000ff]foreground and background colors[r]!!!", (Vector2){ 100, 160 }, 20.0f, 2.0f, BLACK); + DrawTextStyled(GetFontDefault(), "This changes the [c00ff00ff]alpha[r] relative [cffffffff][b000000ff]from source[r] [cff000088]color[r]!!!", + (Vector2){ 100, 200 }, 20.0f, 2.0f, (Color){ 0, 0, 0, 100 }); + // Get pointer to formated text const char *text = TextFormat("Let's be [c%02x%02x%02xFF]CREATIVE[r] !!!", colRandom.r, colRandom.g, colRandom.b); - DrawTextStyled(GetFontDefault(), text, (Vector2){ 100, 220 }, 40.0f, 2.0f, BLACK); + DrawTextStyled(GetFontDefault(), text, (Vector2){ 100, 240 }, 40.0f, 2.0f, BLACK); textSize = MeasureTextStyled(GetFontDefault(), text, 40.0f, 2.0f); - DrawRectangleLines(100, 220, (int)textSize.x, (int)textSize.y, GREEN); + DrawRectangleLines(100, 240, (int)textSize.x, (int)textSize.y, GREEN); EndDrawing(); //---------------------------------------------------------------------------------- @@ -171,8 +174,16 @@ static void DrawTextStyled(Font font, const char *text, Vector2 position, float // Convert hex color text into actual Color unsigned int colHexValue = strtoul(colHexText, NULL, 16); - if (text[i - 1] == 'c') colFront = GetColor(colHexValue); - else if (text[i - 1] == 'b') colBack = GetColor(colHexValue); + if (text[i - 1] == 'c') + { + colFront = GetColor(colHexValue); + colFront.a *= (float)color.a / 255.0f; + } + else if (text[i - 1] == 'b') + { + colBack = GetColor(colHexValue); + colBack.a *= (float)color.a / 255.0f; + } i += (colHexCount + 1); // Skip color value retrieved and ']' continue; // Do not draw characters