BREAKING CHANGE: Read description
Changes: - Font structure has been redesigned, CharInfo structure contained character rectangle within font texture, it has not much sense, considering that it was an information relative to the font atlas generated and not the character itself, so character rectangles have been moved out from CharInfo to Font. - CharInfo included a data parameters to contain character pixel data (usually grayscale), generated on TTF font generation. It was inconsistent with other fonts types, so, now CharInfo includes directly an Image of the glyph. - REDESIGNED: GenImageFontAtlas(), additional recs parameter added, loaded and filled inside the function to export atlas characters rectangles, instead of silently modify the input CharInfo data. - REVIEWED: ImageTextEx(), funtion retrieved the font atlas image from the GPU, that was slow and problematic in several platforms. Now it uses directly the CharInfo image. Support for unicode codepoints has also been added. - REDESIGNED: ImageDraw(), now it includes an additional parameter, the color tint, not only it could be useful for several situations but also function signature is more consistent with similar functions. - ADDED: ImageFromImage() to generate a new image from a piece of another image. - REVIEWED: GetNextCodepoint(), renamed parameters to be more clear. Also all examples and games that were affected by those changes have been reviewed.
This commit is contained in:
parent
543c0ba30d
commit
b4d67499a7
7 changed files with 264 additions and 208 deletions
15
src/raylib.h
15
src/raylib.h
|
@ -263,18 +263,18 @@ typedef struct NPatchInfo {
|
|||
// Font character info
|
||||
typedef struct CharInfo {
|
||||
int value; // Character value (Unicode)
|
||||
Rectangle rec; // Character rectangle in sprite font
|
||||
int offsetX; // Character offset X when drawing
|
||||
int offsetY; // Character offset Y when drawing
|
||||
int advanceX; // Character advance position X
|
||||
unsigned char *data; // Character pixel data (grayscale)
|
||||
Image image; // Character image data
|
||||
} CharInfo;
|
||||
|
||||
// Font type, includes texture and charSet array data
|
||||
typedef struct Font {
|
||||
Texture2D texture; // Font texture
|
||||
int baseSize; // Base size (default chars height)
|
||||
int charsCount; // Number of characters
|
||||
Texture2D texture; // Characters texture atlas
|
||||
Rectangle *recs; // Characters rectangles in texture
|
||||
CharInfo *chars; // Characters info data
|
||||
} Font;
|
||||
|
||||
|
@ -1100,6 +1100,7 @@ RLAPI void UpdateTexture(Texture2D texture, const void *pixels);
|
|||
|
||||
// Image manipulation functions
|
||||
RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations)
|
||||
RLAPI Image ImageFromImage(Image image, Rectangle rec); // Create an image from another image piece
|
||||
RLAPI void ImageToPOT(Image *image, Color fillColor); // Convert image to POT (power-of-two)
|
||||
RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format
|
||||
RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image
|
||||
|
@ -1115,7 +1116,7 @@ RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp);
|
|||
RLAPI Color *ImageExtractPalette(Image image, int maxPaletteSize, int *extractCount); // Extract color palette from image to maximum size (memory should be freed)
|
||||
RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font)
|
||||
RLAPI Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Color tint); // Create an image from text (custom sprite font)
|
||||
RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image
|
||||
RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint); // Draw a source image within a destination image (tint applied to source)
|
||||
RLAPI void ImageDrawRectangle(Image *dst, Rectangle rec, Color color); // Draw rectangle within an image
|
||||
RLAPI void ImageDrawRectangleLines(Image *dst, Rectangle rec, int thick, Color color); // Draw rectangle lines within an image
|
||||
RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination)
|
||||
|
@ -1165,7 +1166,7 @@ RLAPI Font LoadFont(const char *fileName);
|
|||
RLAPI Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int charsCount); // Load font from file with extended parameters
|
||||
RLAPI Font LoadFontFromImage(Image image, Color key, int firstChar); // Load font from Image (XNA style)
|
||||
RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, int type); // Load font data for further use
|
||||
RLAPI Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int padding, int packMethod); // Generate image font atlas using chars info
|
||||
RLAPI Image GenImageFontAtlas(const CharInfo *chars, Rectangle **recs, int charsCount, int fontSize, int padding, int packMethod); // Generate image font atlas using chars info
|
||||
RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM)
|
||||
|
||||
// Text drawing functions
|
||||
|
@ -1180,8 +1181,8 @@ RLAPI void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontS
|
|||
RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font
|
||||
RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font
|
||||
RLAPI int GetGlyphIndex(Font font, int character); // Get index position for a unicode character on font
|
||||
RLAPI int GetNextCodepoint(const char *text, int *count); // Returns next codepoint in a UTF8 encoded string
|
||||
// NOTE: 0x3f(`?`) is returned on failure, `count` will hold the total number of bytes processed
|
||||
RLAPI int GetNextCodepoint(const char *text, int *bytesProcessed); // Returns next codepoint in a UTF8 encoded string
|
||||
// NOTE: 0x3f('?') is returned on failure
|
||||
|
||||
// Text strings management functions
|
||||
// NOTE: Some strings allocate memory internally for returned strings, just be careful!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue