Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security and clarity improvements #341

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/AudioDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AudioDevice {
*
* @throws raylib::RaylibException Throws if the AudioDevice failed to initialize.
*/
AudioDevice(bool lateInit = false) {
explicit AudioDevice(bool lateInit = false) {
if (!lateInit) {
Init();
}
Expand All @@ -34,7 +34,7 @@ class AudioDevice {
*
* @throws raylib::RaylibException Throws if the AudioDevice failed to initialize.
*/
void Init() {
static void Init() {
::InitAudioDevice();
if (!IsReady()) {
throw RaylibException("Failed to initialize AudioDevice");
Expand All @@ -44,12 +44,12 @@ class AudioDevice {
/**
* Close the audio device and context.
*/
void Close() { ::CloseAudioDevice(); }
static void Close() { ::CloseAudioDevice(); }

/**
* Check if audio device has been initialized successfully.
*/
bool IsReady() const { return ::IsAudioDeviceReady(); }
static bool IsReady() { return ::IsAudioDeviceReady(); }

/**
* Set master volume (listener).
Expand Down
13 changes: 8 additions & 5 deletions include/AudioStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ namespace raylib {
*/
class AudioStream : public ::AudioStream {
public:
AudioStream(const ::AudioStream& music) { set(music); }
AudioStream(const ::AudioStream& music)
: ::AudioStream(music) {
// Nothing.
}

AudioStream(
rAudioBuffer* buffer = nullptr,
Expand All @@ -34,7 +37,7 @@ class AudioStream : public ::AudioStream {

AudioStream(const AudioStream&) = delete;

AudioStream(AudioStream&& other) {
AudioStream(AudioStream&& other) noexcept {
set(other);

other.buffer = nullptr;
Expand Down Expand Up @@ -96,7 +99,7 @@ class AudioStream : public ::AudioStream {
/**
* Check if any audio stream buffers requires refill
*/
bool IsProcessed() const { return ::IsAudioStreamProcessed(*this); }
[[nodiscard]] bool IsProcessed() const { return ::IsAudioStreamProcessed(*this); }

/**
* Play audio stream
Expand Down Expand Up @@ -125,7 +128,7 @@ class AudioStream : public ::AudioStream {
/**
* Check if audio stream is playing
*/
bool IsPlaying() const { return ::IsAudioStreamPlaying(*this); }
[[nodiscard]] bool IsPlaying() const { return ::IsAudioStreamPlaying(*this); }

/**
* Stop audio stream
Expand Down Expand Up @@ -182,7 +185,7 @@ class AudioStream : public ::AudioStream {
/**
* Retrieve whether or not the audio stream is ready.
*/
bool IsValid() const { return ::IsAudioStreamValid(*this); }
[[nodiscard]] bool IsValid() const { return ::IsAudioStreamValid(*this); }

/**
* Load audio stream (to stream raw audio pcm data)
Expand Down
7 changes: 5 additions & 2 deletions include/AutomationEventList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ namespace raylib {
*/
class AutomationEventList : public ::AutomationEventList {
public:
AutomationEventList(const ::AutomationEventList& automationEventList) { set(automationEventList); }
AutomationEventList(const ::AutomationEventList& automationEventList)
: ::AutomationEventList(automationEventList) {
// Nothing.
}

/**
* Load an empty automation events list.
Expand All @@ -27,7 +30,7 @@ class AutomationEventList : public ::AutomationEventList {

AutomationEventList(const AutomationEventList&) = delete;

AutomationEventList(AutomationEventList&& other) {
AutomationEventList(AutomationEventList&& other) noexcept {
set(other);

other.capacity = 0;
Expand Down
6 changes: 3 additions & 3 deletions include/BoundingBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ class BoundingBox : public ::BoundingBox {
/**
* Detect collision between two boxes
*/
bool CheckCollision(const ::BoundingBox& box2) const { return CheckCollisionBoxes(*this, box2); }
[[nodiscard]] bool CheckCollision(const ::BoundingBox& box2) const { return CheckCollisionBoxes(*this, box2); }

/**
* Detect collision between box and sphere
*/
bool CheckCollision(::Vector3 center, float radius) const { return CheckCollisionBoxSphere(*this, center, radius); }
[[nodiscard]] bool CheckCollision(::Vector3 center, float radius) const { return CheckCollisionBoxSphere(*this, center, radius); }

/**
* Detect collision between ray and bounding box
*/
bool CheckCollision(const ::Ray& ray) const { return GetRayCollisionBox(ray, *this).hit; }
[[nodiscard]] bool CheckCollision(const ::Ray& ray) const { return GetRayCollisionBox(ray, *this).hit; }

/**
* Get collision information between ray and bounding box
Expand Down
13 changes: 8 additions & 5 deletions include/Camera2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ namespace raylib {
*/
class Camera2D : public ::Camera2D {
public:
Camera2D(const ::Camera2D& camera) { set(camera); }
Camera2D(const ::Camera2D& camera)
: ::Camera2D(camera) {
// Nothing.
}

Camera2D() {}
Camera2D() : ::Camera2D() {}
Camera2D(::Vector2 offset, ::Vector2 target, float rotation = 0.0f, float zoom = 1.0f)
: ::Camera2D{offset, target, rotation, zoom} {}

Expand All @@ -40,17 +43,17 @@ class Camera2D : public ::Camera2D {
/**
* Returns camera 2d transform matrix
*/
Matrix GetMatrix() const { return ::GetCameraMatrix2D(*this); }
[[nodiscard]] Matrix GetMatrix() const { return ::GetCameraMatrix2D(*this); }

/**
* Returns the world space position for a 2d camera screen space position
*/
Vector2 GetScreenToWorld(::Vector2 position) const { return ::GetScreenToWorld2D(position, *this); }
[[nodiscard]] Vector2 GetScreenToWorld(::Vector2 position) const { return ::GetScreenToWorld2D(position, *this); }

/**
* Returns the screen space position for a 2d world space position
*/
Vector2 GetWorldToScreen(::Vector2 position) const { return ::GetWorldToScreen2D(position, *this); }
[[nodiscard]] Vector2 GetWorldToScreen(::Vector2 position) const { return ::GetWorldToScreen2D(position, *this); }
protected:
void set(const ::Camera2D& camera) {
offset = camera.offset;
Expand Down
2 changes: 1 addition & 1 deletion include/Camera3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace raylib {
*/
class Camera3D : public ::Camera3D {
public:
Camera3D(const ::Camera3D& camera) { set(camera); }
Camera3D(const ::Camera3D& camera) : ::Camera3D(camera) { }

/**
* Create a new Camera3D.
Expand Down
24 changes: 12 additions & 12 deletions include/Color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,43 @@ class Color : public ::Color {
/**
* Get Color structure from hexadecimal value
*/
Color(unsigned int hexValue) { set(::GetColor(hexValue)); }
explicit Color(unsigned int hexValue) : ::Color(::GetColor(hexValue)) { }

Color(void* srcPtr, int format) { set(::GetPixelColor(srcPtr, format)); }
Color(void* srcPtr, int format) : ::Color(::GetPixelColor(srcPtr, format)) { }

/**
* Returns hexadecimal value for a Color
*/
int ToInt() const { return ::ColorToInt(*this); }
[[nodiscard]] int ToInt() const { return ::ColorToInt(*this); }

/**
* Returns hexadecimal value for a Color
*/
operator int() const { return ::ColorToInt(*this); }
explicit operator int() const { return ::ColorToInt(*this); }

std::string ToString() const { return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a); }
[[nodiscard]] std::string ToString() const { return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a); }

operator std::string() const { return ToString(); }
explicit operator std::string() const { return ToString(); }

/**
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
*/
Color Fade(float alpha) const { return ::Fade(*this, alpha); }
[[nodiscard]] Color Fade(float alpha) const { return ::Fade(*this, alpha); }

/**
* Returns Color normalized as float [0..1]
*/
Vector4 Normalize() const { return ::ColorNormalize(*this); }
[[nodiscard]] Vector4 Normalize() const { return ::ColorNormalize(*this); }

/**
* Returns Color from normalized values [0..1]
*/
Color(::Vector4 normalized) { set(::ColorFromNormalized(normalized)); }
explicit Color(::Vector4 normalized) : Color(::ColorFromNormalized(normalized)) { }

/**
* Returns HSV values for a Color
*/
Vector3 ToHSV() const { return ::ColorToHSV(*this); }
[[nodiscard]] Vector3 ToHSV() const { return ::ColorToHSV(*this); }

GETTERSETTER(unsigned char, R, r)
GETTERSETTER(unsigned char, G, g)
Expand Down Expand Up @@ -206,7 +206,7 @@ class Color : public ::Color {
/**
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
*/
Color Alpha(float alpha) const { return ::ColorAlpha(*this, alpha); }
[[nodiscard]] Color Alpha(float alpha) const { return ::ColorAlpha(*this, alpha); }

Color Lerp(::Color color2, float factor) {
return ::ColorLerp(*this, color2, factor);
Expand All @@ -215,7 +215,7 @@ class Color : public ::Color {
/**
* Returns src alpha-blended into dst color with tint
*/
Color AlphaBlend(::Color dst, ::Color tint) const { return ::ColorAlphaBlend(dst, *this, tint); }
[[nodiscard]] Color AlphaBlend(::Color dst, ::Color tint) const { return ::ColorAlphaBlend(dst, *this, tint); }

static Color LightGray() { return LIGHTGRAY; }
static Color Gray() { return GRAY; }
Expand Down
18 changes: 9 additions & 9 deletions include/Font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class Font : public ::Font {
/**
* Retrieves the default Font.
*/
Font() { set(::GetFontDefault()); }
Font() : ::Font(::GetFontDefault()) { }

Font(const ::Font& font) { set(font); }
Font(const ::Font& font) : ::Font(font) { }

/**
* Loads a Font from the given file.
Expand Down Expand Up @@ -84,7 +84,7 @@ class Font : public ::Font {

Font(const Font&) = delete;

Font(Font&& other) {
Font(Font&& other) noexcept {
set(other);

other.baseSize = 0;
Expand Down Expand Up @@ -203,7 +203,7 @@ class Font : public ::Font {
/**
* Returns if the font is ready to be used.
*/
bool IsValid() const { return ::IsFontValid(*this); }
[[nodiscard]] bool IsValid() const { return ::IsFontValid(*this); }

/**
* Draw text using font and additional parameters.
Expand Down Expand Up @@ -286,33 +286,33 @@ class Font : public ::Font {
/**
* Measure string size for Font
*/
Vector2 MeasureText(const char* text, float fontSize, float spacing) const {
[[nodiscard]] Vector2 MeasureText(const char* text, float fontSize, float spacing) const {
return ::MeasureTextEx(*this, text, fontSize, spacing);
}

/**
* Measure string size for Font
*/
Vector2 MeasureText(const std::string& text, float fontSize, float spacing) const {
[[nodiscard]] Vector2 MeasureText(const std::string& text, float fontSize, float spacing) const {
return ::MeasureTextEx(*this, text.c_str(), fontSize, spacing);
}

/**
* Get index position for a unicode character on font
*/
int GetGlyphIndex(int character) const { return ::GetGlyphIndex(*this, character); }
[[nodiscard]] int GetGlyphIndex(int character) const { return ::GetGlyphIndex(*this, character); }

/**
* Create an image from text (custom sprite font)
*/
::Image ImageText(const char* text, float fontSize, float spacing, ::Color tint) const {
[[nodiscard]] ::Image ImageText(const char* text, float fontSize, float spacing, ::Color tint) const {
return ::ImageTextEx(*this, text, fontSize, spacing, tint);
}

/**
* Create an image from text (custom sprite font)
*/
::Image ImageText(const std::string& text, float fontSize, float spacing, ::Color tint) const {
[[nodiscard]] ::Image ImageText(const std::string& text, float fontSize, float spacing, ::Color tint) const {
return ::ImageTextEx(*this, text.c_str(), fontSize, spacing, tint);
}
protected:
Expand Down
Loading
Loading