Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[text] Added DrawFPSEx() with Color arg (READ DESCRIPTION) #1675

Closed
wants to merge 1 commit into from
Closed

[text] Added DrawFPSEx() with Color arg (READ DESCRIPTION) #1675

wants to merge 1 commit into from

Conversation

OkiStuff
Copy link

@OkiStuff OkiStuff commented Mar 24, 2021

This Pull Request is aimed at adding a roadmap feature
See the roadmap here: #1523

On the raylib roadmap there was
text: Redesign DrawFPS() to support Color parameter like other draw functions. BREAKING CHANGE
But it doesn't have to break existing projects

We could have

// Draws current FPS
// NOTE: Uses default font
void DrawFPSEx(int posX, int posY, Color tint)
{
    DrawText(TextFormat("%2i FPS", GetFPS()), posX, posY, 20, tint);
}

(Note, this is what is in the PR)
So existing projects still work.
You can even add the size as a parameter

// Draws current FPS
// NOTE: Uses default font
void DrawFPSEx(int posX, int posY, int fontSize, Color tint)
{
    DrawText(TextFormat("%2i FPS", GetFPS()), posX, posY, fontSize, tint);
}

(Note, the code above is not in the actual PR, but if you do want to be able to change the fontSize, tell me in the comments and I will add it)

And if you want font support too

void DrawFPSEx(Font font, int posX, int posY, int fontSize, Color tint)
{
    if (font.texture.id != 0)
    {
       Vector2 pos = { (float)(posX), (float)(posY) };

        int defaultFontSize = 10;
        if (fontSize < defaultFontSize) fontSize = defaultFontSize;
        int spacing = fontSize/defaultFontSize;       

       DrawTextEx(font, TextFormat("%2i FPS", GetFPS()), pos, (float)(fontSize), (float)(spacing), tint);
    }
}

(Note, the code above is not in the actual PR, but if you do want to be able to change the font, tell me in the comments and I will add it)

@OkiStuff
Copy link
Author

also little note
In

void DrawFPS(int posX, int posY)
{
    DrawText(TextFormat("%2i FPS", GetFPS()), posX, posY, 20, LIME);
}

the comment said

// Shows current FPS on top-left corner

but it shows the current FPS wherever the posX and posY is so I just changed it to

// Draws current FPS

to not have any confusion. You can change it back if you want

@OkiStuff OkiStuff mentioned this pull request Mar 24, 2021
22 tasks
@raysan5
Copy link
Owner

raysan5 commented Mar 24, 2021

@OkiStuff Finally I decided it was not required adding a new function to the API just for a functionality that user can do with a line of code, I mean, why adding several additional lines of code and the maintenance involved while user can do the same with just one line of code?

In any case, I'll review the comment.

@raysan5 raysan5 closed this Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants