Skip to content

Commit

Permalink
CLIENT-GAME: Fix text responsive
Browse files Browse the repository at this point in the history
PATCH
  • Loading branch information
TTENSHII committed Sep 28, 2023
1 parent 4b67ae2 commit 21d99f1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/Client/Raylib/Graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ namespace Raylib {
_position(position),
_fontSize(fontSize),
_color(color),
_pixelPosition(position)
_pixelPosition(position),
_currentFontSize(fontSize)
{
}

Expand All @@ -643,7 +644,7 @@ namespace Raylib {
_text.c_str(),
static_cast<int>(_pixelPosition.X()),
static_cast<int>(_pixelPosition.Y()),
static_cast<int>(_fontSize),
static_cast<int>(_currentFontSize),
{_color.R(), _color.G(), _color.B(), _color.A()});
}

Expand All @@ -653,7 +654,7 @@ namespace Raylib {
GetFontDefault(),
_text.c_str(),
{_pixelPosition.X(), _pixelPosition.Y()},
_fontSize,
_currentFontSize,
spacing,
{_color.R(), _color.G(), _color.B(), _color.A()});
}
Expand All @@ -666,7 +667,7 @@ namespace Raylib {
{_pixelPosition.X(), _pixelPosition.Y()},
{origin.X(), origin.Y()},
rotation,
_fontSize,
_currentFontSize,
spacing,
{_color.R(), _color.G(), _color.B(), _color.A()});
}
Expand Down Expand Up @@ -701,4 +702,9 @@ namespace Raylib {
_pixelPosition = position;
}

void Text::setCurrentFontSize(float fontSize)
{
_currentFontSize = fontSize;
}

} // namespace Raylib
2 changes: 2 additions & 0 deletions src/Client/Raylib/Graphics/Graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ namespace Raylib {
void setFontSize(float fontSize);
Vector2 getPosition() const;
void setPixelPosition(Vector2 position);
void setCurrentFontSize(float fontSize);

private:
std::string _text;
float _fontSize;
float _currentFontSize;
Color _color;
Vector2 _position;
Vector2 _pixelPosition;
Expand Down
2 changes: 1 addition & 1 deletion src/Client/SceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Types::CollisionRect collisionRect = {46, 46};
const Raylib::Vector2 textPos = {20, 50};
constexpr float musicVolume = 0.02F;
constexpr float soundVolume = 0.1F;
constexpr float fontScale = 20.0F;
constexpr float fontScale = 2.0F;
const float playerWidth = 50.0F;
const float playerHeight = 50.0F;

Expand Down
3 changes: 3 additions & 0 deletions src/Client/Systems/Graphic/GraphicSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,11 @@ namespace Systems {
(text.x() * static_cast<float>(GetScreenWidth())) / denominator;
float y =
(text.y() * static_cast<float>(GetScreenHeight())) / denominator;
float fsz = (text.getFontSize() * static_cast<float>(GetScreenWidth()))
/ denominator;

text.setPixelPosition({x, y});
text.setCurrentFontSize(fsz);
text.draw();
}

Expand Down

0 comments on commit 21d99f1

Please sign in to comment.