From c144c71f2711792aaa78e38691e8962aae02ecab Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 2 Jan 2021 12:10:48 -0500 Subject: [PATCH] Fix more references --- CHANGELOG.md | 3 ++- include/BoundingBox.hpp | 2 +- include/Camera2D.hpp | 5 +++++ include/Camera3D.hpp | 4 ++++ include/Color.hpp | 34 +++++++++++++++++++++++++++++----- include/Image.hpp | 9 ++++++++- include/Material.hpp | 4 ++-- include/Matrix.hpp | 16 ++++++++-------- include/Mesh.hpp | 4 ++-- include/Model.hpp | 18 +++++++++++------- include/ModelAnimation.hpp | 4 ++-- include/Music.hpp | 4 ++-- include/Ray.hpp | 4 ++-- include/RayHitInfo.hpp | 4 ++-- include/Rectangle.hpp | 6 +++--- include/Shader.hpp | 4 ++-- include/Sound.hpp | 4 ++-- include/Texture.hpp | 19 +++++++++++++++---- include/Vector2.hpp | 4 ++-- include/Vector3.hpp | 6 +++--- include/Vector4.hpp | 4 ++-- include/Wave.hpp | 4 ++-- include/Window.hpp | 17 ++++++++++++----- 23 files changed, 123 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb3fd2f..bcbbf7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,10 +14,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - `Mouse::SetX()` and `Mouse::SetY()` +- Most objects are now passed by reference - Error correction when unloading images, materials, models and meshes ### Changed -- `Mouse` functions are now `static`. Use `Mouse::SetX()` instead of instantiating a `Mouse` object. +- `Mouse` functions are now `static`. Use `Mouse::SetX()` instead of using `Mouse mouse`. - `Camera*::BeginMode()` and `Camera*::EndMode()` no longer have 2D/3D in the name ## [v3.5.0-alpha1] - 2020-12-26 diff --git a/include/BoundingBox.hpp b/include/BoundingBox.hpp index 7edbd78..9565c0d 100644 --- a/include/BoundingBox.hpp +++ b/include/BoundingBox.hpp @@ -66,7 +66,7 @@ class BoundingBox : public ::BoundingBox { /** * Draw a bounding box with wires */ - inline BoundingBox& Draw(::Color color = WHITE) { + inline BoundingBox& Draw(::Color color = {255, 255, 255, 255}) { DrawBoundingBox(*this, color); return *this; } diff --git a/include/Camera2D.hpp b/include/Camera2D.hpp index 0c8fb2f..89ea0e1 100644 --- a/include/Camera2D.hpp +++ b/include/Camera2D.hpp @@ -32,6 +32,11 @@ namespace raylib { class Camera2D : public ::Camera2D { public: + Camera2D() {} + Camera2D(const ::Camera2D& camera) { + set(camera); + } + Camera2D(::Vector2 offsetValue, ::Vector2 targetValue, float rotationValue = 0, float zoomValue = 1) { offset = offsetValue; diff --git a/include/Camera3D.hpp b/include/Camera3D.hpp index 5114291..d7b2aad 100644 --- a/include/Camera3D.hpp +++ b/include/Camera3D.hpp @@ -32,6 +32,10 @@ namespace raylib { class Camera3D : public ::Camera3D { public: + Camera3D(const ::Camera3D& camera) { + set(camera); + } + Camera3D(::Vector3 positionValue, ::Vector3 targetValue, ::Vector3 upValue, float fovyValue = 0, int typeValue = 0) { position = positionValue; diff --git a/include/Color.hpp b/include/Color.hpp index b4cf831..6959e33 100644 --- a/include/Color.hpp +++ b/include/Color.hpp @@ -34,11 +34,8 @@ namespace raylib { class Color : public ::Color { public: - Color(::Color color) { - r = color.r; - g = color.g; - b = color.b; - a = color.a; + Color(const ::Color& color) { + set(color); } Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha) : @@ -245,6 +242,33 @@ class Color : public ::Color { return ::ColorAlphaBlend(dst, *this, tint); } + inline static Color LightGray() { return LIGHTGRAY; } + inline static Color Gray() { return GRAY; } + inline static Color DarkGray() { return DARKGRAY; } + inline static Color Yellow() { return YELLOW; } + inline static Color Gold() { return GOLD; } + inline static Color Orange() { return ORANGE; } + inline static Color Pink() { return PINK; } + inline static Color Red() { return RED; } + inline static Color Maroon() { return MAROON; } + inline static Color Green() { return GREEN; } + inline static Color Lime() { return LIME; } + inline static Color DarkGreen() { return DARKGREEN; } + inline static Color SkyBlue() { return SKYBLUE; } + inline static Color Blue() { return BLUE; } + inline static Color DarkBlue() { return DARKBLUE; } + inline static Color Purple() { return PURPLE; } + inline static Color Violet() { return VIOLET; } + inline static Color DarkPurple() { return DARKPURPLE; } + inline static Color Beige() { return BEIGE; } + inline static Color Brown() { return BROWN; } + inline static Color DarkBrown() { return DARKBROWN; } + inline static Color White() { return WHITE; } + inline static Color Black() { return BLACK; } + inline static Color Blank() { return BLANK; } + inline static Color Magenta() { return MAGENTA; } + inline static Color RayWhite() { return RAYWHITE; } + protected: inline void set(const ::Color& color) { r = color.r; diff --git a/include/Image.hpp b/include/Image.hpp index 79c8b35..5fef8d5 100644 --- a/include/Image.hpp +++ b/include/Image.hpp @@ -203,6 +203,13 @@ class Image : public ::Image { GETTERSETTER(int, Mipmaps, mipmaps) GETTERSETTER(int, Format, format) + /** + * Retrieve the width and height of the image. + */ + inline ::Vector2 GetSize() { + return {static_cast(width), static_cast(height)}; + } + /** * Create an image duplicate (useful for transformations) */ @@ -236,7 +243,7 @@ class Image : public ::Image { /** * Apply alpha mask to image */ - inline Image& AlphaMask(::Image alphaMask) { + inline Image& AlphaMask(const ::Image& alphaMask) { ::ImageAlphaMask(this, alphaMask); return *this; } diff --git a/include/Material.hpp b/include/Material.hpp index 036df04..5d8b1ef 100644 --- a/include/Material.hpp +++ b/include/Material.hpp @@ -34,7 +34,7 @@ namespace raylib { class Material : public ::Material { public: - Material(::Material material) { + Material(const ::Material& material) { set(material); } @@ -91,7 +91,7 @@ class Material : public ::Material { } protected: - inline void set(::Material material) { + inline void set(const ::Material& material) { shader = material.shader; maps = material.maps; params = material.params; diff --git a/include/Matrix.hpp b/include/Matrix.hpp index 85a3216..3a7c1dc 100644 --- a/include/Matrix.hpp +++ b/include/Matrix.hpp @@ -45,7 +45,7 @@ extern "C" { namespace raylib { class Matrix : public ::Matrix { public: - Matrix(::Matrix mat) { + Matrix(const ::Matrix& mat) { set(mat); } @@ -186,19 +186,19 @@ class Matrix : public ::Matrix { return ::MatrixIdentity(); } - Matrix Add(::Matrix right) { + Matrix Add(const ::Matrix& right) { return ::MatrixAdd(*this, right); } - Matrix operator+(const Matrix& matrix) { + Matrix operator+(const ::Matrix& matrix) { return ::MatrixAdd(*this, matrix); } - Matrix Subtract(::Matrix right) { + Matrix Subtract(const ::Matrix& right) { return ::MatrixSubtract(*this, right); } - Matrix operator-(const Matrix& matrix) { + Matrix operator-(const ::Matrix& matrix) { return ::MatrixSubtract(*this, matrix); } @@ -230,11 +230,11 @@ class Matrix : public ::Matrix { return ::MatrixScale(x, y, z); } - Matrix Multiply(Matrix right) const { + Matrix Multiply(const ::Matrix& right) const { return ::MatrixMultiply(*this, right); } - Matrix operator*(const Matrix& matrix) { + Matrix operator*(const ::Matrix& matrix) { return ::MatrixMultiply(*this, matrix); } @@ -275,7 +275,7 @@ class Matrix : public ::Matrix { #endif protected: - inline void set(::Matrix mat) { + inline void set(const ::Matrix& mat) { m0 = mat.m0; m1 = mat.m1; m2 = mat.m2; diff --git a/include/Mesh.hpp b/include/Mesh.hpp index 6d4b836..6c5e65f 100644 --- a/include/Mesh.hpp +++ b/include/Mesh.hpp @@ -36,7 +36,7 @@ namespace raylib { class Mesh : public ::Mesh { public: - Mesh(::Mesh mesh) { + Mesh(const ::Mesh& mesh) { set(mesh); } @@ -216,7 +216,7 @@ class Mesh : public ::Mesh { } protected: - inline void set(::Mesh mesh) { + inline void set(const ::Mesh& mesh) { vertexCount = mesh.vertexCount; triangleCount = mesh.triangleCount; vertices = mesh.vertices; diff --git a/include/Model.hpp b/include/Model.hpp index 29c8794..204a6f8 100644 --- a/include/Model.hpp +++ b/include/Model.hpp @@ -34,7 +34,7 @@ namespace raylib { class Model : public ::Model { public: - Model(::Model model) { + Model(const ::Model& model) { set(model); } @@ -42,7 +42,7 @@ class Model : public ::Model { set(::LoadModel(fileName.c_str())); } - Model(::Mesh mesh) { + Model(const ::Mesh& mesh) { set(::LoadModelFromMesh(mesh)); } @@ -122,7 +122,9 @@ class Model : public ::Model { /** * Draw a model (with texture if set) */ - inline Model& Draw(::Vector3 position, float scale = 1.0f, ::Color tint = WHITE) { + inline Model& Draw(::Vector3 position, + float scale = 1.0f, + ::Color tint = {255, 255, 255, 255}) { ::DrawModel(*this, position, scale, tint); return *this; } @@ -135,7 +137,7 @@ class Model : public ::Model { ::Vector3 rotationAxis, float rotationAngle = 0.0f, ::Vector3 scale = {1.0f, 1.0f, 1.0f}, - ::Color tint = WHITE) { + ::Color tint = {255, 255, 255, 255}) { ::DrawModelEx(*this, position, rotationAxis, rotationAngle, scale, tint); return *this; } @@ -143,7 +145,9 @@ class Model : public ::Model { /** * Draw a model wires (with texture if set) */ - inline Model& DrawWires(::Vector3 position, float scale = 1.0f, ::Color tint = WHITE) { + inline Model& DrawWires(::Vector3 position, + float scale = 1.0f, + ::Color tint = {255, 255, 255, 255}) { ::DrawModelWires(*this, position, scale, tint); return *this; } @@ -156,13 +160,13 @@ class Model : public ::Model { ::Vector3 rotationAxis, float rotationAngle = 0.0f, ::Vector3 scale = {1.0f, 1.0f, 1.0f}, - ::Color tint = WHITE) { + ::Color tint = {255, 255, 255, 255}) { ::DrawModelWiresEx(*this, position, rotationAxis, rotationAngle, scale, tint); return *this; } protected: - inline void set(::Model model) { + inline void set(const ::Model& model) { transform = model.transform; meshCount = model.meshCount; diff --git a/include/ModelAnimation.hpp b/include/ModelAnimation.hpp index 1ce060c..34919d2 100644 --- a/include/ModelAnimation.hpp +++ b/include/ModelAnimation.hpp @@ -38,7 +38,7 @@ namespace raylib { */ class ModelAnimation : public ::ModelAnimation { public: - ModelAnimation(::ModelAnimation model) { + ModelAnimation(const ::ModelAnimation& model) { set(model); } @@ -93,7 +93,7 @@ class ModelAnimation : public ::ModelAnimation { } protected: - inline void set(::ModelAnimation model) { + inline void set(const ::ModelAnimation& model) { boneCount = model.boneCount; bones = model.bones; frameCount = model.frameCount; diff --git a/include/Music.hpp b/include/Music.hpp index e746b90..74c1e9c 100644 --- a/include/Music.hpp +++ b/include/Music.hpp @@ -33,7 +33,7 @@ namespace raylib { class Music : public ::Music { public: - Music(::Music music) { + Music(const ::Music& music) { set(music); } @@ -152,7 +152,7 @@ class Music : public ::Music { } protected: - inline void set(::Music music) { + inline void set(const ::Music& music) { ctxType = music.ctxType; ctxData = music.ctxData; looping = music.looping; diff --git a/include/Ray.hpp b/include/Ray.hpp index b4ef036..27b1e04 100644 --- a/include/Ray.hpp +++ b/include/Ray.hpp @@ -37,7 +37,7 @@ namespace raylib { */ class Ray : public ::Ray { public: - Ray(::Ray ray) { + Ray(const ::Ray& ray) { set(ray); } @@ -115,7 +115,7 @@ class Ray : public ::Ray { } protected: - inline void set(::Ray ray) { + inline void set(const ::Ray& ray) { position = ray.position; direction = ray.direction; } diff --git a/include/RayHitInfo.hpp b/include/RayHitInfo.hpp index f1e1a5a..fa44fd6 100644 --- a/include/RayHitInfo.hpp +++ b/include/RayHitInfo.hpp @@ -34,7 +34,7 @@ namespace raylib { */ class RayHitInfo : public ::RayHitInfo { public: - RayHitInfo(::RayHitInfo ray) { + RayHitInfo(const ::RayHitInfo& ray) { set(ray); } @@ -82,7 +82,7 @@ class RayHitInfo : public ::RayHitInfo { GETTERSETTER(::Vector3, Normal, normal) protected: - inline void set(::RayHitInfo ray) { + inline void set(const ::RayHitInfo& ray) { hit = ray.hit; distance = ray.distance; position = ray.position; diff --git a/include/Rectangle.hpp b/include/Rectangle.hpp index 15e790d..40a80ab 100644 --- a/include/Rectangle.hpp +++ b/include/Rectangle.hpp @@ -32,7 +32,7 @@ namespace raylib { class Rectangle : public ::Rectangle { public: - Rectangle(::Rectangle vec) { + Rectangle(const ::Rectangle& vec) { set(vec); } @@ -94,7 +94,7 @@ class Rectangle : public ::Rectangle { return *this; } - inline Rectangle& DrawLinesEx(int lineThick, ::Color color) { + inline Rectangle& DrawLines(::Color color, int lineThick) { ::DrawRectangleLinesEx(*this, lineThick, color); return *this; } @@ -139,7 +139,7 @@ class Rectangle : public ::Rectangle { } protected: - inline void set(::Rectangle rect) { + inline void set(const ::Rectangle& rect) { x = rect.x; y = rect.y; width = rect.width; diff --git a/include/Shader.hpp b/include/Shader.hpp index f38837b..6f664e4 100644 --- a/include/Shader.hpp +++ b/include/Shader.hpp @@ -34,7 +34,7 @@ namespace raylib { class Shader : public ::Shader { public: - Shader(::Shader shader) { + Shader(const ::Shader& shader) { set(shader); } @@ -153,7 +153,7 @@ class Shader : public ::Shader { } protected: - inline void set(::Shader shader) { + inline void set(const ::Shader& shader) { id = shader.id; locs = shader.locs; } diff --git a/include/Sound.hpp b/include/Sound.hpp index c2e229e..80255a1 100644 --- a/include/Sound.hpp +++ b/include/Sound.hpp @@ -36,7 +36,7 @@ namespace raylib { */ class Sound : public ::Sound { public: - Sound(::Sound vec) { + Sound(const ::Sound& vec) { set(vec); } @@ -152,7 +152,7 @@ class Sound : public ::Sound { } protected: - inline void set(::Sound sound) { + inline void set(const ::Sound& sound) { sampleCount = sound.sampleCount; stream = sound.stream; } diff --git a/include/Texture.hpp b/include/Texture.hpp index c6a3ed3..19bf29a 100644 --- a/include/Texture.hpp +++ b/include/Texture.hpp @@ -35,6 +35,10 @@ namespace raylib { class Texture : public ::Texture { public: + Texture(const ::Texture& texture) { + set(texture); + } + Texture() { set(::GetTextureDefault()); } @@ -70,6 +74,13 @@ class Texture : public ::Texture { return *this; } + /** + * Retrieve the width and height of the texture. + */ + inline ::Vector2 GetSize() { + return {static_cast(width), static_cast(height)}; + } + /** * Load texture from image data */ @@ -117,7 +128,7 @@ class Texture : public ::Texture { /** * Get pixel data from GPU texture and return an Image */ - inline Image GetTextureData() const { + inline ::Image GetData() const { return ::GetTextureData(*this); } @@ -125,7 +136,7 @@ class Texture : public ::Texture { * Get pixel data from GPU texture and return an Image */ inline operator raylib::Image() { - return GetTextureData(); + return GetData(); } /** @@ -229,13 +240,13 @@ class Texture : public ::Texture { /** * Define default texture used to draw shapes */ - inline Texture& SetShapesTexture(::Rectangle source) { + inline Texture& SetShapes(::Rectangle source) { ::SetShapesTexture(*this, source); return *this; } protected: - inline void set(::Texture texture) { + inline void set(const ::Texture& texture) { id = texture.id; width = texture.width; height = texture.height; diff --git a/include/Vector2.hpp b/include/Vector2.hpp index 4d8e800..d3e5011 100644 --- a/include/Vector2.hpp +++ b/include/Vector2.hpp @@ -36,7 +36,7 @@ namespace raylib { class Vector2 : public ::Vector2 { public: - Vector2(::Vector2 vec) { + Vector2(const ::Vector2& vec) { set(vec); } @@ -339,7 +339,7 @@ class Vector2 : public ::Vector2 { } protected: - inline void set(::Vector2 vec) { + inline void set(const ::Vector2& vec) { x = vec.x; y = vec.y; } diff --git a/include/Vector3.hpp b/include/Vector3.hpp index 46c894e..767f076 100644 --- a/include/Vector3.hpp +++ b/include/Vector3.hpp @@ -36,7 +36,7 @@ namespace raylib { class Vector3 : public ::Vector3 { public: - Vector3(::Vector3 vec) { + Vector3(const ::Vector3& vec) { set(vec); } @@ -271,7 +271,7 @@ class Vector3 : public ::Vector3 { } inline Vector3& DrawCubeTexture( - ::Texture2D texture, + const ::Texture2D& texture, float width, float height, float length, @@ -325,7 +325,7 @@ class Vector3 : public ::Vector3 { } protected: - inline void set(::Vector3 vec) { + inline void set(const ::Vector3& vec) { x = vec.x; y = vec.y; z = vec.z; diff --git a/include/Vector4.hpp b/include/Vector4.hpp index cba7fb7..36fda5f 100644 --- a/include/Vector4.hpp +++ b/include/Vector4.hpp @@ -37,7 +37,7 @@ namespace raylib { class Vector4 : public ::Vector4 { public: - Vector4(::Vector4 vec) { + Vector4(const ::Vector4& vec) { set(vec); } @@ -167,7 +167,7 @@ class Vector4 : public ::Vector4 { } protected: - inline void set(::Vector4 vec4) { + inline void set(const ::Vector4& vec4) { x = vec4.x; y = vec4.y; z = vec4.z; diff --git a/include/Wave.hpp b/include/Wave.hpp index e2c101e..d6eb19a 100644 --- a/include/Wave.hpp +++ b/include/Wave.hpp @@ -33,7 +33,7 @@ namespace raylib { class Wave : public ::Wave { public: - Wave(::Wave wave) { + Wave(const ::Wave& wave) { set(wave); } @@ -160,7 +160,7 @@ class Wave : public ::Wave { } protected: - inline void set(::Wave wave) { + inline void set(const ::Wave& wave) { sampleCount = wave.sampleCount; sampleRate = wave.sampleRate; sampleSize = wave.sampleSize; diff --git a/include/Window.hpp b/include/Window.hpp index 1036d7e..b8018dd 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -57,7 +57,7 @@ class Window { Close(); } - void Init(int width, int height, const std::string& title) { + void Init(int width = 800, int height = 450, const std::string& title = "raylib") { ::InitWindow(width, height, title.c_str()); } @@ -234,6 +234,13 @@ class Window { return *this; } + /** + * Get the screen's width and height. + */ + inline ::Vector2 GetSize() { + return {static_cast(GetWidth()), static_cast(GetHeight())}; + } + /** * Get native window handle */ @@ -260,28 +267,28 @@ class Window { /** * Get current screen width */ - inline int GetScreenWidth() const { + inline int GetWidth() const { return ::GetScreenWidth(); } /** * Get current screen height */ - inline int GetScreenHeight() const { + inline int GetHeight() const { return ::GetScreenHeight(); } /** * Get window position XY on monitor */ - inline Vector2 GetPosition() const { + inline ::Vector2 GetPosition() const { return ::GetWindowPosition(); } /** * Get window scale DPI factor */ - inline Vector2 GetScaleDPI() const { + inline ::Vector2 GetScaleDPI() const { return ::GetWindowScaleDPI(); }