diff --git a/examples/core/core_3d_camera_first_person.cpp b/examples/core/core_3d_camera_first_person.cpp index e7f4a09..9223ed1 100644 --- a/examples/core/core_3d_camera_first_person.cpp +++ b/examples/core/core_3d_camera_first_person.cpp @@ -76,9 +76,9 @@ int main() { DrawRectangle(10, 10, 220, 70, raylib::Color::SkyBlue().Fade(0.5f)); DrawRectangleLines(10, 10, 220, 70, BLUE); - DrawText("First person camera default controls:", 20, 20, 10, BLACK); - DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY); - DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY); + raylib::DrawText("First person camera default controls:", 20, 20, 10, BLACK); + raylib::DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY); + raylib::DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY); } EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples/core/core_basic_window_web.cpp b/examples/core/core_basic_window_web.cpp index 546e6de..7d43df6 100644 --- a/examples/core/core_basic_window_web.cpp +++ b/examples/core/core_basic_window_web.cpp @@ -71,7 +71,7 @@ void UpdateDrawFrame(void) ClearBackground(RAYWHITE); - DrawText("Congrats! You created your first raylib-cpp window!", 190, 200, 20, LIGHTGRAY); + raylib::DrawText("Congrats! You created your first raylib-cpp window!", 190, 200, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples/core/core_drop_files.cpp b/examples/core/core_drop_files.cpp index ab4d4ac..a954bc1 100644 --- a/examples/core/core_drop_files.cpp +++ b/examples/core/core_drop_files.cpp @@ -41,9 +41,9 @@ int main() { // Check if there are files to process. if (droppedFiles.empty()) { - DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY); + raylib::DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY); } else { - DrawText("Dropped files:", 100, 40, 20, DARKGRAY); + raylib::DrawText("Dropped files:", 100, 40, 20, DARKGRAY); // Iterate through all the dropped files. for (int i = 0; i < droppedFiles.size(); i++) { @@ -53,10 +53,10 @@ int main() { DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f)); // Display the path to the dropped file. - DrawText(droppedFiles[i].c_str(), 120, 100 + 40 * i, 10, GRAY); + raylib::DrawText(droppedFiles[i].c_str(), 120, 100 + 40 * i, 10, GRAY); } - DrawText("Drop new files...", 100, 110 + 40 * droppedFiles.size(), 20, DARKGRAY); + raylib::DrawText("Drop new files...", 100, 110 + 40 * droppedFiles.size(), 20, DARKGRAY); } } EndDrawing(); diff --git a/examples/core/core_loading_thread.cpp b/examples/core/core_loading_thread.cpp index c095f10..1d01e76 100644 --- a/examples/core/core_loading_thread.cpp +++ b/examples/core/core_loading_thread.cpp @@ -97,19 +97,19 @@ int main(void) switch (state) { case STATE_WAITING: - DrawText("PRESS ENTER to START LOADING DATA", + raylib::DrawText("PRESS ENTER to START LOADING DATA", 150, 170, 20, DARKGRAY); break; case STATE_LOADING: DrawRectangle(150, 200, dataProgress, 60, SKYBLUE); if ((framesCounter/15)%2) - DrawText("LOADING DATA...", 240, 210, 40, DARKBLUE); + raylib::DrawText("LOADING DATA...", 240, 210, 40, DARKBLUE); break; case STATE_FINISHED: DrawRectangle(150, 200, 500, 60, LIME); - DrawText("DATA LOADED!", 250, 210, 40, GREEN); + raylib::DrawText("DATA LOADED!", 250, 210, 40, GREEN); break; } diff --git a/examples/core/core_random_values.cpp b/examples/core/core_random_values.cpp index 98338cf..1522b84 100644 --- a/examples/core/core_random_values.cpp +++ b/examples/core/core_random_values.cpp @@ -45,9 +45,9 @@ int main() { { window.ClearBackground(RAYWHITE); - DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON); + raylib::DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON); - DrawText(TextFormat("%i", randValue), 360, 180, 80, LIGHTGRAY); + raylib::DrawText(TextFormat("%i", randValue), 360, 180, 80, LIGHTGRAY); } EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples/core/core_world_screen.cpp b/examples/core/core_world_screen.cpp index 3266663..f53486e 100644 --- a/examples/core/core_world_screen.cpp +++ b/examples/core/core_world_screen.cpp @@ -60,11 +60,11 @@ int main() { } camera.EndMode(); - DrawText("Enemy: 100 / 100", + raylib::DrawText("Enemy: 100 / 100", cubeScreenPosition.x - MeasureText("Enemy: 100/100", 20) / 2, cubeScreenPosition.y, 20, BLACK); - DrawText("Text is always on top of the cube", + raylib::DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20)) / 2, 25, 20, GRAY); } diff --git a/examples/physics/physics_demo.cpp b/examples/physics/physics_demo.cpp index 73fdccd..b95adf2 100644 --- a/examples/physics/physics_demo.cpp +++ b/examples/physics/physics_demo.cpp @@ -119,12 +119,12 @@ int main(void) } } - DrawText("Left mouse button to create a polygon", 10, 10, 10, WHITE); - DrawText("Right mouse button to create a circle", 10, 25, 10, WHITE); - DrawText("Press 'R' to reset example", 10, 40, 10, WHITE); + raylib::DrawText("Left mouse button to create a polygon", 10, 10, 10, WHITE); + raylib::DrawText("Right mouse button to create a circle", 10, 25, 10, WHITE); + raylib::DrawText("Press 'R' to reset example", 10, 40, 10, WHITE); - DrawText("Physac", logoX, logoY, 30, WHITE); - DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE); + raylib::DrawText("Physac", logoX, logoY, 30, WHITE); + raylib::DrawText("Powered by", logoX + 50, logoY - 7, 10, WHITE); } EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples/shapes/shapes_collision_area.cpp b/examples/shapes/shapes_collision_area.cpp index 94166ab..8c758bf 100644 --- a/examples/shapes/shapes_collision_area.cpp +++ b/examples/shapes/shapes_collision_area.cpp @@ -86,10 +86,10 @@ int main(void) boxCollision.Draw(LIME); // Draw collision message - DrawText("COLLISION!", GetScreenWidth()/2 - MeasureText("COLLISION!", 20)/2, screenUpperLimit/2 - 10, 20, BLACK); + raylib::DrawText("COLLISION!", GetScreenWidth()/2 - MeasureText("COLLISION!", 20)/2, screenUpperLimit/2 - 10, 20, BLACK); // Draw collision area - DrawText(TextFormat("Collision Area: %i", (int)boxCollision.width*(int)boxCollision.height), GetScreenWidth()/2 - 100, screenUpperLimit + 10, 20, BLACK); + raylib::DrawText(TextFormat("Collision Area: %i", (int)boxCollision.width*(int)boxCollision.height), GetScreenWidth()/2 - 100, screenUpperLimit + 10, 20, BLACK); } DrawFPS(10, 10); diff --git a/examples/text/text_font_loading.cpp b/examples/text/text_font_loading.cpp index c2cf419..31f0dfd 100644 --- a/examples/text/text_font_loading.cpp +++ b/examples/text/text_font_loading.cpp @@ -62,17 +62,17 @@ int main() { window.ClearBackground(RAYWHITE); - DrawText("Hold SPACE to use TTF generated font", 20, 20, 20, LIGHTGRAY); + raylib::DrawText("Hold SPACE to use TTF generated font", 20, 20, 20, LIGHTGRAY); if (!useTtf) { fontBm.DrawText(msg, Vector2{ 20.0f, 100.0f }, fontBm.baseSize, 2, MAROON); - DrawText("Using BMFont (Angelcode) imported", 20, GetScreenHeight() - 30, 20, GRAY); + raylib::DrawText("Using BMFont (Angelcode) imported", 20, GetScreenHeight() - 30, 20, GRAY); } else { fontTtf.DrawText(msg, Vector2{ 20.0f, 100.0f }, fontTtf.baseSize, 2, LIME); - DrawText("Using TTF font generated", 20, GetScreenHeight() - 30, 20, GRAY); + raylib::DrawText("Using TTF font generated", 20, GetScreenHeight() - 30, 20, GRAY); } } window.EndDrawing(); diff --git a/examples/textures/textures_bunnymark.cpp b/examples/textures/textures_bunnymark.cpp index c7b123b..c5e8189 100644 --- a/examples/textures/textures_bunnymark.cpp +++ b/examples/textures/textures_bunnymark.cpp @@ -103,8 +103,8 @@ int main(void) } DrawRectangle(0, 0, screenWidth, 40, BLACK); - DrawText(TextFormat("bunnies: %i", bunnies.size()), 120, 10, 20, GREEN); - DrawText(TextFormat("batched draw calls: %i", 1 + bunnies.size()/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON); + raylib::DrawText(TextFormat("bunnies: %i", bunnies.size()), 120, 10, 20, GREEN); + raylib::DrawText(TextFormat("batched draw calls: %i", 1 + bunnies.size()/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON); DrawFPS(10, 10); } diff --git a/include/Text.hpp b/include/Text.hpp new file mode 100644 index 0000000..e925c88 --- /dev/null +++ b/include/Text.hpp @@ -0,0 +1,128 @@ +#ifndef RAYLIB_CPP_INCLUDE_TEXT_HPP_ +#define RAYLIB_CPP_INCLUDE_TEXT_HPP_ + +#include + +#include "./raylib.hpp" +#include "./RaylibException.hpp" +#include "./raylib-cpp-utils.hpp" + +namespace raylib { +/** + * Text Functions. + */ +class Text { + public: + /** + * Initializes a new Text object. + * @param text Text to initialize. + * @return void. + */ + Text(const std::string& text = "") + { + SetText(text); + } + + /** + * Initializes a new Text object. + * @param text Text to initialize. + * @param posX X position of the text. + * @param posY Y position of the text. + * @return void. + */ + Text(const std::string& text, const int posX, const int posY) + { + SetText(text); + SetPosX(posX); + SetPosY(posY); + } + + /** + * Initializes a new Text object. + * @param text Text to initialize. + * @param position Vector2 position of the text. + * @return void. + */ + Text(const std::string& text, const ::Vector2& position) + { + SetText(text); + SetPosX(static_cast(position.x)); + SetPosY(static_cast(position.y)); + } + + ~Text() { + } + + /** + * @brief Draw text with values in class. + * + */ + void DrawText() { + ::DrawText(_text.c_str(), _posX, _posY, _fontSize, _color); + } + + std::string GetText() const { return _text; } + void SetText(const std::string& text) { _text = text; } + + int GetFontSize() const { return _fontSize; } + void SetFontSize(int fontSize) { _fontSize = fontSize; } + + // Font GetFont() const { return _font; } + // void SetFont(const Font& font) { _font = font; } + + Color GetColor() const { return _color; } + void SetColor(const Color& color) { _color = color; } + + int GetPosX() const { return _posX; } + void SetPosX(int posX) { _posX = posX; } + + int GetPosY() const { return _posY; } + void SetPosY(int posY) { _posY = posY; } + + /** + * Draw text using font and color + * + * @see ::DrawText + */ + static inline void DrawText(const std::string& text, const int posX, const int posY, const int fontSize, const ::Color& color) { + ::DrawText(text.c_str(), posX, posY, fontSize, color); + } + + /** + * Draw text using font and color, with position defined as Vector2 + * + * @see ::DrawText + */ + static inline void DrawText(const std::string& text, const ::Vector2& pos, const int fontSize, const ::Color& color) { + ::DrawText(text.c_str(), static_cast(pos.x), static_cast(pos.y), fontSize, color); + } + + /** + * Draw text using font, color, position, font size and spacing + * + * @see ::DrawTextEx + */ + static inline void DrawTextEx(const Font& font, const std::string& text, const ::Vector2& position, const float fontSize, const float spacing, const ::Color& color) { + ::DrawTextEx(font, text.c_str(), position, fontSize, spacing, color); + } + + /** + * Draw text using font, color, position, origin, font size and spacing + * + * @see ::DrawTextPro + */ + static inline void DrawTextPro(const Font& font, const std::string& text, const ::Vector2& position, const ::Vector2& origin, const float rotation, const float fontSize, const float spacing, const ::Color& color) { + ::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, color); + } + + private: + std::string _text = ""; + int _fontSize = 10; + // Font _font; + Color _color = WHITE; + int _posX = 0; + int _posY = 0; +}; +} // namespace raylib + +#endif // RAYLIB_CPP_INCLUDE_WINDOW_HPP_ diff --git a/include/raylib-cpp.hpp b/include/raylib-cpp.hpp index f92bc5e..628fa99 100644 --- a/include/raylib-cpp.hpp +++ b/include/raylib-cpp.hpp @@ -55,6 +55,7 @@ #include "./RenderTexture.hpp" #include "./Shader.hpp" #include "./Sound.hpp" +#include "./Text.hpp" #include "./Texture.hpp" #include "./Vector2.hpp" #include "./Vector3.hpp"