From 03d170de69d5d9656ea9922d28cb6d3f9970810a Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sun, 17 Jan 2021 02:59:17 -0500 Subject: [PATCH] Fix Fonts --- CHANGELOG.md | 6 ++ examples/core/core_drop_files.cpp | 12 +-- examples/text/text_raylib_fonts.cpp | 37 ++++----- include/CMakeLists.txt | 1 - include/Camera2D.hpp | 7 -- include/Camera3D.hpp | 8 -- include/Color.hpp | 7 -- include/DroppedFiles.hpp | 113 ---------------------------- include/Font.hpp | 28 +++---- include/Functions.hpp | 32 ++++++++ include/raylib-cpp.hpp | 1 - 11 files changed, 73 insertions(+), 179 deletions(-) delete mode 100644 include/DroppedFiles.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index bb6524b..ba0a9cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v3.5.0-beta2] - Unreleased +### Fixed +- `Font.charsPadding` loading +### Removed +- `DroppedFiles` class replaced with `std::vector raylib::GetDroppedFiles()` + ## [v3.5.0-beta1] - 2021-01-02 ### Added - `Model.Draw()` and `Model.DrawWires()` diff --git a/examples/core/core_drop_files.cpp b/examples/core/core_drop_files.cpp index 8a1f612..824009c 100644 --- a/examples/core/core_drop_files.cpp +++ b/examples/core/core_drop_files.cpp @@ -21,8 +21,7 @@ int main() { raylib::Window w(screenWidth, screenHeight, "raylib [core] example - drop files"); - // Create the Dropped Files collection object. - raylib::DroppedFiles droppedFiles; + std::vector droppedFiles; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -32,8 +31,8 @@ int main() { { // Update //---------------------------------------------------------------------------------- - if (droppedFiles.IsFileDropped()) { - droppedFiles.Get(); + if (IsFileDropped()) { + droppedFiles = raylib::GetDroppedFiles(); } //---------------------------------------------------------------------------------- @@ -68,10 +67,5 @@ int main() { //---------------------------------------------------------------------------------- } - // De-Initialization - //-------------------------------------------------------------------------------------- - // ClearDroppedFiles(); // Called for us. - //-------------------------------------------------------------------------------------- - return 0; } diff --git a/examples/text/text_raylib_fonts.cpp b/examples/text/text_raylib_fonts.cpp index 379fa0b..fe400fd 100644 --- a/examples/text/text_raylib_fonts.cpp +++ b/examples/text/text_raylib_fonts.cpp @@ -13,6 +13,7 @@ ********************************************************************************************/ #include +#include #include "raylib-cpp.hpp" @@ -29,7 +30,7 @@ int main() { raylib::Color textColor(DARKGRAY); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - raylib::Font fonts[MAX_FONTS] = { + std::array fonts = { raylib::Font("resources/fonts/alagard.png"), raylib::Font("resources/fonts/pixelplay.png"), raylib::Font("resources/fonts/mecha.png"), @@ -40,22 +41,25 @@ int main() { raylib::Font("resources/fonts/jupiter_crash.png") }; - std::string messages[MAX_FONTS] = { "ALAGARD FONT designed by Hewett Tsoi", - "PIXELPLAY FONT designed by Aleksander Shevchuk", - "MECHA FONT designed by Captain Falcon", - "SETBACK FONT designed by Brian Kent (AEnigma)", - "ROMULUS FONT designed by Hewett Tsoi", - "PIXANTIQUA FONT designed by Gerhard Grossmann", - "ALPHA_BETA FONT designed by Brian Kent (AEnigma)", - "JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" }; + std::array messages = { + "ALAGARD FONT designed by Hewett Tsoi", + "PIXELPLAY FONT designed by Aleksander Shevchuk", + "MECHA FONT designed by Captain Falcon", + "SETBACK FONT designed by Brian Kent (AEnigma)", + "ROMULUS FONT designed by Hewett Tsoi", + "PIXANTIQUA FONT designed by Gerhard Grossmann", + "ALPHA_BETA FONT designed by Brian Kent (AEnigma)", + "JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" + }; - const int spacings[MAX_FONTS] = { 2, 4, 8, 4, 3, 4, 4, 1 }; + std::array spacings = { 2, 4, 8, 4, 3, 4, 4, 1 }; - Vector2 positions[MAX_FONTS]; + std::array positions; - for (int i = 0; i < MAX_FONTS; i++) + for (int i = 0; i < fonts.size(); i++) { - positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i].c_str(), fonts[i].baseSize*2, spacings[i]).x/2; + auto size = fonts[i].MeasureText(messages[i], fonts[i].baseSize * 2, spacings[i]); + positions[i].x = screenWidth/2 - size.x/2; positions[i].y = 60 + fonts[i].baseSize + 45*i; } @@ -64,7 +68,7 @@ int main() { positions[4].y += 2; positions[7].y -= 8; - raylib::Color colors[MAX_FONTS] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED }; + std::array colors = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED }; //-------------------------------------------------------------------------------------- // Main game loop @@ -84,15 +88,14 @@ int main() { textColor.DrawText("free fonts included with raylib", 250, 20, 20); textColor.DrawLine(220, 50, 590, 50); - for (int i = 0; i < MAX_FONTS; i++) + for (int i = 0; i < fonts.size(); i++) { - fonts[i].DrawText(messages[i].c_str(), positions[i], fonts[i].baseSize*2, spacings[i], colors[i]); + fonts[i].DrawText(messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]); } EndDrawing(); //---------------------------------------------------------------------------------- } - //-------------------------------------------------------------------------------------- return 0; } diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 845d013..522f263 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -11,7 +11,6 @@ install(FILES Camera2D.hpp Camera3D.hpp Color.hpp - DroppedFiles.hpp Functions.hpp Font.hpp Gamepad.hpp diff --git a/include/Camera2D.hpp b/include/Camera2D.hpp index 89ea0e1..38b985b 100644 --- a/include/Camera2D.hpp +++ b/include/Camera2D.hpp @@ -98,13 +98,6 @@ class Camera2D : public ::Camera2D { rotation = camera.rotation; zoom = camera.zoom; } - - inline void set(const Camera2D& camera) { - offset = camera.offset; - target = camera.target; - rotation = camera.rotation; - zoom = camera.zoom; - } }; } // namespace raylib diff --git a/include/Camera3D.hpp b/include/Camera3D.hpp index 9920ba6..7ff4fb0 100644 --- a/include/Camera3D.hpp +++ b/include/Camera3D.hpp @@ -178,14 +178,6 @@ class Camera3D : public ::Camera3D { fovy = camera.fovy; type = camera.type; } - - inline void set(const Camera3D& camera) { - position = camera.position; - target = camera.target; - up = camera.up; - fovy = camera.fovy; - type = camera.type; - } }; typedef Camera3D Camera; diff --git a/include/Color.hpp b/include/Color.hpp index 6959e33..a59be08 100644 --- a/include/Color.hpp +++ b/include/Color.hpp @@ -276,13 +276,6 @@ class Color : public ::Color { b = color.b; a = color.a; } - - inline void set(const Color& color) { - r = color.r; - g = color.g; - b = color.b; - a = color.a; - } }; } // namespace raylib diff --git a/include/DroppedFiles.hpp b/include/DroppedFiles.hpp deleted file mode 100644 index bb6250a..0000000 --- a/include/DroppedFiles.hpp +++ /dev/null @@ -1,113 +0,0 @@ -/* -* LICENSE: zlib/libpng -* -* raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified, -* BSD-like license that allows static linking with closed source software: -* -* Copyright (c) 2020 Rob Loach (@RobLoach) -* -* This software is provided "as-is", without any express or implied warranty. In no event -* will the authors be held liable for any damages arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, including commercial -* applications, and to alter it and redistribute it freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not claim that you -* wrote the original software. If you use this software in a product, an acknowledgment -* in the product documentation would be appreciated but is not required. -* -* 2. Altered source versions must be plainly marked as such, and must not be misrepresented -* as being the original software. -* -* 3. This notice may not be removed or altered from any source distribution. -*/ - -#ifndef RAYLIB_CPP_INCLUDE_DROPPEDFILES_HPP_ -#define RAYLIB_CPP_INCLUDE_DROPPEDFILES_HPP_ - -#include - -#include "./raylib.hpp" - -namespace raylib { -/** - * @see raylib::GetDroppedFiles() - */ -class DroppedFiles { - public: - DroppedFiles() { - Get(); - } - - /** - * Get the dropped files names. - */ - DroppedFiles& Get() { - m_files = ::GetDroppedFiles(&m_count); - return *this; - } - - /** - * Check if a file has been dropped into window. - */ - inline bool IsFileDropped() const { - return ::IsFileDropped(); - } - - /** - * Clear dropped files paths buffer. - */ - inline DroppedFiles& Clear() { - ::ClearDroppedFiles(); - m_count = 0; - m_files = NULL; - return *this; - } - - ~DroppedFiles() { - Clear(); - } - - inline std::string operator[](int pos) { - return at(pos); - } - - inline int Count() const { - return m_count; - } - - inline int size() const { - return m_count; - } - - inline bool empty() const { - return m_count == 0; - } - - inline void clear() { - Clear(); - } - - inline std::string front() const { - return at(0); - } - - inline std::string back() const { - return at(m_count - 1); - } - - std::string at(int pos) const { - if (m_files != NULL && pos < m_count && pos >= 0) { - return std::string(m_files[pos]); - } - // TODO(RobLoach): Throw exception when out of range. - return ""; - } - - protected: - char** m_files; - int m_count; -}; -} // namespace raylib - -#endif // RAYLIB_CPP_INCLUDE_DROPPEDFILES_HPP_ diff --git a/include/Font.hpp b/include/Font.hpp index c4a19b8..7de9695 100644 --- a/include/Font.hpp +++ b/include/Font.hpp @@ -79,11 +79,6 @@ class Font : public ::Font { return *this; } - Font& operator=(const Font& font) { - set(font); - return *this; - } - inline Font& DrawText(const std::string& text, ::Vector2 position, float fontSize, float spacing, ::Color tint = WHITE) { ::DrawTextEx(*this, text.c_str(), position, fontSize, spacing, tint); @@ -91,19 +86,27 @@ class Font : public ::Font { } inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing, - bool wordWrap, ::Color tint = WHITE) { + bool wordWrap = false, ::Color tint = WHITE) { ::DrawTextRec(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint); return *this; } inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing, - bool wordWrap, Color tint, int selectStart, int selectLength, ::Color selectText, + bool wordWrap, ::Color tint, int selectStart, int selectLength, ::Color selectText, ::Color selectBack) { ::DrawTextRecEx(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint, selectStart, selectLength, selectText, selectBack); return *this; } + /** + * Draw one character (codepoint) + */ + inline Font& DrawText(int codepoint, ::Vector2 position, float fontSize, ::Color tint = { 255, 255, 255, 255 }) { + ::DrawTextCodepoint(*this, codepoint, position, fontSize, tint); + return *this; + } + /** * Measure string size for Font */ @@ -121,7 +124,7 @@ class Font : public ::Font { /** * Create an image from text (custom sprite font) */ - inline Image ImageText(const std::string& text, float fontSize, + inline ::Image ImageText(const std::string& text, float fontSize, float spacing, ::Color tint) const { return ::ImageTextEx(*this, text.c_str(), fontSize, spacing, tint); } @@ -130,14 +133,7 @@ class Font : public ::Font { void set(const ::Font& font) { baseSize = font.baseSize; charsCount = font.charsCount; - texture = font.texture; - recs = font.recs; - chars = font.chars; - } - - void set(const Font& font) { - baseSize = font.baseSize; - charsCount = font.charsCount; + charsPadding = font.charsPadding; texture = font.texture; recs = font.recs; chars = font.chars; diff --git a/include/Functions.hpp b/include/Functions.hpp index 2c8d53c..39e7772 100644 --- a/include/Functions.hpp +++ b/include/Functions.hpp @@ -197,6 +197,38 @@ inline void OpenURL(const std::string& url) { return ::OpenURL(url.c_str()); } +inline bool IsGamepadName(int gamepad, const std::string& name) { + return ::IsGamepadName(gamepad, name.c_str()); +} + +inline void UpdateCamera(Camera& camera) { + ::UpdateCamera(&camera); +} + +inline Image LoadImage(const std::string& fileName) { + return ::LoadImage(fileName.c_str()); +} + +inline Image LoadImageRaw(const std::string& fileName, int width, int height, int format, int headerSize) { + return ::LoadImageRaw(fileName.c_str(), width, height, format, headerSize); +} + +inline Image LoadImageAnim(const std::string& fileName, int *frames) { + return ::LoadImageAnim(fileName.c_str(), frames); +} + +inline Image LoadImageFromMemory(const std::string& fileType, const unsigned char *fileData, int dataSize) { + return ::LoadImageFromMemory(fileType.c_str(), fileData, dataSize); +} + +inline bool ExportImage(const Image& image, const std::string& fileName) { + return ::ExportImage(image, fileName.c_str()); +} + +inline bool ExportImageAsCode(const Image& image, const std::string& fileName) { + return ::ExportImageAsCode(image, fileName.c_str()); +} + } // namespace raylib #endif // RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_ diff --git a/include/raylib-cpp.hpp b/include/raylib-cpp.hpp index a553835..8e64045 100644 --- a/include/raylib-cpp.hpp +++ b/include/raylib-cpp.hpp @@ -73,7 +73,6 @@ #include "./Camera2D.hpp" #include "./Camera3D.hpp" #include "./Color.hpp" -#include "./DroppedFiles.hpp" #include "./Functions.hpp" #include "./Font.hpp" #include "./Gamepad.hpp"