Skip to content
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [x.x.x] - xxxx-xx-xx
## [4.0.0] - 2021-11-04
### Changes
- Update to [raylib 4.0.0](https://github.com/raysan5/raylib/releases/tag/4.0.0)
- For tests, replaced catch.hpp with `assert()` calls
- Added assignment operators for objects ([#142](https://github.com/RobLoach/raylib-cpp/pull/142) by [@marciejewiczow](https://github.com/maciejewiczow))
- Replaced `NULL` with `nullptr`
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.11)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
project (raylib-cpp
VERSION 3.7.0
VERSION 4.0.0
DESCRIPTION "raylib-cpp C++ Object Oriented Wrapper for raylib"
HOMEPAGE_URL "https://github.com/robloach/raylib-cpp"
LANGUAGES C CXX)
Expand Down
2 changes: 1 addition & 1 deletion examples/core/core_random_values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int main() {

DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON);

DrawText(FormatText("%i", randValue), 360, 180, 80, LIGHTGRAY);
DrawText(TextFormat("%i", randValue), 360, 180, 80, LIGHTGRAY);
}
EndDrawing();
//----------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/models/models_first_person_maze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main(void)

// NOTE: By default each cube is mapped to one part of texture atlas
raylib::Texture texture("resources/cubicmap_atlas.png"); // Load map texture
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture

// Get map image data to be used for collision detection
Color *mapPixels = imMap.LoadColors();
Expand Down
2 changes: 1 addition & 1 deletion examples/shapes/shapes_collision_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int main(void)
DrawText("COLLISION!", GetScreenWidth()/2 - MeasureText("COLLISION!", 20)/2, screenUpperLimit/2 - 10, 20, BLACK);

// Draw collision area
DrawText(FormatText("Collision Area: %i", (int)boxCollision.width*(int)boxCollision.height), GetScreenWidth()/2 - 100, screenUpperLimit + 10, 20, BLACK);
DrawText(TextFormat("Collision Area: %i", (int)boxCollision.width*(int)boxCollision.height), GetScreenWidth()/2 - 100, screenUpperLimit + 10, 20, BLACK);
}

DrawFPS(10, 10);
Expand Down
4 changes: 2 additions & 2 deletions examples/textures/textures_bunnymark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ int main(void)
}

