Updated raylib-cpp header files

This commit is contained in:
2025-09-08 22:06:21 -04:00
parent a0a658ca8a
commit fff611cc72
45 changed files with 2533 additions and 2382 deletions

View File

@@ -3,47 +3,43 @@
#include <string>
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./RaylibException.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Music stream type (audio file streaming from memory)
*/
class Music : public ::Music {
public:
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} {}
public:
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);
}
Music(const ::Music& music) : ::Music(music) { }
/**
* Load music stream from file
*
* @throws raylib::RaylibException Throws if the music failed to load.
*/
Music(const std::string& fileName) {
Load(fileName);
}
Music(const std::string& fileName) { Load(fileName); }
/**
* Load music stream from memory
*
* @throws raylib::RaylibException Throws if the music failed to load.
*/
Music(const std::string& fileType, unsigned char* data, int dataSize) {
Load(fileType, data, dataSize);
}
Music(const std::string& fileType, unsigned char* data, int dataSize) { Load(fileType, data, dataSize); }
Music(const Music&) = delete;
Music(Music&& other) {
Music(Music&& other) noexcept {
set(other);
other.stream = {};
@@ -56,15 +52,13 @@ class Music : public ::Music {
/**
* Unload music stream
*/
~Music() {
Unload();
}
~Music() { Unload(); }
GETTERSETTER(::AudioStream, Stream, stream)
GETTERSETTER(unsigned int, FrameCount, frameCount)
GETTER(::AudioStream, Stream, stream)
GETTER(unsigned int, FrameCount, frameCount)
GETTERSETTER(bool, Looping, looping)
GETTERSETTER(int, CtxType, ctxType)
GETTERSETTER(void*, CtxData, ctxData)
GETTER(int, CtxType, ctxType)
GETTER(void*, CtxData, ctxData)
Music& operator=(const ::Music& music) {
set(music);
@@ -93,14 +87,12 @@ class Music : public ::Music {
/**
* Unload music stream
*/
inline void Unload() {
::UnloadMusicStream(*this);
}
void Unload() { ::UnloadMusicStream(*this); }
/**
* Start music playing
*/
inline Music& Play() {
Music& Play() {
::PlayMusicStream(*this);
return *this;
}
@@ -108,7 +100,7 @@ class Music : public ::Music {
/**
* Updates buffers for music streaming
*/
inline Music& Update() {
Music& Update() {
::UpdateMusicStream(*this);
return *this;
}
@@ -116,7 +108,7 @@ class Music : public ::Music {
/**
* Stop music playing
*/
inline Music& Stop() {
Music& Stop() {
::StopMusicStream(*this);
return *this;
}
@@ -124,7 +116,7 @@ class Music : public ::Music {
/**
* Pause music playing
*/
inline Music& Pause() {
Music& Pause() {
::PauseMusicStream(*this);
return *this;
}
@@ -132,7 +124,7 @@ class Music : public ::Music {
/**
* Resume music playing
*/
inline Music& Resume() {
Music& Resume() {
::ResumeMusicStream(*this);
return *this;
}
@@ -140,7 +132,7 @@ class Music : public ::Music {
/**
* Seek music to a position (in seconds)
*/
inline Music& Seek(float position) {
Music& Seek(float position) {
SeekMusicStream(*this, position);
return *this;
}
@@ -148,14 +140,12 @@ class Music : public ::Music {
/**
* Check if music is playing
*/
inline bool IsPlaying() const {
return ::IsMusicStreamPlaying(*this);
}
[[nodiscard]] bool IsPlaying() const { return ::IsMusicStreamPlaying(*this); }
/**
* Set volume for music
*/
inline Music& SetVolume(float volume) {
Music& SetVolume(float volume) {
::SetMusicVolume(*this, volume);
return *this;
}
@@ -163,7 +153,7 @@ class Music : public ::Music {
/**
* Set pitch for music
*/
inline Music& SetPitch(float pitch) {
Music& SetPitch(float pitch) {
::SetMusicPitch(*this, pitch);
return *this;
}
@@ -171,7 +161,7 @@ class Music : public ::Music {
/**
* Set pan for a music (0.5 is center)
*/
inline Music& SetPan(float pan = 0.5f) {
Music& SetPan(float pan = 0.5f) {
::SetMusicPan(*this, pan);
return *this;
}
@@ -179,16 +169,12 @@ class Music : public ::Music {
/**
* Get music time length (in seconds)
*/
inline float GetTimeLength() const {
return ::GetMusicTimeLength(*this);
}
[[nodiscard]] float GetTimeLength() const { return ::GetMusicTimeLength(*this); }
/**
* Get current music time played (in seconds)
*/
inline float GetTimePlayed() const {
return ::GetMusicTimePlayed(*this);
}
[[nodiscard]] float GetTimePlayed() const { return ::GetMusicTimePlayed(*this); }
/**
* Load music stream from file
@@ -197,7 +183,7 @@ class Music : public ::Music {
*/
void Load(const std::string& fileName) {
set(::LoadMusicStream(fileName.c_str()));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException(TextFormat("Failed to load Music from file: %s", fileName.c_str()));
}
}
@@ -209,7 +195,7 @@ class Music : public ::Music {
*/
void Load(const std::string& fileType, unsigned char* data, int dataSize) {
set(::LoadMusicStreamFromMemory(fileType.c_str(), data, dataSize));
if (!IsReady()) {
if (!IsValid()) {
throw RaylibException(TextFormat("Failed to load Music from %s file dat", fileType.c_str()));
}
}
@@ -219,11 +205,8 @@ class Music : public ::Music {
*
* @return True or false depending on whether the Music has been loaded.
*/
inline bool IsReady() const {
return ::IsMusicReady(*this);
}
protected:
bool IsValid() const { return ::IsMusicValid(*this); }
protected:
void set(const ::Music& music) {
stream = music.stream;
frameCount = music.frameCount;
@@ -232,8 +215,8 @@ class Music : public ::Music {
ctxData = music.ctxData;
}
};
} // namespace raylib
} // namespace raylib
using RMusic = raylib::Music;
#endif // RAYLIB_CPP_INCLUDE_MUSIC_HPP_
#endif // RAYLIB_CPP_INCLUDE_MUSIC_HPP_