Skip to content

Commit

Permalink
WARNING: BREAKING CHANGE
Browse files Browse the repository at this point in the history
Added a bunch of useful text management functions.
Consequently, some already available functions like `FormatText()` and `SubText()` has been renamed for consistency. Created temporal fallbacks for old names.
raylib version bumped to 2.3.
  • Loading branch information
raysan5 committed Dec 26, 2018
1 parent 9a8320c commit 01338b0
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 46 deletions.
4 changes: 2 additions & 2 deletions examples/shapes/shapes_logo_raylib_anim.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* raylib [shapes] example - raylib logo animation
*
* This example has been created using raylib 1.4 (www.raylib.com)
* This example has been created using raylib 2.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
Expand Down Expand Up @@ -140,7 +140,7 @@ int main()

DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha));

DrawText(SubText("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
DrawText(TextSubtext("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
}
else if (state == 4)
{
Expand Down
4 changes: 2 additions & 2 deletions examples/text/text_writing_anim.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* raylib [text] example - Text Writing Animation
*
* This example has been created using raylib 1.4 (www.raylib.com)
* This example has been created using raylib 2.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
Expand Down Expand Up @@ -44,7 +44,7 @@ int main()

ClearBackground(RAYWHITE);

DrawText(SubText(message, 0, framesCounter/10), 210, 160, 20, MAROON);
DrawText(TextSubtext(message, 0, framesCounter/10), 210, 160, 20, MAROON);

DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, LIGHTGRAY);
DrawText("PRESS [SPACE] to SPEED UP!", 239, 300, 20, LIGHTGRAY);
Expand Down
6 changes: 3 additions & 3 deletions games/transmission/screens/screen_gameplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,18 @@ void InitGameplayScreen(void)
{
foundWord = false;

messageWords[currentWord - 1].rec.width = (int)MeasureTextEx(fontMessage, SubText(missions[currentMission].msg, wordInitPosX, (i - wordInitPosX)), 30, 0).x;
messageWords[currentWord - 1].rec.width = (int)MeasureTextEx(fontMessage, TextSubtext(missions[currentMission].msg, wordInitPosX, (i - wordInitPosX)), 30, 0).x;
messageWords[currentWord - 1].rec.height = fontMessage.baseSize;

strncpy(messageWords[currentWord - 1].text, SubText(missions[currentMission].msg, wordInitPosX, (i - wordInitPosX)), i - wordInitPosX);
strncpy(messageWords[currentWord - 1].text, TextSubtext(missions[currentMission].msg, wordInitPosX, (i - wordInitPosX)), i - wordInitPosX);
}

if (c == '@') // One word to change
{
foundWord = true;
missions[currentMission].msg[i] = ' ';

offsetX = (int)MeasureTextEx(fontMessage, SubText(missions[currentMission].msg, wordInitPosY, (i + 1) - wordInitPosY), 30, 0).x;
offsetX = (int)MeasureTextEx(fontMessage, TextSubtext(missions[currentMission].msg, wordInitPosY, (i + 1) - wordInitPosY), 30, 0).x;

messageWords[currentWord].rec.x = offsetX;
messageWords[currentWord].rec.y = offsetY;
Expand Down
2 changes: 1 addition & 1 deletion games/transmission/screens/screen_mission.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void DrawMissionScreen(void)
DrawTexturePro(texBackline, sourceRecBackLine, destRecBackLine, (Vector2){0,0},0, Fade(WHITE, fadeBackLine));

if (writeNumber) DrawTextEx(fontMission, FormatText("Filtración #%02i ", currentMission + 1), numberPosition, missionSize + 10, 0, numberColor);
DrawTextEx(fontMission, SubText(missions[currentMission].brief, 0, missionLenght), missionPosition, missionSize, 0, missionColor);
DrawTextEx(fontMission, TextSubtext(missions[currentMission].brief, 0, missionLenght), missionPosition, missionSize, 0, missionColor);
if (writeKeyword && blinkKeyWord) DrawTextEx(fontMission, FormatText("Keyword: %s", missions[currentMission].key), keywordPosition, missionSize + 10, 0, keywordColor);

if (showButton)
Expand Down
4 changes: 2 additions & 2 deletions games/transmission/screens/screen_title.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ void UpdateTitleScreen(void)
void DrawTitleScreen(void)
{
DrawTexture(texBackground, 0,0, WHITE);
DrawTextEx(fontTitle, SubText(textTitle, 0, transmissionLenght), transmissionPosition, titleSize, 0, titleColor);
DrawTextEx(fontTitle, SubText(textTitle, 12, missionLenght), missionPositon, titleSize, 0, titleColor);
DrawTextEx(fontTitle, TextSubtext(textTitle, 0, transmissionLenght), transmissionPosition, titleSize, 0, titleColor);
DrawTextEx(fontTitle, TextSubtext(textTitle, 12, missionLenght), missionPositon, titleSize, 0, titleColor);

DrawButton("start");
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
**********************************************************************************************/

#define RAYLIB_VERSION "2.2-dev"
#define RAYLIB_VERSION "2.3-dev"

// Edit to control what features Makefile'd raylib is compiled with
#if defined(RAYLIB_CMAKE)
Expand Down
8 changes: 4 additions & 4 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3176,17 +3176,17 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i

// NOTE: delay represents the time between frames in the gif, if we capture a gif frame every
// 10 game frames and each frame trakes 16.6ms (60fps), delay between gif frames should be ~16.6*10.
GifBegin(FormatText("screenrec%03i.gif", screenshotCounter), screenWidth, screenHeight, (int)(GetFrameTime()*10.0f), 8, false);
GifBegin(TextFormat("screenrec%03i.gif", screenshotCounter), screenWidth, screenHeight, (int)(GetFrameTime()*10.0f), 8, false);
screenshotCounter++;

TraceLog(LOG_INFO, "Begin animated GIF recording: %s", FormatText("screenrec%03i.gif", screenshotCounter));
TraceLog(LOG_INFO, "Begin animated GIF recording: %s", TextFormat("screenrec%03i.gif", screenshotCounter));
}
}
else
#endif // SUPPORT_GIF_RECORDING
#if defined(SUPPORT_SCREEN_CAPTURE)
{
TakeScreenshot(FormatText("screenshot%03i.png", screenshotCounter));
TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter));
screenshotCounter++;
}
#endif // SUPPORT_SCREEN_CAPTURE
Expand Down Expand Up @@ -4454,7 +4454,7 @@ static void LogoAnimation(void)

DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha));