DrawRectangle(0, 0, screenWidth, 40, BLACK);
DrawText(FormatText("bunnies: %i", bunnies.size()), 120, 10, 20, GREEN);
DrawText(FormatText("batched draw calls: %i", 1 + bunnies.size()/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON);
DrawText(TextFormat("bunnies: %i", bunnies.size()), 120, 10, 20, GREEN);
DrawText(TextFormat("batched draw calls: %i", 1 + bunnies.size()/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON);

DrawFPS(10, 10);
}
Expand Down
12 changes: 6 additions & 6 deletions include/AudioStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AudioStream : public ::AudioStream {
* Init audio stream (to stream raw audio pcm data)
*/
AudioStream(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels = 2) {
set(InitAudioStream(SampleRate, SampleSize, Channels));
set(LoadAudioStream(SampleRate, SampleSize, Channels));
}

AudioStream(const AudioStream&) = delete;
Expand All @@ -33,7 +33,7 @@ class AudioStream : public ::AudioStream {
}

~AudioStream() {
Close();
Unload();
}

GETTERSETTER(rAudioBuffer *, Buffer, buffer)
Expand All @@ -53,7 +53,7 @@ class AudioStream : public ::AudioStream {
return *this;
}

Close();
Unload();
set(other);

other.buffer = nullptr;
Expand All @@ -73,10 +73,10 @@ class AudioStream : public ::AudioStream {
}

/**
* Close audio stream and free memory
* Unload audio stream and free memory
*/
inline void Close() {
::CloseAudioStream(*this);
inline void Unload() {
::UnloadAudioStream(*this);
}

/**
Expand Down
11 changes: 9 additions & 2 deletions include/BoundingBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BoundingBox : public ::BoundingBox {
* Compute mesh bounding box limits
*/
BoundingBox(const ::Mesh& mesh) {
set(::MeshBoundingBox(mesh));
set(::GetMeshBoundingBox(mesh));
}

BoundingBox(::Vector3 minMax) : ::BoundingBox{minMax, minMax} {}
Expand Down Expand Up @@ -58,7 +58,14 @@ class BoundingBox : public ::BoundingBox {
* Detect collision between ray and bounding box
*/
inline bool CheckCollision(const ::Ray& ray) const {
return CheckCollisionRayBox(ray, *this);
return GetRayCollisionBox(ray, *this).hit;
}

/**
* Get collision information between ray and bounding box
*/
inline RayCollision GetCollision(const ::Ray& ray) const {
return GetRayCollisionBox(ray, *this);
}

private:
Expand Down
2 changes: 1 addition & 1 deletion include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ install(FILES
physac.hpp
Physics.hpp
Ray.hpp
RayHitInfo.hpp
RayCollision.hpp
raylib-cpp-utils.hpp
raylib-cpp.hpp
raylib.hpp
Expand Down
2 changes: 1 addition & 1 deletion include/Camera3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Camera3D : public ::Camera3D {
const ::Texture2D& texture,
::Rectangle sourceRec,
::Vector3 center,
float size,
::Vector2 size,
::Color tint = {255, 255, 255, 255}) {
::DrawBillboardRec(*this, texture, sourceRec, center, size, tint);
return *this;
Expand Down
15 changes: 8 additions & 7 deletions include/Color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Color : public ::Color {
/**
* Get Color structure from hexadecimal value
*/
Color(int hexValue) {
Color(unsigned int hexValue) {
set(::GetColor(hexValue));
}

Expand Down Expand Up @@ -163,13 +163,14 @@ class Color : public ::Color {
}

inline Color& DrawText(
const ::Font& font,
const ::Font font,
const std::string& text,
::Rectangle rec,
::Vector2 position,
::Vector2 origin,
float rotation,
float fontSize,
float spacing,
bool wordWrap = false) {
::DrawTextRec(font, text.c_str(), rec, fontSize, spacing, wordWrap, *this);
float spacing) {
::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, *this);
return *this;
}

Expand Down Expand Up @@ -198,7 +199,7 @@ class Color : public ::Color {
return *this;
}

inline Color& DrawRectangleLines(::Rectangle rec, int lineThick) {
inline Color& DrawRectangleLines(::Rectangle rec, float lineThick) {
::DrawRectangleLinesEx(rec, lineThick, *this);
return *this;
}
Expand Down
51 changes: 23 additions & 28 deletions include/Font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class Font : public ::Font {
set(other);

other.baseSize = 0;
other.charsCount = 0;
other.charsPadding = 0;
other.texture = { 0 };
other.glyphCount = 0;
other.glyphPadding = 0;
other.texture = {};
other.recs = nullptr;
other.chars = nullptr;
other.glyphs = nullptr;
}

~Font() {
Expand All @@ -60,11 +60,11 @@ class Font : public ::Font {
}

GETTERSETTER(int, BaseSize, baseSize)
GETTERSETTER(int, CharsCount, charsCount)
GETTERSETTER(int, CharsPadding, charsPadding)
GETTERSETTER(int, GlyphCount, glyphCount)
GETTERSETTER(int, GlyphPadding, glyphPadding)
GETTERSETTER(::Texture2D, Texture, texture)
GETTERSETTER(::Rectangle*, Recs, recs)
GETTERSETTER(::CharInfo*, Chars, chars)
GETTERSETTER(::GlyphInfo*, Glyphs, glyphs)

Font& operator=(const ::Font& font) {
set(font);
Expand All @@ -82,11 +82,11 @@ class Font : public ::Font {
set(other);

other.baseSize = 0;
other.charsCount = 0;
other.charsPadding = 0;
other.texture = { 0 };
other.glyphCount = 0;
other.glyphPadding = 0;
other.texture = {};
other.recs = nullptr;
other.chars = nullptr;
other.glyphs = nullptr;

return *this;
}
Expand All @@ -100,20 +100,15 @@ class Font : public ::Font {
return *this;
}

inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing,
bool wordWrap = false, ::Color tint = WHITE) {
::DrawTextRec(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint);
return *this;
}

/**
* Draw text using font inside rectangle limits with support for text selection.
*/
inline Font& DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing,
bool wordWrap, ::Color tint, int selectStart, int selectLength, ::Color selectText,
::Color selectBack) {
::DrawTextRecEx(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint,
selectStart, selectLength, selectText, selectBack);
inline Font& DrawText(
const std::string& text,
::Vector2 position,
::Vector2 origin,
float rotation,
float fontSize,
float spacing,
::Color tint = WHITE) {
::DrawTextPro(*this, text.c_str(), position, origin, rotation, fontSize, spacing, tint);
return *this;
}

Expand Down Expand Up @@ -153,11 +148,11 @@ class Font : public ::Font {
private:
void set(const ::Font& font) {
baseSize = font.baseSize;
charsCount = font.charsCount;
charsPadding = font.charsPadding;
glyphCount = font.glyphCount;
glyphPadding = font.glyphPadding;
texture = font.texture;
recs = font.recs;
chars = font.chars;
glyphs = font.glyphs;
}
};
} // namespace raylib
Expand Down
9 changes: 1 addition & 8 deletions include/Functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ RLCPPAPI inline void TakeScreenshot(const std::string& fileName) {
RLCPPAPI std::string LoadFileText(const std::string& fileName) {
char* text = ::LoadFileText(fileName.c_str());
std::string output(text);
::UnloadFileText((unsigned char*)text);
::UnloadFileText(text);
return output;
}

Expand Down Expand Up @@ -189,13 +189,6 @@ RLCPPAPI inline void OpenURL(const std::string& url) {
return ::OpenURL(url.c_str());
}

/**
* Check gamepad name (if available)
*/
RLCPPAPI inline bool IsGamepadName(int gamepad, const std::string& name) {
return ::IsGamepadName(gamepad, name.c_str());
}

/**
* Update camera depending on selected mode
*/
Expand Down
7 changes: 0 additions & 7 deletions include/Gamepad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ class Gamepad {
return ::IsGamepadAvailable(number);
}

/**
* Check gamepad name (if available)
*/
inline bool IsName(const std::string& name) const {
return ::IsGamepadName(number, name.c_str());
}

/**
* Return gamepad internal name id
*/
Expand Down
38 changes: 21 additions & 17 deletions include/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ class Image : public ::Image {
}

Image(const ::Texture2D& texture) {
set(::GetTextureData(texture));
set(::LoadImageFromTexture(texture));
}

Image(int width, int height, ::Color color = {255, 255, 255, 255}) {
set(::GenImageColor(width, height, color));
}

Image(const std::string& text, int fontSize, ::Color color = {255, 255, 255, 255}) {
set(::ImageText(text.c_str(), fontSize, color));
}

Image(const ::Font& font, const std::string& text, float fontSize, float spacing,
::Color tint = {255, 255, 255, 255}) {
set(::ImageTextEx(font, text.c_str(), fontSize, spacing, tint));
Expand Down Expand Up @@ -74,8 +78,8 @@ class Image : public ::Image {
/**
* Get pixel data from screen buffer and return an Image (screenshot)
*/
static ::Image GetScreenData() {
return ::GetScreenData();
static ::Image LoadFromScreen() {
return ::LoadImageFromScreen();
}

/**
Expand Down Expand Up @@ -122,14 +126,6 @@ class Image : public ::Image {
return ::GenImageWhiteNoise(width, height, factor);
}

/**
* Generate image: perlin noise
*/
static ::Image PerlinNoise(int width, int height, int offsetX, int offsetY,
float scale = 1.0f) {
return ::GenImagePerlinNoise(width, height, offsetX, offsetY, scale);
}

/**
* Generate image: cellular algorithm. Bigger tileSize means bigger cells
*/
Expand Down Expand Up @@ -272,18 +268,26 @@ class Image : public ::Image {
}

/**
* Apply alpha mask to image
* Crop image depending on alpha value
*/
inline Image& AlphaMask(const ::Image& alphaMask) {
::ImageAlphaMask(this, alphaMask);
inline Image& AlphaCrop(float threshold) {
::ImageAlphaCrop(this, threshold);
return *this;
}

/**
* Crop image depending on alpha value
* Clear alpha channel to desired color
*/
inline Image& AlphaCrop(float threshold) {
::ImageAlphaCrop(this, threshold);
inline Image& AlphaClear(::Color color, float threshold) {
::ImageAlphaClear(this, color, threshold);
return *this;
}

/**
* Apply alpha mask to image
*/
inline Image& AlphaMask(const ::Image& alphaMask) {
::ImageAlphaMask(this, alphaMask);
return *this;
}

Expand Down
Loading