Add DrawTextGradientV, DrawTextCodepointGradientV
This commit is contained in:
parent
4bc8d3761c
commit
3c3733337d
|
|
@ -9287,6 +9287,41 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "DrawTextGradientV",
|
||||
"description": "Draw text with vertical gradient",
|
||||
"returnType": "void",
|
||||
"params": [
|
||||
{
|
||||
"type": "Font",
|
||||
"name": "font"
|
||||
},
|
||||
{
|
||||
"type": "const char *",
|
||||
"name": "text"
|
||||
},
|
||||
{
|
||||
"type": "Vector2",
|
||||
"name": "position"
|
||||
},
|
||||
{
|
||||
"type": "float",
|
||||
"name": "fontSize"
|
||||
},
|
||||
{
|
||||
"type": "float",
|
||||
"name": "spacing"
|
||||
},
|
||||
{
|
||||
"type": "Color",
|
||||
"name": "topTint"
|
||||
},
|
||||
{
|
||||
"type": "Color",
|
||||
"name": "bottomTint"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "DrawTextPro",
|
||||
"description": "Draw text using Font and pro parameters (rotation)",
|
||||
|
|
@ -9353,6 +9388,37 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "DrawTextCodepointGradientV",
|
||||
"description": "Draw one character (codepoint) with vertical gradient",
|
||||
"returnType": "void",
|
||||
"params": [
|
||||
{
|
||||
"type": "Font",
|
||||
"name": "font"
|
||||
},
|
||||
{
|
||||
"type": "int",
|
||||
"name": "codepoint"
|
||||
},
|
||||
{
|
||||
"type": "Vector2",
|
||||
"name": "position"
|
||||
},
|
||||
{
|
||||
"type": "float",
|
||||
"name": "fontSize"
|
||||
},
|
||||
{
|
||||
"type": "Color",
|
||||
"name": "topTint"
|
||||
},
|
||||
{
|
||||
"type": "Color",
|
||||
"name": "bottomTint"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "DrawTextCodepoints",
|
||||
"description": "Draw multiple character (codepoint)",
|
||||
|
|
|
|||
|
|
@ -6671,6 +6671,20 @@ return {
|
|||
{type = "Color", name = "tint"}
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "DrawTextGradientV",
|
||||
description = "Draw text with vertical gradient",
|
||||
returnType = "void",
|
||||
params = {
|
||||
{type = "Font", name = "font"},
|
||||
{type = "const char *", name = "text"},
|
||||
{type = "Vector2", name = "position"},
|
||||
{type = "float", name = "fontSize"},
|
||||
{type = "float", name = "spacing"},
|
||||
{type = "Color", name = "topTint"},
|
||||
{type = "Color", name = "bottomTint"}
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "DrawTextPro",
|
||||
description = "Draw text using Font and pro parameters (rotation)",
|
||||
|
|
@ -6698,6 +6712,19 @@ return {
|
|||
{type = "Color", name = "tint"}
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "DrawTextCodepointGradientV",
|
||||
description = "Draw one character (codepoint) with vertical gradient",
|
||||
returnType = "void",
|
||||
params = {
|
||||
{type = "Font", name = "font"},
|
||||
{type = "int", name = "codepoint"},
|
||||
{type = "Vector2", name = "position"},
|
||||
{type = "float", name = "fontSize"},
|
||||
{type = "Color", name = "topTint"},
|
||||
{type = "Color", name = "bottomTint"}
|
||||
}
|
||||
},
|
||||
{
|
||||
name = "DrawTextCodepoints",
|
||||
description = "Draw multiple character (codepoint)",
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -679,7 +679,7 @@
|
|||
<Param type="unsigned int" name="frames" desc="" />
|
||||
</Callback>
|
||||
</Callbacks>
|
||||
<Functions count="584">
|
||||
<Functions count="586">
|
||||
<Function name="InitWindow" retType="void" paramCount="3" desc="Initialize window and OpenGL context">
|
||||
<Param type="int" name="width" desc="" />
|
||||
<Param type="int" name="height" desc="" />
|
||||
|
|
@ -2351,6 +2351,15 @@
|
|||
<Param type="float" name="spacing" desc="" />
|
||||
<Param type="Color" name="tint" desc="" />
|
||||
</Function>
|
||||
<Function name="DrawTextGradientV" retType="void" paramCount="7" desc="Draw text with vertical gradient">
|
||||
<Param type="Font" name="font" desc="" />
|
||||
<Param type="const char *" name="text" desc="" />
|
||||
<Param type="Vector2" name="position" desc="" />
|
||||
<Param type="float" name="fontSize" desc="" />
|
||||
<Param type="float" name="spacing" desc="" />
|
||||
<Param type="Color" name="topTint" desc="" />
|
||||
<Param type="Color" name="bottomTint" desc="" />
|
||||
</Function>
|
||||
<Function name="DrawTextPro" retType="void" paramCount="8" desc="Draw text using Font and pro parameters (rotation)">
|
||||
<Param type="Font" name="font" desc="" />
|
||||
<Param type="const char *" name="text" desc="" />
|
||||
|
|
@ -2368,6 +2377,14 @@
|
|||
<Param type="float" name="fontSize" desc="" />
|
||||
<Param type="Color" name="tint" desc="" />
|
||||
</Function>
|
||||
<Function name="DrawTextCodepointGradientV" retType="void" paramCount="6" desc="Draw one character (codepoint) with vertical gradient">
|
||||
<Param type="Font" name="font" desc="" />
|
||||
<Param type="int" name="codepoint" desc="" />
|
||||
<Param type="Vector2" name="position" desc="" />
|
||||
<Param type="float" name="fontSize" desc="" />
|
||||
<Param type="Color" name="topTint" desc="" />
|
||||
<Param type="Color" name="bottomTint" desc="" />
|
||||
</Function>
|
||||
<Function name="DrawTextCodepoints" retType="void" paramCount="7" desc="Draw multiple character (codepoint)">
|
||||
<Param type="Font" name="font" desc="" />
|
||||
<Param type="const int *" name="codepoints" desc="" />
|
||||
|
|
|
|||
|
|
@ -1480,8 +1480,10 @@ RLAPI bool ExportFontAsCode(Font font, const char *fileName);
|
|||
RLAPI void DrawFPS(int posX, int posY); // Draw current FPS
|
||||
RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font)
|
||||
RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters
|
||||
RLAPI void DrawTextGradientV(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color topTint, Color bottomTint); // Draw text with vertical gradient
|
||||
RLAPI void DrawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint); // Draw text using Font and pro parameters (rotation)
|
||||
RLAPI void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSize, Color tint); // Draw one character (codepoint)
|
||||
RLAPI void DrawTextCodepointGradientV(Font font, int codepoint, Vector2 position, float fontSize, Color topTint, Color bottomTint); // Draw one character (codepoint) with vertical gradient
|
||||
RLAPI void DrawTextCodepoints(Font font, const int *codepoints, int codepointCount, Vector2 position, float fontSize, float spacing, Color tint); // Draw multiple character (codepoint)
|
||||
|
||||
// Text font info functions
|
||||
|
|
|
|||
77
src/rtext.c
77
src/rtext.c
|
|
@ -145,6 +145,7 @@ static Font LoadBMFont(const char *fileName); // Load a BMFont file (AngelCode
|
|||
#if defined(SUPPORT_FILEFORMAT_BDF)
|
||||
static GlyphInfo *LoadFontDataBDF(const unsigned char *fileData, int dataSize, int *codepoints, int codepointCount, int *outFontSize);
|
||||
#endif
|
||||
static void _DrawTextureGradientV(Texture2D texture, Rectangle source, Rectangle dest, Color topTint, Color bottomTint);
|
||||
static int textLineSpacing = 2; // Text vertical line spacing in pixels (between lines)
|
||||
|
||||
#if defined(SUPPORT_DEFAULT_FONT)
|
||||
|
|
@ -1168,6 +1169,12 @@ void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
|
|||
// Draw text using Font
|
||||
// NOTE: chars spacing is NOT proportional to fontSize
|
||||
void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint)
|
||||
{
|
||||
DrawTextGradientV(font, text, position, fontSize, spacing, tint, tint);
|
||||
}
|
||||
|
||||
// Draw text with vertical gradient
|
||||
void DrawTextGradientV(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color topTint, Color bottomTint)
|
||||
{
|
||||
if (font.texture.id == 0) font = GetFontDefault(); // Security check in case of not valid font
|
||||
|
||||
|
|
@ -1195,7 +1202,7 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f
|
|||
{
|
||||
if ((codepoint != ' ') && (codepoint != '\t'))
|
||||
{
|
||||
DrawTextCodepoint(font, codepoint, (Vector2){ position.x + textOffsetX, position.y + textOffsetY }, fontSize, tint);
|
||||
DrawTextCodepointGradientV(font, codepoint, (Vector2){ position.x + textOffsetX, position.y + textOffsetY }, fontSize, topTint, bottomTint);
|
||||
}
|
||||
|
||||
if (font.glyphs[index].advanceX == 0) textOffsetX += ((float)font.recs[index].width*scaleFactor + spacing);
|
||||
|
|
@ -1222,6 +1229,12 @@ void DrawTextPro(Font font, const char *text, Vector2 position, Vector2 origin,
|
|||
|
||||
// Draw one character (codepoint)
|
||||
void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSize, Color tint)
|
||||
{
|
||||
DrawTextCodepointGradientV(font, codepoint, position, fontSize, tint, tint);
|
||||
}
|
||||
|
||||
// Draw one character (codepoint) with vertical gradient
|
||||
void DrawTextCodepointGradientV(Font font, int codepoint, Vector2 position, float fontSize, Color topTint, Color bottomTint)
|
||||
{
|
||||
// Character index position in sprite font
|
||||
// NOTE: In case a codepoint is not available in the font, index returned points to '?'
|
||||
|
|
@ -1241,7 +1254,7 @@ void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSiz
|
|||
font.recs[index].width + 2.0f*font.glyphPadding, font.recs[index].height + 2.0f*font.glyphPadding };
|
||||
|
||||
// Draw the character texture on the screen
|
||||
DrawTexturePro(font.texture, srcRec, dstRec, (Vector2){ 0, 0 }, 0.0f, tint);
|
||||
_DrawTextureGradientV(font.texture, srcRec, dstRec, topTint, bottomTint);
|
||||
}
|
||||
|
||||
// Draw multiple character (codepoints)
|
||||
|
|
@ -2593,4 +2606,64 @@ static GlyphInfo *LoadFontDataBDF(const unsigned char *fileData, int dataSize, i
|
|||
}
|
||||
#endif // SUPPORT_FILEFORMAT_BDF
|
||||
|
||||
// Draw texture with vertical gradient
|
||||
// Same as DrawTexturePro, but without origin and rotation parameters and with an additional color parameter.
|
||||
// The two parameters topTint and bottomTint determine the gradient.
|
||||
static void _DrawTextureGradientV(Texture2D texture, Rectangle source, Rectangle dest, Color topTint, Color bottomTint)
|
||||
{
|
||||
// Check if texture is valid
|
||||
if (texture.id > 0)
|
||||
{
|
||||
float width = (float)texture.width;
|
||||
float height = (float)texture.height;
|
||||
|
||||
bool flipX = false;
|
||||
|
||||
if (source.width < 0) { flipX = true; source.width *= -1; }
|
||||
if (source.height < 0) source.y -= source.height;
|
||||
|
||||
if (dest.width < 0) dest.width *= -1;
|
||||
if (dest.height < 0) dest.height *= -1;
|
||||
|
||||
float x = dest.x;
|
||||
float y = dest.y;
|
||||
Vector2 topLeft = (Vector2){ x, y };
|
||||
Vector2 topRight = (Vector2){ x + dest.width, y };
|
||||
Vector2 bottomLeft = (Vector2){ x, y + dest.height };
|
||||
Vector2 bottomRight = (Vector2){ x + dest.width, y + dest.height };
|
||||
|
||||
rlSetTexture(texture.id);
|
||||
rlBegin(RL_QUADS);
|
||||
|
||||
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer
|
||||
|
||||
// Top-left corner for texture and quad
|
||||
rlColor4ub(topTint.r, topTint.g, topTint.b, topTint.a);
|
||||
if (flipX) rlTexCoord2f((source.x + source.width)/width, source.y/height);
|
||||
else rlTexCoord2f(source.x/width, source.y/height);
|
||||
rlVertex2f(topLeft.x, topLeft.y);
|
||||
|
||||
// Bottom-left corner for texture and quad
|
||||
rlColor4ub(bottomTint.r, bottomTint.g, bottomTint.b, bottomTint.a);
|
||||
if (flipX) rlTexCoord2f((source.x + source.width)/width, (source.y + source.height)/height);
|
||||
else rlTexCoord2f(source.x/width, (source.y + source.height)/height);
|
||||
rlVertex2f(bottomLeft.x, bottomLeft.y);
|
||||
|
||||
// Bottom-right corner for texture and quad
|
||||
rlColor4ub(bottomTint.r, bottomTint.g, bottomTint.b, bottomTint.a);
|
||||
if (flipX) rlTexCoord2f(source.x/width, (source.y + source.height)/height);
|
||||
else rlTexCoord2f((source.x + source.width)/width, (source.y + source.height)/height);
|
||||
rlVertex2f(bottomRight.x, bottomRight.y);
|
||||
|
||||
// Top-right corner for texture and quad
|
||||
rlColor4ub(topTint.r, topTint.g, topTint.b, topTint.a);
|
||||
if (flipX) rlTexCoord2f(source.x/width, source.y/height);
|
||||
else rlTexCoord2f((source.x + source.width)/width, source.y/height);
|
||||
rlVertex2f(topRight.x, topRight.y);
|
||||
|
||||
rlEnd();
|
||||
rlSetTexture(0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SUPPORT_MODULE_RTEXT
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user