From 95d52073805397be285e2b4ca0d5760b6f663199 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 20 Aug 2022 16:01:59 -0400 Subject: [PATCH] Update to raylib 4.2 --- clib.json | 1 + include/AudioDevice.hpp | 13 ++-- include/AudioStream.hpp | 49 ++++++++++++--- include/BoundingBox.hpp | 12 +--- include/CMakeLists.txt | 1 + include/Camera2D.hpp | 1 + include/Camera3D.hpp | 4 +- include/Color.hpp | 15 +++-- include/Font.hpp | 70 ++++++++++++++------- include/Gamepad.hpp | 5 ++ include/Image.hpp | 117 +++++++++++++++++++++--------------- include/Material.hpp | 5 ++ include/Matrix.hpp | 11 +++- include/Mesh.hpp | 59 ++++++++++++------ include/Model.hpp | 31 ++++++---- include/ModelAnimation.hpp | 7 ++- include/Mouse.hpp | 34 +++++++++++ include/Music.hpp | 60 ++++++++++-------- include/Physics.hpp | 1 + include/Ray.hpp | 41 ++++++++----- include/RayCollision.hpp | 1 + include/RaylibException.hpp | 1 + include/Rectangle.hpp | 1 + include/RenderTexture.hpp | 1 + include/Shader.hpp | 7 +++ include/Sound.hpp | 47 ++++++++++----- include/Text.hpp | 1 + include/Texture.hpp | 68 +++++++++++++++------ include/Touch.hpp | 51 ++++++++++++++++ include/Vector2.hpp | 24 +++++--- include/Vector3.hpp | 1 + include/Vector4.hpp | 1 + include/VrStereoConfig.hpp | 31 +++++----- include/Wave.hpp | 47 ++++++++------- include/Window.hpp | 53 ++++++++++++++-- include/raylib-cpp.hpp | 1 + 36 files changed, 620 insertions(+), 253 deletions(-) create mode 100644 include/Touch.hpp diff --git a/clib.json b/clib.json index f61d4ca..7c23867 100644 --- a/clib.json +++ b/clib.json @@ -53,6 +53,7 @@ "include/Sound.hpp", "include/Text.hpp", "include/Texture.hpp", + "include/Touch.hpp", "include/Vector2.hpp", "include/Vector3.hpp", "include/Vector4.hpp", diff --git a/include/AudioDevice.hpp b/include/AudioDevice.hpp index eec3edb..f8eb1fe 100644 --- a/include/AudioDevice.hpp +++ b/include/AudioDevice.hpp @@ -20,9 +20,7 @@ class AudioDevice { */ AudioDevice(bool lateInit = false) { if (!lateInit) { - if (!Init()) { - throw RaylibException("Failed to initialize AudioDevice"); - } + Init(); } } @@ -35,10 +33,14 @@ class AudioDevice { /** * Initialize audio device and context. + * + * @throws raylib::RaylibException Throws if the AudioDevice failed to initialize. */ - inline bool Init() { + inline void Init() { ::InitAudioDevice(); - return IsReady(); + if (!IsReady()) { + throw RaylibException("Failed to initialize AudioDevice"); + } } /** @@ -66,6 +68,7 @@ class AudioDevice { } }; } // namespace raylib + using RAudioDevice = raylib::AudioDevice; #endif // RAYLIB_CPP_INCLUDE_AUDIODEVICE_HPP_ diff --git a/include/AudioStream.hpp b/include/AudioStream.hpp index 5846e84..4a47d4f 100644 --- a/include/AudioStream.hpp +++ b/include/AudioStream.hpp @@ -28,10 +28,8 @@ class AudioStream : public ::AudioStream { * * @throws raylib::RaylibException Throws if the AudioStream failed to load. */ - AudioStream(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels = 2) { - if (!Load(SampleRate, SampleSize, Channels)) { - throw RaylibException("Failed to create AudioStream"); - } + AudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels = 2) { + Load(sampleRate, sampleSize, channels); } AudioStream(const AudioStream&) = delete; @@ -144,7 +142,7 @@ class AudioStream : public ::AudioStream { /** * Set volume for audio stream (1.0 is max level) */ - inline AudioStream& SetVolume(float volume) { + inline AudioStream& SetVolume(float volume = 1.0f) { ::SetAudioStreamVolume(*this, volume); return *this; } @@ -157,6 +155,14 @@ class AudioStream : public ::AudioStream { return *this; } + /** + * Set pan for audio stream (0.5 is centered) + */ + inline AudioStream& SetPan(float pan = 0.5f) { + ::SetAudioStreamPitch(*this, pan); + return *this; + } + /** * Default size for new audio streams */ @@ -164,6 +170,27 @@ class AudioStream : public ::AudioStream { ::SetAudioStreamBufferSizeDefault(size); } + /** + * Audio thread callback to request new data + */ + inline void SetCallback(::AudioCallback callback) { + ::SetAudioStreamCallback(*this, callback); + } + + /** + * Attach audio stream processor to stream + */ + inline void AttachProcessor(::AudioCallback processor) { + ::SetAudioStreamCallback(*this, processor); + } + + /** + * Detach audio stream processor from stream + */ + inline void DetachProcessor(::AudioCallback processor) { + ::SetAudioStreamCallback(*this, processor); + } + /** * Retrieve whether or not the audio stream is ready. */ @@ -172,13 +199,16 @@ class AudioStream : public ::AudioStream { } /** - * Init audio stream (to stream raw audio pcm data) + * Load audio stream (to stream raw audio pcm data) * - * @return True or false depending on if the audio stream initialized properly. + * @throws raylib::RaylibException Throws if the AudioStream failed to load. */ - bool Load(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels = 2) { + void Load(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels = 2) { + Unload(); set(::LoadAudioStream(SampleRate, SampleSize, Channels)); - return IsReady(); + if (!IsReady()) { + throw RaylibException("Failed to load audio stream"); + } } private: @@ -191,6 +221,7 @@ class AudioStream : public ::AudioStream { } }; } // namespace raylib + using RAudioStream = raylib::AudioStream; #endif // RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_ diff --git a/include/BoundingBox.hpp b/include/BoundingBox.hpp index 2021443..ef56d18 100644 --- a/include/BoundingBox.hpp +++ b/include/BoundingBox.hpp @@ -10,13 +10,6 @@ namespace raylib { */ class BoundingBox : public ::BoundingBox { public: - /* - * Set the bounding box to default: min (0, 0, 0) and max (0, 0, 0). - */ - BoundingBox() : ::BoundingBox{::Vector3{0, 0, 0}, ::Vector3{ 0, 0, 0 }} { - // Nothing. - } - /* * Copy a bounding box from another bounding box. */ @@ -31,7 +24,7 @@ class BoundingBox : public ::BoundingBox { set(::GetMeshBoundingBox(mesh)); } - BoundingBox(::Vector3 minMax) : ::BoundingBox{minMax, minMax} {} + BoundingBox(::Vector3 minMax = ::Vector3{0.0f, 0.0f, 0.0f}) : ::BoundingBox{minMax, minMax} {} BoundingBox(::Vector3 min, ::Vector3 max) : ::BoundingBox{min, max} {} GETTERSETTER(::Vector3, Min, min) @@ -46,7 +39,7 @@ class BoundingBox : public ::BoundingBox { * Draw a bounding box with wires */ inline BoundingBox& Draw(::Color color = {255, 255, 255, 255}) { - DrawBoundingBox(*this, color); + ::DrawBoundingBox(*this, color); return *this; } @@ -89,6 +82,7 @@ class BoundingBox : public ::BoundingBox { } }; } // namespace raylib + using RBoundingBox = raylib::BoundingBox; #endif // RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_ diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index e0cf767..d520d5f 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -37,6 +37,7 @@ install(FILES Sound.hpp Text.hpp Texture.hpp + Touch.hpp Vector2.hpp Vector3.hpp Vector4.hpp diff --git a/include/Camera2D.hpp b/include/Camera2D.hpp index edcd0e9..64678d8 100644 --- a/include/Camera2D.hpp +++ b/include/Camera2D.hpp @@ -69,6 +69,7 @@ class Camera2D : public ::Camera2D { } }; } // namespace raylib + using RCamera2D = raylib::Camera2D; #endif // RAYLIB_CPP_INCLUDE_CAMERA2D_HPP_ diff --git a/include/Camera3D.hpp b/include/Camera3D.hpp index fd52f4e..26b71f6 100644 --- a/include/Camera3D.hpp +++ b/include/Camera3D.hpp @@ -60,7 +60,7 @@ class Camera3D : public ::Camera3D { } /** - * Get transform matrix for camera + * Get camera transform matrix (view matrix) */ inline Matrix GetMatrix() const { return ::GetCameraMatrix(*this); @@ -159,7 +159,9 @@ class Camera3D : public ::Camera3D { }; typedef Camera3D Camera; + } // namespace raylib + using RCamera = raylib::Camera; using RCamera3D = raylib::Camera3D; diff --git a/include/Color.hpp b/include/Color.hpp index b8e6509..02fd6e2 100644 --- a/include/Color.hpp +++ b/include/Color.hpp @@ -49,11 +49,8 @@ class Color : public ::Color { set(::GetColor(hexValue)); } - /** - * Returns Color from normalized values [0..1] - */ - Color(::Vector4 normalized) { - set(::ColorFromNormalized(normalized)); + Color(void *srcPtr, int format) { + set(::GetPixelColor(srcPtr, format)); } /** @@ -84,6 +81,13 @@ class Color : public ::Color { return ::ColorNormalize(*this); } + /** + * Returns Color from normalized values [0..1] + */ + Color(::Vector4 normalized) { + set(::ColorFromNormalized(normalized)); + } + /** * Returns HSV values for a Color */ @@ -254,6 +258,7 @@ class Color : public ::Color { }; } // namespace raylib + using RColor = raylib::Color; #endif // RAYLIB_CPP_INCLUDE_COLOR_HPP_ diff --git a/include/Font.hpp b/include/Font.hpp index 87a5dd1..5a1810b 100644 --- a/include/Font.hpp +++ b/include/Font.hpp @@ -22,6 +22,9 @@ class Font : public ::Font { // Nothing. } + /** + * Retrieves the default Font. + */ Font() { set(::GetFontDefault()); } @@ -38,9 +41,7 @@ class Font : public ::Font { * @throws raylib::RaylibException Throws if the given font failed to initialize. */ Font(const std::string& fileName) { - if (!Load(fileName)) { - throw RaylibException("Failed to load Font from file"); - } + Load(fileName); } /** @@ -53,9 +54,7 @@ class Font : public ::Font { * @see ::LoadFontEx */ Font(const std::string& fileName, int fontSize, int* fontChars = 0, int charCount = 0) { - if (!Load(fileName, fontSize, fontChars, charCount)) { - throw RaylibException("Failed to load font from font with extras"); - } + Load(fileName, fontSize, fontChars, charCount); } /** @@ -68,9 +67,7 @@ class Font : public ::Font { * @see ::LoadFontFromImage() */ Font(const ::Image& image, ::Color key, int firstChar) { - if (!Load(image, key, firstChar)) { - throw RaylibException("Failed to load Texture from Image"); - } + Load(image, key, firstChar); } /** @@ -82,9 +79,7 @@ class Font : public ::Font { */ Font(const std::string& fileType, const unsigned char* fileData, int dataSize, int fontSize, int *fontChars, int charsCount) { - if (!Load(fileType, fileData, dataSize, fontSize, fontChars, charsCount)) { - throw RaylibException("Failed to load Texture from file data"); - } + Load(fileType, fileData, dataSize, fontSize, fontChars, charsCount); } Font(const Font&) = delete; @@ -146,13 +141,15 @@ class Font : public ::Font { * * @param fileName The filename of the font to load. * - * @return True of false depending on if the font loaded successfully. + * @throws raylib::RaylibException Throws if the given font failed to initialize. * * @see ::LoadFont() */ - bool Load(const std::string& fileName) { + void Load(const std::string& fileName) { set(::LoadFont(fileName.c_str())); - return baseSize > 0; + if (!IsReady()) { + throw new RaylibException("Failed to load Font with from file: " + fileName); + } } /** @@ -161,24 +158,37 @@ class Font : public ::Font { * @param fileName The filename of the font to load. * @param fontSize The desired size of the font. * - * @return True of false depending on if the font loaded successfully. + * @throws raylib::RaylibException Throws if the given font failed to initialize. * * @see ::LoadFontEx() */ - bool Load(const std::string& fileName, int fontSize, int* fontChars, int charCount) { + void Load(const std::string& fileName, int fontSize, int* fontChars, int charCount) { set(::LoadFontEx(fileName.c_str(), fontSize, fontChars, charCount)); - return baseSize > 0; + if (!IsReady()) { + throw new RaylibException("Failed to load Font with from file with font size: " + fileName); + } } - bool Load(const ::Image& image, ::Color key, int firstChar) { + void Load(const ::Image& image, ::Color key, int firstChar) { set(::LoadFontFromImage(image, key, firstChar)); - return baseSize > 0; + if (!IsReady()) { + throw new RaylibException("Failed to load Font with from image"); + } } - bool Load(const std::string& fileType, const unsigned char* fileData, int dataSize, int fontSize, + void Load(const std::string& fileType, const unsigned char* fileData, int dataSize, int fontSize, int *fontChars, int charsCount) { set(::LoadFontFromMemory(fileType.c_str(), fileData, dataSize, fontSize, fontChars, charsCount)); + if (!IsReady()) { + throw new RaylibException("Failed to load Font " + fileType + " with from file data"); + } + } + + /** + * Returns if the font is ready to be used. + */ + bool IsReady() { return baseSize > 0; } @@ -191,6 +201,15 @@ class Font : public ::Font { return *this; } + /** + * Draw text using font and additional parameters. + */ + inline Font& DrawText(const std::string& text, int posX, int posY, float fontSize, + float spacing, ::Color tint = WHITE) { + ::DrawTextEx(*this, text.c_str(), {static_cast(posX), static_cast(posY)}, fontSize, spacing, tint); + return *this; + } + inline Font& DrawText( const std::string& text, ::Vector2 position, @@ -214,6 +233,14 @@ class Font : public ::Font { return *this; } + /** + * Draw multiple character (codepoint) + */ + inline Font& DrawText(const int *codepoints, int count, ::Vector2 position, float fontSize, float spacing, ::Color tint = { 255, 255, 255, 255 }) { + ::DrawTextCodepoints(*this, codepoints, count, position, fontSize, spacing, tint); + return *this; + } + /** * Measure string size for Font */ @@ -247,6 +274,7 @@ class Font : public ::Font { } }; } // namespace raylib + using RFont = raylib::Font; #endif // RAYLIB_CPP_INCLUDE_FONT_HPP_ diff --git a/include/Gamepad.hpp b/include/Gamepad.hpp index 5ac975f..b65e926 100644 --- a/include/Gamepad.hpp +++ b/include/Gamepad.hpp @@ -108,12 +108,17 @@ class Gamepad { return ::GetGamepadAxisMovement(number, axis); } + inline int SetMappings(const std::string& mappings) { + return SetGamepadMappings(mappings.c_str()); + } + private: inline void set(int gamepadNumber) { number = gamepadNumber; } }; } // namespace raylib + using RGamepad = raylib::Gamepad; #endif // RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_ diff --git a/include/Image.hpp b/include/Image.hpp index ab9770a..c68edf7 100644 --- a/include/Image.hpp +++ b/include/Image.hpp @@ -6,6 +6,7 @@ #include "./raylib.hpp" #include "./raylib-cpp-utils.hpp" #include "./RaylibException.hpp" +#include "./Color.hpp" namespace raylib { /** @@ -35,9 +36,7 @@ class Image : public ::Image { * @see Load() */ Image(const std::string& fileName) { - if (!Load(fileName)) { - throw RaylibException(TextFormat("Failed to load Image from file: %s", fileName.c_str())); - } + Load(fileName); } /** @@ -47,10 +46,8 @@ class Image : public ::Image { * * @see LoadRaw() */ - Image(const std::string& fileName, int width, int height, int format, int headerSize) { - if (!Load(fileName, width, height, format, headerSize)) { - throw RaylibException(TextFormat("Failed to load Image from file: %s", fileName.c_str())); - } + Image(const std::string& fileName, int width, int height, int format, int headerSize = 0) { + Load(fileName, width, height, format, headerSize); } /** @@ -61,9 +58,7 @@ class Image : public ::Image { * @see LoadAnim() */ Image(const std::string& fileName, int* frames) { - if (!Load(fileName, frames)) { - throw RaylibException(TextFormat("Failed to load Image from animation: %s", fileName.c_str())); - } + Load(fileName, frames); } /** @@ -72,9 +67,7 @@ class Image : public ::Image { * @throws raylib::RaylibException Thrown if the image failed to load from the file. */ Image(const std::string& fileType, const unsigned char* fileData, int dataSize) { - if (!Load(fileType, fileData, dataSize)) { - throw RaylibException("Failed to load Image from memory"); - } + Load(fileType, fileData, dataSize); } /** @@ -83,9 +76,7 @@ class Image : public ::Image { * @throws raylib::RaylibException Thrown if the image failed to load from the file. */ Image(const ::Texture2D& texture) { - if (!Load(texture)) { - throw RaylibException("Failed to load Image from Texture"); - } + Load(texture); } Image(int width, int height, ::Color color = {255, 255, 255, 255}) { @@ -223,64 +214,74 @@ class Image : public ::Image { /** * Load image from file into CPU memory (RAM) * - * @return Whether or not the image was loaded successfully. + * @throws raylib::RaylibException Thrown if the image failed to load from the file. * * @see ::LoadImage() */ - bool Load(const std::string& fileName) { + void Load(const std::string& fileName) { set(::LoadImage(fileName.c_str())); - return IsReady(); + if (!IsReady()) { + throw RaylibException("Failed to load Image from file: " + fileName); + } } /** * Load image from RAW file data. * - * @return Whether or not the raw image data was loaded successfully. + * @throws raylib::RaylibException Thrown if the image failed to load from the file. * * @see ::LoadImageRaw() */ - bool Load(const std::string& fileName, int width, int height, int format, int headerSize) { + void Load(const std::string& fileName, int width, int height, int format, int headerSize) { set(::LoadImageRaw(fileName.c_str(), width, height, format, headerSize)); - return IsReady(); + if (!IsReady()) { + throw RaylibException("Failed to load Image from file: " + fileName); + } } /** * Load image sequence from file (frames appended to image.data). * - * @return Whether or not the image animation was loaded successfully. + * @throws raylib::RaylibException Thrown if the image animation to load from the file. * * @see ::LoadImageAnim() */ - bool Load(const std::string& fileName, int* frames) { + void Load(const std::string& fileName, int* frames) { set(::LoadImageAnim(fileName.c_str(), frames)); - return IsReady(); + if (!IsReady()) { + throw RaylibException("Failed to load Image from file: " + fileName); + } } /** * Load image from memory buffer, fileType refers to extension: i.e. "png". * - * @return Whether or not the image data was loaded successfully. + * @throws raylib::RaylibException Thrown if the image animation to load from the file. * * @see ::LoadImageFromMemory() */ - bool Load( + void Load( const std::string& fileType, const unsigned char *fileData, int dataSize) { set(::LoadImageFromMemory(fileType.c_str(), fileData, dataSize)); - return IsReady(); + if (!IsReady()) { + throw RaylibException("Failed to load Image data with file type: " + fileType); + } } /** * Load an image from the given file. * - * @return True or false depending on whether or not the image was loaded from the texture. + * @throws raylib::RaylibException Thrown if the image animation to load from the file. * * @see ::LoadImageFromTexture() */ - bool Load(const ::Texture2D& texture) { + void Load(const ::Texture2D& texture) { set(::LoadImageFromTexture(texture)); - return IsReady(); + if (!IsReady()) { + throw RaylibException("Failed to load Image from texture."); + } } /** @@ -295,17 +296,24 @@ class Image : public ::Image { /** * Export image data to file, returns true on success + * + * @throws raylib::RaylibException Thrown if the image failed to load from the file. */ - inline bool Export(const std::string& fileName) const { - // TODO(RobLoach): Switch to an invalid loading exception on false. - return ::ExportImage(*this, fileName.c_str()); + inline void Export(const std::string& fileName) const { + if (!::ExportImage(*this, fileName.c_str())) { + throw RaylibException(TextFormat("Failed to export Image to file: %s", fileName.c_str())); + } } /** * Export image as code file defining an array of bytes, returns true on success + * + * @throws raylib::RaylibException Thrown if the image failed to load from the file. */ - inline bool ExportAsCode(const std::string& fileName) const { - return ::ExportImageAsCode(*this, fileName.c_str()); + inline void ExportAsCode(const std::string& fileName) const { + if (!::ExportImageAsCode(*this, fileName.c_str())) { + throw RaylibException(TextFormat("Failed to export Image code to file: %s", fileName.c_str())); + } } GETTERSETTER(void*, Data, data) @@ -335,6 +343,14 @@ class Image : public ::Image { return ::ImageFromImage(*this, rec); } + /** + * Convert image data to desired format + */ + inline Image& Format(int newFormat) { + ::ImageFormat(this, newFormat); + return *this; + } + /** * Convert image to POT (power-of-two) */ @@ -344,10 +360,10 @@ class Image : public ::Image { } /** - * Convert image data to desired format + * Crop an image to area defined by a rectangle */ - inline Image& Format(int newFormat) { - ::ImageFormat(this, newFormat); + inline Image& Crop(::Rectangle crop) { + ::ImageCrop(this, crop); return *this; } @@ -383,14 +399,6 @@ class Image : public ::Image { return *this; } - /** - * Crop an image to area defined by a rectangle - */ - inline Image& Crop(::Rectangle crop) { - ::ImageCrop(this, crop); - return *this; - } - /** * Crop an image to a new given width and height. */ @@ -553,6 +561,20 @@ class Image : public ::Image { return ::GetImageAlphaBorder(*this, threshold); } + /** + * Get image pixel color at (x, y) position + */ + inline raylib::Color GetColor(int x = 0, int y = 0) const { + return ::GetImageColor(*this, x, y); + } + + /** + * Get image pixel color at vector position + */ + inline raylib::Color GetColor(::Vector2 position) const { + return ::GetImageColor(*this, static_cast(position.x), static_cast(position.y)); + } + /** * Clear image background with given color */ @@ -728,6 +750,7 @@ class Image : public ::Image { } }; } // namespace raylib + using RImage = raylib::Image; #endif // RAYLIB_CPP_INCLUDE_IMAGE_HPP_ diff --git a/include/Material.hpp b/include/Material.hpp index dc1b6b6..e0a8cc8 100644 --- a/include/Material.hpp +++ b/include/Material.hpp @@ -31,6 +31,10 @@ class Material : public ::Material { other.maps = nullptr; other.shader = {}; + other.params[0] = 0.0f; + other.params[1] = 0.0f; + other.params[2] = 0.0f; + other.params[3] = 0.0f; } ~Material() { @@ -118,6 +122,7 @@ class Material : public ::Material { } }; } // namespace raylib + using RMaterial = raylib::Material; #endif // RAYLIB_CPP_INCLUDE_MATERIAL_HPP_ diff --git a/include/Matrix.hpp b/include/Matrix.hpp index ed73d8e..6767b87 100644 --- a/include/Matrix.hpp +++ b/include/Matrix.hpp @@ -179,11 +179,19 @@ class Matrix : public ::Matrix { /** * Set shader uniform value (matrix 4x4) */ - inline Matrix& SetShaderValue(::Shader shader, int uniformLoc) { + inline Matrix& SetShaderValue(const ::Shader& shader, int uniformLoc) { ::SetShaderValueMatrix(shader, uniformLoc, *this); return *this; } + inline static Matrix GetCamera(const ::Camera& camera) { + return ::GetCameraMatrix(camera); + } + + inline static Matrix GetCamera(const ::Camera2D& camera) { + return ::GetCameraMatrix2D(camera); + } + #endif private: @@ -207,6 +215,7 @@ class Matrix : public ::Matrix { } }; } // namespace raylib + using RMatrix = raylib::Matrix; #endif // RAYLIB_CPP_INCLUDE_MATRIX_HPP_ diff --git a/include/Mesh.hpp b/include/Mesh.hpp index bdf2520..b077382 100644 --- a/include/Mesh.hpp +++ b/include/Mesh.hpp @@ -19,22 +19,36 @@ class Mesh : public ::Mesh { set(mesh); } - Mesh(int vertexCount, int triangleCount) : ::Mesh{ + Mesh(int vertexCount = 0, + int triangleCount = 0, + float *vertices = nullptr, + float *texcoords = nullptr, + float *texcoords2 = nullptr, + float *normals = nullptr, + float *tangents = nullptr, + unsigned char *colors = nullptr, + unsigned short *indices = nullptr, + float *animVertices = nullptr, + float *animNormals = nullptr, + unsigned char *boneIds = nullptr, + float *boneWeights = nullptr, + unsigned int vaoId = 0, + unsigned int *vboId = nullptr) : ::Mesh{ vertexCount, triangleCount, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - 0, - nullptr + vertices, + texcoords, + texcoords2, + normals, + tangents, + colors, + indices, + animVertices, + animNormals, + boneIds, + boneWeights, + vaoId, + vboId } {} /** @@ -110,6 +124,13 @@ class Mesh : public ::Mesh { return ::GenMeshCylinder(radius, height, slices); } + /** + * Generate cone/pyramid mesh + */ + static ::Mesh Cone(float radius, float height, int slices) { + return ::GenMeshCone(radius, height, slices); + } + /** * Generate torus mesh */ @@ -222,10 +243,13 @@ class Mesh : public ::Mesh { /** * Export mesh data to file + * + * @throws raylib::RaylibException Throws if failed to export the Mesh. */ - inline bool Export(const std::string& fileName) { - // TODO(RobLoach): Switch to an exception when failed. - return ExportMesh(*this, fileName.c_str()); + inline void Export(const std::string& fileName) { + if (!::ExportMesh(*this, fileName.c_str())) { + throw new RaylibException("Failed to export the Mesh"); + } } /** @@ -294,6 +318,7 @@ class Mesh : public ::Mesh { } }; } // namespace raylib + using RMesh = raylib::Mesh; #endif // RAYLIB_CPP_INCLUDE_MESH_HPP_ diff --git a/include/Model.hpp b/include/Model.hpp index 6889b1a..45b0823 100644 --- a/include/Model.hpp +++ b/include/Model.hpp @@ -27,6 +27,8 @@ class Model : public ::Model { /* * Load a model from a file. + * + * @throws raylib::RaylibException Throws if failed to load the Modal. */ Model(const std::string& fileName) { Load(fileName); @@ -34,6 +36,8 @@ class Model : public ::Model { /* * Load a model from a mesh. + * + * @throws raylib::RaylibException Throws if failed to load the Modal. */ Model(const ::Mesh& mesh) { Load(mesh); @@ -48,12 +52,13 @@ class Model : public ::Model { Model(Model&& other) { set(other); - other.materials = nullptr; + other.meshCount = 0; other.materialCount = 0; other.meshes = nullptr; - other.meshCount = 0; - other.bones = nullptr; + other.materials = nullptr; + other.meshMaterial = nullptr; other.boneCount = 0; + other.bones = nullptr; other.bindPose = nullptr; } @@ -82,12 +87,13 @@ class Model : public ::Model { Unload(); set(other); - other.bones = nullptr; - other.boneCount = 0; - other.materials = nullptr; + other.meshCount = 0; other.materialCount = 0; other.meshes = nullptr; - other.meshCount = 0; + other.materials = nullptr; + other.meshMaterial = nullptr; + other.boneCount = 0; + other.bones = nullptr; other.bindPose = nullptr; return *this; @@ -205,27 +211,25 @@ class Model : public ::Model { /** * Loads a Model from the given file. * - * @return True of false depending on whether or not the model was successfully loaded. + * @throws raylib::RaylibException Throws if failed to load the Modal. */ - bool Load(const std::string& fileName) { + void Load(const std::string& fileName) { set(::LoadModel(fileName.c_str())); if (!IsReady()) { throw RaylibException("Failed to load Model from " + fileName); } - return IsReady(); } /** * Loads a Model from the given Mesh. * - * @return True of false depending on whether or not the model was successfully loaded. + * @throws raylib::RaylibException Throws if failed to load the Modal. */ - bool Load(const ::Mesh& mesh) { + void Load(const ::Mesh& mesh) { set(::LoadModelFromMesh(mesh)); if (!IsReady()) { throw RaylibException("Failed to load Model from Mesh"); } - return IsReady(); } private: @@ -245,6 +249,7 @@ class Model : public ::Model { }; } // namespace raylib + using RModel = raylib::Model; #endif // RAYLIB_CPP_INCLUDE_MODEL_HPP_ diff --git a/include/ModelAnimation.hpp b/include/ModelAnimation.hpp index 7b57a9d..a3a4555 100644 --- a/include/ModelAnimation.hpp +++ b/include/ModelAnimation.hpp @@ -24,8 +24,8 @@ class ModelAnimation : public ::ModelAnimation { set(other); other.boneCount = 0; - other.bones = nullptr; other.frameCount = 0; + other.bones = nullptr; other.framePoses = nullptr; } @@ -67,8 +67,8 @@ class ModelAnimation : public ::ModelAnimation { set(other); other.boneCount = 0; - other.bones = nullptr; other.frameCount = 0; + other.bones = nullptr; other.framePoses = nullptr; return *this; @@ -99,12 +99,13 @@ class ModelAnimation : public ::ModelAnimation { private: void set(const ::ModelAnimation& model) { boneCount = model.boneCount; - bones = model.bones; frameCount = model.frameCount; + bones = model.bones; framePoses = model.framePoses; } }; } // namespace raylib + using RModelAnimation = raylib::ModelAnimation; #endif // RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_ diff --git a/include/Mouse.hpp b/include/Mouse.hpp index fbd2779..c0708bb 100644 --- a/include/Mouse.hpp +++ b/include/Mouse.hpp @@ -63,6 +63,13 @@ class Mouse { ::SetMousePosition(static_cast(position.x), static_cast(position.y)); } + /** + * Get mouse delta between frames + */ + static inline Vector2 GetDelta() { + return ::GetMouseDelta(); + } + static inline void SetOffset(int offsetX = 0, int offsetY = 0) { ::SetMouseOffset(offsetX, offsetY); } @@ -79,10 +86,22 @@ class Mouse { ::SetMouseScale(scale.x, scale.y); } + /** + * Get mouse wheel movement for X or Y, whichever is larger + */ static inline float GetWheelMove() { return ::GetMouseWheelMove(); } + /** + * Get mouse wheel movement for both X and Y + * + * @see ::GetMouseWheelMoveV() + */ + static inline Vector2 GetWheelMoveV() { + return GetMouseWheelMoveV(); + } + /** * Sets the current mouse cursor icon. * @@ -112,8 +131,23 @@ class Mouse { static inline Vector2 GetTouchPosition(int index) { return ::GetTouchPosition(index); } + + /** + * Get a ray trace from mouse position + */ + static inline Ray GetRay(::Vector2 mousePosition, const ::Camera& camera) { + return ::GetMouseRay(mousePosition, camera); + } + + /** + * Get a ray trace from mouse position + */ + static inline Ray GetRay(const ::Camera& camera) { + return ::GetMouseRay(::GetMousePosition(), camera); + } }; } // namespace raylib + using RMouse = raylib::Mouse; #endif // RAYLIB_CPP_INCLUDE_MOUSE_HPP_ diff --git a/include/Music.hpp b/include/Music.hpp index e7e630d..c528a9f 100644 --- a/include/Music.hpp +++ b/include/Music.hpp @@ -13,16 +13,11 @@ namespace raylib { */ class Music : public ::Music { public: - /** - * Default Music constructor to build an empty Music object. - */ - Music() { - ctxType = 0; - ctxData = nullptr; - looping = false; - frameCount = 0; - stream.buffer = nullptr; - } + Music(::AudioStream stream = {nullptr, nullptr, 0, 0, 0}, + unsigned int frameCount = 0, + bool looping = false, + int ctxType = 0, + void *ctxData = nullptr) : ::Music{stream, frameCount, looping, ctxType, ctxData} {} Music(const ::Music& music) { set(music); @@ -34,9 +29,7 @@ class Music : public ::Music { * @throws raylib::RaylibException Throws if the music failed to load. */ Music(const std::string& fileName) { - if (!Load(fileName)) { - throw RaylibException(TextFormat("Failed to load Music from file: %s", fileName.c_str())); - } + Load(fileName); } /** @@ -45,9 +38,7 @@ class Music : public ::Music { * @throws raylib::RaylibException Throws if the music failed to load. */ Music(const std::string& fileType, unsigned char* data, int dataSize) { - if (!Load(fileType, data, dataSize)) { - throw RaylibException(TextFormat("Failed to load Music from %s file", fileType.c_str())); - } + Load(fileType, data, dataSize); } Music(const Music&) = delete; @@ -55,11 +46,11 @@ class Music : public ::Music { Music(Music&& other) { set(other); + other.stream = {}; + other.frameCount = 0; + other.looping = false; other.ctxType = 0; other.ctxData = nullptr; - other.looping = false; - other.frameCount = 0; - other.stream = {}; } /** @@ -177,6 +168,14 @@ class Music : public ::Music { return *this; } + /** + * Set pan for a music (0.5 is center) + */ + inline Music& SetPan(float pan = 0.5f) { + ::SetMusicPan(*this, pan); + return *this; + } + /** * Get music time length (in seconds) */ @@ -193,18 +192,26 @@ class Music : public ::Music { /** * Load music stream from file + * + * @throws raylib::RaylibException Throws if the music failed to load. */ - bool Load(const std::string& fileName) { + void Load(const std::string& fileName) { set(::LoadMusicStream(fileName.c_str())); - return IsReady(); + if (!IsReady()) { + throw RaylibException(TextFormat("Failed to load Music from file: %s", fileName.c_str())); + } } /** * Load music stream from memory + * + * @throws raylib::RaylibException Throws if the music failed to load. */ - bool Load(const std::string& fileType, unsigned char* data, int dataSize) { + void Load(const std::string& fileType, unsigned char* data, int dataSize) { set(::LoadMusicStreamFromMemory(fileType.c_str(), data, dataSize)); - return IsReady(); + if (!IsReady()) { + throw RaylibException(TextFormat("Failed to load Music from %s file dat", fileType.c_str())); + } } /** @@ -218,14 +225,15 @@ class Music : public ::Music { private: void set(const ::Music& music) { + stream = music.stream; + frameCount = music.frameCount; + looping = music.looping; ctxType = music.ctxType; ctxData = music.ctxData; - looping = music.looping; - frameCount = music.frameCount; - stream = music.stream; } }; } // namespace raylib + using RMusic = raylib::Music; #endif // RAYLIB_CPP_INCLUDE_MUSIC_HPP_ diff --git a/include/Physics.hpp b/include/Physics.hpp index 656ee34..2a660a1 100644 --- a/include/Physics.hpp +++ b/include/Physics.hpp @@ -125,6 +125,7 @@ class Physics { } }; } // namespace raylib + using RPhysics = raylib::Physics; #endif // RAYLIB_CPP_INCLUDE_PHYSICS_HPP_ diff --git a/include/Ray.hpp b/include/Ray.hpp index 23b5333..46911ae 100644 --- a/include/Ray.hpp +++ b/include/Ray.hpp @@ -15,11 +15,12 @@ class Ray : public ::Ray { set(ray); } - Ray(::Vector3 position, ::Vector3 direction = {0.0f, 0.0f, 0.0f}) : ::Ray{position, direction} { + Ray(::Vector3 position = {0.0f, 0.0f, 0.0f}, ::Vector3 direction = {0.0f, 0.0f, 0.0f}) : + ::Ray{position, direction} { // Nothing. } - Ray(::Vector2 mousePosition, ::Camera camera) { + Ray(::Vector2 mousePosition, const ::Camera& camera) { set(::GetMouseRay(mousePosition, camera)); } @@ -39,46 +40,53 @@ class Ray : public ::Ray { return *this; } - /** - * Detect collision between ray and sphere - */ - inline bool CheckCollisionSphere(::Vector3 center, float radius) const { - return GetRayCollisionSphere(*this, center, radius).hit; - } - /** * Get collision information between ray and sphere */ inline RayCollision GetCollision(::Vector3 center, float radius) const { - return GetRayCollisionSphere(*this, center, radius); + return ::GetRayCollisionSphere(*this, center, radius); } /** * Detect collision between ray and box */ - inline bool CheckCollision(const ::BoundingBox& box) const { - return GetRayCollisionBox(*this, box).hit; + inline RayCollision GetCollision(const ::BoundingBox& box) const { + return ::GetRayCollisionBox(*this, box); } /** * Get collision information between ray and mesh */ inline RayCollision GetCollision(const ::Mesh& mesh, const ::Matrix& transform) const { - return GetRayCollisionMesh(*this, mesh, transform); + return ::GetRayCollisionMesh(*this, mesh, transform); } /** * Get collision info between ray and triangle */ inline RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const { - return GetRayCollisionTriangle(*this, p1, p2, p3); + return ::GetRayCollisionTriangle(*this, p1, p2, p3); } /** * Get collision info between ray and quad */ - inline RayCollision GetCollision(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4) const { - return GetRayCollisionQuad(*this, p1, p2, p3, p4); + inline RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3, ::Vector3 p4) const { + return ::GetRayCollisionQuad(*this, p1, p2, p3, p4); + } + + /** + * Get a ray trace from mouse position + */ + inline static Ray GetMouse(::Vector2 mousePosition, const ::Camera& camera) { + return ::GetMouseRay(mousePosition, camera); + } + + /** + * Get a ray trace from mouse position + */ + inline static Ray GetMouse(const ::Camera& camera) { + return ::GetMouseRay(::GetMousePosition(), camera); } private: @@ -88,6 +96,7 @@ class Ray : public ::Ray { } }; } // namespace raylib + using RRay = raylib::Ray; #endif // RAYLIB_CPP_INCLUDE_RAY_HPP_ diff --git a/include/RayCollision.hpp b/include/RayCollision.hpp index cf037e6..9821d22 100644 --- a/include/RayCollision.hpp +++ b/include/RayCollision.hpp @@ -73,6 +73,7 @@ class RayCollision : public ::RayCollision { } }; } // namespace raylib + using RRayCollision = raylib::RayCollision; #endif // RAYLIB_CPP_INCLUDE_RAYCOLLISION_HPP_ diff --git a/include/RaylibException.hpp b/include/RaylibException.hpp index f116042..1adb5a7 100644 --- a/include/RaylibException.hpp +++ b/include/RaylibException.hpp @@ -32,6 +32,7 @@ class RaylibException : public std::runtime_error { }; } // namespace raylib + using RRaylibException = raylib::RaylibException; #endif // RAYLIB_CPP_INCLUDE_RAYLIBEXCEPTION_HPP_ diff --git a/include/Rectangle.hpp b/include/Rectangle.hpp index 490576b..80fb8a4 100644 --- a/include/Rectangle.hpp +++ b/include/Rectangle.hpp @@ -167,6 +167,7 @@ class Rectangle : public ::Rectangle { } }; } // namespace raylib + using RRectangle = raylib::Rectangle; #endif // RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_ diff --git a/include/RenderTexture.hpp b/include/RenderTexture.hpp index 4f17158..8d1fe11 100644 --- a/include/RenderTexture.hpp +++ b/include/RenderTexture.hpp @@ -114,6 +114,7 @@ class RenderTexture : public ::RenderTexture { }; typedef RenderTexture RenderTexture2D; } // namespace raylib + using RRenderTexture = raylib::RenderTexture; using RRenderTexture2D = raylib::RenderTexture2D; diff --git a/include/Shader.hpp b/include/Shader.hpp index 87d88c8..f2bb6d2 100644 --- a/include/Shader.hpp +++ b/include/Shader.hpp @@ -78,10 +78,16 @@ class Shader : public ::Shader { return *this; } + /** + * Unload shader from GPU memory (VRAM) + */ ~Shader() { Unload(); } + /** + * Unload shader from GPU memory (VRAM) + */ void Unload() { if (locs != nullptr) { ::UnloadShader(*this); @@ -176,6 +182,7 @@ class Shader : public ::Shader { } }; } // namespace raylib + using RShader = raylib::Shader; #endif // RAYLIB_CPP_INCLUDE_SHADER_HPP_ diff --git a/include/Sound.hpp b/include/Sound.hpp index 3515770..f01abed 100644 --- a/include/Sound.hpp +++ b/include/Sound.hpp @@ -22,8 +22,8 @@ class Sound : public ::Sound { Sound& operator=(const Sound&) = delete; Sound() { + stream = { nullptr, nullptr, 0, 0, 0 }; frameCount = 0; - stream.buffer = nullptr; } Sound(::AudioStream stream, unsigned int frameCount) : ::Sound{stream, frameCount} { @@ -33,7 +33,7 @@ class Sound : public ::Sound { Sound(Sound&& other) { set(other); - other.stream = { 0, 0, 0, 0, 0 }; + other.stream = { nullptr, nullptr, 0, 0, 0 }; other.frameCount = 0; } @@ -43,9 +43,7 @@ class Sound : public ::Sound { * @throws raylib::RaylibException Throws if the Sound failed to load. */ Sound(const std::string& fileName) { - if (!Load(fileName)) { - throw RaylibException(TextFormat("Failed to load Sound from file: %s", fileName.c_str())); - } + Load(fileName); } /** @@ -54,9 +52,7 @@ class Sound : public ::Sound { * @throws raylib::RaylibException Throws if the Sound failed to load. */ Sound(const ::Wave& wave) { - if (!Load(wave)) { - throw RaylibException("Failed to load Sound from Wave"); - } + Load(wave); } ~Sound() { @@ -74,7 +70,7 @@ class Sound : public ::Sound { Unload(); set(other); other.frameCount = 0; - other.stream = { 0, 0, 0, 0 }; + other.stream = { nullptr, nullptr, 0, 0, 0 }; return *this; } @@ -173,25 +169,38 @@ class Sound : public ::Sound { return *this; } + /** + * Set pan for a sound (0.5 is center) + */ + inline Sound& SetPan(float pan = 0.5f) { + ::SetSoundPan(*this, pan); + return *this; + } + /** * Load a sound from the given file. * - * @return True or false depending on loading worked. + * @throws raylib::RaylibException Throws if the Sound failed to load. */ - bool Load(const std::string& fileName) { + void Load(const std::string& fileName) { set(::LoadSound(fileName.c_str())); - return IsReady(); + if (!IsReady()) { + throw new RaylibException("Failed to load Sound from file"); + } } /** * Loads the given Wave object into the Sound. + * + * @throws raylib::RaylibException Throws if the Sound failed to load. */ - bool Load(const ::Wave& wave) { + void Load(const ::Wave& wave) { set(::LoadSoundFromWave(wave)); - return IsReady(); + if (!IsReady()) { + throw new RaylibException("Failed to load Wave"); + } } - /** * Retrieve whether or not the Sound buffer is loaded. * @@ -201,6 +210,13 @@ class Sound : public ::Sound { return stream.buffer != nullptr; } + /** + * Get number of sounds playing in the multichannel + */ + int GetPlaying() { + return ::GetSoundsPlaying(); + } + private: void set(const ::Sound& sound) { frameCount = sound.frameCount; @@ -208,6 +224,7 @@ class Sound : public ::Sound { } }; } // namespace raylib + using RSound = raylib::Sound; #endif // RAYLIB_CPP_INCLUDE_SOUND_HPP_ diff --git a/include/Text.hpp b/include/Text.hpp index 1090c8f..335d688 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -206,6 +206,7 @@ class Text { } }; } // namespace raylib + using RText = raylib::Text; #endif // RAYLIB_CPP_INCLUDE_TEXT_HPP_ diff --git a/include/Texture.hpp b/include/Texture.hpp index 383b854..ee9a7d0 100644 --- a/include/Texture.hpp +++ b/include/Texture.hpp @@ -25,8 +25,10 @@ class Texture : public ::Texture { /** * Move/Create a texture structure manually. */ - Texture(unsigned int id, int width, int height, - int mipmaps = 1, int format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8) + Texture(unsigned int id, + int width, int height, + int mipmaps = 1, + int format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8) : ::Texture{id, width, height, mipmaps, format} { // Nothing. } @@ -242,18 +244,6 @@ class Texture : public ::Texture { return *this; } - inline Texture& Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin = {0, 0}, - float rotation = 0, ::Color tint = {255, 255, 255, 255}) { - ::DrawTexturePro(*this, sourceRec, destRec, origin, rotation, tint); - return *this; - } - - inline Texture& Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin = {0, 0}, - float rotation = 0, ::Color tint = {255, 255, 255, 255}) { - ::DrawTextureNPatch(*this, nPatchInfo, destRec, origin, rotation, tint); - return *this; - } - inline Texture& Draw(::Vector3 position, float width, float height, float length, ::Color tint = {255, 255, 255, 255}) { ::DrawCubeTexture(*this, position, width, height, length, tint); @@ -266,13 +256,56 @@ class Texture : public ::Texture { return *this; } - inline Texture& DrawPoly(Vector2 center, Vector2 *points, - Vector2 *texcoords, int pointsCount, - Color tint = {255, 255, 255, 255}) { + inline Texture& Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin = {0, 0}, + float rotation = 0, ::Color tint = {255, 255, 255, 255}) { + ::DrawTexturePro(*this, sourceRec, destRec, origin, rotation, tint); + return *this; + } + + inline Texture& Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin = {0, 0}, + float rotation = 0, ::Color tint = {255, 255, 255, 255}) { + ::DrawTextureNPatch(*this, nPatchInfo, destRec, origin, rotation, tint); + return *this; + } + + inline Texture& DrawPoly(::Vector2 center, ::Vector2 *points, + ::Vector2 *texcoords, int pointsCount, + ::Color tint = {255, 255, 255, 255}) { ::DrawTexturePoly(*this, center, points, texcoords, pointsCount, tint); return *this; } + /** + * Draw a billboard texture + */ + inline Texture& DrawBillboard(const ::Camera& camera, + ::Vector3 position, float size, + ::Color tint = {255, 255, 255, 255}) { + ::DrawBillboard(camera, *this, position, size, tint); + return *this; + } + + /** + * Draw a billboard texture defined by source + */ + inline Texture& DrawBillboard(const ::Camera& camera, + ::Rectangle source, ::Vector3 position, ::Vector2 size, + ::Color tint = {255, 255, 255, 255}) { + DrawBillboardRec(camera, *this, source, position, size, tint); + return *this; + } + + /** + * Draw a billboard texture defined by source and rotation + */ + inline Texture& DrawBillboard(const ::Camera& camera, + ::Rectangle source, Vector3 position, + ::Vector3 up, Vector2 size, Vector2 origin, float rotation, + ::Color tint = {255, 255, 255, 255}) { + DrawBillboardPro(camera, *this, source, position, up, size, origin, rotation, tint); + return *this; + } + /** * Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...) */ @@ -326,6 +359,7 @@ typedef Texture Texture2D; typedef Texture TextureCubemap; } // namespace raylib + using RTexture = raylib::Texture; using RTexture2D = raylib::Texture2D; using RTextureCubemap = raylib::TextureCubemap; diff --git a/include/Touch.hpp b/include/Touch.hpp new file mode 100644 index 0000000..9a7a4ba --- /dev/null +++ b/include/Touch.hpp @@ -0,0 +1,51 @@ +#ifndef RAYLIB_CPP_INCLUDE_TOUCH_HPP_ +#define RAYLIB_CPP_INCLUDE_TOUCH_HPP_ + +#include "./raylib.hpp" + +namespace raylib { +/** + * Input-related functions: touch + */ +class Touch { + public: + /** + * Get touch position X for touch point 0 (relative to screen size) + */ + inline static int GetX() { + return ::GetTouchX(); + } + + /** + * Get touch position Y for touch point 0 (relative to screen size) + */ + inline static int GetY() { + return ::GetTouchY(); + } + + /** + * Get touch position XY for a touch point index (relative to screen size) + */ + inline static Vector2 GetPosition(int index) { + return ::GetTouchPosition(index); + } + + /** + * Get touch point identifier for given index + */ + inline static int GetPointId(int index) { + return ::GetTouchPointId(index); + } + + /** + * Get number of touch points + */ + inline static int GetPointCount() { + return ::GetTouchPointCount(); + } +}; +} // namespace raylib + +using RTouch = raylib::Touch; + +#endif // RAYLIB_CPP_INCLUDE_MOUSE_HPP_ diff --git a/include/Vector2.hpp b/include/Vector2.hpp index f28a31f..fe954ab 100644 --- a/include/Vector2.hpp +++ b/include/Vector2.hpp @@ -288,22 +288,22 @@ class Vector2 : public ::Vector2 { } #endif - inline Vector2& DrawPixel(::Color color) { + inline Vector2& DrawPixel(::Color color = {0, 0, 0, 255}) { ::DrawPixelV(*this, color); return *this; } - inline Vector2& DrawLine(::Vector2 endPos, ::Color color) { + inline Vector2& DrawLine(::Vector2 endPos, ::Color color = {0, 0, 0, 255}) { ::DrawLineV(*this, endPos, color); return *this; } - inline Vector2& DrawLine(::Vector2 endPos, float thick, ::Color color) { + inline Vector2& DrawLine(::Vector2 endPos, float thick, ::Color color = {0, 0, 0, 255}) { ::DrawLineEx(*this, endPos, thick, color); return *this; } - inline Vector2& DrawLineBezier(::Vector2 endPos, float thick, ::Color color) { + inline Vector2& DrawLineBezier(::Vector2 endPos, float thick, ::Color color = {0, 0, 0, 255}) { ::DrawLineBezier(*this, endPos, thick, color); return *this; } @@ -315,7 +315,7 @@ class Vector2 : public ::Vector2 { ::Vector2 endPos, ::Vector2 controlPos, float thick, - ::Color color) { + ::Color color = {0, 0, 0, 255}) { ::DrawLineBezierQuad(*this, endPos, controlPos, thick, color); return *this; } @@ -323,17 +323,17 @@ class Vector2 : public ::Vector2 { /** * Draw a color-filled circle (Vector version) */ - inline Vector2& DrawCircle(float radius, ::Color color) { + inline Vector2& DrawCircle(float radius, ::Color color = {0, 0, 0, 255}) { ::DrawCircleV(*this, radius, color); return *this; } - inline Vector2& DrawRectangle(::Vector2 size, ::Color color) { + inline Vector2& DrawRectangle(::Vector2 size, ::Color color = {0, 0, 0, 255}) { ::DrawRectangleV(*this, size, color); return *this; } - inline Vector2& DrawPoly(int sides, float radius, float rotation, ::Color color) { + inline Vector2& DrawPoly(int sides, float radius, float rotation, ::Color color = {0, 0, 0, 255}) { ::DrawPoly(*this, sides, radius, rotation, color); return *this; } @@ -383,6 +383,13 @@ class Vector2 : public ::Vector2 { return ::CheckCollisionLines(*this, endPos1, startPos2, endPos2, collisionPoint); } + /** + * Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold] + */ + inline bool CheckCollisionPointLine(::Vector2 p1, ::Vector2 p2, int threshold = 1) { + return ::CheckCollisionPointLine(*this, p1, p2, threshold); + } + private: void set(const ::Vector2& vec) { x = vec.x; @@ -391,6 +398,7 @@ class Vector2 : public ::Vector2 { }; } // namespace raylib + using RVector2 = raylib::Vector2; #endif // RAYLIB_CPP_INCLUDE_VECTOR2_HPP_ diff --git a/include/Vector3.hpp b/include/Vector3.hpp index 5e8b9d8..7ee3fd3 100644 --- a/include/Vector3.hpp +++ b/include/Vector3.hpp @@ -362,6 +362,7 @@ class Vector3 : public ::Vector3 { } }; } // namespace raylib + using RVector3 = raylib::Vector3; #endif // RAYLIB_CPP_INCLUDE_VECTOR3_HPP_ diff --git a/include/Vector4.hpp b/include/Vector4.hpp index 2fcb68f..57e3cb2 100644 --- a/include/Vector4.hpp +++ b/include/Vector4.hpp @@ -165,6 +165,7 @@ class Vector4 : public ::Vector4 { // Alias the Vector4 as Quaternion. typedef Vector4 Quaternion; } // namespace raylib + using RVector4 = raylib::Vector4; using RQuaternion = raylib::Quaternion; diff --git a/include/VrStereoConfig.hpp b/include/VrStereoConfig.hpp index e158675..e163d89 100644 --- a/include/VrStereoConfig.hpp +++ b/include/VrStereoConfig.hpp @@ -11,13 +11,13 @@ namespace raylib { class VrStereoConfig : public ::VrStereoConfig { public: VrStereoConfig(const ::VrDeviceInfo& info) { - Init(info); + Load(info); } /** * Load VR stereo config for VR simulator device parameters */ - inline void Init(const ::VrDeviceInfo& info) { + inline void Load(const ::VrDeviceInfo& info) { set(LoadVrStereoConfig(info)); } @@ -39,7 +39,7 @@ class VrStereoConfig : public ::VrStereoConfig { /** * End stereo rendering */ - inline VrStereoConfig& EndDrawing() { + inline VrStereoConfig& EndMode() { ::EndVrStereoMode(); return *this; } @@ -54,24 +54,25 @@ class VrStereoConfig : public ::VrStereoConfig { private: void set(const ::VrStereoConfig& config) { projection[0] = config.projection[0]; - viewOffset[1] = config.viewOffset[1]; - projection[0] = config.projection[0]; + projection[1] = config.projection[1]; + viewOffset[0] = config.viewOffset[0]; viewOffset[1] = config.viewOffset[1]; leftLensCenter[0] = config.leftLensCenter[0]; leftLensCenter[1] = config.leftLensCenter[1]; - rightLensCenter[0] = config.leftLensCenter[0]; - rightLensCenter[1] = config.leftLensCenter[1]; - leftScreenCenter[0] = config.leftLensCenter[0]; - leftScreenCenter[1] = config.leftLensCenter[1]; - rightScreenCenter[0] = config.leftLensCenter[0]; - rightScreenCenter[1] = config.leftLensCenter[1]; - scale[0] = config.leftLensCenter[0]; - scale[1] = config.leftLensCenter[1]; - scaleIn[0] = config.leftLensCenter[0]; - scaleIn[1] = config.leftLensCenter[1]; + rightLensCenter[0] = config.rightLensCenter[0]; + rightLensCenter[1] = config.rightLensCenter[1]; + leftScreenCenter[0] = config.leftScreenCenter[0]; + leftScreenCenter[1] = config.leftScreenCenter[1]; + rightScreenCenter[0] = config.rightScreenCenter[0]; + rightScreenCenter[1] = config.rightScreenCenter[1]; + scale[0] = config.scale[0]; + scale[1] = config.scale[1]; + scaleIn[0] = config.scaleIn[0]; + scaleIn[1] = config.scaleIn[1]; } }; } // namespace raylib + using RVrStereoConfig = raylib::VrStereoConfig; #endif // RAYLIB_CPP_INCLUDE_VRSTEREOCONFIG_HPP_ diff --git a/include/Wave.hpp b/include/Wave.hpp index be5d052..bd3e276 100644 --- a/include/Wave.hpp +++ b/include/Wave.hpp @@ -28,20 +28,20 @@ class Wave : public ::Wave { /** * Load wave data from file + * + * @throws raylib::RaylibException Throws if the Wave failed to load. */ Wave(const std::string& fileName) { - if (!Load(fileName)) { - throw RaylibException(TextFormat("Failed to load Wave from file: %s", fileName.c_str())); - } + Load(fileName); } /** * Load wave from memory buffer, fileType refers to extension: i.e. "wav" + * + * @throws raylib::RaylibException Throws if the Wave failed to load. */ Wave(const std::string& fileType, const unsigned char *fileData, int dataSize) { - if (!Load(fileType, fileData, dataSize)) { - throw RaylibException("Failed to load Wave from memory"); - } + Load(fileType, fileData, dataSize); } Wave(const Wave& other) { @@ -104,14 +104,6 @@ class Wave : public ::Wave { return *this; } - /** - * Convert wave data to desired format - */ - inline Wave& Format(int SampleRate, int SampleSize, int Channels = 2) { - ::WaveFormat(this, SampleRate, SampleSize, Channels); - return *this; - } - /** * Copy a wave to a new wave */ @@ -127,6 +119,14 @@ class Wave : public ::Wave { return *this; } + /** + * Convert wave data to desired format + */ + inline Wave& Format(int SampleRate, int SampleSize, int Channels = 2) { + ::WaveFormat(this, SampleRate, SampleSize, Channels); + return *this; + } + /** * Load samples data from wave as a floats array */ @@ -137,7 +137,7 @@ class Wave : public ::Wave { /** * Unload samples data loaded with LoadWaveSamples() */ - inline void UnloadSamples(float *samples) { + inline static void UnloadSamples(float *samples) { ::UnloadWaveSamples(samples); } @@ -184,21 +184,25 @@ class Wave : public ::Wave { /** * Load wave data from file. * - * @return True or false depending on if the Wave data was loaded properly. + * @throws raylib::RaylibException Throws if the Wave failed to load. */ - bool Load(const std::string& fileName) { + void Load(const std::string& fileName) { set(::LoadWave(fileName.c_str())); - return IsReady(); + if (!IsReady()) { + throw RaylibException("Failed to load Wave from file: " + fileName); + } } /** * Load wave from memory buffer, fileType refers to extension: i.e. "wav" * - * @return True or false depending on if the Wave data was loaded properly. + * @throws raylib::RaylibException Throws if the Wave failed to load. */ - bool Load(const std::string& fileType, const unsigned char *fileData, int dataSize) { + void Load(const std::string& fileType, const unsigned char *fileData, int dataSize) { set(::LoadWaveFromMemory(fileType.c_str(), fileData, dataSize)); - return IsReady(); + if (!IsReady()) { + throw RaylibException("Failed to load Wave from file data of type: " + fileType); + } } /** @@ -221,6 +225,7 @@ class Wave : public ::Wave { }; } // namespace raylib + using RWave = raylib::Wave; #endif // RAYLIB_CPP_INCLUDE_WAVE_HPP_ diff --git a/include/Window.hpp b/include/Window.hpp index fe2998a..7acf428 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -5,6 +5,7 @@ #include "./raylib.hpp" #include "./RaylibException.hpp" +#include "./Vector2.hpp" namespace raylib { /** @@ -12,14 +13,21 @@ namespace raylib { */ class Window { public: + /** + * Build a Window object, but defer the initialization. Ensure you call Init() manually. + * + * @see Init() + */ Window() { - // need to create it manually with Init(). + // Nothing. } /** * Initialize window and OpenGL context. + * + * @throws raylib::RaylibException Thrown if the window failed to initiate. */ - Window(int width, int height, const std::string& title) { + Window(int width, int height, const std::string& title = "raylib") { Init(width, height, title); } @@ -256,6 +264,14 @@ class Window { return *this; } + /** + * Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP) + */ + inline Window& SetOpacity(float opacity) { + ::SetWindowOpacity(opacity); + return *this; + } + /** * Set window dimensions */ @@ -307,20 +323,48 @@ class Window { return ::GetScreenHeight(); } + /** + * Get current render width (it considers HiDPI) + */ + inline int GetRenderWidth() const { + return ::GetRenderWidth(); + } + + /** + * Get current render height (it considers HiDPI) + */ + inline int GetRenderHeight() const { + return ::GetRenderHeight(); + } + /** * 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(); } + /** + * Set clipboard text content + */ + inline void SetClipboardText(const std::string& text) { + SetClipboardText(text.c_str()); + } + + /** + * Get clipboard text content + */ + inline const std::string& GetClipboardText() { + return GetClipboardText(); + } + /** * Set target FPS (maximum) */ @@ -359,6 +403,7 @@ class Window { } }; } // namespace raylib + using RWindow = raylib::Window; #endif // RAYLIB_CPP_INCLUDE_WINDOW_HPP_ diff --git a/include/raylib-cpp.hpp b/include/raylib-cpp.hpp index 74301f9..bb221c2 100644 --- a/include/raylib-cpp.hpp +++ b/include/raylib-cpp.hpp @@ -57,6 +57,7 @@ #include "./Sound.hpp" #include "./Text.hpp" #include "./Texture.hpp" +#include "./Touch.hpp" #include "./Vector2.hpp" #include "./Vector3.hpp" #include "./Vector4.hpp"