-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add raybuff.hpp - a header-only (or at least for now) thing to empover raylib's structs with power of C++ operator overloading. - Move existing operator overloads from utility.hpp -> raybuff.hpp - Add operator overloads for operator+ and operator-.
- Loading branch information
Showing
4 changed files
with
48 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
#include "raylib.h" | ||
// For clamp | ||
#include <algorithm> | ||
|
||
// Overloads to fuel raylib's C structs with power of C++. | ||
// Header-only for now, coz its kinda smol. | ||
|
||
// Equality operator. | ||
bool operator==(const Color& c1, const Color& c2) { | ||
return c1.r == c2.r && c1.g == c2.g && c1.b == c2.b && c1.a == c2.a; | ||
} | ||
|
||
bool operator==(const Vector2& v1, const Vector2& v2) { | ||
return v1.x == v2.x && v1.y == v2.y; | ||
} | ||
|
||
bool operator==(const Rectangle& r1, const Rectangle& r2) { | ||
return r1.x == r2.x && r1.y == r2.y && r1.width == r2.width && r1.height == r2.height; | ||
} | ||
|
||
// Addition operator. Iirc these should always return new objects. | ||
Color operator+(const Color& c1, const Color& c2) { | ||
return { | ||
std::clamp((c1.r + c2.r), 0, 255), | ||
std::clamp((c1.g + c2.g), 0, 255), | ||
std::clamp((c1.b + c2.b), 0, 255), | ||
std::clamp((c1.a + c2.a), 0, 255)}; | ||
} | ||
|
||
Vector2 operator+(const Vector2& v1, const Vector2& v2) { | ||
return {v1.x + v2.x, v1.y + v2.y}; | ||
} | ||
|
||
// Subtraction operator. | ||
Color operator-(const Color& c1, const Color& c2) { | ||
return { | ||
std::clamp((c1.r - c2.r), 0, 255), | ||
std::clamp((c1.g - c2.g), 0, 255), | ||
std::clamp((c1.b - c2.b), 0, 255), | ||
std::clamp((c1.a - c2.a), 0, 255)}; | ||
} | ||
|
||
Vector2 operator-(const Vector2& v1, const Vector2& v2) { | ||
return {v1.x - v2.x, v1.y - v2.y}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters