From fd835204008d03bdbeb159f97bf836508cde23d7 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sun, 25 Oct 2020 12:40:17 -0400 Subject: [PATCH 1/2] Use const functions --- include/AudioDevice.hpp | 2 +- include/AudioStream.hpp | 4 ++-- include/BoundingBox.hpp | 6 +++--- include/Camera2D.hpp | 6 +++--- include/Camera3D.hpp | 6 +++--- include/Color.hpp | 6 +++--- include/DroppedFiles.hpp | 14 +++++++------- include/Font.hpp | 2 +- include/Gamepad.hpp | 20 ++++++++++---------- include/Image.hpp | 2 +- include/Matrix.hpp | 2 +- include/Model.hpp | 4 ++-- include/ModelAnimation.hpp | 4 ++-- include/Mouse.hpp | 22 +++++++++++----------- include/Music.hpp | 6 +++--- include/Physics.hpp | 10 +++++----- include/Ray.hpp | 6 +++--- include/Rectangle.hpp | 6 +++--- include/Shader.hpp | 2 +- include/Sound.hpp | 2 +- include/Texture2D.hpp | 2 +- include/Vector2.hpp | 2 +- include/Vector3.hpp | 2 +- include/Vector4.hpp | 2 +- include/VrSimulator.hpp | 2 +- include/Window.hpp | 30 +++++++++++++++--------------- include/raylib-cpp-utils.hpp | 2 +- 27 files changed, 87 insertions(+), 87 deletions(-) diff --git a/include/AudioDevice.hpp b/include/AudioDevice.hpp index aad11ad..81884e5 100644 --- a/include/AudioDevice.hpp +++ b/include/AudioDevice.hpp @@ -51,7 +51,7 @@ namespace raylib { /** * Check if audio device has been initialized successfully. */ - inline bool IsReady() { + inline bool IsReady() const { return ::IsAudioDeviceReady(); } diff --git a/include/AudioStream.hpp b/include/AudioStream.hpp index 6991d97..287a698 100644 --- a/include/AudioStream.hpp +++ b/include/AudioStream.hpp @@ -72,7 +72,7 @@ namespace raylib { /** * Check if any audio stream buffers requires refill */ - inline bool IsProcessed() { + inline bool IsProcessed() const { return ::IsAudioStreamProcessed(*this); } @@ -103,7 +103,7 @@ namespace raylib { /** * Check if audio stream is playing */ - inline bool IsPlaying() { + inline bool IsPlaying() const { return ::IsAudioStreamPlaying(*this); } diff --git a/include/BoundingBox.hpp b/include/BoundingBox.hpp index f910175..e787b72 100644 --- a/include/BoundingBox.hpp +++ b/include/BoundingBox.hpp @@ -47,15 +47,15 @@ namespace raylib { return *this; } - inline bool CheckCollision(::BoundingBox box2) { + inline bool CheckCollision(::BoundingBox box2) const { return CheckCollisionBoxes(*this, box2); } - inline bool CheckCollision(::Vector3 center, float radius) { + inline bool CheckCollision(::Vector3 center, float radius) const { return CheckCollisionBoxSphere(*this, center, radius); } - inline bool CheckCollision(::Ray ray) { + inline bool CheckCollision(::Ray ray) const { return CheckCollisionRayBox(ray, *this); } }; diff --git a/include/Camera2D.hpp b/include/Camera2D.hpp index 77c1305..a2bc69c 100644 --- a/include/Camera2D.hpp +++ b/include/Camera2D.hpp @@ -60,13 +60,13 @@ namespace raylib { return *this; } - inline Matrix GetMatrix() { + inline Matrix GetMatrix() const { return ::GetCameraMatrix2D(*this); } - inline Vector2 GetWorldToScreen2D(Vector2 position) { + inline Vector2 GetWorldToScreen2D(Vector2 position) const { return ::GetWorldToScreen2D(position, *this); } - inline Vector2 GetScreenToWorld2D(Vector2 position) { + inline Vector2 GetScreenToWorld2D(Vector2 position) const { return ::GetScreenToWorld2D(position, *this); } }; diff --git a/include/Camera3D.hpp b/include/Camera3D.hpp index b8a8dd2..e3dde1e 100644 --- a/include/Camera3D.hpp +++ b/include/Camera3D.hpp @@ -66,7 +66,7 @@ namespace raylib { return *this; } - inline Matrix GetMatrix() { + inline Matrix GetMatrix() const { return ::GetCameraMatrix(*this); } @@ -100,11 +100,11 @@ namespace raylib { return *this; } - inline Ray GetMouseRay(::Vector2 mousePosition) { + inline Ray GetMouseRay(::Vector2 mousePosition) const { return ::GetMouseRay(mousePosition, *this); } - inline Vector2 GetWorldToScreen(::Vector3 position) { + inline Vector2 GetWorldToScreen(::Vector3 position) const { return ::GetWorldToScreen(position, *this); } diff --git a/include/Color.hpp b/include/Color.hpp index 1430a7b..9b9669c 100644 --- a/include/Color.hpp +++ b/include/Color.hpp @@ -90,7 +90,7 @@ namespace raylib { static Color Magenta; static Color RayWhite; - int ToInt() { + int ToInt() const { return ::ColorToInt(*this); } @@ -102,11 +102,11 @@ namespace raylib { return a; } - Vector4 Normalize() { + Vector4 Normalize() const { return ::ColorNormalize(*this); } - Vector3 ToHSV() { + Vector3 ToHSV() const { return ::ColorToHSV(*this); } diff --git a/include/DroppedFiles.hpp b/include/DroppedFiles.hpp index 258758a..272b2e7 100644 --- a/include/DroppedFiles.hpp +++ b/include/DroppedFiles.hpp @@ -32,7 +32,7 @@ namespace raylib { /** * Check if a file has been dropped into window. */ - inline bool IsFileDropped() { + inline bool IsFileDropped() const { return ::IsFileDropped(); } @@ -52,15 +52,15 @@ namespace raylib { return at(pos); } - inline int Count() { + inline int Count() const { return m_count; } - inline int size() { + inline int size() const { return m_count; } - inline bool empty() { + inline bool empty() const { return m_count == 0; } @@ -68,15 +68,15 @@ namespace raylib { Clear(); } - inline std::string front() { + inline std::string front() const { return at(0); } - inline std::string back() { + inline std::string back() const { return at(m_count - 1); } - std::string at(int pos) { + std::string at(int pos) const { if (m_files != NULL && pos < m_count && pos >= 0) { return std::string(m_files[pos]); } diff --git a/include/Font.hpp b/include/Font.hpp index 975e37d..f8b9ef0 100644 --- a/include/Font.hpp +++ b/include/Font.hpp @@ -93,7 +93,7 @@ namespace raylib { return ::MeasureTextEx(*this, text.c_str(), fontSize, spacing); } - inline int GetGlyphIndex(int character) { + inline int GetGlyphIndex(int character) const { return ::GetGlyphIndex(*this, character); } }; diff --git a/include/Gamepad.hpp b/include/Gamepad.hpp index 9b00611..01efb04 100644 --- a/include/Gamepad.hpp +++ b/include/Gamepad.hpp @@ -34,39 +34,39 @@ namespace raylib { operator int() const { return number; } - inline bool IsAvailable() { + inline bool IsAvailable() const { return ::IsGamepadAvailable(number); } - inline bool IsName(const std::string& name) { + inline bool IsName(const std::string& name) const { return ::IsGamepadName(number, name.c_str()); } - std::string GetName() { + std::string GetName() const { return std::string(::GetGamepadName(number)); } - inline bool IsButtonPressed(int button) { + inline bool IsButtonPressed(int button) const { return ::IsGamepadButtonPressed(number, button); } - inline bool IsButtonDown(int button) { + inline bool IsButtonDown(int button) const { return ::IsGamepadButtonDown(number, button); } - inline bool IsButtonReleased(int button) { + inline bool IsButtonReleased(int button) const { return ::IsGamepadButtonReleased(number, button); } - inline bool IsButtonUp(int button) { + inline bool IsButtonUp(int button) const { return ::IsGamepadButtonUp(number, button); } - inline int GetButtonPressed() { + inline int GetButtonPressed() const { return ::GetGamepadButtonPressed(); } - inline int GetAxisCount() { + inline int GetAxisCount() const { return ::GetGamepadAxisCount(number); } - inline float GetAxisMovement(int axis) { + inline float GetAxisMovement(int axis) const { return ::GetGamepadAxisMovement(number, axis); } }; diff --git a/include/Image.hpp b/include/Image.hpp index 859d4df..03390fe 100644 --- a/include/Image.hpp +++ b/include/Image.hpp @@ -247,7 +247,7 @@ namespace raylib { return ::GetImagePalette(*this, maxPaletteSize, extractCount); } - inline Rectangle GetAlphaBorder(float threshold) { + inline Rectangle GetAlphaBorder(float threshold) const { return ::GetImageAlphaBorder(*this, threshold); } diff --git a/include/Matrix.hpp b/include/Matrix.hpp index 3b54aab..83e8c2c 100644 --- a/include/Matrix.hpp +++ b/include/Matrix.hpp @@ -198,7 +198,7 @@ namespace raylib { return ::MatrixLookAt(eye, target, up); } - float16 ToFloatV() { + inline float16 ToFloatV() { return ::MatrixToFloatV(*this); } operator float16() { diff --git a/include/Model.hpp b/include/Model.hpp index 1e589d5..49e3040 100644 --- a/include/Model.hpp +++ b/include/Model.hpp @@ -68,7 +68,7 @@ namespace raylib { return *this; } - inline RayHitInfo GetCollision(::Ray ray) { + inline RayHitInfo GetCollision(::Ray ray) const { return ::GetCollisionRayModel(ray, *this); } @@ -77,7 +77,7 @@ namespace raylib { return *this; } - inline bool IsModelAnimationValid(::ModelAnimation anim) { + inline bool IsModelAnimationValid(::ModelAnimation anim) const { return ::IsModelAnimationValid(*this, anim); } }; diff --git a/include/ModelAnimation.hpp b/include/ModelAnimation.hpp index db261af..ee8e987 100644 --- a/include/ModelAnimation.hpp +++ b/include/ModelAnimation.hpp @@ -54,11 +54,11 @@ namespace raylib { return *this; } - inline bool IsValid(::Model model) { + inline bool IsValid(::Model model) const { return ::IsModelAnimationValid(model, *this); } - inline bool IsModelAnimationValid(::Model model) { + inline bool IsModelAnimationValid(::Model model) const { return ::IsModelAnimationValid(model, *this); } }; diff --git a/include/Mouse.hpp b/include/Mouse.hpp index 07bc3e6..2aff9fe 100644 --- a/include/Mouse.hpp +++ b/include/Mouse.hpp @@ -14,22 +14,22 @@ extern "C"{ namespace raylib { class Mouse { public: - inline bool IsButtonPressed(int button) { + inline bool IsButtonPressed(int button) const { return ::IsMouseButtonPressed(button); } - inline bool IsButtonDown(int button) { + inline bool IsButtonDown(int button) const { return ::IsMouseButtonDown(button); } - inline bool IsButtonReleased(int button) { + inline bool IsButtonReleased(int button) const { return ::IsMouseButtonReleased(button); } - inline bool IsButtonUp(int button) { + inline bool IsButtonUp(int button) const { return ::IsMouseButtonUp(button); } - inline int GetX() { + inline int GetX() const { return ::GetMouseX(); } - inline int GetY() { + inline int GetY() const { return ::GetMouseY(); } inline Mouse& SetX(int x) { @@ -40,7 +40,7 @@ namespace raylib { ::SetMouseOffset(GetX(), y); return *this; } - inline Vector2 GetPosition() { + inline Vector2 GetPosition() const { return ::GetMousePosition(); } inline Mouse& SetPosition(int x, int y) { @@ -55,16 +55,16 @@ namespace raylib { ::SetMouseScale(scaleX, scaleY); return *this; } - inline float GetWheelMove() { + inline float GetWheelMove() const { return ::GetMouseWheelMove(); } - inline int GetTouchX() { + inline int GetTouchX() const { return ::GetTouchX(); } - inline int GetTouchY() { + inline int GetTouchY() const { return ::GetTouchY(); } - inline Vector2 GetTouchPosition(int index) { + inline Vector2 GetTouchPosition(int index) const { return ::GetTouchPosition(index); } }; diff --git a/include/Music.hpp b/include/Music.hpp index e4191c7..6ba1c5a 100644 --- a/include/Music.hpp +++ b/include/Music.hpp @@ -75,7 +75,7 @@ namespace raylib { ::ResumeMusicStream(*this); return *this; } - inline bool IsPlaying() { + inline bool IsPlaying() const { return ::IsMusicPlaying(*this); } inline Music& SetVolume(float volume) { @@ -86,10 +86,10 @@ namespace raylib { ::SetMusicPitch(*this, pitch); return *this; } - inline float GetTimeLength() { + inline float GetTimeLength() const { return ::GetMusicTimeLength(*this); } - inline float GetTimePlayed() { + inline float GetTimePlayed() const { return ::GetMusicTimePlayed(*this); } diff --git a/include/Physics.hpp b/include/Physics.hpp index a07e707..5e3c068 100644 --- a/include/Physics.hpp +++ b/include/Physics.hpp @@ -77,19 +77,19 @@ namespace raylib { ::PhysicsShatter(body, position, force); return *this; } - inline int GetBodiesCount() { + inline int GetBodiesCount() const { return ::GetPhysicsBodiesCount(); } - inline PhysicsBody GetBody(int index) { + inline PhysicsBody GetBody(int index) const { return ::GetPhysicsBody(index); } - inline int GetShapeType(int index) { + inline int GetShapeType(int index) const { return ::GetPhysicsShapeType(index); } - inline int GetShapeVerticesCount(int index) { + inline int GetShapeVerticesCount(int index) const { return ::GetPhysicsShapeVerticesCount(index); } - inline Vector2 GetShapeVertex(PhysicsBody body, int vertex) { + inline Vector2 GetShapeVertex(PhysicsBody body, int vertex) const { return ::GetPhysicsShapeVertex(body, vertex); } inline Physics& SetBodyRotation(PhysicsBody body, float radians) { diff --git a/include/Ray.hpp b/include/Ray.hpp index 1a5cf18..88d986b 100644 --- a/include/Ray.hpp +++ b/include/Ray.hpp @@ -52,15 +52,15 @@ namespace raylib { return *this; } - inline bool CheckCollisionSphere(::Vector3 center, float radius) { + inline bool CheckCollisionSphere(::Vector3 center, float radius) const { return CheckCollisionRaySphere(*this, center, radius); } - inline bool CheckCollisionSphereEx(::Vector3 center, float radius, ::Vector3 *collisionPoint) { + inline bool CheckCollisionSphereEx(::Vector3 center, float radius, ::Vector3 *collisionPoint) const { return CheckCollisionRaySphereEx(*this, center, radius, collisionPoint); } - inline bool CheckCollisionBox(::BoundingBox box) { + inline bool CheckCollisionBox(::BoundingBox box) const { return CheckCollisionRayBox(*this, box); } diff --git a/include/Rectangle.hpp b/include/Rectangle.hpp index 7c6b822..800b660 100644 --- a/include/Rectangle.hpp +++ b/include/Rectangle.hpp @@ -90,15 +90,15 @@ namespace raylib { return *this; } - inline bool CheckCollision(::Rectangle rec2) { + inline bool CheckCollision(::Rectangle rec2) const { return ::CheckCollisionRecs(*this, rec2); } - inline Rectangle GetCollision(::Rectangle rec2) { + inline Rectangle GetCollision(::Rectangle rec2) const { return ::GetCollisionRec(*this, rec2); } - inline bool CheckCollision(::Vector2 point) { + inline bool CheckCollision(::Vector2 point) const { return ::CheckCollisionPointRec(point, *this); } }; diff --git a/include/Shader.hpp b/include/Shader.hpp index d48e036..bd45c8f 100644 --- a/include/Shader.hpp +++ b/include/Shader.hpp @@ -72,7 +72,7 @@ namespace raylib { return *this; } - inline int GetLocation(const std::string& uniformName) { + inline int GetLocation(const std::string& uniformName) const { return ::GetShaderLocation(*this, uniformName.c_str()); } }; diff --git a/include/Sound.hpp b/include/Sound.hpp index 51b1cfc..4c166dc 100644 --- a/include/Sound.hpp +++ b/include/Sound.hpp @@ -87,7 +87,7 @@ namespace raylib { return *this; } - inline bool IsPlaying() { + inline bool IsPlaying() const { return ::IsSoundPlaying(*this); } inline Sound& SetVolume(float volume) { diff --git a/include/Texture2D.hpp b/include/Texture2D.hpp index 25c6246..70315ba 100644 --- a/include/Texture2D.hpp +++ b/include/Texture2D.hpp @@ -84,7 +84,7 @@ namespace raylib { return *this; } - inline Image GetTextureData() { + inline Image GetTextureData() const { return ::GetTextureData(*this); } inline operator raylib::Image() { diff --git a/include/Vector2.hpp b/include/Vector2.hpp index 1b5cc8d..caeefa2 100644 --- a/include/Vector2.hpp +++ b/include/Vector2.hpp @@ -152,7 +152,7 @@ namespace raylib { return *this; } - float Length() { + float Length() const { return Vector2Length(*this); } diff --git a/include/Vector3.hpp b/include/Vector3.hpp index 5ffc6dd..94910b7 100644 --- a/include/Vector3.hpp +++ b/include/Vector3.hpp @@ -160,7 +160,7 @@ namespace raylib { return *this; } - float Length() { + float Length() const { return Vector3Length(*this); } diff --git a/include/Vector4.hpp b/include/Vector4.hpp index 3a3946c..0a2f289 100644 --- a/include/Vector4.hpp +++ b/include/Vector4.hpp @@ -89,7 +89,7 @@ namespace raylib { return QuaternionToMatrix(*this); } - float Length() { + float Length() const { return QuaternionLength(*this); } diff --git a/include/VrSimulator.hpp b/include/VrSimulator.hpp index 9f9b934..764dc18 100644 --- a/include/VrSimulator.hpp +++ b/include/VrSimulator.hpp @@ -30,7 +30,7 @@ namespace raylib { Close(); } - inline bool IsReady() { + inline bool IsReady() const { return ::IsVrSimulatorReady(); } diff --git a/include/Window.hpp b/include/Window.hpp index f730de5..43a1771 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -66,20 +66,20 @@ namespace raylib { inline static bool IsReady() { return ::IsWindowReady(); }; - inline bool IsMinimized() { + inline bool IsMinimized() const { return ::IsWindowMinimized(); } - inline bool IsFocused() { + inline bool IsFocused() const { return ::IsWindowFocused(); } - inline bool IsResized() { + inline bool IsResized() const { return ::IsWindowResized(); } - inline bool IsHidden() { + inline bool IsHidden() const { return ::IsWindowHidden(); } - inline bool IsFullscreen() { + inline bool IsFullscreen() const { return ::IsWindowFullscreen(); } inline Window& ToggleFullscreen() { @@ -118,7 +118,7 @@ namespace raylib { ::SetWindowSize(width, height); return *this; } - inline void* GetHandle() { + inline void* GetHandle() const { return ::GetWindowHandle(); } @@ -131,27 +131,27 @@ namespace raylib { return *this; } - inline int GetScreenWidth() { + inline int GetScreenWidth() const { return ::GetScreenWidth(); } - inline int GetScreenHeight() { + inline int GetScreenHeight() const { return ::GetScreenHeight(); } - inline Vector2 GetPosition() { + inline Vector2 GetPosition() const { return ::GetWindowPosition(); } - inline Vector2 GetScaleDPI() { + inline Vector2 GetScaleDPI() const { return ::GetWindowScaleDPI(); } - std::string GetMonitorName(int monitor) { + std::string GetMonitorName(int monitor) const { return std::string(::GetMonitorName(monitor)); } - std::string GetClipboardText() { + std::string GetClipboardText() const { return std::string(::GetClipboardText()); } @@ -164,13 +164,13 @@ namespace raylib { ::SetTargetFPS(fps); return *this; } - inline int GetFPS() { + inline int GetFPS() const { return ::GetFPS(); } - inline float GetFrameTime() { + inline float GetFrameTime() const { return ::GetFrameTime(); } - inline double GetTime() { + inline double GetTime() const { return ::GetTime(); } }; diff --git a/include/raylib-cpp-utils.hpp b/include/raylib-cpp-utils.hpp index 7425adc..b000c5b 100644 --- a/include/raylib-cpp-utils.hpp +++ b/include/raylib-cpp-utils.hpp @@ -10,7 +10,7 @@ * @param name The machine-readable name of the property. */ #define GETTERSETTER(type, method, name) \ - inline type Get##method() { return name; } \ + inline type Get##method() const { return name; } \ inline void Set##method(type value) { name = value; } #endif From 8b159b2b906494211b9bcc66be675e62e963443b Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sun, 25 Oct 2020 12:43:38 -0400 Subject: [PATCH 2/2] Make Fade a const function --- include/Color.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/Color.hpp b/include/Color.hpp index 9b9669c..f8367fb 100644 --- a/include/Color.hpp +++ b/include/Color.hpp @@ -96,10 +96,8 @@ namespace raylib { operator int() const { return ::ColorToInt(*this); } - Color Fade(float alpha) { - Color a; - a.set(::Fade(*this, alpha)); - return a; + Color Fade(float alpha) const { + return ::Fade(*this, alpha); } Vector4 Normalize() const {