DrawText(SubText("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
DrawText(TextSubtext("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
}

EndDrawing();
Expand Down
26 changes: 21 additions & 5 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
#define MAGENTA CLITERAL{ 255, 0, 255, 255 } // Magenta
#define RAYWHITE CLITERAL{ 245, 245, 245, 255 } // My own White (raylib logo)

// Temporal hack to avoid breaking old codebases using
// deprecated raylib implementation of these functions
#define FormatText TextFormat
#define SubText TextSubText

//----------------------------------------------------------------------------------
// Structures Definition
//----------------------------------------------------------------------------------
Expand Down Expand Up @@ -1111,11 +1116,22 @@ RLAPI int MeasureText(const char *text, int fontSize);
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

// Text string edition functions
RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed'
RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string
RLAPI char **SplitText(char *text, char delimiter, int *strCount); // Split text string into multiple strings (memory should be freed manually!)
RLAPI bool IsEqualText(const char *text1, const char *text2); // Check if two text string are equal
// Text strings management functions
// NOTE: Some strings allocate memory internally for returned strings, just be careful!
RLAPI bool TextIsEqual(const char *text1, const char *text2); // Check if two text string are equal
RLAPI unsigned int TextLength(const char *text); // Get text length, checks for '\0' ending
RLAPI const char *TextFormat(const char *text, ...); // Text formatting with variables (sprintf)
RLAPI const char *TextSubtext(const char *text, int position, int length); // Get a piece of a text string
RLAPI const char *TextReplace(char *text, const char *replace, const char *by); // Replace text string (memory should be freed!)
RLAPI const char *TextInsert(const char *text, const char *insert, int position); // Insert text in a position (memory should be freed!)
RLAPI const char *TextJoin(const char **textList, int count, const char *delimiter); // Join text strings with delimiter
RLAPI char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings (memory should be freed!)
RLAPI void TextSplitEx(const char *text, char delimiter, int *count, const char **ptrs, int *lengths); // Get pointers to substrings separated by delimiter
RLAPI void TextAppend(char *text, const char *append, int *position); // Append text at specific position and move cursor!
RLAPI int TextFindIndex(const char *text, const char *find); // Find first text occurrence within a string
RLAPI const char *TextToUpper(const char *text); // Get upper case version of provided string
RLAPI const char *TextToLower(const char *text); // Get lower case version of provided string
RLAPI const char *TextToPascal(const char *text); // Get Pascal case notation version of provided string

//------------------------------------------------------------------------------------
// Basic 3d Shapes Drawing Functions (Module: models)
Expand Down
Loading

0 comments on commit 01338b0

Please sign in to comment.