From 0186631967f1c1111dd82b168868c872abc358e9 Mon Sep 17 00:00:00 2001 From: StillGreen-san <40620628+StillGreen-san@users.noreply.github.com> Date: Sat, 1 Feb 2025 17:14:46 +0100 Subject: [PATCH 01/19] fix memory leak in FileData::Load --- include/FileData.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/FileData.hpp b/include/FileData.hpp index 7c880106..8ccb29c8 100644 --- a/include/FileData.hpp +++ b/include/FileData.hpp @@ -31,7 +31,10 @@ class FileData { GETTER(int, BytesRead, bytesRead) void Load(const std::string& fileName) { Load(fileName.c_str()); } - void Load(const char* fileName) { data = ::LoadFileData(fileName, &bytesRead); } + void Load(const char* fileName) { + Unload(); + data = ::LoadFileData(fileName, &bytesRead); + } void Unload() { if (data != nullptr) { From e54015953ea5bde56be17eeddd4924a22bf2d0c1 Mon Sep 17 00:00:00 2001 From: StillGreen-san <40620628+StillGreen-san@users.noreply.github.com> Date: Sat, 1 Feb 2025 17:16:11 +0100 Subject: [PATCH 02/19] reset bytesRead in FileData::Unload --- include/FileData.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/FileData.hpp b/include/FileData.hpp index 8ccb29c8..979179fb 100644 --- a/include/FileData.hpp +++ b/include/FileData.hpp @@ -40,6 +40,7 @@ class FileData { if (data != nullptr) { ::UnloadFileData(data); data = nullptr; + bytesRead = 0; } } private: From 536e7d01df963e22461d6e6342b4a19a931dfcc7 Mon Sep 17 00:00:00 2001 From: Humza Qureshi Date: Wed, 5 Feb 2025 15:01:55 -0500 Subject: [PATCH 03/19] change const char** to const char* const* in TextSplit ::TextSplit returns a char** now, so you can't cast to a const char** implicitly. By specifying const char* const*, we allow implicit conversions from both char** and const char**. The strings are copied into the vector anyway, so adding the extra const specifier changes nothing. --- include/Functions.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Functions.hpp b/include/Functions.hpp index 901815fa..27b083ca 100644 --- a/include/Functions.hpp +++ b/include/Functions.hpp @@ -393,7 +393,7 @@ TextReplace(const std::string& text, const std::string& replace, const std::stri */ [[maybe_unused]] RLCPPAPI std::vector TextSplit(const std::string& text, char delimiter) { int count; - const char** split = ::TextSplit(text.c_str(), delimiter, &count); + const char* const* split = ::TextSplit(text.c_str(), delimiter, &count); return std::vector(split, split + count); } From 93e7885bc475bcf69f32f4ebdbf398f007a9ed2f Mon Sep 17 00:00:00 2001 From: Le Juez Victor <90587919+Bigfoot71@users.noreply.github.com> Date: Thu, 13 Mar 2025 18:53:02 +0100 Subject: [PATCH 04/19] add `Window::GetMonitor()` method --- include/Window.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/Window.hpp b/include/Window.hpp index 34a42187..02283787 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -349,6 +349,11 @@ class Window { */ static Vector2 GetPosition() { return ::GetWindowPosition(); } + /* + * Get current window monitor + */ + static int GetMonitor() { return ::GetCurrentMonitor(); } + /** * Get window scale DPI factor */ From 7435a205b2f2679c669d3cba0e75200b481d1c10 Mon Sep 17 00:00:00 2001 From: Le Juez Victor <90587919+Bigfoot71@users.noreply.github.com> Date: Sat, 15 Mar 2025 20:22:45 +0100 Subject: [PATCH 05/19] update default Camera3D construction parameters --- include/Camera3D.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Camera3D.hpp b/include/Camera3D.hpp index 74da8b9e..42b180c8 100644 --- a/include/Camera3D.hpp +++ b/include/Camera3D.hpp @@ -25,9 +25,9 @@ class Camera3D : public ::Camera3D { */ Camera3D( ::Vector3 position, - ::Vector3 target = ::Vector3{0.0f, 0.0f, 0.0f}, + ::Vector3 target = ::Vector3{0.0f, 0.0f, -1.0f}, ::Vector3 up = ::Vector3{0.0f, 1.0f, 0.0f}, - float fovy = 0, + float fovy = 45.0f, int projection = CAMERA_PERSPECTIVE) : ::Camera3D{position, target, up, fovy, projection} {} From 7a3d330674c2e4e8e5810c94d63846a74cfc2684 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 19 Mar 2025 14:10:37 -0400 Subject: [PATCH 06/19] Add window::Drawing() --- examples/core/core_basic_window.cpp | 4 +--- include/Window.hpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/examples/core/core_basic_window.cpp b/examples/core/core_basic_window.cpp index 68a17090..7df35381 100644 --- a/examples/core/core_basic_window.cpp +++ b/examples/core/core_basic_window.cpp @@ -41,12 +41,10 @@ int main() { // Draw //---------------------------------------------------------------------------------- - BeginDrawing(); - { + while (window.Drawing()) { window.ClearBackground(RAYWHITE); textColor.DrawText("Congrats! You created your first window!", 190, 200, 20); } - EndDrawing(); //---------------------------------------------------------------------------------- } diff --git a/include/Window.hpp b/include/Window.hpp index 02283787..ef3d63b0 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -410,6 +410,32 @@ class Window { * @see ::SetConfigFlags */ static void SetConfigFlags(unsigned int flags) { ::SetConfigFlags(flags); } + + /** + * Used to handle the BeginDrawing() and EndDrawing() calls. + * + * @code + * while (window.Drawing()) { + * DrawRectangle(); + * } + * @endcode + * + * @return True of false depending if we're within the BeginDrawing() / EndDrawing() scope. + */ + bool Drawing() { + if (m_drawing == false) { + BeginDrawing(); + m_drawing = true; + } + else { + EndDrawing(); + m_drawing = false; + } + return m_drawing; + } + + protected: + bool m_drawing = false; }; } // namespace raylib From 9bb0d6ffec5825cc75438da43220c50225250d93 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 19 Mar 2025 14:12:42 -0400 Subject: [PATCH 07/19] draawing: flip the statement --- include/Window.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/Window.hpp b/include/Window.hpp index ef3d63b0..84271068 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -423,14 +423,15 @@ class Window { * @return True of false depending if we're within the BeginDrawing() / EndDrawing() scope. */ bool Drawing() { - if (m_drawing == false) { - BeginDrawing(); - m_drawing = true; - } - else { + if (m_drawing) { EndDrawing(); m_drawing = false; } + else { + BeginDrawing(); + m_drawing = true; + } + return m_drawing; } From db8c70bf3a2aa17508a5afcd2f1aeb37e6416568 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 20 Mar 2025 13:44:31 -0400 Subject: [PATCH 08/19] Update Drawing() documentation --- include/Window.hpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/Window.hpp b/include/Window.hpp index 84271068..54fe00f7 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -412,7 +412,7 @@ class Window { static void SetConfigFlags(unsigned int flags) { ::SetConfigFlags(flags); } /** - * Used to handle the BeginDrawing() and EndDrawing() calls. + * Alternates between calling `BeginDrawing()` and `EndDrawing()`. * * @code * while (window.Drawing()) { @@ -420,7 +420,7 @@ class Window { * } * @endcode * - * @return True of false depending if we're within the BeginDrawing() / EndDrawing() scope. + * @return True if we're within the `BeginDrawing()` scope. */ bool Drawing() { if (m_drawing) { @@ -436,6 +436,11 @@ class Window { } protected: + /** + * Handles the internal drawing state for calling either `BeginDrawing()` or `EndDrawing()` from the `Drawing()` function. + * + * @see Drawing() + */ bool m_drawing = false; }; } // namespace raylib From 075d6103e94a733d0c0b7f001c263f1bfbb28a34 Mon Sep 17 00:00:00 2001 From: Mathieu Ropert Date: Mon, 14 Apr 2025 15:04:09 +0200 Subject: [PATCH 09/19] Fix vector3d default init and add tests --- include/Vector3.hpp | 2 +- tests/raylib_cpp_test.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/Vector3.hpp b/include/Vector3.hpp index 99d54e97..3ef06fa5 100644 --- a/include/Vector3.hpp +++ b/include/Vector3.hpp @@ -22,7 +22,7 @@ class Vector3 : public ::Vector3 { Vector3(float x, float y, float z) : ::Vector3{x, y, z} {} Vector3(float x, float y) : ::Vector3{x, y, 0} {} Vector3(float x) : ::Vector3{x, 0, 0} {} - Vector3() {} + Vector3() : ::Vector3{0, 0, 0} {} Vector3(::Color color) { set(ColorToHSV(color)); } diff --git a/tests/raylib_cpp_test.cpp b/tests/raylib_cpp_test.cpp index 45524095..78f81658 100644 --- a/tests/raylib_cpp_test.cpp +++ b/tests/raylib_cpp_test.cpp @@ -38,6 +38,21 @@ int main(int argc, char* argv[]) { raylib::Vector2 doublesize = size * 2.0f; AssertEqual(size.x, 50); AssertEqual(doublesize.x, 100); + + const raylib::Vector2 zero2d; + AssertEqual(zero2d.x, 0); + AssertEqual(zero2d.y, 0); + + const raylib::Vector3 zero3d; + AssertEqual(zero3d.x, 0); + AssertEqual(zero3d.y, 0); + AssertEqual(zero3d.z, 0); + + const raylib::Vector4 zero4d; + AssertEqual(zero4d.x, 0); + AssertEqual(zero4d.y, 0); + AssertEqual(zero4d.z, 0); + AssertEqual(zero4d.w, 0); } // Color From e64f5f634796a6dab64433f9157879098e05d8d8 Mon Sep 17 00:00:00 2001 From: Toyosatomimi no Miko <110693261+mikomikotaishi@users.noreply.github.com> Date: Thu, 29 May 2025 12:46:43 -0400 Subject: [PATCH 10/19] Add support for C++20 modules --- CMakeLists.txt | 14 +++ README.md | 18 ++++ include/raymath.hpp | 2 + modules/CMakeLists.txt | 30 ++++++ modules/raylib.cppm | 211 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 275 insertions(+) create mode 100644 modules/CMakeLists.txt create mode 100644 modules/raylib.cppm diff --git a/CMakeLists.txt b/CMakeLists.txt index f637e9d5..8dfa16bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,20 @@ option(BUILD_RAYLIB_CPP_EXAMPLES "Examples" ${RAYLIB_CPP_IS_MAIN}) # Include Directory add_subdirectory(include) +# Modules +option(BUILD_RAYLIB_CPP_MODULES "Build C++ modules support" OFF) + +if(BUILD_RAYLIB_CPP_MODULES) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) + message(STATUS "Building raylib-cpp C++ modules (CMake ${CMAKE_VERSION} supports modules)") + add_subdirectory(modules) + else() + message(WARNING "Skipping raylib-cpp C++ modules (requires CMake 3.28+, found ${CMAKE_VERSION})") + endif() +else() + message(STATUS "raylib-cpp C++ modules support is disabled. Enable with -BUILD_RAYLIB_CPP_MODULES=ON") +endif() + # Examples if(BUILD_RAYLIB_CPP_EXAMPLES) add_subdirectory(examples) diff --git a/README.md b/README.md index 70566007..ef8e9d3c 100644 --- a/README.md +++ b/README.md @@ -253,6 +253,24 @@ raylib::Vector2 direction(50, 50); raylib::Vector2 newDirection = direction.Rotate(30); ``` +### Modules + +If using C++20 or later, by passing `BUILD_RAYLIB_CPP_MODULES` to the build system the library may be imported as a module by using `import raylib;`. + +```cpp +import raylib; + +int main() { + int screenWidth = 800; + int screenHeight = 450; + + raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window"); + raylib::Texture logo("raylib_logo.png"); + + // ... +} +``` + ## Getting Started *raylib-cpp* is a header-only library. This means in order to use it, you must link your project to [raylib](https://www.raylib.com/), and then include [`raylib-cpp.hpp`](raylib-cpp/include/raylib-cpp.hpp). diff --git a/include/raymath.hpp b/include/raymath.hpp index f166488e..41e37cf3 100644 --- a/include/raymath.hpp +++ b/include/raymath.hpp @@ -8,9 +8,11 @@ extern "C" { #endif #ifndef RAYLIB_CPP_NO_MATH +#ifndef BUILD_RAYLIB_CPP_MODULES #ifndef RAYMATH_STATIC_INLINE #define RAYMATH_STATIC_INLINE #endif +#endif #ifdef __GNUC__ #pragma GCC diagnostic push // These throw a warnings on visual studio, need to check if __GNUC__ is defined to use it. #pragma GCC diagnostic ignored "-Wmissing-field-initializers" diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt new file mode 100644 index 00000000..b61a34fd --- /dev/null +++ b/modules/CMakeLists.txt @@ -0,0 +1,30 @@ +file(GLOB_RECURSE RAYLIB_CPP_MODULES raylib.cppm) + +add_library(raylib_cpp_modules) + +cmake_minimum_required(VERSION 3.28) + +if(NOT COMMAND configure_cpp_module_target) + function(configure_cpp_module_target target) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) + target_sources(${target} PUBLIC FILE_SET CXX_MODULES FILES ${RAYLIB_CPP_MODULES}) + else() + message(WARNING "C++ modules require CMake 3.28+. Using standard compilation.") + target_sources(${target} PRIVATE ${RAYLIB_CPP_MODULES}) + endif() + endfunction() +endif() + +configure_cpp_module_target(raylib_cpp_modules) + +target_link_libraries(raylib_cpp_modules + PUBLIC + raylib_cpp +) + +target_include_directories(raylib_cpp_modules + PRIVATE + ${PROJECT_SOURCE_DIR}/include +) + +target_compile_features(raylib_cpp_modules PUBLIC cxx_std_20) \ No newline at end of file diff --git a/modules/raylib.cppm b/modules/raylib.cppm new file mode 100644 index 00000000..2fcea73d --- /dev/null +++ b/modules/raylib.cppm @@ -0,0 +1,211 @@ +/** + * @file raylib.cppm + * @brief Module file exporting all symbols in raylib-cpp. + */ + +module; + +#define BUILD_RAYLIB_CPP_MODULES +#define RLCPPAPI +#define RAYMATH_IMPLEMENTATION +#include "../include/raylib-cpp.hpp" + +export module raylib; + +/** + * @namespace raylib + * @brief All raylib-cpp classes and functions appear in the raylib namespace. + */ +export namespace raylib { + // Classes + using raylib::AudioDevice; + using raylib::AudioStream; + using raylib::AutomationEventList; + using raylib::BoundingBox; + using raylib::Camera; // Alias for Camera3D + using raylib::Camera2D; + using raylib::Camera3D; + using raylib::Color; + using raylib::FileData; + using raylib::FileText; + using raylib::Font; + using raylib::Gamepad; + using raylib::Image; + using raylib::Material; + using raylib::Matrix; + using raylib::Mesh; + using raylib::Model; + using raylib::ModelAnimation; + using raylib::Music; + using raylib::Ray; + using raylib::RayCollision; + using raylib::RaylibException; + using raylib::Rectangle; + using raylib::RenderTexture; + using raylib::RenderTexture2D; // Alias for RenderTexture + using raylib::Shader; + using raylib::Sound; + using raylib::Text; + using raylib::Texture; + using raylib::Texture2D; // Alias for Texture + using raylib::TextureCubemap; // Alias for Texture + using raylib::TextureUnmanaged; + using raylib::Texture2DUnmanaged; // Alias for TextureUnmanaged + using raylib::TextureCubemapUnmanaged; // Alias for TextureUnmanaged + using raylib::Vector2; + using raylib::Vector3; + using raylib::Vector4; + using raylib::Quaternion; // Alias for Vector4 + using raylib::VrStereoConfig; + using raylib::Wave; + using raylib::Window; + + // From Functions.hpp + using raylib::InitWindow; + using raylib::SetWindowTitle; + using raylib::GetMonitorName; + using raylib::SetClipboardText; + using raylib::GetClipboardText; + using raylib::TakeScreenshot; + using raylib::GetGamepadName; + using raylib::LoadFileText; + using raylib::SaveFileText; + using raylib::FileExists; + using raylib::DirectoryExists; + using raylib::IsFileExtension; + using raylib::GetFileExtension; + using raylib::GetFileName; + using raylib::GetFileNameWithoutExt; + using raylib::GetDirectoryPath; + using raylib::GetPrevDirectoryPath; + using raylib::GetWorkingDirectory; + using raylib::LoadDirectoryFiles; + using raylib::ChangeDirectory; + using raylib::LoadDroppedFiles; + using raylib::GetFileModTime; + using raylib::OpenURL; + using raylib::LoadImage; + using raylib::LoadImageRaw; + using raylib::LoadImageAnim; + using raylib::LoadImageFromMemory; + using raylib::ExportImage; + using raylib::ExportImageAsCode; + using raylib::DrawText; + using raylib::DrawTextEx; + using raylib::DrawTextPro; + using raylib::LoadFont; + using raylib::LoadFontEx; + using raylib::MeasureText; + using raylib::TextIsEqual; + using raylib::TextLength; + using raylib::TextSubtext; + using raylib::TextReplace; + using raylib::TextInsert; + using raylib::TextSplit; + using raylib::TextFindIndex; + using raylib::TextToUpper; + using raylib::TextToLower; + using raylib::TextToPascal; + using raylib::TextToInteger; + + /** + * @namespace raylib::Keyboard + * @brief Input-related functions: keyboard + */ + namespace Keyboard { + using raylib::Keyboard::IsKeyPressed; + using raylib::Keyboard::IsKeyPressedRepeat; + using raylib::Keyboard::IsKeyDown; + using raylib::Keyboard::IsKeyReleased; + using raylib::Keyboard::IsKeyUp; + using raylib::Keyboard::GetKeyPressed; + using raylib::Keyboard::GetCharPressed; + } + + /** + * @namespace raylib::Mouse + * @brief Input-related functions: mouse + */ + namespace Mouse { + using raylib::Mouse::IsButtonPressed; + using raylib::Mouse::IsButtonDown; + using raylib::Mouse::IsButtonReleased; + using raylib::Mouse::IsButtonUp; + using raylib::Mouse::GetX; + using raylib::Mouse::GetY; + using raylib::Mouse::SetX; + using raylib::Mouse::SetY; + using raylib::Mouse::GetPosition; + using raylib::Mouse::SetPosition; + using raylib::Mouse::GetDelta; + using raylib::Mouse::SetOffset; + using raylib::Mouse::SetScale; + using raylib::Mouse::GetWheelMove; + using raylib::Mouse::GetWheelMoveV; + using raylib::Mouse::SetCursor; + using raylib::Mouse::GetTouchX; + using raylib::Mouse::GetTouchY; + using raylib::Mouse::GetTouchPosition; + using raylib::Mouse::GetRay; + } + + /** + * @namespace raylib::Touch + * @brief Input-related functions: touch + */ + namespace Touch { + using raylib::Touch::GetX; + using raylib::Touch::GetY; + using raylib::Touch::GetPosition; + using raylib::Touch::GetPointId; + using raylib::Touch::GetPointCount; + } + + +} // namespace raylib + +#ifdef RAYLIB_CPP_R_PREFIXES +export { + using RAudioDevice = raylib::AudioDevice; + using RAudioStream = raylib::AudioStream; + using RAutomationEventList = raylib::AutomationEventList; + using RBoundingBox = raylib::BoundingBox; + using RCamera = raylib::Camera; // Alias for Camera3D + using RCamera2D = raylib::Camera2D; + using RCamera3D = raylib::Camera3D; + using RColor = raylib::Color; + using RFileData = raylib::FileData; + using RFileText = raylib::FileText; + using RFont = raylib::Font; + using RGamepad = raylib::Gamepad; + using RImage = raylib::Image; + using RMaterial = raylib::Material; + using RMatrix = raylib::Matrix; + using RMesh = raylib::Mesh; + using RModel = raylib::Model; + using RModelAnimation = raylib::ModelAnimation; + using RMusic = raylib::Music; + using RRay = raylib::Ray; + using RRayCollision = raylib::RayCollision; + using RRaylibException = raylib::RaylibException; + using RRectangle = raylib::Rectangle; + using RRenderTexture = raylib::RenderTexture; + using RRenderTexture2D = raylib::RenderTexture2D; // Alias for RenderTexture + using RShader = raylib::Shader; + using RSound = raylib::Sound; + using RText = raylib::Text; + using RTexture = raylib::Texture; + using RTexture2D = raylib::Texture2D; // Alias for Texture + using RTextureCubemap = raylib::TextureCubemap; // Alias for Texture + using RTextureUnmanaged = raylib::TextureUnmanaged; + using RTexture2DUnmanaged = raylib::Texture2DUnmanaged; // Alias for TextureUnmanaged + using RTextureCubemapUnmanaged = raylib::TextureCubemapUnmanaged; // Alias for TextureUnmanaged + using RVector2 = raylib::Vector2; + using RVector3 = raylib::Vector3; + using RVector4 = raylib::Vector4; + using RQuaternion = raylib::Quaternion; // Alias for Vector4 + using RVrStereoConfig = raylib::VrStereoConfig; + using RWave = raylib::Wave; + using RWindow = raylib::Window; +} +#endif From f1d55148c98bcac539da68b7b3ca299886851ad0 Mon Sep 17 00:00:00 2001 From: lukasx999 <116069013+lukasx999@users.noreply.github.com> Date: Mon, 2 Jun 2025 01:14:33 +0200 Subject: [PATCH 11/19] added loglevel to window constructor --- include/Window.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/Window.hpp b/include/Window.hpp index 54fe00f7..1ec89203 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -27,14 +27,15 @@ class Window { * @param height The height of the window. * @param title The desired title of the window. * @param flags The ConfigFlags to set prior to initializing the window. See SetConfigFlags for more details. + * @param logLevel The the current threshold (minimum) log level * * @see ::SetConfigFlags() * @see ConfigFlags * * @throws raylib::RaylibException Thrown if the window failed to initiate. */ - Window(int width, int height, const std::string& title = "raylib", unsigned int flags = 0) { - Init(width, height, title, flags); + Window(int width, int height, const std::string& title = "raylib", unsigned int flags = 0, TraceLogLevel logLevel = LOG_ALL) { + Init(width, height, title, flags, logLevel); } /** @@ -55,10 +56,11 @@ class Window { * * @throws raylib::RaylibException Thrown if the window failed to initiate. */ - static void Init(int width = 800, int height = 450, const std::string& title = "raylib", unsigned int flags = 0) { + static void Init(int width = 800, int height = 450, const std::string& title = "raylib", unsigned int flags = 0, TraceLogLevel logLevel = LOG_ALL) { if (flags != 0) { ::SetConfigFlags(flags); } + ::SetTraceLogLevel(logLevel); ::InitWindow(width, height, title.c_str()); if (!::IsWindowReady()) { throw RaylibException("Failed to create Window"); From 9ea795df58a32e6cdd5621bf58283496235005dc Mon Sep 17 00:00:00 2001 From: lukasx999 <116069013+lukasx999@users.noreply.github.com> Date: Mon, 2 Jun 2025 17:05:43 +0200 Subject: [PATCH 12/19] added more cursor functions to window class --- include/Window.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/Window.hpp b/include/Window.hpp index 1ec89203..20c5138d 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -91,6 +91,21 @@ class Window { */ static bool IsCursorOnScreen() { return ::IsCursorOnScreen(); } + /** + * Check if cursor is not visible + */ + static bool IsCursorHidden() { return ::IsCursorHidden(); } + + /** + * Hides cursor + */ + static void HideCursor() { ::HideCursor(); } + + /** + * Shows cursor + */ + static void ShowCursor() { ::ShowCursor(); } + /** * Check if window is currently fullscreen */ From fb42454103000c5fde3524e74876452b432edd08 Mon Sep 17 00:00:00 2001 From: Miko <110693261+mikomikotaishi@users.noreply.github.com> Date: Sun, 8 Jun 2025 01:05:36 +0000 Subject: [PATCH 13/19] Add Colors namespace that re-exports macros as constexpr --- modules/raylib.cppm | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/modules/raylib.cppm b/modules/raylib.cppm index 2fcea73d..201e17ff 100644 --- a/modules/raylib.cppm +++ b/modules/raylib.cppm @@ -10,6 +10,33 @@ module; #define RAYMATH_IMPLEMENTATION #include "../include/raylib-cpp.hpp" +#undef LIGHTGRAY +#undef GRAY +#undef DARKGRAY +#undef YELLOW +#undef GOLD +#undef ORANGE +#undef PINK +#undef RED +#undef MAROON +#undef GREEN +#undef LIME +#undef DARKGREEN +#undef SKYBLUE +#undef BLUE +#undef DARKBLUE +#undef PURPLE +#undef VIOLET +#undef DARKPURPLE +#undef BEIGE +#undef BROWN +#undef DARKBROWN +#undef WHITE +#undef BLACK +#undef BLANK +#undef MAGENTA +#undef RAYWHITE + export module raylib; /** @@ -108,6 +135,39 @@ export namespace raylib { using raylib::TextToPascal; using raylib::TextToInteger; + /** + * @namespace raylib::Colors + * @brief Re-exports all Color macros as inline constexpr + */ + namespace Colors { + inline constexpr ::Color LIGHTGRAY = CLITERAL(::Color){ 200, 200, 200, 255 }; + inline constexpr ::Color GRAY = CLITERAL(::Color){ 130, 130, 130, 255 }; + inline constexpr ::Color DARKGRAY = CLITERAL(::Color){ 80, 80, 80, 255 }; + inline constexpr ::Color YELLOW = CLITERAL(::Color){ 253, 249, 0, 255 }; + inline constexpr ::Color GOLD = CLITERAL(::Color){ 255, 203, 0, 255 }; + inline constexpr ::Color ORANGE = CLITERAL(::Color){ 255, 161, 0, 255 }; + inline constexpr ::Color PINK = CLITERAL(::Color){ 255, 109, 194, 255 }; + inline constexpr ::Color RED = CLITERAL(::Color){ 230, 41, 55, 255 }; + inline constexpr ::Color MAROON = CLITERAL(::Color){ 190, 33, 55, 255 }; + inline constexpr ::Color GREEN = CLITERAL(::Color){ 0, 228, 48, 255 }; + inline constexpr ::Color LIME = CLITERAL(::Color){ 0, 158, 47, 255 }; + inline constexpr ::Color DARKGREEN = CLITERAL(::Color){ 0, 117, 44, 255 }; + inline constexpr ::Color SKYBLUE = CLITERAL(::Color){ 102, 191, 255, 255 }; + inline constexpr ::Color BLUE = CLITERAL(::Color){ 0, 121, 241, 255 }; + inline constexpr ::Color DARKBLUE = CLITERAL(::Color){ 0, 82, 172, 255 }; + inline constexpr ::Color PURPLE = CLITERAL(::Color){ 200, 122, 255, 255 }; + inline constexpr ::Color VIOLET = CLITERAL(::Color){ 135, 60, 190, 255 }; + inline constexpr ::Color DARKPURPLE = CLITERAL(::Color){ 112, 31, 126, 255 }; + inline constexpr ::Color BEIGE = CLITERAL(::Color){ 211, 176, 131, 255 }; + inline constexpr ::Color BROWN = CLITERAL(::Color){ 127, 106, 79, 255 }; + inline constexpr ::Color DARKBROWN = CLITERAL(::Color){ 76, 63, 47, 255 }; + inline constexpr ::Color WHITE = CLITERAL(::Color){ 255, 255, 255, 255 }; + inline constexpr ::Color BLACK = CLITERAL(::Color){ 0, 0, 0, 255 }; + inline constexpr ::Color BLANK = CLITERAL(::Color){ 0, 0, 0, 0 }; + inline constexpr ::Color MAGENTA = CLITERAL(::Color){ 255, 0, 255, 255 }; + inline constexpr ::Color RAYWHITE = CLITERAL(::Color){ 245, 245, 245, 255 }; + } + /** * @namespace raylib::Keyboard * @brief Input-related functions: keyboard From 1502bdf12821b14f7ee111a502a0abf14f1f4ee3 Mon Sep 17 00:00:00 2001 From: Miko <110693261+mikomikotaishi@users.noreply.github.com> Date: Tue, 10 Jun 2025 02:09:38 +0000 Subject: [PATCH 14/19] Add missing enum types --- modules/raylib.cppm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/raylib.cppm b/modules/raylib.cppm index 201e17ff..536c7fbe 100644 --- a/modules/raylib.cppm +++ b/modules/raylib.cppm @@ -8,7 +8,7 @@ module; #define BUILD_RAYLIB_CPP_MODULES #define RLCPPAPI #define RAYMATH_IMPLEMENTATION -#include "../include/raylib-cpp.hpp" +#include "raylib-cpp.hpp" #undef LIGHTGRAY #undef GRAY @@ -87,6 +87,29 @@ export namespace raylib { using raylib::Wave; using raylib::Window; + // Enums + using ::ConfigFlags; + using ::TraceLogLevel; + using ::KeyboardKey; + using ::MouseButton; + using ::MouseCursor; + using ::GamepadButton; + using ::GamepadAxis; + using ::MaterialMapIndex; + using ::ShaderLocationIndex; + using ::ShaderUniformDataType; + using ::ShaderAttributeDataType; + using ::PixelFormat; + using ::TextureFilter; + using ::TextureWrap; + using ::CubemapLayout; + using ::FontType; + using ::BlendMode; + using ::Gesture; + using ::CameraMode; + using ::CameraProjection; + using ::NPatchLayout; + // From Functions.hpp using raylib::InitWindow; using raylib::SetWindowTitle; From 42bff0839674353184f3bd4529cf8940277a5745 Mon Sep 17 00:00:00 2001 From: Miko <110693261+mikomikotaishi@users.noreply.github.com> Date: Tue, 10 Jun 2025 05:05:35 +0000 Subject: [PATCH 15/19] Should include a directory above --- modules/raylib.cppm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/raylib.cppm b/modules/raylib.cppm index 536c7fbe..e0903f86 100644 --- a/modules/raylib.cppm +++ b/modules/raylib.cppm @@ -8,7 +8,7 @@ module; #define BUILD_RAYLIB_CPP_MODULES #define RLCPPAPI #define RAYMATH_IMPLEMENTATION -#include "raylib-cpp.hpp" +#include "../include/raylib-cpp.hpp" #undef LIGHTGRAY #undef GRAY From 61eb563a48c3bcd36e6a684056790f25fd0a9e3a Mon Sep 17 00:00:00 2001 From: Miko <110693261+mikomikotaishi@users.noreply.github.com> Date: Wed, 20 Aug 2025 14:49:18 +0000 Subject: [PATCH 16/19] Update modules examples to use using statements --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ef8e9d3c..dd5b59f3 100644 --- a/README.md +++ b/README.md @@ -260,12 +260,15 @@ If using C++20 or later, by passing `BUILD_RAYLIB_CPP_MODULES` to the build syst ```cpp import raylib; +using raylib::Texture; +using raylib::Window; + int main() { int screenWidth = 800; int screenHeight = 450; - raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window"); - raylib::Texture logo("raylib_logo.png"); + Window window(screenWidth, screenHeight, "raylib-cpp - basic window"); + Texture logo("raylib_logo.png"); // ... } From e483d5820e8fe9425c5066c36df2597537b5a78d Mon Sep 17 00:00:00 2001 From: Serhii Zasenko Date: Tue, 21 Oct 2025 14:28:25 +0300 Subject: [PATCH 17/19] Fix use of old-style cast --- include/TextureUnmanaged.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/TextureUnmanaged.hpp b/include/TextureUnmanaged.hpp index c561e6e1..fa65431f 100644 --- a/include/TextureUnmanaged.hpp +++ b/include/TextureUnmanaged.hpp @@ -294,7 +294,7 @@ class TextureUnmanaged : public ::Texture { } TextureUnmanaged& SetMaterial(const ::Material& material, int mapType = MATERIAL_MAP_NORMAL) { - ::SetMaterialTexture((::Material*)(&material), mapType, *this); + ::SetMaterialTexture(const_cast<::Material*>(&material), mapType, *this); return *this; } From 4a4f296ce86888d0ecf12abb1e393e2b53a79284 Mon Sep 17 00:00:00 2001 From: Serhii Zasenko Date: Fri, 24 Oct 2025 13:48:30 +0300 Subject: [PATCH 18/19] Add test compile warning flag effc++ and fix findings --- include/Gamepad.hpp | 2 +- tests/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Gamepad.hpp b/include/Gamepad.hpp index 83a82e9c..0362020c 100644 --- a/include/Gamepad.hpp +++ b/include/Gamepad.hpp @@ -12,7 +12,7 @@ namespace raylib { */ class Gamepad { public: - Gamepad(int gamepadNumber = 0) { set(gamepadNumber); } + Gamepad(int gamepadNumber = 0) : number(gamepadNumber) {}; int number; GETTERSETTER(int, Number, number) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b97ad6e5..e34d5507 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,7 +8,7 @@ add_executable(raylib_cpp_test raylib_cpp_test.cpp) if (MSVC) target_compile_options(raylib_cpp_test PRIVATE /Wall /W4) else() - target_compile_options(raylib_cpp_test PRIVATE -Wall -Wextra -Wconversion -Wsign-conversion) + target_compile_options(raylib_cpp_test PRIVATE -Wall -Wextra -Wconversion -Wsign-conversion -Weffc++) endif() target_link_libraries(raylib_cpp_test raylib_cpp raylib) From d82a8553a336fe3f5e01e45d2155d8aa7c8dec7c Mon Sep 17 00:00:00 2001 From: Serhii Zasenko Date: Wed, 12 Nov 2025 10:19:41 +0200 Subject: [PATCH 19/19] Add vector add/sub float operations - Vector2 add/sub float operations - Vector3 add/sub float operations --- include/Vector2.hpp | 46 +++++++++++++++++++++++++++++++++++++++++++++ include/Vector3.hpp | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/include/Vector2.hpp b/include/Vector2.hpp index b351edd9..bcbb8387 100644 --- a/include/Vector2.hpp +++ b/include/Vector2.hpp @@ -68,6 +68,29 @@ class Vector2 : public ::Vector2 { return *this; } + /** + * Add vector and float value + */ + Vector2 Add(float value) const { + return Vector2AddValue(*this, value); + } + + /** + * Add vector and float value + */ + Vector2 operator+(float value) const { + return Vector2AddValue(*this, value); + } + + /** + * Add vector and float value + */ + Vector2& operator+=(float value) { + set(Vector2AddValue(*this, value)); + + return *this; + } + /** * Subtract two vectors (v1 - v2) */ @@ -87,6 +110,29 @@ class Vector2 : public ::Vector2 { return *this; } + /** + * Subtract vector by float value + */ + [[nodiscard]] Vector2 Subtract(float value) const { + return Vector2SubtractValue(*this, value); + } + + /** + * Subtract vector by float value + */ + Vector2 operator-(float value) const { + return Vector2SubtractValue(*this, value); + } + + /** + * Subtract vector by float value + */ + Vector2& operator-=(float value) { + set(Vector2SubtractValue(*this, value)); + + return *this; + } + /** * Negate vector */ diff --git a/include/Vector3.hpp b/include/Vector3.hpp index 3ef06fa5..c4fbb8f3 100644 --- a/include/Vector3.hpp +++ b/include/Vector3.hpp @@ -60,6 +60,26 @@ class Vector3 : public ::Vector3 { return *this; } + /** + * Add vector and float value + */ + [[nodiscard]] Vector3 Add(float value) const { + return Vector3AddValue(*this, value); + } + + /** + * Add vector and float value + */ + Vector3 operator+(float value) const { + return Vector3AddValue(*this, value); + } + + Vector3& operator+=(float value) { + set(Vector3AddValue(*this, value)); + + return *this; + } + /** * Subtract two vectors. */ @@ -76,6 +96,26 @@ class Vector3 : public ::Vector3 { return *this; } + /** + * Subtract vector by float value + */ + [[nodiscard]] Vector3 Subtract(float value) const { + return Vector3SubtractValue(*this, value); + } + + /** + * Subtract vector by float value + */ + Vector3 operator-(float value) const { + return Vector3SubtractValue(*this, value); + } + + Vector3& operator-=(float value) { + set(Vector3SubtractValue(*this, value)); + + return *this; + } + /** * Negate provided vector (invert direction) */