init commit

This commit is contained in:
Alex Lardner
2026-07-04 19:08:19 -07:00
parent 40dc51d21a
commit d7890c9808
106 changed files with 13653 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
#ifndef RAYLIB_CPP_INCLUDE_AUDIODEVICE_HPP_
#define RAYLIB_CPP_INCLUDE_AUDIODEVICE_HPP_
#include "./RaylibException.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Audio device management functions.
*/
class AudioDevice {
public:
/**
* Initialize audio device and context.
*
* @param lateInit Whether or not to post-pone initializing the context.
*
* @throws raylib::RaylibException Throws if the AudioDevice failed to initialize.
*/
explicit AudioDevice(bool lateInit = false) {
if (!lateInit) {
Init();
}
}
AudioDevice(const AudioDevice&) = delete;
AudioDevice& operator=(const AudioDevice&) = delete;
/**
* Close the audio device and context.
*/
~AudioDevice() { Close(); }
/**
* Initialize audio device and context.
*
* @throws raylib::RaylibException Throws if the AudioDevice failed to initialize.
*/
static void Init() {
::InitAudioDevice();
if (!IsReady()) {
throw RaylibException("Failed to initialize AudioDevice");
}
}
/**
* Close the audio device and context.
*/
static void Close() { ::CloseAudioDevice(); }
/**
* Check if audio device has been initialized successfully.
*/
static bool IsReady() { return ::IsAudioDeviceReady(); }
/**
* Set master volume (listener).
*
* @param volume The desired volume to set.
*/
AudioDevice& SetVolume(float volume) {
::SetMasterVolume(volume);
return *this;
}
};
} // namespace raylib
using RAudioDevice = raylib::AudioDevice;
#endif // RAYLIB_CPP_INCLUDE_AUDIODEVICE_HPP_
+55
View File
@@ -0,0 +1,55 @@
#ifndef RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_
#define RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_
#include "./AudioStreamUnmanaged.hpp"
namespace raylib {
/**
* AudioStream management functions.
*
* The audio stream will be unloaded on object destruction. Use raylib::AudioStreamUnmanaged if you're looking to not unload.
*
* @see raylib::AudioStreamUnmanaged
*/
class AudioStream : public AudioStreamUnmanaged {
public:
using AudioStreamUnmanaged::AudioStreamUnmanaged;
AudioStream(const AudioStream&) = delete;
AudioStream& operator=(const AudioStream&) = delete;
AudioStream(AudioStream&& other) noexcept {
set(other);
other.buffer = nullptr;
other.processor = nullptr;
other.sampleRate = 0;
other.sampleSize = 0;
other.channels = 0;
}
AudioStream& operator=(AudioStream&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.buffer = nullptr;
other.processor = nullptr;
other.sampleRate = 0;
other.sampleSize = 0;
other.channels = 0;
return *this;
}
~AudioStream() { Unload(); }
void Load(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels = 2) {
Unload();
AudioStreamUnmanaged::Load(sampleRate, sampleSize, channels);
}
};
} // namespace raylib
using RAudioStream = raylib::AudioStream;
#endif // RAYLIB_CPP_INCLUDE_AUDIOSTREAM_HPP_
+200
View File
@@ -0,0 +1,200 @@
#ifndef RAYLIB_CPP_INCLUDE_AUDIOSTREAMUNMANAGED_HPP_
#define RAYLIB_CPP_INCLUDE_AUDIOSTREAMUNMANAGED_HPP_
#include "./RaylibException.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* An AudioStream that is not managed by C++ RAII.
*
* Make sure to Unload() this if needed, otherwise use raylib::AudioStream.
*
* @see raylib::AudioStream
*/
class AudioStreamUnmanaged : public ::AudioStream {
public:
/**
* Creates an AudioStreamUnmanaged from an existing AudioStream struct.
*/
AudioStreamUnmanaged(const ::AudioStream& stream) : ::AudioStream(stream) {}
/**
* Creates an AudioStreamUnmanaged from its components.
*/
AudioStreamUnmanaged(
rAudioBuffer* buffer = nullptr,
rAudioProcessor* processor = nullptr,
unsigned int sampleRate = 0,
unsigned int sampleSize = 0,
unsigned int channels = 0)
: ::AudioStream{buffer, processor, sampleRate, sampleSize, channels} {}
/**
* Init audio stream (to stream raw audio PCM data).
*
* @throws raylib::RaylibException Throws if the AudioStream failed to load.
*/
AudioStreamUnmanaged(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels = 2) {
Load(sampleRate, sampleSize, channels);
}
GETTER(rAudioBuffer*, Buffer, buffer)
GETTER(rAudioProcessor*, Processor, processor)
GETTER(unsigned int, SampleRate, sampleRate)
GETTER(unsigned int, SampleSize, sampleSize)
GETTER(unsigned int, Channels, channels)
AudioStreamUnmanaged& operator=(const ::AudioStream& stream) {
set(stream);
return *this;
}
/**
* Load audio stream (to stream raw audio PCM data).
*
* Does NOT call Unload() first — that is the responsibility of the managed class.
*
* @throws raylib::RaylibException Throws if the AudioStream failed to load.
*/
void Load(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels = 2) {
set(::LoadAudioStream(sampleRate, sampleSize, channels));
if (!IsValid()) {
throw RaylibException("Failed to load audio stream");
}
}
/**
* Unload audio stream and free memory.
*/
void Unload() {
// Protect against calling UnloadAudioStream() twice.
if (buffer != nullptr) {
::UnloadAudioStream(*this);
buffer = nullptr;
}
}
/**
* Update audio stream buffers with data.
*/
AudioStreamUnmanaged& Update(const void* data, int samplesCount) {
::UpdateAudioStream(*this, data, samplesCount);
return *this;
}
/**
* Check if any audio stream buffers require refill.
*/
RLCPP_NODISCARD bool IsProcessed() const { return ::IsAudioStreamProcessed(*this); }
/**
* Play audio stream.
*/
AudioStreamUnmanaged& Play() {
::PlayAudioStream(*this);
return *this;
}
/**
* Pause audio stream.
*/
AudioStreamUnmanaged& Pause() {
::PauseAudioStream(*this);
return *this;
}
/**
* Resume audio stream.
*/
AudioStreamUnmanaged& Resume() {
::ResumeAudioStream(*this);
return *this;
}
/**
* Check if audio stream is playing.
*/
RLCPP_NODISCARD bool IsPlaying() const { return ::IsAudioStreamPlaying(*this); }
/**
* Stop audio stream.
*/
AudioStreamUnmanaged& Stop() {
::StopAudioStream(*this);
return *this;
}
/**
* Set volume for audio stream (1.0 is max level).
*/
AudioStreamUnmanaged& SetVolume(float volume = 1.0f) {
::SetAudioStreamVolume(*this, volume);
return *this;
}
/**
* Set pitch for audio stream (1.0 is base level).
*/
AudioStreamUnmanaged& SetPitch(float pitch) {
::SetAudioStreamPitch(*this, pitch);
return *this;
}
/**
* Set pan for audio stream (0.5 is centered).
*/
AudioStreamUnmanaged& SetPan(float pan = 0.5f) {
::SetAudioStreamPan(*this, pan);
return *this;
}
/**
* Default size for new audio streams.
*/
static void SetBufferSizeDefault(int size) { ::SetAudioStreamBufferSizeDefault(size); }
/**
* Audio thread callback to request new data.
*/
AudioStreamUnmanaged& SetCallback(::AudioCallback callback) {
::SetAudioStreamCallback(*this, callback);
return *this;
}
/**
* Attach audio stream processor to stream.
*/
AudioStreamUnmanaged& AttachProcessor(::AudioCallback processor) {
::AttachAudioStreamProcessor(*this, processor);
return *this;
}
/**
* Detach audio stream processor from stream.
*/
AudioStreamUnmanaged& DetachProcessor(::AudioCallback processor) {
::DetachAudioStreamProcessor(*this, processor);
return *this;
}
/**
* Retrieve whether or not the audio stream is ready.
*/
RLCPP_NODISCARD bool IsValid() const { return ::IsAudioStreamValid(*this); }
protected:
void set(const ::AudioStream& stream) {
buffer = stream.buffer;
processor = stream.processor;
sampleRate = stream.sampleRate;
sampleSize = stream.sampleSize;
channels = stream.channels;
}
};
} // namespace raylib
using RAudioStreamUnmanaged = raylib::AudioStreamUnmanaged;
#endif // RAYLIB_CPP_INCLUDE_AUDIOSTREAMUNMANAGED_HPP_
+142
View File
@@ -0,0 +1,142 @@
#ifndef RAYLIB_CPP_INCLUDE_AUTOMATIONEVENTLIST_HPP_
#define RAYLIB_CPP_INCLUDE_AUTOMATIONEVENTLIST_HPP_
#include "./RaylibException.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* AutomationEventList management functions
*/
class AutomationEventList : public ::AutomationEventList {
public:
AutomationEventList(const ::AutomationEventList& automationEventList)
: ::AutomationEventList(automationEventList) {
// Nothing.
}
/**
* Load an empty automation events list.
*/
AutomationEventList() { set(::LoadAutomationEventList(0)); }
/**
* Load automation events list from file.
*
* @param fileName The file path to load the automation events list from.
*/
AutomationEventList(const char* fileName) { Load(fileName); }
AutomationEventList(const AutomationEventList&) = delete;
AutomationEventList(AutomationEventList&& other) noexcept {
set(other);
other.capacity = 0;
other.count = 0;
other.events = nullptr;
}
~AutomationEventList() { Unload(); }
GETTER(unsigned int, Capacity, capacity)
GETTER(unsigned int, Count, count)
GETTER(AutomationEvent*, Events, events)
AutomationEventList& operator=(const ::AutomationEventList& other) {
set(other);
return *this;
}
AutomationEventList& operator=(const AutomationEventList&) = delete;
AutomationEventList& operator=(AutomationEventList&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.capacity = 0;
other.count = 0;
other.events = nullptr;
return *this;
}
/**
* Load audio stream (to stream raw audio pcm data)
*
* @throws raylib::RaylibException Throws if the AutomationEventList failed to load.
*/
void Load(const char* fileName) {
Unload();
set(::LoadAutomationEventList(fileName));
if (!IsValid()) {
throw RaylibException("Failed to load automation event list");
}
}
/**
* Update audio stream buffers with data
*/
void Unload() {
if (!IsValid()) {
return;
}
// The function signature of UnloadAutomationEventList() changes from raylib 5.0.
#if RAYLIB_VERSION_MAJOR == 5
#if RAYLIB_VERSION_MINOR == 0
::UnloadAutomationEventList(this);
#elif RAYLIB_VERSION_MINOR >= 1
::UnloadAutomationEventList(*this);
#endif
#else
::UnloadAutomationEventList(*this);
#endif
}
bool IsValid() { return events != nullptr; }
bool Export(const char* fileName) { return ::ExportAutomationEventList(*this, fileName); }
void Set() { ::SetAutomationEventList(this); }
void SetBaseFrame(int frame) {
Set();
::SetAutomationEventBaseFrame(frame);
}
void StartRecording() {
Set();
::StartAutomationEventRecording();
}
void StopRecording() {
Set();
::StopAutomationEventRecording();
}
void Play(int index) {
if (index < 0 || static_cast<unsigned int>(index) >= this->count) {
return;
}
Set();
::PlayAutomationEvent(this->events[index]);
}
protected:
void set(const ::AutomationEventList& other) {
capacity = other.capacity;
count = other.count;
events = other.events;
}
};
} // namespace raylib
using RAutomationEventList = raylib::AutomationEventList;
#endif // RAYLIB_CPP_INCLUDE_AUTOMATIONEVENTLIST_HPP_
+83
View File
@@ -0,0 +1,83 @@
#ifndef RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_
#define RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Bounding box type
*/
class BoundingBox : public ::BoundingBox {
public:
/*
* Copy a bounding box from another bounding box.
*/
constexpr BoundingBox(const ::BoundingBox& box) : ::BoundingBox{box.min, box.max} {
// Nothing.
}
/**
* Compute mesh bounding box limits
*/
BoundingBox(const ::Mesh& mesh) { set(::GetMeshBoundingBox(mesh)); }
constexpr BoundingBox(::Vector3 minMax = ::Vector3{0.0f, 0.0f, 0.0f}) : ::BoundingBox{minMax, minMax} {}
constexpr BoundingBox(::Vector3 min, ::Vector3 max) : ::BoundingBox{min, max} {}
GETTERSETTER(::Vector3, Min, min)
GETTERSETTER(::Vector3, Max, max)
BoundingBox& operator=(const ::BoundingBox& box) {
set(box);
return *this;
}
[[nodiscard]] std::string ToString() const {
return TextFormat(
"BoundingBox(min=(%f, %f, %f), max=(%f, %f, %f))",
min.x, min.y, min.z, max.x, max.y, max.z
);
}
operator std::string() const { return ToString(); }
/**
* Draw a bounding box with wires
*/
void Draw(::Color color = {255, 255, 255, 255}) const { ::DrawBoundingBox(*this, color); }
/**
* Detect collision between two boxes
*/
RLCPP_NODISCARD bool CheckCollision(const ::BoundingBox& box2) const { return CheckCollisionBoxes(*this, box2); }
/**
* Detect collision between box and sphere
*/
RLCPP_NODISCARD bool CheckCollision(::Vector3 center, float radius) const { return CheckCollisionBoxSphere(*this, center, radius); }
/**
* Detect collision between ray and bounding box
*/
RLCPP_NODISCARD bool CheckCollision(const ::Ray& ray) const { return GetRayCollisionBox(ray, *this).hit; }
/**
* Get collision information between ray and bounding box
*/
RayCollision GetCollision(const ::Ray& ray) const { return GetRayCollisionBox(ray, *this); }
protected:
void set(const ::BoundingBox& box) {
min = box.min;
max = box.max;
}
void set(const ::Vector3& _min, const ::Vector3& _max) {
min = _min;
max = _max;
}
};
} // namespace raylib
using RBoundingBox = raylib::BoundingBox;
#endif // RAYLIB_CPP_INCLUDE_BOUNDINGBOX_HPP_
+67
View File
@@ -0,0 +1,67 @@
add_library(raylib_cpp INTERFACE)
set(RAYLIB_CPP_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/AudioDevice.hpp
${CMAKE_CURRENT_SOURCE_DIR}/AudioStream.hpp
${CMAKE_CURRENT_SOURCE_DIR}/AutomationEventList.hpp
${CMAKE_CURRENT_SOURCE_DIR}/BoundingBox.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Camera2D.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Camera3D.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Color.hpp
${CMAKE_CURRENT_SOURCE_DIR}/FileData.hpp
${CMAKE_CURRENT_SOURCE_DIR}/FileText.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Font.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Functions.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Gamepad.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Image.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Keyboard.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Material.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Matrix.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Mesh.hpp
${CMAKE_CURRENT_SOURCE_DIR}/MeshUnmanaged.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Model.hpp
${CMAKE_CURRENT_SOURCE_DIR}/ModelAnimation.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Mouse.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Music.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Quaternion.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Ray.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RayCollision.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RaylibException.hpp
${CMAKE_CURRENT_SOURCE_DIR}/raylib-cpp-utils.hpp
${CMAKE_CURRENT_SOURCE_DIR}/raylib-cpp.hpp
${CMAKE_CURRENT_SOURCE_DIR}/raylib.hpp
${CMAKE_CURRENT_SOURCE_DIR}/raymath.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Rectangle.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RenderTexture.hpp
${CMAKE_CURRENT_SOURCE_DIR}/ShaderUnmanaged.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Shader.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Sound.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Text.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Texture.hpp
${CMAKE_CURRENT_SOURCE_DIR}/TextureUnmanaged.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Touch.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Vector2.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Vector3.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Vector4.hpp
${CMAKE_CURRENT_SOURCE_DIR}/VrStereoConfig.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Wave.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Window.hpp
)
# Include Directory
target_include_directories(raylib_cpp INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/)
# Set the header files as install files.
install(FILES
${RAYLIB_CPP_HEADERS}
DESTINATION include
)
if (RAYLIB_CPP_IS_MAIN)
# @TODO: add examples files
add_custom_target(format
COMMAND clang-format
-i
${RAYLIB_CPP_HEADERS}
)
endif()
+68
View File
@@ -0,0 +1,68 @@
#ifndef RAYLIB_CPP_INCLUDE_CAMERA2D_HPP_
#define RAYLIB_CPP_INCLUDE_CAMERA2D_HPP_
#include "./Vector2.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Camera2D type, defines a 2d camera
*/
class Camera2D : public ::Camera2D {
public:
Camera2D(const ::Camera2D& camera)
: ::Camera2D(camera) {
// Nothing.
}
Camera2D(::Vector2 offset = {}, ::Vector2 target = {}, float rotation = 0.0f, float zoom = 1.0f)
: ::Camera2D{offset, target, rotation, zoom} {}
Camera2D& BeginMode() {
::BeginMode2D(*this);
return *this;
}
Camera2D& EndMode() {
::EndMode2D();
return *this;
}
GETTERSETTER(::Vector2, Offset, offset)
GETTERSETTER(::Vector2, Target, target)
GETTERSETTER(float, Rotation, rotation)
GETTERSETTER(float, Zoom, zoom)
Camera2D& operator=(const ::Camera2D& camera) {
set(camera);
return *this;
}
/**
* Returns camera 2d transform matrix
*/
RLCPP_NODISCARD Matrix GetMatrix() const { return ::GetCameraMatrix2D(*this); }
/**
* Returns the world space position for a 2d camera screen space position
*/
RLCPP_NODISCARD Vector2 GetScreenToWorld(::Vector2 position) const { return ::GetScreenToWorld2D(position, *this); }
/**
* Returns the screen space position for a 2d world space position
*/
RLCPP_NODISCARD Vector2 GetWorldToScreen(::Vector2 position) const { return ::GetWorldToScreen2D(position, *this); }
protected:
void set(const ::Camera2D& camera) {
offset = camera.offset;
target = camera.target;
rotation = camera.rotation;
zoom = camera.zoom;
}
};
} // namespace raylib
using RCamera2D = raylib::Camera2D;
#endif // RAYLIB_CPP_INCLUDE_CAMERA2D_HPP_
+146
View File
@@ -0,0 +1,146 @@
#ifndef RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
#define RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
#include "./Vector3.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Camera type, defines a camera position/orientation in 3d space
*/
class Camera3D : public ::Camera3D {
public:
Camera3D(const ::Camera3D& camera) : ::Camera3D(camera) { }
/**
* Create a new Camera3D.
*
* @param position Camera position
* @param target Camera target it looks-at
* @param up Camera up vector (rotation over its axis)
* @param fovy Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in
* orthographic
* @param projection Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
*/
Camera3D(
::Vector3 position = ::Vector3{0.0f, 0.0f, 0.0f},
::Vector3 target = ::Vector3{0.0f, 0.0f, -1.0f},
::Vector3 up = ::Vector3{0.0f, 1.0f, 0.0f},
float fovy = 45.0f,
int projection = CAMERA_PERSPECTIVE)
: ::Camera3D{position, target, up, fovy, projection} {}
GETTERSETTER(::Vector3, Position, position)
GETTERSETTER(::Vector3, Target, target)
GETTERSETTER(::Vector3, Up, up)
GETTERSETTER(float, Fovy, fovy)
GETTERSETTER(int, Projection, projection)
Camera3D& operator=(const ::Camera3D& camera) {
set(camera);
return *this;
}
[[nodiscard]] std::string ToString() const {
return TextFormat(
"Camera3D(position=(%f, %f, %f), target=(%f, %f, %f), fovy=%f)",
position.x, position.y, position.z,
target.x, target.y, target.z,
fovy
);
}
operator std::string() const { return ToString(); }
/**
* Initializes 3D mode with custom camera (3D)
*/
Camera3D& BeginMode() {
::BeginMode3D(*this);
return *this;
}
/**
* Ends 3D mode and returns to default 2D orthographic mode
*/
Camera3D& EndMode() {
::EndMode3D();
return *this;
}
/**
* Get camera transform matrix (view matrix)
*/
Matrix GetMatrix() const { return ::GetCameraMatrix(*this); }
/**
* Update camera position for selected mode
*/
Camera3D& Update(int mode) {
::UpdateCamera(this, mode);
return *this;
}
/**
* Update camera movement/rotation
*/
Camera3D& Update(::Vector3 movement, ::Vector3 rotation, float zoom = 1.0f) {
::UpdateCameraPro(this, movement, rotation, zoom);
return *this;
}
/**
* Returns a ray trace from mouse position
*/
Ray GetMouseRay(::Vector2 mousePosition) const { return ::GetMouseRay(mousePosition, *this); }
/**
* Returns the screen space position for a 3d world space position
*/
Vector2 GetWorldToScreen(::Vector3 position) const { return ::GetWorldToScreen(position, *this); }
/**
* Get a ray trace from screen position (i.e mouse) in a viewport
*/
Ray GetScreenToWorldRay(::Vector2 position, int width, int height) {
return ::GetScreenToWorldRayEx(position, *this, width, height);
}
/**
* Draw a billboard texture.
*/
void
DrawBillboard(const ::Texture2D& texture, ::Vector3 center, float size, ::Color tint = {255, 255, 255, 255}) const {
::DrawBillboard(*this, texture, center, size, tint);
}
/**
* Draw a billboard texture defined by source.
*/
void DrawBillboard(
const ::Texture2D& texture,
::Rectangle sourceRec,
::Vector3 center,
::Vector2 size,
::Color tint = {255, 255, 255, 255}) const {
::DrawBillboardRec(*this, texture, sourceRec, center, size, tint);
}
protected:
void set(const ::Camera3D& camera) {
position = camera.position;
target = camera.target;
up = camera.up;
fovy = camera.fovy;
projection = camera.projection;
}
};
using Camera = Camera3D;
} // namespace raylib
using RCamera = raylib::Camera;
using RCamera3D = raylib::Camera3D;
#endif // RAYLIB_CPP_INCLUDE_CAMERA3D_HPP_
+259
View File
@@ -0,0 +1,259 @@
#ifndef RAYLIB_CPP_INCLUDE_COLOR_HPP_
#define RAYLIB_CPP_INCLUDE_COLOR_HPP_
#include <string>
#include "./Vector4.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Color type, RGBA (32bit)
*/
class Color : public ::Color {
public:
constexpr Color(const ::Color& color) : ::Color{color.r, color.g, color.b, color.a} {}
constexpr Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255)
: ::Color{red, green, blue, alpha} {};
/**
* Black.
*/
constexpr Color() : ::Color{0, 0, 0, 255} {};
/**
* Returns a Color from HSV values
*/
Color(::Vector3 hsv) { set(::ColorFromHSV(hsv.x, hsv.y, hsv.z)); }
/**
* Returns a Color from HSV values
*/
static ::Color FromHSV(float hue, float saturation, float value) { return ::ColorFromHSV(hue, saturation, value); }
/**
* Get Color structure from hexadecimal value
*/
explicit Color(unsigned int hexValue) : ::Color(::GetColor(hexValue)) { }
Color(void* srcPtr, int format) : ::Color(::GetPixelColor(srcPtr, format)) { }
/**
* Returns hexadecimal value for a Color
*/
RLCPP_NODISCARD int ToInt() const { return ::ColorToInt(*this); }
/**
* Returns hexadecimal value for a Color
*/
explicit operator int() const { return ::ColorToInt(*this); }
RLCPP_NODISCARD std::string ToString() const { return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a); }
explicit operator std::string() const { return ToString(); }
/**
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
*/
RLCPP_NODISCARD Color Fade(float alpha) const { return ::Fade(*this, alpha); }
/**
* Returns Color normalized as float [0..1]
*/
RLCPP_NODISCARD Vector4 Normalize() const { return ::ColorNormalize(*this); }
/**
* Returns Color from normalized values [0..1]
*/
explicit Color(::Vector4 normalized) : Color(::ColorFromNormalized(normalized)) { }
/**
* Returns HSV values for a Color
*/
RLCPP_NODISCARD Vector3 ToHSV() const { return ::ColorToHSV(*this); }
GETTERSETTER(unsigned char, R, r)
GETTERSETTER(unsigned char, G, g)
GETTERSETTER(unsigned char, B, b)
GETTERSETTER(unsigned char, A, a)
Color& operator=(const ::Color& color) {
set(color);
return *this;
}
/**
* Set background color (framebuffer clear color)
*/
Color& ClearBackground() {
::ClearBackground(*this);
return *this;
}
void DrawPixel(int x, int y) const { ::DrawPixel(x, y, *this); }
/**
* Draw a pixel
*/
void DrawPixel(::Vector2 pos) const { ::DrawPixelV(pos, *this); }
/**
* Draw a line
*/
void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY) const {
::DrawLine(startPosX, startPosY, endPosX, endPosY, *this);
}
/**
* Draw a line using Vector points
*/
void DrawLine(::Vector2 startPos, ::Vector2 endPos) const { ::DrawLineV(startPos, endPos, *this); }
/**
* Draw a line using Vector points, with a given thickness
*/
void DrawLine(::Vector2 startPos, ::Vector2 endPos, float thick) const {
::DrawLineEx(startPos, endPos, thick, *this);
}
void DrawLineBezier(::Vector2 startPos, ::Vector2 endPos, float thick = 1.0f) const {
::DrawLineBezier(startPos, endPos, thick, *this);
}
void DrawLineStrip(::Vector2* points, int numPoints) const { ::DrawLineStrip(points, numPoints, *this); }
void DrawText(const char* text, int posX = 0, int posY = 0, int fontSize = 10.0f) const {
::DrawText(text, posX, posY, fontSize, *this);
}
void DrawText(const std::string& text, int posX = 0, int posY = 0, int fontSize = 10.0f) const {
::DrawText(text.c_str(), posX, posY, fontSize, *this);
}
void DrawText(const ::Font& font, const char* text, ::Vector2 position, float fontSize, float spacing) const {
::DrawTextEx(font, text, position, fontSize, spacing, *this);
}
void
DrawText(const ::Font& font, const std::string& text, ::Vector2 position, float fontSize, float spacing) const {
::DrawTextEx(font, text.c_str(), position, fontSize, spacing, *this);
}
void DrawText(
const ::Font& font,
const char* text,
::Vector2 position,
::Vector2 origin,
float rotation,
float fontSize,
float spacing) const {
::DrawTextPro(font, text, position, origin, rotation, fontSize, spacing, *this);
}
void DrawText(
const ::Font& font,
const std::string& text,
::Vector2 position,
::Vector2 origin,
float rotation,
float fontSize,
float spacing) const {
::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, *this);
}
void DrawRectangle(int posX, int posY, int width, int height) const {
::DrawRectangle(posX, posY, width, height, *this);
}
void DrawRectangle(::Vector2 position, ::Vector2 size) const { ::DrawRectangleV(position, size, *this); }
void DrawRectangle(::Rectangle rec) const { ::DrawRectangleRec(rec, *this); }
void DrawRectangle(::Rectangle rec, ::Vector2 origin, float rotation) const {
::DrawRectanglePro(rec, origin, rotation, *this);
}
void DrawRectangleLines(int posX, int posY, int width, int height) const {
::DrawRectangleLines(posX, posY, width, height, *this);
}
void DrawRectangleLines(::Rectangle rec, float lineThick) const { ::DrawRectangleLinesEx(rec, lineThick, *this); }
bool IsEqual(::Color color) {
return ::ColorIsEqual(*this, color);
}
bool operator==(const ::Color& other) const { return ::ColorIsEqual(*this, other); }
bool operator!=(const ::Color& other) const { return !::ColorIsEqual(*this, other); }
/**
* Get color multiplied with another color
*/
Color Tint(::Color tint) { return ::ColorTint(*this, tint); }
/**
* Get color with brightness correction, brightness factor goes from -1.0f to 1.0f
*/
Color Brightness(float factor) { return ::ColorBrightness(*this, factor); }
/**
* Get color with contrast correction, contrast values between -1.0f and 1.0f
*/
Color Contrast(float contrast) { return ::ColorContrast(*this, contrast); }
/**
* Returns color with alpha applied, alpha goes from 0.0f to 1.0f
*/
RLCPP_NODISCARD Color Alpha(float alpha) const { return ::ColorAlpha(*this, alpha); }
Color Lerp(::Color color2, float factor) {
return ::ColorLerp(*this, color2, factor);
}
/**
* Returns src alpha-blended into dst color with tint
*/
RLCPP_NODISCARD Color AlphaBlend(::Color dst, ::Color tint) const { return ::ColorAlphaBlend(dst, *this, tint); }
static Color LightGray() { return LIGHTGRAY; }
static Color Gray() { return GRAY; }
static Color DarkGray() { return DARKGRAY; }
static Color Yellow() { return YELLOW; }
static Color Gold() { return GOLD; }
static Color Orange() { return ORANGE; }
static Color Pink() { return PINK; }
static Color Red() { return RED; }
static Color Maroon() { return MAROON; }
static Color Green() { return GREEN; }
static Color Lime() { return LIME; }
static Color DarkGreen() { return DARKGREEN; }
static Color SkyBlue() { return SKYBLUE; }
static Color Blue() { return BLUE; }
static Color DarkBlue() { return DARKBLUE; }
static Color Purple() { return PURPLE; }
static Color Violet() { return VIOLET; }
static Color DarkPurple() { return DARKPURPLE; }
static Color Beige() { return BEIGE; }
static Color Brown() { return BROWN; }
static Color DarkBrown() { return DARKBROWN; }
static Color White() { return WHITE; }
static Color Black() { return BLACK; }
static Color Blank() { return BLANK; }
static Color Magenta() { return MAGENTA; }
static Color RayWhite() { return RAYWHITE; }
protected:
void set(const ::Color& color) {
r = color.r;
g = color.g;
b = color.b;
a = color.a;
}
};
} // namespace raylib
using RColor = raylib::Color;
#endif // RAYLIB_CPP_INCLUDE_COLOR_HPP_
+55
View File
@@ -0,0 +1,55 @@
#ifndef RAYLIB_CPP_INCLUDE_FILEDATA_HPP_
#define RAYLIB_CPP_INCLUDE_FILEDATA_HPP_
#include <string>
#include <utility>
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
class FileData {
public:
FileData() = default;
FileData(const FileData&) = delete;
FileData(FileData&& other) noexcept : data(other.data), bytesRead(other.bytesRead) {
other.data = nullptr;
other.bytesRead = 0;
}
FileData& operator=(const FileData&) = delete;
FileData& operator=(FileData&& other) noexcept {
std::swap(data, other.data);
std::swap(bytesRead, other.bytesRead);
return *this;
}
~FileData() { Unload(); }
explicit FileData(const std::string& fileName) { Load(fileName); }
GETTER(const unsigned char*, Data, data)
GETTER(int, BytesRead, bytesRead)
void Load(const std::string& fileName) { Load(fileName.c_str()); }
void Load(const char* fileName) {
Unload();
data = ::LoadFileData(fileName, &bytesRead);
}
void Unload() {
if (data != nullptr) {
::UnloadFileData(data);
data = nullptr;
bytesRead = 0;
}
}
private:
unsigned char* data{nullptr};
int bytesRead{0};
};
} // namespace raylib
using RFileData = raylib::FileData;
#endif // RAYLIB_CPP_INCLUDE_FILEDATA_HPP_
+60
View File
@@ -0,0 +1,60 @@
#ifndef RAYLIB_CPP_INCLUDE_FILETEXT_HPP_
#define RAYLIB_CPP_INCLUDE_FILETEXT_HPP_
#include <string>
#include <utility>
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
class FileText {
public:
FileText() = default;
FileText(const FileText&) = delete;
FileText(FileText&& other) noexcept : data(other.data), length(other.length) {
other.data = nullptr;
other.length = 0;
}
FileText& operator=(const FileText&) = delete;
FileText& operator=(FileText&& other) noexcept {
std::swap(data, other.data);
std::swap(length, other.length);
return *this;
}
~FileText() { Unload(); }
explicit FileText(const std::string& fileName) { Load(fileName); }
GETTER(const char*, Data, data)
GETTER(unsigned int, Length, length)
RLCPP_NODISCARD const char* c_str() const { return data; }
RLCPP_NODISCARD std::string ToString() const { return data; }
explicit operator std::string() const { return data; }
void Load(const std::string& fileName) { Load(fileName.c_str()); }
void Load(const char* fileName) {
data = ::LoadFileText(fileName);
length = ::TextLength(data);
}
void Unload() {
if (data != nullptr) {
::UnloadFileText(data);
data = nullptr;
length = 0;
}
}
private:
char* data{nullptr};
unsigned int length{0};
};
} // namespace raylib
using RFileText = raylib::FileText;
#endif // RAYLIB_CPP_INCLUDE_FILETEXT_HPP_
+84
View File
@@ -0,0 +1,84 @@
#ifndef RAYLIB_CPP_INCLUDE_FONT_HPP_
#define RAYLIB_CPP_INCLUDE_FONT_HPP_
#include "./FontUnmanaged.hpp"
namespace raylib {
/**
* Font type, includes texture and charSet array data.
*
* The font will be unloaded on object destruction. Use raylib::FontUnmanaged if you're looking to not unload.
*
* @see raylib::FontUnmanaged
*/
class Font : public FontUnmanaged {
public:
using FontUnmanaged::FontUnmanaged;
Font(const Font&) = delete;
Font& operator=(const Font&) = delete;
Font(Font&& other) noexcept {
set(other);
other.baseSize = 0;
other.glyphCount = 0;
other.glyphPadding = 0;
other.texture = {};
other.recs = nullptr;
other.glyphs = nullptr;
}
Font& operator=(Font&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.baseSize = 0;
other.glyphCount = 0;
other.glyphPadding = 0;
other.texture = {};
other.recs = nullptr;
other.glyphs = nullptr;
return *this;
}
Font& operator=(const ::Font& font) {
Unload();
set(font);
return *this;
}
~Font() { Unload(); }
void Load(const std::string& fileName) {
Unload();
FontUnmanaged::Load(fileName);
}
void Load(const std::string& fileName, int fontSize, const int* codepoints = nullptr, int codepointCount = 0) {
Unload();
FontUnmanaged::Load(fileName, fontSize, codepoints, codepointCount);
}
void Load(const ::Image& image, ::Color key, int firstChar) {
Unload();
FontUnmanaged::Load(image, key, firstChar);
}
void Load(
const std::string& fileType,
const unsigned char* fileData,
int dataSize,
int fontSize,
const int* codepoints,
int codepointCount) {
Unload();
FontUnmanaged::Load(fileType, fileData, dataSize, fontSize, codepoints, codepointCount);
}
};
} // namespace raylib
using RFont = raylib::Font;
#endif // RAYLIB_CPP_INCLUDE_FONT_HPP_
+312
View File
@@ -0,0 +1,312 @@
#ifndef RAYLIB_CPP_INCLUDE_FONTUNMANAGED_HPP_
#define RAYLIB_CPP_INCLUDE_FONTUNMANAGED_HPP_
#include <string>
#include "./RaylibException.hpp"
#include "./TextureUnmanaged.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* A Font that is not managed by C++ RAII.
*
* Make sure to Unload() this if needed, otherwise use raylib::Font.
*
* @see raylib::Font
*/
class FontUnmanaged : public ::Font {
public:
FontUnmanaged(
int baseSize,
int glyphCount,
int glyphPadding,
::Texture2D texture,
::Rectangle* recs = nullptr,
::GlyphInfo* glyphs = nullptr)
: ::Font{baseSize, glyphCount, glyphPadding, texture, recs, glyphs} {
// Nothing.
}
/**
* Retrieves the default Font.
*/
FontUnmanaged() : ::Font(::GetFontDefault()) {}
/**
* Creates a FontUnmanaged from an existing Font struct.
*/
FontUnmanaged(const ::Font& font) : ::Font(font) {}
/**
* Loads a Font from the given file.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*/
FontUnmanaged(const std::string& fileName) { Load(fileName); }
/**
* Loads a Font from the given file, with generation parameters.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*/
FontUnmanaged(const std::string& fileName, int fontSize, const int* codepoints = nullptr, int codepointCount = 0) {
Load(fileName, fontSize, codepoints, codepointCount);
}
/**
* Loads a Font from the given image with a color key.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*/
FontUnmanaged(const ::Image& image, ::Color key, int firstChar) { Load(image, key, firstChar); }
/**
* Loads a font from memory, based on the given file type and file data.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*/
FontUnmanaged(
const std::string& fileType,
const unsigned char* fileData,
int dataSize,
int fontSize,
const int* codepoints,
int codepointCount) {
Load(fileType, fileData, dataSize, fontSize, codepoints, codepointCount);
}
GETTER(int, BaseSize, baseSize)
GETTER(int, GlyphCount, glyphCount)
GETTER(int, GlyphPadding, glyphPadding)
GETTER(::Rectangle*, Recs, recs)
GETTER(::GlyphInfo*, Glyphs, glyphs)
/**
* Get the texture atlas containing the glyphs.
*/
TextureUnmanaged GetTexture() { return texture; }
RLCPP_NODISCARD TextureUnmanaged GetTexture() const { return texture; }
/**
* Set the texture atlas containing the glyphs.
*/
void SetTexture(const ::Texture& newTexture) { texture = newTexture; }
FontUnmanaged& operator=(const ::Font& font) {
set(font);
return *this;
}
/**
* Loads a font from a given file.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*/
void Load(const std::string& fileName) {
set(::LoadFont(fileName.c_str()));
if (!IsValid()) {
throw RaylibException("Failed to load Font with from file: " + fileName);
}
}
/**
* Loads a font from a given file with generation parameters.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*/
void Load(const std::string& fileName, int fontSize, const int* codepoints = nullptr, int codepointCount = 0) {
set(::LoadFontEx(fileName.c_str(), fontSize, codepoints, codepointCount));
if (!IsValid()) {
throw RaylibException("Failed to load Font with from file with font size: " + fileName);
}
}
/**
* Loads a font from an image with a color key.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*/
void Load(const ::Image& image, ::Color key, int firstChar) {
set(::LoadFontFromImage(image, key, firstChar));
if (!IsValid()) {
throw RaylibException("Failed to load Font with from image");
}
}
/**
* Loads a font from memory.
*
* @throws raylib::RaylibException Throws if the given font failed to initialize.
*/
void Load(
const std::string& fileType,
const unsigned char* fileData,
int dataSize,
int fontSize,
const int* codepoints,
int codepointCount) {
set(::LoadFontFromMemory(fileType.c_str(), fileData, dataSize, fontSize, codepoints, codepointCount));
if (!IsValid()) {
throw RaylibException("Failed to load Font " + fileType + " with from file data");
}
}
/**
* Unload font from memory.
*/
void Unload() {
// Protect against calling UnloadFont() twice.
if (baseSize != 0) {
::UnloadFont(*this);
baseSize = 0;
}
}
/**
* Returns if the font is ready to be used.
*/
RLCPP_NODISCARD bool IsValid() const { return ::IsFontValid(*this); }
/**
* Draw text using font and additional parameters.
*/
void DrawText(const char* text, ::Vector2 position, float fontSize, float spacing, ::Color tint = WHITE) const {
::DrawTextEx(*this, text, position, fontSize, spacing, tint);
}
/**
* Draw text using font and additional parameters.
*/
void DrawText(
const std::string& text,
::Vector2 position,
float fontSize,
float spacing,
::Color tint = WHITE) const {
::DrawTextEx(*this, text.c_str(), position, fontSize, spacing, tint);
}
/**
* Draw text using font and additional parameters.
*/
void DrawText(const char* text, int posX, int posY, float fontSize, float spacing, ::Color tint = WHITE) const {
::DrawTextEx(*this, text, {static_cast<float>(posX), static_cast<float>(posY)}, fontSize, spacing, tint);
}
/**
* Draw text using font and additional parameters.
*/
void DrawText(
const std::string& text,
int posX,
int posY,
float fontSize,
float spacing,
::Color tint = WHITE) const {
::DrawTextEx(
*this,
text.c_str(),
{static_cast<float>(posX), static_cast<float>(posY)},
fontSize,
spacing,
tint);
}
/**
* Draw text using font with pro parameters (rotation).
*/
void DrawText(
const char* text,
::Vector2 position,
::Vector2 origin,
float rotation,
float fontSize,
float spacing,
::Color tint = WHITE) const {
::DrawTextPro(*this, text, position, origin, rotation, fontSize, spacing, tint);
}
/**
* Draw text using font with pro parameters (rotation).
*/
void DrawText(
const std::string& text,
::Vector2 position,
::Vector2 origin,
float rotation,
float fontSize,
float spacing,
::Color tint = WHITE) const {
::DrawTextPro(*this, text.c_str(), position, origin, rotation, fontSize, spacing, tint);
}
/**
* Draw one character (codepoint).
*/
void DrawText(int codepoint, ::Vector2 position, float fontSize, ::Color tint = {255, 255, 255, 255}) const {
::DrawTextCodepoint(*this, codepoint, position, fontSize, tint);
}
/**
* Draw multiple characters (codepoints).
*/
void DrawText(
const int* codepoints,
int count,
::Vector2 position,
float fontSize,
float spacing,
::Color tint = {255, 255, 255, 255}) const {
::DrawTextCodepoints(*this, codepoints, count, position, fontSize, spacing, tint);
}
/**
* Measure string size for Font.
*/
RLCPP_NODISCARD Vector2 MeasureText(const char* text, float fontSize, float spacing) const {
return ::MeasureTextEx(*this, text, fontSize, spacing);
}
/**
* Measure string size for Font.
*/
RLCPP_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.
*/
RLCPP_NODISCARD int GetGlyphIndex(int character) const { return ::GetGlyphIndex(*this, character); }
/**
* Create an image from text (custom sprite font).
*/
RLCPP_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).
*/
RLCPP_NODISCARD ::Image ImageText(const std::string& text, float fontSize, float spacing, ::Color tint) const {
return ::ImageTextEx(*this, text.c_str(), fontSize, spacing, tint);
}
protected:
void set(const ::Font& font) {
baseSize = font.baseSize;
glyphCount = font.glyphCount;
glyphPadding = font.glyphPadding;
texture = font.texture;
recs = font.recs;
glyphs = font.glyphs;
}
};
} // namespace raylib
using RFontUnmanaged = raylib::FontUnmanaged;
#endif // RAYLIB_CPP_INCLUDE_FONTUNMANAGED_HPP_
+464
View File
@@ -0,0 +1,464 @@
/**
* C++ wrapper functions for raylib.
*/
#ifndef RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
#define RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
#include <string>
#include <vector>
#include "./raylib.hpp"
/**
* Allow changing the declare type for all raylib-cpp global functions. Defaults to static.
*/
#ifndef RLCPPAPI
#define RLCPPAPI static
#endif
namespace raylib {
/**
* Initialize window and OpenGL context
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline void InitWindow(int width, int height, const std::string& title = "raylib") {
::InitWindow(width, height, title.c_str());
}
/**
* Set title for window
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline void SetWindowTitle(const std::string& title) {
::SetWindowTitle(title.c_str());
}
/**
* Get the human-readable, UTF-8 encoded name of the primary monitor
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string GetMonitorName(int monitor = 0) {
return ::GetMonitorName(monitor);
}
/**
* Set clipboard text content
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline void SetClipboardText(const std::string& text) {
::SetClipboardText(text.c_str());
}
/**
* Get clipboard text content
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string GetClipboardText() {
return ::GetClipboardText();
}
/**
* Takes a screenshot of current screen (saved a .png)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline void TakeScreenshot(const std::string& fileName) {
::TakeScreenshot(fileName.c_str());
}
/**
* Get gamepad internal name id
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string GetGamepadName(int gamepad) {
return ::GetGamepadName(gamepad);
}
/**
* Load text data from file (read)
*/
RLCPP_MAYBEUNUSED RLCPPAPI std::string LoadFileText(const std::string& fileName) {
char* text = ::LoadFileText(fileName.c_str());
std::string output(text);
::UnloadFileText(text);
return output;
}
/**
* Save text data to file (write)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool SaveFileText(const std::string& fileName, const std::string& text) {
return ::SaveFileText(fileName.c_str(), text.c_str());
}
/**
* Check if file exists
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool FileExists(const std::string& fileName) {
return ::FileExists(fileName.c_str());
}
/**
* Check if directory path exists
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool DirectoryExists(const std::string& dirPath) {
return ::DirectoryExists(dirPath.c_str());
}
/**
* Check file extension (including point: .png, .wav)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool IsFileExtension(const std::string& fileName, const std::string& ext) {
return ::IsFileExtension(fileName.c_str(), ext.c_str());
}
/**
* Get pointer to extension for a filename string (including point: ".png")
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string GetFileExtension(const std::string& fileName) {
return ::GetFileExtension(fileName.c_str());
}
/**
* Get pointer to filename for a path string
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string GetFileName(const std::string& filePath) {
return ::GetFileName(filePath.c_str());
}
/**
* Get filename string without extension
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string GetFileNameWithoutExt(const std::string& filePath) {
return ::GetFileNameWithoutExt(filePath.c_str());
}
/**
* Get full path for a given fileName with path
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string GetDirectoryPath(const std::string& filePath) {
return ::GetDirectoryPath(filePath.c_str());
}
/**
* Get previous directory path for a given path
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string GetPrevDirectoryPath(const std::string& dirPath) {
return ::GetPrevDirectoryPath(dirPath.c_str());
}
/**
* Get current working directory
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string GetWorkingDirectory() {
return ::GetWorkingDirectory();
}
/**
* Get filenames in a directory path
*/
RLCPP_MAYBEUNUSED RLCPPAPI std::vector<std::string> LoadDirectoryFiles(const std::string& dirPath) {
FilePathList files = ::LoadDirectoryFiles(dirPath.c_str());
std::vector<std::string> output(files.paths, files.paths + files.count);
::UnloadDirectoryFiles(files);
return output;
}
/**
* Load directory filepaths with extension filtering and optional subdirectory scanning
*/
RLCPP_MAYBEUNUSED RLCPPAPI std::vector<std::string>
LoadDirectoryFilesEx(const std::string& basePath, const std::string& filter, bool scanSubdirs = false) {
FilePathList files = ::LoadDirectoryFilesEx(basePath.c_str(), filter.c_str(), scanSubdirs);
std::vector<std::string> output(files.paths, files.paths + files.count);
::UnloadDirectoryFiles(files);
return output;
}
/**
* Change working directory, return true on success
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool ChangeDirectory(const std::string& dir) {
return ::ChangeDirectory(dir.c_str());
}
/**
* Get dropped files names
*/
RLCPP_MAYBEUNUSED RLCPPAPI std::vector<std::string> LoadDroppedFiles() {
if (!::IsFileDropped()) {
return std::vector<std::string>();
}
FilePathList files = ::LoadDroppedFiles();
std::vector<std::string> output(files.paths, files.paths + files.count);
::UnloadDroppedFiles(files);
return output;
}
/**
* Get file modification time (last write time)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline long GetFileModTime(const std::string& fileName) { // NOLINT
return ::GetFileModTime(fileName.c_str());
}
/**
* Open URL with default system browser (if available)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline void OpenURL(const std::string& url) {
return ::OpenURL(url.c_str());
}
/**
* Load an image.
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline ::Image LoadImage(const std::string& fileName) {
return ::LoadImage(fileName.c_str());
}
/**
* Load an image from RAW file data
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline ::Image
LoadImageRaw(const std::string& fileName, int width, int height, int format, int headerSize) {
return ::LoadImageRaw(fileName.c_str(), width, height, format, headerSize);
}
/**
* Load animated image data
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline ::Image LoadImageAnim(const std::string& fileName, int* frames) {
return ::LoadImageAnim(fileName.c_str(), frames);
}
/**
* Load image from memory buffer, fileType refers to extension like "png"
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline ::Image
LoadImageFromMemory(const std::string& fileType, const unsigned char* fileData, int dataSize) {
return ::LoadImageFromMemory(fileType.c_str(), fileData, dataSize);
}
/**
* Export image data to file
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool ExportImage(const Image& image, const std::string& fileName) {
return ::ExportImage(image, fileName.c_str());
}
/**
* Export image as code file (.h) defining an array of bytes
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool ExportImageAsCode(const Image& image, const std::string& fileName) {
return ::ExportImageAsCode(image, fileName.c_str());
}
/**
* Draw text (using default font)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline void DrawText(const char* text, int posX, int posY, int fontSize, ::Color color) {
::DrawText(text, posX, posY, fontSize, color);
}
/**
* Draw text (using default font)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline void
DrawText(const std::string& text, int posX, int posY, int fontSize, ::Color color) {
::DrawText(text.c_str(), posX, posY, fontSize, color);
}
/**
* Draw text using font and additional parameters
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline void
DrawTextEx(const Font& font, const char* text, Vector2 position, float fontSize, float spacing, ::Color tint) {
::DrawTextEx(font, text, position, fontSize, spacing, tint);
}
/**
* Draw text using font and additional parameters
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline void
DrawTextEx(const Font& font, const std::string& text, Vector2 position, float fontSize, float spacing, ::Color tint) {
::DrawTextEx(font, text.c_str(), position, fontSize, spacing, tint);
}
/**
* Draw text using Font and pro parameters (rotation)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline void DrawTextPro(
const Font& font,
const char* text,
Vector2 position,
Vector2 origin,
float rotation,
float fontSize,
float spacing,
::Color tint) {
::DrawTextPro(font, text, position, origin, rotation, fontSize, spacing, tint);
}
/**
* Draw text using Font and pro parameters (rotation)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline void DrawTextPro(
const Font& font,
const std::string& text,
Vector2 position,
Vector2 origin,
float rotation,
float fontSize,
float spacing,
::Color tint) {
::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, tint);
}
/**
* Load font from file (filename must include file extension)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline ::Font LoadFont(const std::string& fileName) {
return ::LoadFont(fileName.c_str());
}
/**
* Load font from file (filename must include file extension)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline ::Font
LoadFontEx(const std::string& fileName, int fontSize, const int* codepoints = nullptr, int codepointCount = 0) {
return ::LoadFontEx(fileName.c_str(), fontSize, codepoints, codepointCount);
}
/**
* Measure string width for default font
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline int MeasureText(const char* text, int fontSize) {
return ::MeasureText(text, fontSize);
}
/**
* Measure string width for default font
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline int MeasureText(const std::string& text, int fontSize) {
return ::MeasureText(text.c_str(), fontSize);
}
/**
* Check if two text string are equal
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool TextIsEqual(const char* text1, const char* text2) {
return ::TextIsEqual(text1, text2);
}
/**
* Check if two text string are equal
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool TextIsEqual(const std::string& text1, const std::string& text2) {
return ::TextIsEqual(text1.c_str(), text2.c_str());
}
/**
* Get text length, checks for '\0' ending
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline unsigned int TextLength(const char* text) {
return ::TextLength(text);
}
/**
* Get text length, checks for '\0' ending
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline unsigned int TextLength(const std::string& text) {
return ::TextLength(text.c_str());
}
/**
* Get a piece of a text string
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string TextSubtext(const std::string& text, int position, int length) {
return ::TextSubtext(text.c_str(), position, length);
}
/**
* Replace text string
*/
RLCPP_MAYBEUNUSED RLCPPAPI std::string
TextReplace(const std::string& text, const std::string& replace, const std::string& by) {
const char* output = ::TextReplace(text.c_str(), replace.c_str(), by.c_str());
if (output != NULL) {
return std::string(output);
}
return "";
}
/**
* Insert text in a position
*/
RLCPP_MAYBEUNUSED RLCPPAPI std::string TextInsert(const std::string& text, const std::string& insert, int position) {
const char* output = ::TextInsert(text.c_str(), insert.c_str(), position);
if (output != NULL) {
return std::string(output);
}
return "";
}
/**
* Split text into multiple strings
*/
RLCPP_MAYBEUNUSED RLCPPAPI std::vector<std::string> TextSplit(const std::string& text, char delimiter) {
int count;
const char* const* split = ::TextSplit(text.c_str(), delimiter, &count);
return std::vector<std::string>(split, split + count);
}
/**
* Find first text occurrence within a string
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline int TextFindIndex(const std::string& text, const std::string& find) {
return ::TextFindIndex(text.c_str(), find.c_str());
}
/**
* Get upper case version of provided string
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string TextToUpper(const std::string& text) {
return ::TextToUpper(text.c_str());
}
/**
* Get lower case version of provided string
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string TextToLower(const std::string& text) {
return ::TextToLower(text.c_str());
}
/**
* Get Pascal case notation version of provided string
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string TextToPascal(const std::string& text) {
return ::TextToPascal(text.c_str());
}
/**
* Get Snake case notation version of provided string
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string TextToSnake(const std::string& text) {
return ::TextToSnake(text.c_str());
}
/**
* Get Camel case notation version of provided string
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline std::string TextToCamel(const std::string& text) {
return ::TextToCamel(text.c_str());
}
/**
* Get integer value from text (negative values not supported)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline int TextToInteger(const std::string& text) {
return ::TextToInteger(text.c_str());
}
/**
* Get float value from text
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline float TextToFloat(const std::string& text) {
return ::TextToFloat(text.c_str());
}
} // namespace raylib
#endif // RAYLIB_CPP_INCLUDE_FUNCTIONS_HPP_
+106
View File
@@ -0,0 +1,106 @@
#ifndef RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
#define RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
#include <string>
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Input-related functions: gamepads
*/
class Gamepad {
public:
Gamepad(int gamepadNumber = 0) : number(gamepadNumber) {};
int number;
GETTERSETTER(int, Number, number)
Gamepad& operator=(const Gamepad& gamepad) {
if (this != &gamepad) {
set(static_cast<int>(gamepad));
}
return *this;
}
Gamepad& operator=(int gamepadNumber) {
if (this->number != gamepadNumber) {
set(gamepadNumber);
}
return *this;
}
explicit operator int() const { return number; }
/**
* Detect if a gamepad is available
*/
RLCPP_NODISCARD bool IsAvailable() const { return ::IsGamepadAvailable(number); }
/**
* Detect if a gamepad is available
*/
static bool IsAvailable(int number) { return ::IsGamepadAvailable(number); }
/**
* Return gamepad internal name id
*/
RLCPP_NODISCARD std::string GetName() const { return ::GetGamepadName(number); }
/**
* Return gamepad internal name id
*/
explicit operator std::string() const { return GetName(); }
/**
* Detect if a gamepad button has been pressed once
*/
RLCPP_NODISCARD bool IsButtonPressed(int button) const { return ::IsGamepadButtonPressed(number, button); }
/**
* Detect if a gamepad button is being pressed
*/
RLCPP_NODISCARD bool IsButtonDown(int button) const { return ::IsGamepadButtonDown(number, button); }
/**
* Detect if a gamepad button has been released once
*/
RLCPP_NODISCARD bool IsButtonReleased(int button) const { return ::IsGamepadButtonReleased(number, button); }
/**
* Detect if a gamepad button is NOT being pressed
*/
RLCPP_NODISCARD bool IsButtonUp(int button) const { return ::IsGamepadButtonUp(number, button); }
/**
* Get the last gamepad button pressed
*/
static int GetButtonPressed() { return ::GetGamepadButtonPressed(); }
/**
* Return gamepad axis count for a gamepad
*/
RLCPP_NODISCARD int GetAxisCount() const { return ::GetGamepadAxisCount(number); }
/**
* Return axis movement value for a gamepad axis
*/
RLCPP_NODISCARD float GetAxisMovement(int axis) const { return ::GetGamepadAxisMovement(number, axis); }
static int SetMappings(const std::string& mappings) { return SetGamepadMappings(mappings.c_str()); }
/**
* Set gamepad vibration for both motors (duration in seconds)
*/
void SetVibration(float leftMotor, float rightMotor, float duration) const {
::SetGamepadVibration(number, leftMotor, rightMotor, duration);
}
protected:
void set(int gamepadNumber) { number = gamepadNumber; }
};
} // namespace raylib
using RGamepad = raylib::Gamepad;
#endif // RAYLIB_CPP_INCLUDE_GAMEPAD_HPP_
+775
View File
@@ -0,0 +1,775 @@
#ifndef RAYLIB_CPP_INCLUDE_IMAGE_HPP_
#define RAYLIB_CPP_INCLUDE_IMAGE_HPP_
#include <string>
#include "./Color.hpp"
#include "./RaylibException.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Image type, bpp always RGBA (32bit)
*
* Data stored in CPU memory (RAM)
*/
class Image : public ::Image {
public:
Image(
void* data = nullptr,
int width = 0,
int height = 0,
int mipmaps = 1,
int format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
: ::Image{data, width, height, mipmaps, format} {
// Nothing.
}
Image(const ::Image& image) : ::Image(image) { }
/**
* Load an image from the given file.
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*
* @see Load()
*/
Image(const std::string& fileName) { Load(fileName); }
/**
* Load a raw image from the given file, with the provided width, height, and formats.
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*
* @see LoadRaw()
*/
Image(const std::string& fileName, int width, int height, int format, int headerSize = 0) {
Load(fileName, width, height, format, headerSize);
}
/**
* Load an animation image from the given file.
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*
* @see LoadAnim()
*/
Image(const std::string& fileName, int* frames) { Load(fileName, frames); }
/**
* Load an image from the given file.
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*/
Image(const std::string& fileType, const unsigned char* fileData, int dataSize) {
Load(fileType, fileData, dataSize);
}
/**
* Load an image from the given file.
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*/
Image(const ::Texture2D& texture) { Load(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));
}
Image(const Image& other) { set(other.Copy()); }
Image(Image&& other) noexcept {
set(other);
other.data = nullptr;
other.width = 0;
other.height = 0;
other.mipmaps = 0;
other.format = 0;
}
[[nodiscard]] std::string ToString() const { return TextFormat("Image(width=%d, height=%d)", width, height); }
operator std::string() const { return ToString(); }
static ::Image Text(const std::string& text, int fontSize, ::Color color = {255, 255, 255, 255}) {
return ::ImageText(text.c_str(), fontSize, color);
}
static ::Image Text(
const ::Font& font,
const std::string& text,
float fontSize,
float spacing,
::Color tint = {255, 255, 255, 255}) {
return ::ImageTextEx(font, text.c_str(), fontSize, spacing, tint);
}
/**
* Get pixel data from screen buffer and return an Image (screenshot)
*/
static ::Image LoadFromScreen() { return ::LoadImageFromScreen(); }
/**
* Generate image: plain color
*/
static ::Image Color(int width, int height, ::Color color = {255, 255, 255, 255}) {
return ::GenImageColor(width, height, color);
}
/**
* Generate image: linear gradient
*/
static ::Image GradientLinear(int width, int height, int direction, ::Color start, ::Color end) {
return ::GenImageGradientLinear(width, height, direction, start, end);
}
/**
* Generate image: radial gradient
*/
static ::Image GradientRadial(int width, int height, float density, ::Color inner, ::Color outer) {
return ::GenImageGradientRadial(width, height, density, inner, outer);
}
/**
* Generate image: checked
*/
static ::Image Checked(
int width,
int height,
int checksX,
int checksY,
::Color col1 = {255, 255, 255, 255},
::Color col2 = {0, 0, 0, 255}) {
return ::GenImageChecked(width, height, checksX, checksY, col1, col2);
}
/**
* Generate image: white noise
*/
static ::Image WhiteNoise(int width, int height, float factor) {
return ::GenImageWhiteNoise(width, height, factor);
}
/**
* Generate image: cellular algorithm. Bigger tileSize means bigger cells
*/
static ::Image Cellular(int width, int height, int tileSize) { return ::GenImageCellular(width, height, tileSize); }
/**
* Get clipboard image content.
*/
static ::Image GetClipboard() { return ::GetClipboardImage(); }
~Image() { Unload(); }
Image& operator=(const ::Image& image) {
set(image);
return *this;
}
Image& operator=(const Image& other) {
if (this == &other) {
return *this;
}
Unload();
set(other.Copy());
return *this;
}
Image& operator=(Image&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.data = nullptr;
other.width = 0;
other.height = 0;
other.mipmaps = 0;
other.format = 0;
return *this;
}
/**
* Load image from file into CPU memory (RAM)
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*
* @see ::LoadImage()
*/
void Load(const std::string& fileName) {
set(::LoadImage(fileName.c_str()));
if (!IsValid()) {
throw RaylibException("Failed to load Image from file: " + fileName);
}
}
/**
* Load image from RAW file data.
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*
* @see ::LoadImageRaw()
*/
void Load(const std::string& fileName, int width, int height, int format, int headerSize) {
set(::LoadImageRaw(fileName.c_str(), width, height, format, headerSize));
if (!IsValid()) {
throw RaylibException("Failed to load Image from file: " + fileName);
}
}
/**
* Load image sequence from file (frames appended to image.data).
*
* @throws raylib::RaylibException Thrown if the image animation to load from the file.
*
* @see ::LoadImageAnim()
*/
void Load(const std::string& fileName, int* frames) {
set(::LoadImageAnim(fileName.c_str(), frames));
if (!IsValid()) {
throw RaylibException("Failed to load Image from file: " + fileName);
}
}
/**
* Load image from memory buffer, fileType refers to extension: i.e. "png".
*
* @throws raylib::RaylibException Thrown if the image animation to load from the file.
*
* @see ::LoadImageFromMemory()
*/
void Load(const std::string& fileType, const unsigned char* fileData, int dataSize) {
set(::LoadImageFromMemory(fileType.c_str(), fileData, dataSize));
if (!IsValid()) {
throw RaylibException("Failed to load Image data with file type: " + fileType);
}
}
/**
* Load an image from the given file.
*
* @throws raylib::RaylibException Thrown if the image animation to load from the file.
*
* @see ::LoadImageFromTexture()
*/
void Load(const ::Texture2D& texture) {
set(::LoadImageFromTexture(texture));
if (!IsValid()) {
throw RaylibException("Failed to load Image from texture.");
}
}
/**
* Unload image from CPU memory (RAM)
*/
void Unload() {
if (data != nullptr) {
::UnloadImage(*this);
data = nullptr;
}
}
/**
* Export image data to file, returns true on success
*
* @throws raylib::RaylibException Thrown if the image failed to load from the file.
*/
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 to memory buffer
*/
unsigned char* ExportToMemory(const char* fileType, int* fileSize) {
return ::ExportImageToMemory(*this, fileType, fileSize);
}
/**
* 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.
*/
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()));
}
}
GETTER(void*, Data, data)
GETTER(int, Width, width)
GETTER(int, Height, height)
GETTER(int, Mipmaps, mipmaps)
GETTER(int, Format, format)
/**
* Set the width of the image canvas.
*
* @see ResizeCanvas
*/
void SetWidth(int width, int offsetX = 0, int offsetY = 0, ::Color fill = {255, 255, 255, 255}) {
ResizeCanvas(width, height, offsetX, offsetY, fill);
}
/**
* Set the height of the image canvas.
*
* @see ResizeCanvas
*/
void SetHeight(int height, int offsetX = 0, int offsetY = 0, ::Color fill = {255, 255, 255, 255}) {
ResizeCanvas(width, height, offsetX, offsetY, fill);
}
/**
* Retrieve the width and height of the image.
*/
RLCPP_NODISCARD ::Vector2 GetSize() const { return {static_cast<float>(width), static_cast<float>(height)}; }
/**
* Create an image duplicate (useful for transformations)
*/
RLCPP_NODISCARD ::Image Copy() const { return ::ImageCopy(*this); }
/**
* Create an image from another image piece
*/
RLCPP_NODISCARD ::Image FromImage(::Rectangle rec) const { return ::ImageFromImage(*this, rec); }
/**
* Convert image data to desired format
*/
Image& Format(int newFormat) {
::ImageFormat(this, newFormat);
return *this;
}
/**
* Convert image to POT (power-of-two)
*/
Image& ToPOT(::Color fillColor) {
::ImageToPOT(this, fillColor);
return *this;
}
/**
* Crop an image to area defined by a rectangle
*/
Image& Crop(::Rectangle crop) {
::ImageCrop(this, crop);
return *this;
}
/**
* Crop image depending on alpha value
*/
Image& AlphaCrop(float threshold) {
::ImageAlphaCrop(this, threshold);
return *this;
}
/**
* Clear alpha channel to desired color
*/
Image& AlphaClear(::Color color, float threshold) {
::ImageAlphaClear(this, color, threshold);
return *this;
}
/**
* Apply alpha mask to image
*/
Image& AlphaMask(const ::Image& alphaMask) {
::ImageAlphaMask(this, alphaMask);
return *this;
}
/**
* Premultiply alpha channel
*/
Image& AlphaPremultiply() {
::ImageAlphaPremultiply(this);
return *this;
}
/**
* Crop an image to a new given width and height.
*/
Image& Crop(int newWidth, int newHeight) { return Crop(0, 0, newWidth, newHeight); }
/**
* Crop an image to a new given width and height based on a vector.
*/
Image& Crop(::Vector2 size) { return Crop(0, 0, static_cast<int>(size.x), static_cast<int>(size.y)); }
/**
* Crop an image to area defined by a rectangle
*/
Image& Crop(int offsetX, int offsetY, int newWidth, int newHeight) {
::Rectangle rect{
static_cast<float>(offsetX),
static_cast<float>(offsetY),
static_cast<float>(newWidth),
static_cast<float>(newHeight)};
::ImageCrop(this, rect);
return *this;
}
/**
* Resize and image to new size
*/
Image& Resize(int newWidth, int newHeight) {
::ImageResize(this, newWidth, newHeight);
return *this;
}
/**
* Resize and image to new size using Nearest-Neighbor scaling algorithm
*/
Image& ResizeNN(int newWidth, int newHeight) {
::ImageResizeNN(this, newWidth, newHeight);
return *this;
}
/**
* Resize canvas and fill with color
*/
Image&
ResizeCanvas(int newWidth, int newHeight, int offsetX = 0, int offsetY = 0, ::Color color = {255, 255, 255, 255}) {
::ImageResizeCanvas(this, newWidth, newHeight, offsetX, offsetY, color);
return *this;
}
/**
* Generate all mipmap levels for a provided image
*/
Image& Mipmaps() {
::ImageMipmaps(this);
return *this;
}
/**
* Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
*/
Image& Dither(int rBpp, int gBpp, int bBpp, int aBpp) {
::ImageDither(this, rBpp, gBpp, bBpp, aBpp);
return *this;
}
/**
* Flip image vertically
*/
Image& FlipVertical() {
::ImageFlipVertical(this);
return *this;
}
/**
* Flip image horizontally
*/
Image& FlipHorizontal() {
::ImageFlipHorizontal(this);
return *this;
}
/**
* Rotate image by input angle in degrees (-359 to 359)
*/
Image& Rotate(int degrees) {
::ImageRotate(this, degrees);
return *this;
}
/**
* Rotate image clockwise 90deg
*/
Image& RotateCW() {
::ImageRotateCW(this);
return *this;
}
/**
* Rotate image counter-clockwise 90deg
*/
Image& RotateCCW() {
::ImageRotateCCW(this);
return *this;
}
/**
* Modify image color: tint
*/
Image& ColorTint(::Color color = {255, 255, 255, 255}) {
::ImageColorTint(this, color);
return *this;
}
/**
* Modify image color: invert
*/
Image& ColorInvert() {
::ImageColorInvert(this);
return *this;
}
/**
* Modify image color: grayscale
*/
Image& ColorGrayscale() {
::ImageColorGrayscale(this);
return *this;
}
/**
* Modify image color: contrast
*
* @param contrast Contrast values between -100 and 100
*/
Image& ColorContrast(float contrast) {
::ImageColorContrast(this, contrast);
return *this;
}
/**
* Modify image color: brightness
*
* @param brightness Brightness values between -255 and 255
*/
Image& ColorBrightness(int brightness) {
::ImageColorBrightness(this, brightness);
return *this;
}
/**
* Modify image color: replace color
*/
Image& ColorReplace(::Color color, ::Color replace) {
::ImageColorReplace(this, color, replace);
return *this;
}
/**
* Get image alpha border rectangle
*
* @param threshold Threshold is defined as a percentatge: 0.0f -> 1.0f
*/
RLCPP_NODISCARD Rectangle GetAlphaBorder(float threshold) const { return ::GetImageAlphaBorder(*this, threshold); }
/**
* Get image pixel color at (x, y) position
*/
RLCPP_NODISCARD raylib::Color GetColor(int x = 0, int y = 0) const { return ::GetImageColor(*this, x, y); }
/**
* Get image pixel color at vector position
*/
RLCPP_NODISCARD raylib::Color GetColor(::Vector2 position) const {
return ::GetImageColor(*this, static_cast<int>(position.x), static_cast<int>(position.y));
}
/**
* Clear image background with given color
*/
Image& ClearBackground(::Color color = {0, 0, 0, 255}) {
::ImageClearBackground(this, color);
return *this;
}
/**
* Draw pixel within an image
*/
void DrawPixel(int posX, int posY, ::Color color = {255, 255, 255, 255}) {
::ImageDrawPixel(this, posX, posY, color);
}
void DrawPixel(::Vector2 position, ::Color color = {255, 255, 255, 255}) {
::ImageDrawPixelV(this, position, color);
}
void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, ::Color color = {255, 255, 255, 255}) {
::ImageDrawLine(this, startPosX, startPosY, endPosX, endPosY, color);
}
void DrawLine(::Vector2 start, ::Vector2 end, ::Color color = {255, 255, 255, 255}) {
::ImageDrawLineV(this, start, end, color);
}
/**
* Description: Draw a line defining thickness within an image
*/
void DrawLine(::Vector2 start, ::Vector2 end, int thick, ::Color color = {255, 255, 255, 255}) {
ImageDrawLineEx(this, start, end, thick, color);
}
void DrawCircle(int centerX, int centerY, int radius, ::Color color = {255, 255, 255, 255}) {
::ImageDrawCircle(this, centerX, centerY, radius, color);
}
void DrawCircle(::Vector2 center, int radius, ::Color color = {255, 255, 255, 255}) {
::ImageDrawCircleV(this, center, radius, color);
}
void DrawRectangle(int posX, int posY, int width, int height, ::Color color = {255, 255, 255, 255}) {
::ImageDrawRectangle(this, posX, posY, width, height, color);
}
void DrawRectangle(Vector2 position, Vector2 size, ::Color color = {255, 255, 255, 255}) {
::ImageDrawRectangleV(this, position, size, color);
}
void DrawRectangle(::Rectangle rec, ::Color color = {255, 255, 255, 255}) {
::ImageDrawRectangleRec(this, rec, color);
}
void DrawRectangleLines(::Rectangle rec, int thick = 1, ::Color color = {255, 255, 255, 255}) {
::ImageDrawRectangleLines(this, rec, thick, color);
}
// TODO: Add ImageDrawTriangle()
void Draw(const ::Image& src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint = {255, 255, 255, 255}) {
::ImageDraw(this, src, srcRec, dstRec, tint);
}
void DrawText(const char* text, ::Vector2 position, int fontSize, ::Color color = {255, 255, 255, 255}) {
::ImageDrawText(this, text, static_cast<int>(position.x), static_cast<int>(position.y), fontSize, color);
}
void DrawText(const std::string& text, ::Vector2 position, int fontSize, ::Color color = {255, 255, 255, 255}) {
::ImageDrawText(
this,
text.c_str(),
static_cast<int>(position.x),
static_cast<int>(position.y),
fontSize,
color);
}
void DrawText(const std::string& text, int x, int y, int fontSize, ::Color color = {255, 255, 255, 255}) {
::ImageDrawText(this, text.c_str(), x, y, fontSize, color);
}
void DrawText(const char* text, int x, int y, int fontSize, ::Color color = {255, 255, 255, 255}) {
::ImageDrawText(this, text, x, y, fontSize, color);
}
void DrawText(
const ::Font& font,
const std::string& text,
::Vector2 position,
float fontSize,
float spacing,
::Color tint = {255, 255, 255, 255}) {
::ImageDrawTextEx(this, font, text.c_str(), position, fontSize, spacing, tint);
}
void DrawText(
const ::Font& font,
const char* text,
::Vector2 position,
float fontSize,
float spacing,
::Color tint = {255, 255, 255, 255}) {
::ImageDrawTextEx(this, font, text, position, fontSize, spacing, tint);
}
/**
* Load color data from image as a Color array (RGBA - 32bit)
*/
RLCPP_NODISCARD ::Color* LoadColors() const { return ::LoadImageColors(*this); }
/**
* Load colors palette from image as a Color array (RGBA - 32bit)
*/
::Color* LoadPalette(int maxPaletteSize, int* colorsCount) const {
return ::LoadImagePalette(*this, maxPaletteSize, colorsCount);
}
/**
* Unload color data loaded with LoadImageColors()
*/
void UnloadColors(::Color* colors) const { ::UnloadImageColors(colors); }
/**
* Unload colors palette loaded with LoadImagePalette()
*/
void UnloadPalette(::Color* colors) const { ::UnloadImagePalette(colors); }
/**
* Load texture from image data.
*/
RLCPP_NODISCARD ::Texture2D LoadTexture() const { return ::LoadTextureFromImage(*this); }
/**
* Loads a texture from the image data.
*
* @see LoadTexture()
*/
operator ::Texture2D() const { return LoadTexture(); }
/**
* Get pixel data size in bytes for certain format
*/
static int GetPixelDataSize(int width, int height, int format = PIXELFORMAT_UNCOMPRESSED_R32G32B32A32) {
return ::GetPixelDataSize(width, height, format);
}
/**
* Returns the pixel data size based on the current image.
*
* @return The pixel data size of the image.
*/
RLCPP_NODISCARD int GetPixelDataSize() const { return ::GetPixelDataSize(width, height, format); }
/**
* Retrieve whether or not the Image has been loaded.
*
* @return True or false depending on whether the Image has been loaded.
*/
RLCPP_NODISCARD bool IsValid() const { return ::IsImageValid(*this); }
/**
* Create an image from a selected channel of another image (GRAYSCALE)
*/
::Image Channel(int selectedChannel) { return ::ImageFromChannel(*this, selectedChannel); }
/**
* Apply custom square convolution kernel to image
*/
void KernelConvolution(const float* kernel, int kernelSize) {
::ImageKernelConvolution(this, kernel, kernelSize);
}
protected:
void set(const ::Image& image) {
data = image.data;
width = image.width;
height = image.height;
mipmaps = image.mipmaps;
format = image.format;
}
};
} // namespace raylib
using RImage = raylib::Image;
#endif // RAYLIB_CPP_INCLUDE_IMAGE_HPP_
+66
View File
@@ -0,0 +1,66 @@
#ifndef RAYLIB_CPP_INCLUDE_KEYBOARD_HPP_
#define RAYLIB_CPP_INCLUDE_KEYBOARD_HPP_
#include "./Functions.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Input-related functions: keyboard
*/
namespace Keyboard {
/**
* Detect if a key has been pressed once
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool IsKeyPressed(int key) {
return ::IsKeyPressed(key);
}
/**
* Detect if a key has been pressed again (Only PLATFORM_DESKTOP)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool IsKeyPressedRepeat(int key) {
return ::IsKeyPressedRepeat(key);
}
/**
* Detect if a key is being pressed
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool IsKeyDown(int key) {
return ::IsKeyDown(key);
}
/**
* Detect if a key has been released once
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool IsKeyReleased(int key) {
return ::IsKeyReleased(key);
}
/**
* Detect if a key is NOT being pressed
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool IsKeyUp(int key) {
return ::IsKeyUp(key);
}
/**
* Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline int GetKeyPressed() {
return ::GetKeyPressed();
}
/**
* Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline int GetCharPressed() {
return ::GetCharPressed();
}
} // namespace Keyboard
} // namespace raylib
namespace RKeyboard = raylib::Keyboard;
#endif // RAYLIB_CPP_INCLUDE_KEYBOARD_HPP_
+54
View File
@@ -0,0 +1,54 @@
#ifndef RAYLIB_CPP_INCLUDE_MATERIAL_HPP_
#define RAYLIB_CPP_INCLUDE_MATERIAL_HPP_
#include "./MaterialUnmanaged.hpp"
namespace raylib {
/**
* Material type (generic).
*
* The material will be unloaded on object destruction. Use raylib::MaterialUnmanaged if you're looking to not unload.
*
* @see raylib::MaterialUnmanaged
*/
class Material : public MaterialUnmanaged {
public:
using MaterialUnmanaged::MaterialUnmanaged;
Material(const Material&) = delete;
Material& operator=(const Material&) = delete;
Material(Material&& other) noexcept {
set(other);
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& operator=(Material&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.maps = nullptr;
other.shader = {};
return *this;
}
Material& operator=(const ::Material& material) {
Unload();
set(material);
return *this;
}
~Material() { Unload(); }
};
} // namespace raylib
using RMaterial = raylib::Material;
#endif // RAYLIB_CPP_INCLUDE_MATERIAL_HPP_
+96
View File
@@ -0,0 +1,96 @@
#ifndef RAYLIB_CPP_INCLUDE_MATERIALUNMANAGED_HPP_
#define RAYLIB_CPP_INCLUDE_MATERIALUNMANAGED_HPP_
#include <string>
#include <vector>
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* A Material that is not managed by C++ RAII.
*
* Make sure to Unload() this if needed, otherwise use raylib::Material.
*
* @see raylib::Material
*/
class MaterialUnmanaged : public ::Material {
public:
/**
* Creates a MaterialUnmanaged from an existing Material struct.
*/
MaterialUnmanaged(const ::Material& material) : ::Material(material) {}
/**
* Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps).
*/
MaterialUnmanaged() : ::Material(::LoadMaterialDefault()) {}
/**
* Load materials from model file.
*/
static std::vector<MaterialUnmanaged> Load(const std::string& fileName) {
int count = 0;
::Material* mats = ::LoadMaterials(fileName.c_str(), &count);
return std::vector<MaterialUnmanaged>(mats, mats + count);
}
GETTERSETTER(::Shader, Shader, shader)
GETTERSETTER(::MaterialMap*, Maps, maps)
MaterialUnmanaged& operator=(const ::Material& material) {
set(material);
return *this;
}
/**
* Unload material from memory.
*/
void Unload() {
if (maps != nullptr) {
::UnloadMaterial(*this);
maps = nullptr;
}
}
/**
* Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...).
*/
MaterialUnmanaged& SetTexture(int mapType, const ::Texture2D& texture) {
::SetMaterialTexture(this, mapType, texture);
return *this;
}
/**
* Draw a 3d mesh with material and transform.
*/
void DrawMesh(const ::Mesh& mesh, ::Matrix transform) const { ::DrawMesh(mesh, *this, transform); }
/**
* Draw multiple mesh instances with material and different transforms.
*/
void DrawMesh(const ::Mesh& mesh, ::Matrix* transforms, int instances) const {
::DrawMeshInstanced(mesh, *this, transforms, instances);
}
/**
* Check if material is ready.
*/
RLCPP_NODISCARD bool IsValid() const { return ::IsMaterialValid(*this); }
protected:
void set(const ::Material& material) {
shader = material.shader;
maps = material.maps;
params[0] = material.params[0];
params[1] = material.params[1];
params[2] = material.params[2];
params[3] = material.params[3];
}
};
} // namespace raylib
using RMaterialUnmanaged = raylib::MaterialUnmanaged;
#endif // RAYLIB_CPP_INCLUDE_MATERIALUNMANAGED_HPP_
+201
View File
@@ -0,0 +1,201 @@
#ifndef RAYLIB_CPP_INCLUDE_MATRIX_HPP_
#define RAYLIB_CPP_INCLUDE_MATRIX_HPP_
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
#include "./raymath.hpp"
#ifndef RAYLIB_CPP_NO_MATH
#include <cmath>
#endif
namespace raylib {
/**
* Matrix type (OpenGL style 4x4 - right handed, column major)
*/
class Matrix : public ::Matrix {
public:
constexpr Matrix(const ::Matrix& mat)
: ::Matrix(mat) {
// Nothing.
}
constexpr Matrix(
float m0 = 0,
float m4 = 0,
float m8 = 0,
float m12 = 0,
float m1 = 0,
float m5 = 0,
float m9 = 0,
float m13 = 0,
float m2 = 0,
float m6 = 0,
float m10 = 0,
float m14 = 0,
float m3 = 0,
float m7 = 0,
float m11 = 0,
float m15 = 0)
: ::Matrix{m0, m4, m8, m12, m1, m5, m9, m13, m2, m6, m10, m14, m3, m7, m11, m15} {
// Nothing.
}
GETTERSETTER(float, M0, m0)
GETTERSETTER(float, M1, m1)
GETTERSETTER(float, M2, m2)
GETTERSETTER(float, M3, m3)
GETTERSETTER(float, M4, m4)
GETTERSETTER(float, M5, m5)
GETTERSETTER(float, M6, m6)
GETTERSETTER(float, M7, m7)
GETTERSETTER(float, M8, m8)
GETTERSETTER(float, M9, m9)
GETTERSETTER(float, M10, m10)
GETTERSETTER(float, M11, m11)
GETTERSETTER(float, M12, m12)
GETTERSETTER(float, M13, m13)
GETTERSETTER(float, M14, m14)
GETTERSETTER(float, M15, m15)
Matrix& operator=(const ::Matrix& matrix) {
if (this != &matrix) {
set(matrix);
}
return *this;
}
Matrix& operator=(const Matrix& matrix) {
if (this != &matrix) {
set(matrix);
}
return *this;
}
constexpr bool operator==(const ::Matrix& other) {
return m0 == other.m0 && m1 == other.m1 && m2 == other.m2 && m3 == other.m3 && m4 == other.m4 &&
m5 == other.m5 && m6 == other.m6 && m7 == other.m7 && m8 == other.m8 && m9 == other.m9 &&
m10 == other.m10 && m11 == other.m11 && m12 == other.m12 && m13 == other.m13 && m14 == other.m14 &&
m15 == other.m15;
}
constexpr bool operator!=(const ::Matrix& other) { return !(*this == other); }
[[nodiscard]] std::string ToString() const {
return TextFormat(
"Matrix(\n"
" %f, %f, %f, %f\n"
" %f, %f, %f, %f\n"
" %f, %f, %f, %f\n"
" %f, %f, %f, %f\n"
")",
m0, m4, m8, m12,
m1, m5, m9, m13,
m2, m6, m10, m14,
m3, m7, m11, m15
);
}
operator std::string() const { return ToString(); }
#ifndef RAYLIB_CPP_NO_MATH
/**
* Returns the trace of the matrix (sum of the values along the diagonal)
*/
RLCPP_NODISCARD float Trace() const { return ::MatrixTrace(*this); }
/**
* Transposes provided matrix
*/
RLCPP_NODISCARD Matrix Transpose() const { return ::MatrixTranspose(*this); }
RLCPP_NODISCARD Matrix Invert() const { return ::MatrixInvert(*this); }
static Matrix Identity() { return ::MatrixIdentity(); }
Matrix Add(const ::Matrix& right) { return ::MatrixAdd(*this, right); }
Matrix operator+(const ::Matrix& matrix) { return ::MatrixAdd(*this, matrix); }
Matrix Subtract(const ::Matrix& right) { return ::MatrixSubtract(*this, right); }
Matrix operator-(const ::Matrix& matrix) { return ::MatrixSubtract(*this, matrix); }
static Matrix Translate(float x, float y, float z) { return ::MatrixTranslate(x, y, z); }
static Matrix Rotate(Vector3 axis, float angle) { return ::MatrixRotate(axis, angle); }
static Matrix RotateXYZ(Vector3 angle) { return ::MatrixRotateXYZ(angle); }
static Matrix RotateX(float angle) { return ::MatrixRotateX(angle); }
static Matrix RotateY(float angle) { return ::MatrixRotateY(angle); }
static Matrix RotateZ(float angle) { return ::MatrixRotateZ(angle); }
static Matrix Scale(float x, float y, float z) { return ::MatrixScale(x, y, z); }
RLCPP_NODISCARD Matrix Multiply(const ::Matrix& right) const { return ::MatrixMultiply(*this, right); }
RLCPP_NODISCARD Matrix Multiply(float value) const { return ::MatrixMultiplyValue(*this, value); }
Matrix operator*(const ::Matrix& matrix) { return ::MatrixMultiply(*this, matrix); }
Matrix operator*(float value) { return ::MatrixMultiplyValue(*this, value); }
static Matrix Frustum(double left, double right, double bottom, double top, double near, double far) {
return ::MatrixFrustum(left, right, bottom, top, near, far);
}
static Matrix Perspective(double fovy, double aspect, double near, double far) {
return ::MatrixPerspective(fovy, aspect, near, far);
}
static Matrix Ortho(double left, double right, double bottom, double top, double near, double far) {
return ::MatrixOrtho(left, right, bottom, top, near, far);
}
static Matrix LookAt(Vector3 eye, Vector3 target, Vector3 up) { return ::MatrixLookAt(eye, target, up); }
RLCPP_NODISCARD float16 ToFloatV() const { return ::MatrixToFloatV(*this); }
operator float16() const { return ToFloatV(); }
/**
* Set shader uniform value (matrix 4x4)
*/
Matrix& SetShaderValue(const ::Shader& shader, int uniformLoc) {
::SetShaderValueMatrix(shader, uniformLoc, *this);
return *this;
}
static Matrix GetCamera(const ::Camera& camera) { return ::GetCameraMatrix(camera); }
static Matrix GetCamera(const ::Camera2D& camera) { return ::GetCameraMatrix2D(camera); }
#endif
protected:
void set(const ::Matrix& mat) {
m0 = mat.m0;
m1 = mat.m1;
m2 = mat.m2;
m3 = mat.m3;
m4 = mat.m4;
m5 = mat.m5;
m6 = mat.m6;
m7 = mat.m7;
m8 = mat.m8;
m9 = mat.m9;
m10 = mat.m10;
m11 = mat.m11;
m12 = mat.m12;
m13 = mat.m13;
m14 = mat.m14;
m15 = mat.m15;
}
};
} // namespace raylib
using RMatrix = raylib::Matrix;
#endif // RAYLIB_CPP_INCLUDE_MATRIX_HPP_
+92
View File
@@ -0,0 +1,92 @@
#ifndef RAYLIB_CPP_INCLUDE_MESH_HPP_
#define RAYLIB_CPP_INCLUDE_MESH_HPP_
#include <string>
#include <vector>
#include "./MeshUnmanaged.hpp"
#include "./Model.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Vertex data defining a mesh
*
* The Mesh will be unloaded on object destruction.
*
* @see raylib::MeshUnmanaged
*/
class Mesh : public MeshUnmanaged {
public:
using MeshUnmanaged::MeshUnmanaged;
/**
* Explicitly forbid the copy constructor.
*/
Mesh(const Mesh&) = delete;
/**
* Explicitly forbid copy assignment.
*/
Mesh& operator=(const Mesh&) = delete;
/**
* Move constructor.
*/
Mesh(Mesh&& other) noexcept {
set(other);
other.vertexCount = 0;
other.triangleCount = 0;
other.vertices = nullptr;
other.texcoords = nullptr;
other.texcoords2 = nullptr;
other.normals = nullptr;
other.tangents = nullptr;
other.colors = nullptr;
other.indices = nullptr;
other.animVertices = nullptr;
other.animNormals = nullptr;
other.boneIndices = nullptr;
other.boneWeights = nullptr;
other.boneCount = 0;
other.vaoId = 0;
other.vboId = nullptr;
}
Mesh& operator=(Mesh&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.vertexCount = 0;
other.triangleCount = 0;
other.vertices = nullptr;
other.texcoords = nullptr;
other.texcoords2 = nullptr;
other.normals = nullptr;
other.tangents = nullptr;
other.colors = nullptr;
other.indices = nullptr;
other.animVertices = nullptr;
other.animNormals = nullptr;
other.boneIndices = nullptr;
other.boneWeights = nullptr;
other.boneCount = 0;
other.vaoId = 0;
other.vboId = nullptr;
return *this;
}
~Mesh() { Unload(); }
};
} // namespace raylib
using RMesh = raylib::Mesh;
#endif // RAYLIB_CPP_INCLUDE_MESH_HPP_
+265
View File
@@ -0,0 +1,265 @@
#ifndef RAYLIB_CPP_INCLUDE_MESHUNMANAGED_HPP_
#define RAYLIB_CPP_INCLUDE_MESHUNMANAGED_HPP_
#include <string>
#include <vector>
#include "./BoundingBox.hpp"
#include "./Matrix.hpp"
#include "./Model.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* Vertex data defining a mesh, not managed by C++ RAII.
*
* Make sure to Unload() this if needed, otherwise use raylib::Mesh.
*
* @see raylib::Mesh
*/
class MeshUnmanaged : public ::Mesh {
public:
/**
* Default texture constructor.
*/
MeshUnmanaged() {
vertexCount = 0;
triangleCount = 0;
vertices = nullptr;
texcoords = nullptr;
texcoords2 = nullptr;
normals = nullptr;
tangents = nullptr;
colors = nullptr;
indices = nullptr;
animVertices = nullptr;
animNormals = nullptr;
boneIndices = nullptr;
boneWeights = nullptr;
boneCount = 0;
vaoId = 0;
vboId = nullptr;
}
MeshUnmanaged(const ::Mesh& mesh) { set(mesh); }
MeshUnmanaged(::Mesh&& mesh) { set(mesh); }
/**
* Load meshes from model file
*/
// static std::vector<Mesh> Load(const std::string& fileName) {
// int count = 0;
// ::Mesh* meshes = LoadMeshes(fileName.c_str(), &count);
// return std::vector<Mesh>(meshes, meshes + count);
// }
/**
* Generate polygonal mesh
*/
static ::Mesh Poly(int sides, float radius) { return ::GenMeshPoly(sides, radius); }
/**
* Generate plane mesh (with subdivisions)
*/
static ::Mesh Plane(float width, float length, int resX, int resZ) {
return ::GenMeshPlane(width, length, resX, resZ);
}
/**
* Generate cuboid mesh
*/
static ::Mesh Cube(float width, float height, float length) { return ::GenMeshCube(width, height, length); }
/**
* Generate sphere mesh (standard sphere)
*/
static ::Mesh Sphere(float radius, int rings, int slices) { return ::GenMeshSphere(radius, rings, slices); }
/**
* Generate half-sphere mesh (no bottom cap)
*/
static ::Mesh HemiSphere(float radius, int rings, int slices) { return ::GenMeshHemiSphere(radius, rings, slices); }
/**
* Generate cylinder mesh
*/
static ::Mesh Cylinder(float radius, float height, int slices) { 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
*/
static ::Mesh Torus(float radius, float size, int radSeg, int sides) {
return ::GenMeshTorus(radius, size, radSeg, sides);
}
/**
* Generate trefoil knot mesh
*/
static ::Mesh Knot(float radius, float size, int radSeg, int sides) {
return ::GenMeshKnot(radius, size, radSeg, sides);
}
/**
* Generate heightmap mesh from image data
*/
static ::Mesh Heightmap(const ::Image& heightmap, ::Vector3 size) { return ::GenMeshHeightmap(heightmap, size); }
/**
* Generate cubes-based map mesh from image data
*/
static ::Mesh Cubicmap(const ::Image& cubicmap, ::Vector3 cubeSize) {
return ::GenMeshCubicmap(cubicmap, cubeSize);
}
GETTERSETTER(int, VertexCount, vertexCount)
GETTERSETTER(int, TriangleCount, triangleCount)
GETTERSETTER(float*, Vertices, vertices)
GETTERSETTER(float*, TexCoords, texcoords)
GETTERSETTER(float*, TexCoords2, texcoords2)
GETTERSETTER(float*, Normals, normals)
GETTERSETTER(float*, Tangents, tangents)
GETTERSETTER(unsigned char*, Colors, colors)
GETTERSETTER(unsigned short*, Indices, indices) // NOLINT
GETTERSETTER(float*, AnimVertices, animVertices)
GETTERSETTER(float*, AnimNormals, animNormals)
GETTERSETTER(unsigned char*, BoneIndices, boneIndices)
GETTERSETTER(float*, BoneWeights, boneWeights)
GETTERSETTER(int, BoneCount, boneCount)
GETTERSETTER(unsigned int, VaoId, vaoId)
GETTERSETTER(unsigned int*, VboId, vboId)
MeshUnmanaged& operator=(const ::Mesh& mesh) {
set(mesh);
return *this;
}
[[nodiscard]] std::string ToString() const {
return TextFormat(
"Mesh(vertexCount=%d, triangleCount=%d, boneCount=%d)",
vertexCount, triangleCount, boneCount
);
}
operator std::string() const { return ToString(); }
/**
* Unload mesh from memory (RAM and/or VRAM)
*/
void Unload() {
if (vboId != nullptr) {
::UnloadMesh(*this);
vboId = nullptr;
}
}
/**
* Upload mesh vertex data to GPU (VRAM)
*/
void Upload(bool dynamic = false) { ::UploadMesh(this, dynamic); }
/**
* Upload mesh vertex data to GPU (VRAM)
*/
void UpdateBuffer(int index, void* data, int dataSize, int offset = 0) {
::UpdateMeshBuffer(*this, index, data, dataSize, offset);
}
/**
* Draw a 3d mesh with material and transform
*/
void Draw(const ::Material& material, const ::Matrix& transform) const { ::DrawMesh(*this, material, transform); }
/**
* Draw multiple mesh instances with material and different transforms
*/
void Draw(const ::Material& material, const ::Matrix* transforms, int instances) const {
::DrawMeshInstanced(*this, material, transforms, instances);
}
/**
* Export mesh data to file
*
* @throws raylib::RaylibException Throws if failed to export the Mesh.
*/
void Export(const std::string& fileName) {
if (!::ExportMesh(*this, fileName.c_str())) {
throw RaylibException("Failed to export the Mesh");
}
}
/**
* Export mesh as code file (.h) defining multiple arrays of vertex attributes
*
* @throws raylib::RaylibException Throws if failed to export the Mesh.
*/
void ExportCode(const std::string& fileName) {
if (!::ExportMeshAsCode(*this, fileName.c_str())) {
throw RaylibException("Failed to export the Mesh");
}
}
/**
* Compute mesh bounding box limits
*/
RLCPP_NODISCARD raylib::BoundingBox BoundingBox() const { return ::GetMeshBoundingBox(*this); }
/**
* Compute mesh bounding box limits
*/
operator raylib::BoundingBox() const { return BoundingBox(); }
/**
* Compute mesh tangents
*/
MeshUnmanaged& GenTangents() {
::GenMeshTangents(this);
return *this;
}
/**
* Load model from generated mesh
*/
RLCPP_NODISCARD raylib::Model LoadModelFrom() const { return ::LoadModelFromMesh(*this); }
/**
* Load model from generated mesh
*/
operator raylib::Model() { return ::LoadModelFromMesh(*this); }
/**
* Returns whether or not the Mesh is valid.
*/
RLCPP_NODISCARD bool IsValid() const { return vaoId != 0 && vertexCount > 0; }
protected:
void set(const ::Mesh& mesh) {
vertexCount = mesh.vertexCount;
triangleCount = mesh.triangleCount;
vertices = mesh.vertices;
texcoords = mesh.texcoords;
texcoords2 = mesh.texcoords2;
normals = mesh.normals;
tangents = mesh.tangents;
colors = mesh.colors;
indices = mesh.indices;
animVertices = mesh.animVertices;
animNormals = mesh.animNormals;
boneIndices = mesh.boneIndices;
boneWeights = mesh.boneWeights;
boneCount = mesh.boneCount;
vaoId = mesh.vaoId;
vboId = mesh.vboId;
}
};
} // namespace raylib
using RMeshUnmanaged = raylib::MeshUnmanaged;
#endif // RAYLIB_CPP_INCLUDE_MESHUNMANAGED_HPP_
+86
View File
@@ -0,0 +1,86 @@
#ifndef RAYLIB_CPP_INCLUDE_MODEL_HPP_
#define RAYLIB_CPP_INCLUDE_MODEL_HPP_
#include "./ModelUnmanaged.hpp"
namespace raylib {
class Mesh;
/**
* Model type.
*
* The model will be unloaded on object destruction. Use raylib::ModelUnmanaged if you're looking to not unload.
*
* @see raylib::ModelUnmanaged
*/
class Model : public ModelUnmanaged {
public:
using ModelUnmanaged::ModelUnmanaged;
/**
* The Model constructor with a Mesh() is removed.
*
* Use `raylib::MeshUnmanaged` or `::Mesh` instead, as raylib will take ownership of the data.
*
* @see raylib::MeshUnmanaged
*/
Model(const raylib::Mesh& mesh) = delete;
Model(const Model&) = delete;
Model& operator=(const Model&) = delete;
Model(Model&& other) noexcept {
set(other);
other.meshCount = 0;
other.materialCount = 0;
other.meshes = nullptr;
other.materials = nullptr;
other.meshMaterial = nullptr;
other.skeleton.boneCount = 0;
other.skeleton.bones = nullptr;
other.skeleton.bindPose = nullptr;
other.currentPose = nullptr;
other.boneMatrices = nullptr;
}
Model& operator=(Model&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.meshCount = 0;
other.materialCount = 0;
other.meshes = nullptr;
other.materials = nullptr;
other.meshMaterial = nullptr;
other.skeleton.boneCount = 0;
other.skeleton.bones = nullptr;
other.skeleton.bindPose = nullptr;
other.currentPose = nullptr;
other.boneMatrices = nullptr;
return *this;
}
Model& operator=(const ::Model& model) {
Unload();
set(model);
return *this;
}
~Model() { Unload(); }
void Load(const std::string& fileName) {
Unload();
ModelUnmanaged::Load(fileName);
}
void Load(const ::Mesh& mesh) {
Unload();
ModelUnmanaged::Load(mesh);
}
};
} // namespace raylib
using RModel = raylib::Model;
#endif // RAYLIB_CPP_INCLUDE_MODEL_HPP_
+123
View File
@@ -0,0 +1,123 @@
#ifndef RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
#define RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
#include <string>
#include <vector>
#include "./Mesh.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Model animation
*/
class ModelAnimation : public ::ModelAnimation {
public:
ModelAnimation(const ::ModelAnimation& model) { set(model); }
ModelAnimation(const ModelAnimation&) = delete;
ModelAnimation(ModelAnimation&& other) noexcept {
set(other);
other.boneCount = 0;
other.keyframeCount = 0;
other.keyframePoses = nullptr;
}
// Unloads animation data using populated animCount field, which is set by Load() method.
~ModelAnimation() { Unload(); }
/**
* Load model animations from file
*/
static std::vector<ModelAnimation> Load(const std::string& fileName) {
int count = 0;
::ModelAnimation* modelAnimations = ::LoadModelAnimations(fileName.c_str(), &count);
std::vector<ModelAnimation> mats(modelAnimations, modelAnimations + count);
RL_FREE(modelAnimations);
return mats;
}
GETTERSETTER(int, BoneCount, boneCount)
GETTERSETTER(int, KeyframeCount, keyframeCount)
GETTERSETTER(::Transform**, KeyframePoses, keyframePoses)
ModelAnimation& operator=(const ::ModelAnimation& model) {
set(model);
return *this;
}
ModelAnimation& operator=(const ModelAnimation&) = delete;
ModelAnimation& operator=(ModelAnimation&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.boneCount = 0;
other.keyframeCount = 0;
other.keyframePoses = nullptr;
return *this;
}
/**
* Unload animation data
*/
void Unload() {
if (keyframePoses != nullptr) {
::UnloadModelAnimations(this, 1);
keyframePoses = nullptr;
}
}
static void Unload(ModelAnimation *modelAnimation, int count) {
::UnloadModelAnimations(modelAnimation, count);
}
/**
* Update model animation pose
*/
ModelAnimation& Update(const ::Model& model, float frame) {
::UpdateModelAnimation(model, *this, frame);
return *this;
}
/**
* Blend two animation poses
*/
ModelAnimation& Blend(const ::Model& model, float frameA, const ::ModelAnimation& animB, float frameB, float blend) {
::UpdateModelAnimationEx(model, *this, frameA, animB, frameB, blend);
return *this;
}
/**
* Check model animation skeleton match
*/
RLCPP_NODISCARD bool IsValid(const ::Model& model) const { return ::IsModelAnimationValid(model, *this); }
protected:
void set(const ::ModelAnimation& model) {
boneCount = model.boneCount;
keyframeCount = model.keyframeCount;
keyframePoses = model.keyframePoses;
// Duplicate the name. TextCopy() uses the null terminator, which we ignore here.
for (int i = 0; i < 32; i++) {
name[i] = model.name[i];
}
}
};
} // namespace raylib
using RModelAnimation = raylib::ModelAnimation;
#endif // RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
+211
View File
@@ -0,0 +1,211 @@
#ifndef RAYLIB_CPP_INCLUDE_MODELUNMANAGED_HPP_
#define RAYLIB_CPP_INCLUDE_MODELUNMANAGED_HPP_
#include <string>
#include "./BoundingBox.hpp"
#include "./RaylibException.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* A Model that is not managed by C++ RAII.
*
* Make sure to Unload() this if needed, otherwise use raylib::Model.
*
* @see raylib::Model
*/
class ModelUnmanaged : public ::Model {
public:
/**
* Default constructor.
*/
ModelUnmanaged() {}
/**
* Creates a ModelUnmanaged from an existing Model struct.
*/
ModelUnmanaged(const ::Model& model) : ::Model(model) {}
/**
* Loads a Model from the given file.
*
* @throws raylib::RaylibException Throws if failed to load the Model.
*/
ModelUnmanaged(const std::string& fileName) { Load(fileName); }
/**
* Loads a Model from the given Mesh.
*
* @throws raylib::RaylibException Throws if failed to load the Model.
*/
ModelUnmanaged(const ::Mesh& mesh) { Load(mesh); }
GETTERSETTER(::Matrix, Transform, transform)
GETTERSETTER(int, MeshCount, meshCount)
GETTERSETTER(int, MaterialCount, materialCount)
GETTERSETTER(::Mesh*, Meshes, meshes)
GETTERSETTER(::Material*, Materials, materials)
GETTERSETTER(int*, MeshMaterial, meshMaterial)
GETTERSETTER(int, BoneCount, skeleton.boneCount)
GETTERSETTER(::BoneInfo*, Bones, skeleton.bones)
GETTERSETTER(::Transform*, BindPose, skeleton.bindPose)
GETTERSETTER(::ModelAnimPose, CurrentPose, currentPose)
GETTERSETTER(::Matrix*, BoneMatrices, boneMatrices)
ModelUnmanaged& operator=(const ::Model& model) {
set(model);
return *this;
}
[[nodiscard]] std::string ToString() const { return TextFormat("Model(meshCount=%d, materialCount=%d)", meshCount, materialCount); }
operator std::string() const { return ToString(); }
/**
* Loads a Model from the given file.
*
* @throws raylib::RaylibException Throws if failed to load the Model.
*/
void Load(const std::string& fileName) {
set(::LoadModel(fileName.c_str()));
if (!IsValid()) {
throw RaylibException("Failed to load Model from " + fileName);
}
}
/**
* Loads a Model from the given Mesh.
*
* @throws raylib::RaylibException Throws if failed to load the Model.
*/
void Load(const ::Mesh& mesh) {
set(::LoadModelFromMesh(mesh));
if (!IsValid()) {
throw RaylibException("Failed to load Model from Mesh");
}
}
/**
* Unload model (including meshes) from memory (RAM and/or VRAM).
*/
void Unload() {
if (meshes != nullptr || materials != nullptr) {
::UnloadModel(*this);
meshes = nullptr;
materials = nullptr;
}
}
/**
* Set material for a mesh.
*/
ModelUnmanaged& SetMeshMaterial(int meshId, int materialId) {
::SetModelMeshMaterial(this, meshId, materialId);
return *this;
}
/**
* Update model animation pose.
*/
ModelUnmanaged& UpdateAnimation(const ::ModelAnimation& anim, float frame) {
::UpdateModelAnimation(*this, anim, frame);
return *this;
}
/**
* Blend two model animation poses.
*/
ModelUnmanaged& BlendAnimation(
const ::ModelAnimation& animA,
float frameA,
const ::ModelAnimation& animB,
float frameB,
float blend) {
::UpdateModelAnimationEx(*this, animA, frameA, animB, frameB, blend);
return *this;
}
/**
* Check model animation skeleton match.
*/
RLCPP_NODISCARD bool IsModelAnimationValid(const ::ModelAnimation& anim) const {
return ::IsModelAnimationValid(*this, anim);
}
/**
* Draw a model (with texture if set).
*/
void Draw(::Vector3 position, float scale = 1.0f, ::Color tint = {255, 255, 255, 255}) const {
::DrawModel(*this, position, scale, tint);
}
/**
* Draw a model with extended parameters.
*/
void Draw(
::Vector3 position,
::Vector3 rotationAxis,
float rotationAngle = 0.0f,
::Vector3 scale = {1.0f, 1.0f, 1.0f},
::Color tint = {255, 255, 255, 255}) const {
::DrawModelEx(*this, position, rotationAxis, rotationAngle, scale, tint);
}
/**
* Draw a model wires (with texture if set).
*/
void DrawWires(::Vector3 position, float scale = 1.0f, ::Color tint = {255, 255, 255, 255}) const {
::DrawModelWires(*this, position, scale, tint);
}
/**
* Draw a model wires (with texture if set) with extended parameters.
*/
void DrawWires(
::Vector3 position,
::Vector3 rotationAxis,
float rotationAngle = 0.0f,
::Vector3 scale = {1.0f, 1.0f, 1.0f},
::Color tint = {255, 255, 255, 255}) const {
::DrawModelWiresEx(*this, position, rotationAxis, rotationAngle, scale, tint);
}
/**
* Compute model bounding box limits (considers all meshes).
*/
RLCPP_NODISCARD BoundingBox GetBoundingBox() const { return ::GetModelBoundingBox(*this); }
/**
* Compute model bounding box limits (considers all meshes).
*/
explicit operator BoundingBox() const { return ::GetModelBoundingBox(*this); }
/**
* Determines whether or not the Model has data in it.
*/
RLCPP_NODISCARD bool IsValid() const { return ::IsModelValid(*this); }
protected:
void set(const ::Model& model) {
transform = model.transform;
meshCount = model.meshCount;
materialCount = model.materialCount;
meshes = model.meshes;
materials = model.materials;
meshMaterial = model.meshMaterial;
skeleton.boneCount = model.skeleton.boneCount;
skeleton.bones = model.skeleton.bones;
skeleton.bindPose = model.skeleton.bindPose;
currentPose = model.currentPose;
boneMatrices = model.boneMatrices;
}
};
} // namespace raylib
using RModelUnmanaged = raylib::ModelUnmanaged;
#endif // RAYLIB_CPP_INCLUDE_MODELUNMANAGED_HPP_
+153
View File
@@ -0,0 +1,153 @@
#ifndef RAYLIB_CPP_INCLUDE_MOUSE_HPP_
#define RAYLIB_CPP_INCLUDE_MOUSE_HPP_
#include "./Functions.hpp"
#include "./Vector2.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Input-related functions: mouse
*/
namespace Mouse {
/**
* Detect if a mouse button has been pressed once
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool IsButtonPressed(int button) {
return ::IsMouseButtonPressed(button);
}
/**
* Detect if a mouse button is being pressed
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool IsButtonDown(int button) {
return ::IsMouseButtonDown(button);
}
/**
* Detect if a mouse button has been released once
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline bool IsButtonReleased(int button) {
return ::IsMouseButtonReleased(button);
}
RLCPP_MAYBEUNUSED RLCPPAPI inline bool IsButtonUp(int button) {
return ::IsMouseButtonUp(button);
}
RLCPP_MAYBEUNUSED RLCPPAPI inline int GetX() {
return ::GetMouseX();
}
RLCPP_MAYBEUNUSED RLCPPAPI inline int GetY() {
return ::GetMouseY();
}
RLCPP_MAYBEUNUSED RLCPPAPI inline void SetX(int x) {
::SetMousePosition(x, GetY());
}
RLCPP_MAYBEUNUSED RLCPPAPI inline void SetY(int y) {
::SetMousePosition(GetX(), y);
}
RLCPP_MAYBEUNUSED RLCPPAPI inline Vector2 GetPosition() {
return ::GetMousePosition();
}
RLCPP_MAYBEUNUSED RLCPPAPI inline void SetPosition(int x, int y) {
::SetMousePosition(x, y);
}
RLCPP_MAYBEUNUSED RLCPPAPI inline void SetPosition(::Vector2 position) {
::SetMousePosition(static_cast<int>(position.x), static_cast<int>(position.y));
}
/**
* Get mouse delta between frames
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline Vector2 GetDelta() {
return ::GetMouseDelta();
}
RLCPP_MAYBEUNUSED RLCPPAPI inline void SetOffset(int offsetX = 0, int offsetY = 0) {
::SetMouseOffset(offsetX, offsetY);
}
RLCPP_MAYBEUNUSED RLCPPAPI inline void SetOffset(::Vector2 offset) {
::SetMouseOffset(static_cast<int>(offset.x), static_cast<int>(offset.y));
}
RLCPP_MAYBEUNUSED RLCPPAPI inline void SetScale(float scaleX = 1.0f, float scaleY = 1.0f) {
::SetMouseScale(scaleX, scaleY);
}
RLCPP_MAYBEUNUSED RLCPPAPI inline void SetScale(::Vector2 scale) {
::SetMouseScale(scale.x, scale.y);
}
/**
* Get mouse wheel movement for X or Y, whichever is larger
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline float GetWheelMove() {
return ::GetMouseWheelMove();
}
/**
* Get mouse wheel movement for both X and Y
*
* @see ::GetMouseWheelMoveV()
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline Vector2 GetWheelMoveV() {
return GetMouseWheelMoveV();
}
/**
* Sets the current mouse cursor icon.
*
* @see ::MouseCursor
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline void SetCursor(int cursor = MOUSE_CURSOR_DEFAULT) {
::SetMouseCursor(cursor);
}
/**
* Get touch position X for touch point 0 (relative to screen size)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline int GetTouchX() {
return ::GetTouchX();
}
/**
* Get touch position Y for touch point 0 (relative to screen size)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline int GetTouchY() {
return ::GetTouchY();
}
/**
* Get touch position XY for a touch point index (relative to screen size)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline Vector2 GetTouchPosition(int index) {
return ::GetTouchPosition(index);
}
/**
* Get a ray trace from mouse position
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline Ray GetRay(::Vector2 mousePosition, const ::Camera& camera) {
return ::GetMouseRay(mousePosition, camera);
}
/**
* Get a ray trace from mouse position
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline Ray GetRay(const ::Camera& camera) {
return ::GetMouseRay(::GetMousePosition(), camera);
}
} // namespace Mouse
} // namespace raylib
namespace RMouse = raylib::Mouse;
#endif // RAYLIB_CPP_INCLUDE_MOUSE_HPP_
+66
View File
@@ -0,0 +1,66 @@
#ifndef RAYLIB_CPP_INCLUDE_MUSIC_HPP_
#define RAYLIB_CPP_INCLUDE_MUSIC_HPP_
#include "./MusicUnmanaged.hpp"
namespace raylib {
/**
* Music stream type (audio file streaming from memory).
*
* The music stream will be unloaded on object destruction. Use raylib::MusicUnmanaged if you're looking to not unload.
*
* @see raylib::MusicUnmanaged
*/
class Music : public MusicUnmanaged {
public:
using MusicUnmanaged::MusicUnmanaged;
Music(const Music&) = delete;
Music& operator=(const Music&) = delete;
Music(Music&& other) noexcept {
set(other);
other.stream = {};
other.frameCount = 0;
other.looping = false;
other.ctxType = 0;
other.ctxData = nullptr;
}
Music& operator=(Music&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.ctxType = 0;
other.ctxData = nullptr;
other.looping = false;
other.frameCount = 0;
other.stream = {};
return *this;
}
Music& operator=(const ::Music& music) {
Unload();
set(music);
return *this;
}
~Music() { Unload(); }
void Load(const std::string& fileName) {
Unload();
MusicUnmanaged::Load(fileName);
}
void Load(const std::string& fileType, unsigned char* data, int dataSize) {
Unload();
MusicUnmanaged::Load(fileType, data, dataSize);
}
};
} // namespace raylib
using RMusic = raylib::Music;
#endif // RAYLIB_CPP_INCLUDE_MUSIC_HPP_
+209
View File
@@ -0,0 +1,209 @@
#ifndef RAYLIB_CPP_INCLUDE_MUSICUNMANAGED_HPP_
#define RAYLIB_CPP_INCLUDE_MUSICUNMANAGED_HPP_
#include <string>
#include "./RaylibException.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* A Music stream that is not managed by C++ RAII.
*
* Make sure to Unload() this if needed, otherwise use raylib::Music.
*
* @see raylib::Music
*/
class MusicUnmanaged : public ::Music {
public:
/**
* Creates a MusicUnmanaged with the given components.
*/
MusicUnmanaged(
::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} {}
/**
* Creates a MusicUnmanaged from an existing Music struct.
*/
MusicUnmanaged(const ::Music& music) : ::Music(music) {}
/**
* Load music stream from file.
*
* @throws raylib::RaylibException Throws if the music failed to load.
*/
MusicUnmanaged(const std::string& fileName) { Load(fileName); }
/**
* Load music stream from memory.
*
* @throws raylib::RaylibException Throws if the music failed to load.
*/
MusicUnmanaged(const std::string& fileType, unsigned char* data, int dataSize) {
Load(fileType, data, dataSize);
}
GETTER(::AudioStream, Stream, stream)
GETTER(unsigned int, FrameCount, frameCount)
GETTERSETTER(bool, Looping, looping)
GETTER(int, CtxType, ctxType)
GETTER(void*, CtxData, ctxData)
MusicUnmanaged& operator=(const ::Music& music) {
set(music);
return *this;
}
[[nodiscard]] std::string ToString() const { return TextFormat("Music(frameCount=%u, looping=%s)", frameCount, looping ? "true" : "false"); }
operator std::string() const { return ToString(); }
/**
* Load music stream from file.
*
* @throws raylib::RaylibException Throws if the music failed to load.
*/
void Load(const std::string& fileName) {
set(::LoadMusicStream(fileName.c_str()));
if (!IsValid()) {
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.
*/
void Load(const std::string& fileType, unsigned char* data, int dataSize) {
set(::LoadMusicStreamFromMemory(fileType.c_str(), data, dataSize));
if (!IsValid()) {
throw RaylibException(TextFormat("Failed to load Music from %s file data", fileType.c_str()));
}
}
/**
* Unload music stream.
*/
void Unload() {
if (IsValid()) {
::UnloadMusicStream(*this);
ctxData = nullptr;
ctxType = 0;
}
}
/**
* Start music playing.
*/
MusicUnmanaged& Play() {
::PlayMusicStream(*this);
return *this;
}
/**
* Updates buffers for music streaming.
*/
MusicUnmanaged& Update() {
::UpdateMusicStream(*this);
return *this;
}
/**
* Stop music playing.
*/
MusicUnmanaged& Stop() {
::StopMusicStream(*this);
return *this;
}
/**
* Pause music playing.
*/
MusicUnmanaged& Pause() {
::PauseMusicStream(*this);
return *this;
}
/**
* Resume music playing.
*/
MusicUnmanaged& Resume() {
::ResumeMusicStream(*this);
return *this;
}
/**
* Seek music to a position (in seconds).
*/
MusicUnmanaged& Seek(float position) {
::SeekMusicStream(*this, position);
return *this;
}
/**
* Check if music is playing.
*/
RLCPP_NODISCARD bool IsPlaying() const { return ::IsMusicStreamPlaying(*this); }
/**
* Set volume for music.
*/
MusicUnmanaged& SetVolume(float volume) {
::SetMusicVolume(*this, volume);
return *this;
}
/**
* Set pitch for music.
*/
MusicUnmanaged& SetPitch(float pitch) {
::SetMusicPitch(*this, pitch);
return *this;
}
/**
* Set pan for a music (0.5 is center).
*/
MusicUnmanaged& SetPan(float pan = 0.5f) {
::SetMusicPan(*this, pan);
return *this;
}
/**
* Get music time length (in seconds).
*/
RLCPP_NODISCARD float GetTimeLength() const { return ::GetMusicTimeLength(*this); }
/**
* Get current music time played (in seconds).
*/
RLCPP_NODISCARD float GetTimePlayed() const { return ::GetMusicTimePlayed(*this); }
/**
* Retrieve whether or not the Music has been loaded.
*
* @return True or false depending on whether the Music has been loaded.
*/
RLCPP_NODISCARD bool IsValid() const { return ::IsMusicValid(*this); }
protected:
void set(const ::Music& music) {
stream = music.stream;
frameCount = music.frameCount;
looping = music.looping;
ctxType = music.ctxType;
ctxData = music.ctxData;
}
};
} // namespace raylib
using RMusicUnmanaged = raylib::MusicUnmanaged;
#endif // RAYLIB_CPP_INCLUDE_MUSICUNMANAGED_HPP_
+296
View File
@@ -0,0 +1,296 @@
#ifndef RAYLIB_CPP_INCLUDE_QUATERNION_HPP_
#define RAYLIB_CPP_INCLUDE_QUATERNION_HPP_
#ifndef RAYLIB_CPP_NO_MATH
#include <cmath>
#include <utility>
#endif
#include <string>
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
#include "./raymath.hpp"
namespace raylib {
class Vector4 : public ::Vector4 {};
/**
* Quaternion type
*/
class Quaternion : public ::Quaternion {
public:
constexpr Quaternion(const ::Quaternion& quat) : ::Quaternion{quat.x, quat.y, quat.z, quat.w} {}
explicit constexpr Quaternion(const raylib::Vector4 vec4) : ::Quaternion{vec4.x, vec4.y, vec4.z, vec4.w} {}
explicit constexpr Quaternion(const float x = 0, const float y = 0, const float z = 0, const float w = 1) : ::Quaternion{x, y, z, w} {}
GETTERSETTER(float, X, x)
GETTERSETTER(float, Y, y)
GETTERSETTER(float, Z, z)
GETTERSETTER(float, W, w)
Quaternion& operator=(const ::Quaternion& quaternion) {
set(quaternion);
return *this;
}
/*
* An exact value by value equality comparison.
* Due to floating point inaccuracies consider using Equals instead.
*/
constexpr bool operator==(const ::Quaternion& other) const {
return x == other.x && y == other.y && z == other.z && w == other.w;
}
/*
* An exact value by value inequality comparison.
* Due to floating point inaccuracies consider using Equals instead.
*/
constexpr bool operator!=(const ::Quaternion& other) const { return !(*this == other); }
RLCPP_NODISCARD std::string ToString() const { return ::TextFormat("Quaternion(%f, %f, %f, %f)", x, y, z, w); }
operator std::string() const { return ToString(); }
#ifndef RAYLIB_CPP_NO_MATH
/**
* Add two quaternions
*/
RLCPP_NODISCARD Quaternion Add(const ::Quaternion& quaternion) const { return ::QuaternionAdd(*this, quaternion); }
/**
* Add two quaternions
*/
Quaternion operator+(const ::Quaternion& quaternion) const { return ::QuaternionAdd(*this, quaternion); }
Quaternion& operator+=(const ::Quaternion& quaternion) {
set(::QuaternionAdd(*this, quaternion));
return *this;
}
/**
* Add quaternion and float value
*/
RLCPP_NODISCARD Quaternion Add(const float value) const {
return ::QuaternionAddValue(*this, value);
}
/**
* Add quaternion and float value
*/
Quaternion operator+(const float value) const {
return ::QuaternionAddValue(*this, value);
}
/**
* Add quaternion and float value
*/
Quaternion& operator+=(const float value) {
set(::QuaternionAddValue(*this, value));
return *this;
}
/**
* Add quaternion and float value
*/
friend Quaternion operator+(const float lhs, const Quaternion& rhs) { return rhs + lhs; }
/**
* Subtract two quaternions.
*/
RLCPP_NODISCARD Quaternion Subtract(const ::Quaternion& quaternion) const { return ::QuaternionSubtract(*this, quaternion); }
/**
* Subtract two quaternions.
*/
Quaternion operator-(const ::Quaternion& quaternion) const { return ::QuaternionSubtract(*this, quaternion); }
Quaternion& operator-=(const ::Quaternion& quaternion) {
set(::QuaternionSubtract(*this, quaternion));
return *this;
}
/**
* Subtract quaternion by float value
*/
RLCPP_NODISCARD Quaternion Subtract(const float value) const {
return ::QuaternionSubtractValue(*this, value);
}
/**
* Get identity quaternion
*/
static RLCPP_NODISCARD Quaternion Identity() {
return ::QuaternionIdentity();
}
RLCPP_NODISCARD float Length() const { return ::QuaternionLength(*this); }
RLCPP_NODISCARD Quaternion Normalize() const { return ::QuaternionNormalize(*this); }
RLCPP_NODISCARD Quaternion Invert() const { return ::QuaternionInvert(*this); }
/**
* Multiply quaternion by quaternion
*/
RLCPP_NODISCARD Quaternion Multiply(const ::Quaternion& other) const { return ::QuaternionMultiply(*this, other); }
/**
* Multiply quaternion by quaternion
*/
Quaternion operator*(const ::Quaternion& other) const { return ::QuaternionMultiply(*this, other); }
/**
* Multiply quaternion by quaternion
*/
Quaternion& operator*=(const ::Quaternion& other) {
set(::QuaternionMultiply(*this, other));
return *this;
}
/**
* Scale quaternion components by value (multiply)
*/
RLCPP_NODISCARD Quaternion Scale(const float scale) const { return ::QuaternionScale(*this, scale); }
/**
* Divide quaternion by quaternion
*/
RLCPP_NODISCARD Quaternion Divide(const ::Quaternion& quaternion) const { return ::QuaternionDivide(*this, quaternion); }
/**
* Divide quaternion by quaternion
*/
Quaternion operator/(const ::Quaternion& quaternion) const { return ::QuaternionDivide(*this, quaternion); }
/**
* Divide quaternion by quaternion
*/
Quaternion& operator/=(const ::Quaternion& quaternion) {
set(::QuaternionDivide(*this, quaternion));
return *this;
}
/**
* Divide quaternion components by value
*/
RLCPP_NODISCARD constexpr Quaternion Divide(const float div) const { return ::Quaternion{x / div, y / div, z / div, w / div}; }
RLCPP_NODISCARD Quaternion Lerp(const ::Quaternion& v2, const float amount) const
{
return ::QuaternionLerp(*this, v2, amount);
}
/**
* Calculate normalized linear interpolation between two quaternions
*/
RLCPP_NODISCARD Quaternion Nlerp(const ::Quaternion& v2, const float amount) const {
return ::QuaternionNlerp(*this, v2, amount);
}
/**
* Calculates spherical linear interpolation between two quaternions
*/
RLCPP_NODISCARD Quaternion Slerp(const ::Quaternion& v2, const float amount) const {
return ::QuaternionSlerp(*this, v2, amount);
}
/**
* Calculate quaternion cubic spline interpolation using Cubic Hermite Spline
*/
RLCPP_NODISCARD Quaternion CubicHermiteSpline(
const ::Quaternion& outTangent1,
const ::Quaternion& q2,
const ::Quaternion& inTangent2,
const float t
) const {
return ::QuaternionCubicHermiteSpline(*this, outTangent1, q2, inTangent2, t);
}
/**
* Calculate quaternion based on the rotation from one vector to another
*/
static RLCPP_NODISCARD Quaternion FromVector3ToVector3(const ::Vector3& from, const ::Vector3& to) {
return ::QuaternionFromVector3ToVector3(from, to);
}
/**
* Get a quaternion for a given rotation matrix
*/
static RLCPP_NODISCARD Quaternion FromMatrix(const ::Matrix& mat) {
return ::QuaternionFromMatrix(mat);
}
/**
* Get a matrix for this quaternion
*/
RLCPP_NODISCARD ::Matrix ToMatrix() const {
return ::QuaternionToMatrix(*this);
}
/**
* Get rotation quaternion for an angle and axis
* NOTE: Angle must be provided in radians
*/
static RLCPP_NODISCARD Quaternion FromAxisAngle(const ::Vector3& axis, const float angle) {
return ::QuaternionFromAxisAngle(axis, angle);
}
/**
* Get the rotation angle and axis for this quaternion
*/
void ToAxisAngle(::Vector3* outAxis, float* outAngle) const {
::QuaternionToAxisAngle(*this, outAxis, outAngle);
}
/**
* Get the quaternion equivalent to Euler angles
* NOTE: Rotation order is ZYX
*/
static RLCPP_NODISCARD Quaternion FromEuler(const float pitch, const float yaw, const float roll) {
return ::QuaternionFromEuler(pitch, yaw, roll);
}
/**
* Get the Euler angles equivalent to quaternion
* NOTE: Angles are returned in radians
*/
RLCPP_NODISCARD ::Vector3 ToEuler() const {
return ::QuaternionToEuler(*this);
}
/**
* Transform quaternion given transformation matrix
*/
RLCPP_NODISCARD Quaternion Transform(const ::Matrix& mat) const {
return ::QuaternionTransform(*this, mat);
}
/*
* Check whether two given quaternions are almost equal
*/
RLCPP_NODISCARD bool Equals(const ::Quaternion& other) const {
return static_cast<bool>(::QuaternionEquals(*this, other));
}
#endif
protected:
void set(const ::Quaternion& quat) {
x = quat.x;
y = quat.y;
z = quat.z;
w = quat.w;
}
};
} // namespace raylib
using RQuaternion = raylib::Quaternion;
#endif // RAYLIB_CPP_INCLUDE_QUATERNION_HPP_
+90
View File
@@ -0,0 +1,90 @@
#ifndef RAYLIB_CPP_INCLUDE_RAY_HPP_
#define RAYLIB_CPP_INCLUDE_RAY_HPP_
#include "./RayCollision.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Ray type (useful for raycast)
*/
class Ray : public ::Ray {
public:
Ray(const ::Ray& ray) { set(ray); }
constexpr Ray(::Vector3 position = {0.0f, 0.0f, 0.0f}, ::Vector3 direction = {0.0f, 0.0f, 0.0f})
: ::Ray{position, direction} {
// Nothing.
}
Ray(::Vector2 mousePosition, const ::Camera& camera) { set(::GetMouseRay(mousePosition, camera)); }
Ray& operator=(const ::Ray& ray) {
set(ray);
return *this;
}
GETTERSETTER(::Vector3, Position, position)
GETTERSETTER(::Vector3, Direction, direction)
/**
* Draw a ray line
*/
void Draw(::Color color) const { DrawRay(*this, color); }
/**
* Get collision information between ray and sphere
*/
RayCollision GetCollision(::Vector3 center, float radius) const {
return ::GetRayCollisionSphere(*this, center, radius);
}
/**
* Detect collision between ray and box
*/
RayCollision GetCollision(const ::BoundingBox& box) const { return ::GetRayCollisionBox(*this, box); }
/**
* Get collision information between ray and mesh
*/
RayCollision GetCollision(const ::Mesh& mesh, const ::Matrix& transform) const {
return ::GetRayCollisionMesh(*this, mesh, transform);
}
/**
* Get collision info between ray and triangle
*/
RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const {
return ::GetRayCollisionTriangle(*this, p1, p2, p3);
}
/**
* Get collision info between ray and quad
*/
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
*/
static Ray GetMouse(::Vector2 mousePosition, const ::Camera& camera) {
return ::GetMouseRay(mousePosition, camera);
}
/**
* Get a ray trace from mouse position
*/
static Ray GetMouse(const ::Camera& camera) { return ::GetMouseRay(::GetMousePosition(), camera); }
protected:
void set(const ::Ray& ray) {
position = ray.position;
direction = ray.direction;
}
};
} // namespace raylib
using RRay = raylib::Ray;
#endif // RAYLIB_CPP_INCLUDE_RAY_HPP_
+93
View File
@@ -0,0 +1,93 @@
#ifndef RAYLIB_CPP_INCLUDE_RAYCOLLISION_HPP_
#define RAYLIB_CPP_INCLUDE_RAYCOLLISION_HPP_
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Raycast hit information
*/
class RayCollision : public ::RayCollision {
public:
RayCollision(const ::RayCollision& ray) : ::RayCollision(ray) { }
constexpr RayCollision(bool hit, float distance, ::Vector3 point, ::Vector3 normal)
: ::RayCollision{hit, distance, point, normal} {
// Nothing.
}
/**
* Get collision info between ray and bounding box
*/
RayCollision(const ::Ray& ray, const ::BoundingBox& box)
: ::RayCollision(::GetRayCollisionBox(ray, box)) {
// Nothing.
}
/**
* Get collision info between ray and mesh
*/
RayCollision(const ::Ray& ray, const ::Mesh& mesh, const ::Matrix& transform)
: ::RayCollision(::GetRayCollisionMesh(ray, mesh, transform)) {
// Nothing.
}
/**
* Get collision info between ray and quad
*/
RayCollision(const ::Ray& ray, ::Vector3 p1, ::Vector3 p2, ::Vector3 p3, ::Vector3 p4)
: ::RayCollision(::GetRayCollisionQuad(ray, p1, p2, p3, p4)) {
// Nothing.
}
/**
* Get collision info between ray and sphere
*/
RayCollision(const ::Ray& ray, ::Vector3 center, float radius)
: ::RayCollision(::GetRayCollisionSphere(ray, center, radius)) {
// Nothing.
}
/**
* Get collision info between ray and triangle
*/
RayCollision(const ::Ray& ray, ::Vector3 p1, ::Vector3 p2, ::Vector3 p3)
: ::RayCollision(::GetRayCollisionTriangle(ray, p1, p2, p3)) {
// Nothing.
}
RayCollision& operator=(const ::RayCollision& ray) {
set(ray);
return *this;
}
[[nodiscard]] std::string ToString() const {
return TextFormat(
"RayCollision(hit=%s, distance=%f, point=(%f, %f, %f), normal=(%f, %f, %f))",
hit ? "true" : "false",
distance,
point.x, point.y, point.z,
normal.x, normal.y, normal.z
);
}
operator std::string() const { return ToString(); }
GETTERSETTER(bool, Hit, hit)
GETTERSETTER(float, Distance, distance)
GETTERSETTER(::Vector3, Position, point)
GETTERSETTER(::Vector3, Normal, normal)
protected:
void set(const ::RayCollision& ray) {
hit = ray.hit;
distance = ray.distance;
point = ray.point;
normal = ray.normal;
}
};
} // namespace raylib
using RRayCollision = raylib::RayCollision;
#endif // RAYLIB_CPP_INCLUDE_RAYCOLLISION_HPP_
+36
View File
@@ -0,0 +1,36 @@
#ifndef RAYLIB_CPP_INCLUDE_RAYLIBEXCEPTION_HPP_
#define RAYLIB_CPP_INCLUDE_RAYLIBEXCEPTION_HPP_
#include <stdexcept>
#include <string>
#include "./raylib.hpp"
namespace raylib {
/**
* Exception used for most raylib-related exceptions.
*/
class RaylibException : public std::runtime_error {
public:
/**
* Construct a runtime exception with the given message.
*
* @param message The message to provide for the exception.
*/
explicit RaylibException(const std::string& message) noexcept : std::runtime_error(message) {
// Nothing
}
/**
* Outputs the exception message to TraceLog().
*
* @param logLevel The output status to use when outputing.
*/
void TraceLog(int logLevel = LOG_ERROR) { ::TraceLog(logLevel, std::runtime_error::what()); }
};
} // namespace raylib
using RRaylibException = raylib::RaylibException;
#endif // RAYLIB_CPP_INCLUDE_RAYLIBEXCEPTION_HPP_
+162
View File
@@ -0,0 +1,162 @@
#ifndef RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
#define RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
#include "./Vector2.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Rectangle type
*/
class Rectangle : public ::Rectangle {
public:
constexpr Rectangle(const ::Rectangle& rect) : ::Rectangle{rect.x, rect.y, rect.width, rect.height} {}
constexpr Rectangle(float x = 0, float y = 0, float width = 0, float height = 0) : ::Rectangle{x, y, width, height} {}
constexpr Rectangle(::Vector2 position, ::Vector2 size) : ::Rectangle{position.x, position.y, size.x, size.y} {}
constexpr Rectangle(::Vector2 size) : ::Rectangle{0, 0, size.x, size.y} {}
constexpr Rectangle(::Vector4 rect) : ::Rectangle{rect.x, rect.y, rect.z, rect.w} {}
GETTERSETTER(float, X, x)
GETTERSETTER(float, Y, y)
GETTERSETTER(float, Width, width)
GETTERSETTER(float, Height, height)
Rectangle& operator=(const ::Rectangle& rect) {
set(rect);
return *this;
}
constexpr ::Vector4 ToVector4() const { return {x, y, width, height}; }
constexpr explicit operator ::Vector4() const { return {x, y, width, height}; }
[[nodiscard]] std::string ToString() const { return TextFormat("Rectangle(%fx%f, %fx%f)", x, y, width, height); }
operator std::string() const { return ToString(); }
/**
* Draw a color-filled rectangle
*/
static void Draw(int posX, int posY, int width, int height, ::Color color) {
::DrawRectangle(posX, posY, width, height, color);
}
static void Draw(::Vector2 position, ::Vector2 size, ::Color color) {
::DrawRectangleV(position, size, color);
}
void Draw(::Color color) const { ::DrawRectangleRec(*this, color); }
void Draw(::Vector2 origin, float rotation, ::Color color) const {
::DrawRectanglePro(*this, origin, rotation, color);
}
void DrawGradientV(::Color color1, ::Color color2) const {
::DrawRectangleGradientV(
static_cast<int>(x),
static_cast<int>(y),
static_cast<int>(width),
static_cast<int>(height),
color1,
color2);
}
void DrawGradientH(::Color color1, ::Color color2) const {
::DrawRectangleGradientH(
static_cast<int>(x),
static_cast<int>(y),
static_cast<int>(width),
static_cast<int>(height),
color1,
color2);
}
void DrawGradient(::Color topLeft, ::Color bottomLeft, ::Color bottomRight, ::Color topRight) const {
::DrawRectangleGradientEx(*this, topLeft, bottomLeft, bottomRight, topRight);
}
void DrawLines(::Color color) const {
::DrawRectangleLines(
static_cast<int>(x),
static_cast<int>(y),
static_cast<int>(width),
static_cast<int>(height),
color);
}
void DrawLines(::Color color, float lineThick) const { ::DrawRectangleLinesEx(*this, lineThick, color); }
void DrawRounded(float roundness, int segments, ::Color color) const {
::DrawRectangleRounded(*this, roundness, segments, color);
}
void DrawRoundedLines(float roundness, int segments, ::Color color) const {
::DrawRectangleRoundedLines(*this, roundness, segments, color);
}
void DrawRoundedLines(float roundness, int segments, float lineThick, ::Color color) const {
::DrawRectangleRoundedLinesEx(*this, roundness, segments, lineThick, color);
}
/**
* Check collision between two rectangles
*/
RLCPP_NODISCARD bool CheckCollision(::Rectangle rec2) const { return ::CheckCollisionRecs(*this, rec2); }
/**
* Get collision rectangle for two rectangles collision
*/
RLCPP_NODISCARD ::Rectangle GetCollision(::Rectangle rec2) const { return ::GetCollisionRec(*this, rec2); }
/**
* Check if point is inside rectangle
*/
RLCPP_NODISCARD bool CheckCollision(::Vector2 point) const { return ::CheckCollisionPointRec(point, *this); }
/**
* Check collision between circle and rectangle
*/
RLCPP_NODISCARD bool CheckCollision(::Vector2 center, float radius) const {
return ::CheckCollisionCircleRec(center, radius, *this);
}
RLCPP_NODISCARD Vector2 GetSize() const { return {width, height}; }
Rectangle& SetSize(float newWidth, float newHeight) {
width = newWidth;
height = newHeight;
return *this;
}
Rectangle& SetSize(const ::Vector2& size) { return SetSize(size.x, size.y); }
Rectangle& SetShapesTexture(const ::Texture2D& texture) {
::SetShapesTexture(texture, *this);
return *this;
}
RLCPP_NODISCARD Vector2 GetPosition() const { return {x, y}; }
Rectangle& SetPosition(float newX, float newY) {
x = newX;
y = newY;
return *this;
}
Rectangle& SetPosition(const ::Vector2& position) { return SetPosition(position.x, position.y); }
protected:
void set(const ::Rectangle& rect) {
x = rect.x;
y = rect.y;
width = rect.width;
height = rect.height;
}
};
} // namespace raylib
using RRectangle = raylib::Rectangle;
#endif // RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
+65
View File
@@ -0,0 +1,65 @@
#ifndef RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
#define RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
#include "./RenderTextureUnmanaged.hpp"
namespace raylib {
/**
* RenderTexture type, for texture rendering.
*
* The render texture will be unloaded on object destruction. Use raylib::RenderTextureUnmanaged
* if you're looking to not unload.
*
* @see raylib::RenderTextureUnmanaged
*/
class RenderTexture : public RenderTextureUnmanaged {
public:
using RenderTextureUnmanaged::RenderTextureUnmanaged;
RenderTexture(const RenderTexture&) = delete;
RenderTexture& operator=(const RenderTexture&) = delete;
RenderTexture(RenderTexture&& other) noexcept {
set(other);
other.id = 0;
other.texture = {};
other.depth = {};
}
RenderTexture& operator=(RenderTexture&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.id = 0;
other.texture = {};
other.depth = {};
return *this;
}
RenderTexture& operator=(const ::RenderTexture& other) {
Unload();
set(other);
return *this;
}
~RenderTexture() { Unload(); }
/**
* Unload previous render texture, then load a new one.
*/
void Load(int width, int height) {
Unload();
RenderTextureUnmanaged::Load(width, height);
}
};
using RenderTexture2D = RenderTexture;
} // namespace raylib
using RRenderTexture = raylib::RenderTexture;
using RRenderTexture2D = raylib::RenderTexture2D;
#endif // RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
+123
View File
@@ -0,0 +1,123 @@
#ifndef RAYLIB_CPP_INCLUDE_RENDERTEXTUREUNMANAGED_HPP_
#define RAYLIB_CPP_INCLUDE_RENDERTEXTUREUNMANAGED_HPP_
#include "./RaylibException.hpp"
#include "./TextureUnmanaged.hpp"
#include "./raylib-cpp-utils.hpp"
namespace raylib {
/**
* A RenderTexture that is not managed by C++ RAII.
*
* Make sure to Unload() this if needed, otherwise use raylib::RenderTexture.
*
* @see raylib::RenderTexture
*/
class RenderTextureUnmanaged : public ::RenderTexture {
public:
/**
* Default constructor to build an empty RenderTexture.
*/
RenderTextureUnmanaged() : ::RenderTexture{0, {}, {}} {}
/**
* Creates a RenderTexture from an existing RenderTexture struct.
*/
RenderTextureUnmanaged(const ::RenderTexture& renderTexture) : ::RenderTexture(renderTexture) {}
/**
* Creates a RenderTexture from its components.
*/
RenderTextureUnmanaged(unsigned int id, const ::Texture& texture, const ::Texture& depth)
: ::RenderTexture{id, texture, depth} {}
/**
* Load texture for rendering (framebuffer).
*
* @throws raylib::RaylibException Throws if failed to create the render texture.
*/
RenderTextureUnmanaged(int width, int height) { Load(width, height); }
[[nodiscard]] std::string ToString() const { return TextFormat("RenderTexture(id=%u)", id); }
operator std::string() const { return ToString(); }
GETTER(unsigned int, Id, id)
/**
* Get the color buffer attachment texture.
*/
TextureUnmanaged GetTexture() { return texture; }
RLCPP_NODISCARD TextureUnmanaged GetTexture() const { return texture; }
void SetTexture(const ::Texture& newTexture) { texture = newTexture; }
/**
* Get the depth buffer attachment texture.
*/
TextureUnmanaged GetDepth() { return depth; }
void SetDepth(const ::Texture& newDepth) { depth = newDepth; }
RenderTextureUnmanaged& operator=(const ::RenderTexture& other) {
set(other);
return *this;
}
/**
* Load texture for rendering (framebuffer).
*
* @throws raylib::RaylibException Throws if failed to create the render texture.
*/
void Load(int width, int height) {
set(::LoadRenderTexture(width, height));
if (!IsValid()) {
throw RaylibException("Failed to create RenderTexture");
}
}
/**
* Unload render texture from GPU memory (VRAM).
*/
void Unload() {
if (IsValid()) {
::UnloadRenderTexture(*this);
id = 0;
}
}
/**
* Initializes render texture for drawing.
*/
RenderTextureUnmanaged& BeginMode() {
::BeginTextureMode(*this);
return *this;
}
/**
* Ends drawing to render texture.
*/
RenderTextureUnmanaged& EndMode() {
::EndTextureMode();
return *this;
}
/**
* Retrieves whether or not the render texture is ready.
*/
RLCPP_NODISCARD bool IsValid() const { return ::IsRenderTextureValid(*this); }
protected:
void set(const ::RenderTexture& renderTexture) {
id = renderTexture.id;
texture = renderTexture.texture;
depth = renderTexture.depth;
}
};
using RenderTexture2DUnmanaged = RenderTextureUnmanaged;
} // namespace raylib
using RRenderTextureUnmanaged = raylib::RenderTextureUnmanaged;
using RRenderTexture2DUnmanaged = raylib::RenderTexture2DUnmanaged;
#endif // RAYLIB_CPP_INCLUDE_RENDERTEXTUREUNMANAGED_HPP_
+53
View File
@@ -0,0 +1,53 @@
#ifndef RAYLIB_CPP_INCLUDE_SHADER_HPP_
#define RAYLIB_CPP_INCLUDE_SHADER_HPP_
#include <string>
#include "ShaderUnmanaged.hpp"
#include "Texture.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Shader type (generic)
*/
class Shader : public ShaderUnmanaged {
public:
using ShaderUnmanaged::ShaderUnmanaged;
Shader(const Shader&) = delete;
Shader(Shader&& other) noexcept {
set(other);
other.id = 0;
other.locs = nullptr;
}
Shader& operator=(const Shader&) = delete;
Shader& operator=(Shader&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.id = 0;
other.locs = nullptr;
return *this;
}
/**
* Unload shader from GPU memory (VRAM)
*/
~Shader() { Unload(); }
};
} // namespace raylib
using RShader = raylib::Shader;
#endif // RAYLIB_CPP_INCLUDE_SHADER_HPP_
+160
View File
@@ -0,0 +1,160 @@
#ifndef RAYLIB_CPP_INCLUDE_SHADERUNMANAGED_HPP_
#define RAYLIB_CPP_INCLUDE_SHADERUNMANAGED_HPP_
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
#include <rlgl.h>
#include <string>
namespace raylib {
/**
* Shader type (generic), not managed by C++ RAII.
*/
class ShaderUnmanaged : public ::Shader {
public:
ShaderUnmanaged() : ::Shader{rlGetShaderIdDefault(), rlGetShaderLocsDefault()} {}
ShaderUnmanaged(const ::Shader& shader) : ::Shader(shader) { }
ShaderUnmanaged(unsigned int id, int* locs = nullptr) : ::Shader{id, locs} {}
ShaderUnmanaged(const std::string& vsFileName, const std::string& fsFileName) {
set(::LoadShader(vsFileName.c_str(), fsFileName.c_str()));
}
ShaderUnmanaged(const char* vsFileName, const char* fsFileName) { set(::LoadShader(vsFileName, fsFileName)); }
/**
* Load shader from files and bind default locations.
*
* @see ::LoadShader
*/
static ::Shader Load(const std::string& vsFileName, const std::string& fsFileName) {
return ::LoadShader(vsFileName.c_str(), fsFileName.c_str());
}
static ::Shader Load(const char* vsFileName, const char* fsFileName) {
return ::LoadShader(vsFileName, fsFileName);
}
/**
* Load a shader from memory.
*
* @see ::LoadShaderFromMemory
*/
static ::Shader LoadFromMemory(const std::string& vsCode, const std::string& fsCode) {
return ::LoadShaderFromMemory(vsCode.c_str(), fsCode.c_str());
}
static ::Shader LoadFromMemory(const char* vsCode, const char* fsCode) {
return ::LoadShaderFromMemory(vsCode, fsCode);
}
GETTER(unsigned int, Id, id)
GETTER(int*, Locs, locs)
ShaderUnmanaged& operator=(const ::Shader& shader) {
set(shader);
return *this;
}
[[nodiscard]] std::string ToString() const { return TextFormat("Shader(id=%u)", id); }
operator std::string() const { return ToString(); }
/**
* Begin custom shader drawing.
*/
ShaderUnmanaged& BeginMode() {
::BeginShaderMode(*this);
return *this;
}
/**
* End custom shader drawing (use default shader).
*/
ShaderUnmanaged& EndMode() {
::EndShaderMode();
return *this;
}
/**
* Get shader uniform location
*
* @see GetShaderLocation()
*/
RLCPP_NODISCARD int GetLocation(const std::string& uniformName) const { return ::GetShaderLocation(*this, uniformName.c_str()); }
/**
* Get shader attribute location
*
* @see GetShaderLocationAttrib()
*/
RLCPP_NODISCARD int GetLocationAttrib(const std::string& attribName) const {
return ::GetShaderLocationAttrib(*this, attribName.c_str());
}
/**
* Set shader uniform value
*
* @see SetShaderValue()
*/
ShaderUnmanaged& SetValue(int uniformLoc, const void* value, int uniformType) {
::SetShaderValue(*this, uniformLoc, value, uniformType);
return *this;
}
/**
* Set shader uniform value vector
*
* @see SetShaderValueV()
*/
ShaderUnmanaged& SetValue(int uniformLoc, const void* value, int uniformType, int count) {
::SetShaderValueV(*this, uniformLoc, value, uniformType, count);
return *this;
}
/**
* Set shader uniform value (matrix 4x4)
*
* @see SetShaderValueMatrix()
*/
ShaderUnmanaged& SetValue(int uniformLoc, const ::Matrix& mat) {
::SetShaderValueMatrix(*this, uniformLoc, mat);
return *this;
}
/**
* Set shader uniform value for texture
*
* @see SetShaderValueTexture()
*/
ShaderUnmanaged& SetValue(int uniformLoc, const ::Texture2D& texture) {
::SetShaderValueTexture(*this, uniformLoc, texture);
return *this;
}
/**
* Unload shader from GPU memory (VRAM).
*/
void Unload() {
if (locs != nullptr) {
::UnloadShader(*this);
locs = nullptr;
}
}
/**
* Retrieves whether or not the shader is ready.
*/
RLCPP_NODISCARD bool IsValid() const { return ::IsShaderValid(*this); }
protected:
void set(const ::Shader& shader) {
id = shader.id;
locs = shader.locs;
}
};
} // namespace raylib
using RShaderUnmanaged = raylib::ShaderUnmanaged;
#endif // RAYLIB_CPP_INCLUDE_SHADERUNMANAGED_HPP_
+59
View File
@@ -0,0 +1,59 @@
#ifndef RAYLIB_CPP_INCLUDE_SOUND_HPP_
#define RAYLIB_CPP_INCLUDE_SOUND_HPP_
#include "./SoundUnmanaged.hpp"
namespace raylib {
/**
* Wave/Sound management functions.
*
* The sound will be unloaded on object destruction. Use raylib::SoundUnmanaged if you're looking to not unload.
*
* @code
* raylib::Sound boom("boom.wav");
* boom.Play();
* @endcode
*
* @see raylib::SoundUnmanaged
*/
class Sound : public SoundUnmanaged {
public:
using SoundUnmanaged::SoundUnmanaged;
Sound(const Sound&) = delete;
Sound& operator=(const Sound&) = delete;
Sound(Sound&& other) noexcept {
set(other);
other.stream = {nullptr, nullptr, 0, 0, 0};
other.frameCount = 0;
}
Sound& operator=(Sound&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.frameCount = 0;
other.stream = {nullptr, nullptr, 0, 0, 0};
return *this;
}
~Sound() { Unload(); }
void Load(const std::string& fileName) {
Unload();
SoundUnmanaged::Load(fileName);
}
void Load(const ::Wave& wave) {
Unload();
SoundUnmanaged::Load(wave);
}
};
} // namespace raylib
using RSound = raylib::Sound;
#endif // RAYLIB_CPP_INCLUDE_SOUND_HPP_
+190
View File
@@ -0,0 +1,190 @@
#ifndef RAYLIB_CPP_INCLUDE_SOUNDUNMANAGED_HPP_
#define RAYLIB_CPP_INCLUDE_SOUNDUNMANAGED_HPP_
#include <string>
#include "./RaylibException.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* A Sound that is not managed by C++ RAII.
*
* Make sure to Unload() this if needed, otherwise use raylib::Sound.
*
* @see raylib::Sound
*/
class SoundUnmanaged : public ::Sound {
public:
/**
* Default constructor, creates an empty Sound.
*/
SoundUnmanaged() : ::Sound{{nullptr, nullptr, 0, 0, 0}, 0} {}
/**
* Creates a SoundUnmanaged from its components.
*/
SoundUnmanaged(::AudioStream stream, unsigned int frameCount) : ::Sound{stream, frameCount} {}
/**
* Creates a SoundUnmanaged from an existing Sound struct.
*/
SoundUnmanaged(const ::Sound& sound) : ::Sound(sound) {}
/**
* Loads a Sound from the given file.
*
* @throws raylib::RaylibException Throws if the Sound failed to load.
*/
SoundUnmanaged(const std::string& fileName) { Load(fileName); }
/**
* Loads a Sound from the given Wave.
*
* @throws raylib::RaylibException Throws if the Sound failed to load.
*/
SoundUnmanaged(const ::Wave& wave) { Load(wave); }
GETTER(unsigned int, FrameCount, frameCount)
GETTER(::AudioStream, Stream, stream)
SoundUnmanaged& operator=(const ::Sound& sound) {
set(sound);
return *this;
}
[[nodiscard]] std::string ToString() const { return TextFormat("Sound(frameCount=%u)", frameCount); }
operator std::string() const { return ToString(); }
/**
* Load a sound from the given file.
*
* @throws raylib::RaylibException Throws if the Sound failed to load.
*/
void Load(const std::string& fileName) {
set(::LoadSound(fileName.c_str()));
if (!IsValid()) {
throw RaylibException("Failed to load Sound from file");
}
}
/**
* Load a sound from the given Wave.
*
* @throws raylib::RaylibException Throws if the Sound failed to load.
*/
void Load(const ::Wave& wave) {
set(::LoadSoundFromWave(wave));
if (!IsValid()) {
throw RaylibException("Failed to load Wave");
}
}
/**
* Unload sound.
*/
void Unload() {
// Protect against calling UnloadSound() twice.
if (frameCount != 0) {
::UnloadSound(*this);
frameCount = 0;
}
}
/**
* Update sound buffer with new data.
*/
SoundUnmanaged& Update(const void* data, int samplesCount) {
::UpdateSound(*this, data, samplesCount);
return *this;
}
/**
* Update sound buffer with new data, assuming it's the same sample count.
*/
SoundUnmanaged& Update(const void* data) {
::UpdateSound(*this, data, static_cast<int>(frameCount));
return *this;
}
/**
* Play a sound.
*/
SoundUnmanaged& Play() {
::PlaySound(*this);
return *this;
}
/**
* Stop playing a sound.
*/
SoundUnmanaged& Stop() {
::StopSound(*this);
return *this;
}
/**
* Pause a sound.
*/
SoundUnmanaged& Pause() {
::PauseSound(*this);
return *this;
}
/**
* Resume a paused sound.
*/
SoundUnmanaged& Resume() {
::ResumeSound(*this);
return *this;
}
/**
* Check if a sound is currently playing.
*/
RLCPP_NODISCARD bool IsPlaying() const { return ::IsSoundPlaying(*this); }
/**
* Set volume for a sound (1.0 is max level).
*/
SoundUnmanaged& SetVolume(float volume) {
::SetSoundVolume(*this, volume);
return *this;
}
/**
* Set pitch for a sound (1.0 is base level).
*/
SoundUnmanaged& SetPitch(float pitch) {
::SetSoundPitch(*this, pitch);
return *this;
}
/**
* Set pan for a sound (0.5 is center).
*/
SoundUnmanaged& SetPan(float pan = 0.5f) {
::SetSoundPan(*this, pan);
return *this;
}
/**
* Retrieve whether or not the Sound buffer is loaded.
*
* @return True or false depending on whether the Sound buffer is loaded.
*/
RLCPP_NODISCARD bool IsValid() const { return ::IsSoundValid(*this); }
protected:
void set(const ::Sound& sound) {
stream = sound.stream;
frameCount = sound.frameCount;
}
};
} // namespace raylib
using RSoundUnmanaged = raylib::SoundUnmanaged;
#endif // RAYLIB_CPP_INCLUDE_SOUNDUNMANAGED_HPP_
+199
View File
@@ -0,0 +1,199 @@
#ifndef RAYLIB_CPP_INCLUDE_TEXT_HPP_
#define RAYLIB_CPP_INCLUDE_TEXT_HPP_
#include <string>
#include "./RaylibException.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Text Functions.
*/
class Text {
public:
/**
* The internal text.
*/
std::string text;
/**
* The size of the text.
*/
float fontSize;
/**
* The color of the text.
*/
::Color color;
/**
* The internal raylib font to use for the text.
*/
::Font font;
/**
* The character spacing for the text.
*/
float spacing;
/**
* Initializes a new Text object.
*
* @param text Text to initialize.
* @param fontSize The size of the text.
* @param color The color of the font.
* @param font Font to initialize.
* @param spacing The spacing of the text.
*/
Text(
const std::string& text = "",
float fontSize = 10,
const ::Color& color = WHITE,
const ::Font& font = ::GetFontDefault(),
float spacing = 0)
: text(text)
, fontSize(fontSize)
, color(color)
, font(font)
, spacing(spacing) {
// Nothing.
}
/**
* Initializes a new Text object with a custom font.
*
* @param font Font to initialize.
* @param text Text to initialize.
* @param fontSize The size of the text.
* @param spacing The spacing of the text.
* @param color The color of the font.
*/
Text(
const ::Font& font,
const std::string& text = "",
float fontSize = 10,
float spacing = 0,
const ::Color& color = WHITE)
: text(text)
, fontSize(fontSize)
, color(color)
, font(font)
, spacing(spacing) {
// Nothing.
}
GETTERSETTER(const std::string&, Text, text)
GETTERSETTER(float, FontSize, fontSize)
GETTERSETTER(::Font, Font, font)
GETTERSETTER(::Color, Color, color)
GETTERSETTER(float, Spacing, spacing)
/**
* Draw text with values in class.
*/
void Draw(const ::Vector2& position) const { ::DrawTextEx(font, text.c_str(), position, fontSize, spacing, color); }
/**
* Draw text with values in class.
*/
void Draw(int posX, int posY) const {
::DrawTextEx(
font,
text.c_str(),
{static_cast<float>(posX), static_cast<float>(posY)},
fontSize,
spacing,
color);
}
/**
* Draw text using Font and pro parameters (rotation).
*
* @see DrawTextPro()
*/
void Draw(const ::Vector2& position, float rotation, const ::Vector2& origin = {0, 0}) const {
::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, color);
}
/**
* Measure string width for default font
*/
RLCPP_NODISCARD int Measure() const { return ::MeasureText(text.c_str(), static_cast<int>(fontSize)); }
/**
* Measure string size for Font
*/
RLCPP_NODISCARD Vector2 MeasureEx() const { return ::MeasureTextEx(font, text.c_str(), fontSize, spacing); }
Text& operator=(const Text& other) {
if (this == &other) {
return *this;
}
text = other.text;
fontSize = other.fontSize;
color = other.color;
font = other.font;
spacing = other.spacing;
return *this;
}
/**
* Draw text using font and color
*
* @see ::DrawText
*/
static void
Draw(const std::string& text, const int posX, const int posY, const int fontSize, const ::Color& color) {
::DrawText(text.c_str(), posX, posY, fontSize, color);
}
/**
* Draw text using font and color, with position defined as Vector2
*
* @see ::DrawText
*/
static void Draw(const std::string& text, const ::Vector2& pos, const int fontSize, const ::Color& color) {
::DrawText(text.c_str(), static_cast<int>(pos.x), static_cast<int>(pos.y), fontSize, color);
}
/**
* Draw text using font, color, position, font size and spacing
*
* @see ::DrawTextEx
*/
static void Draw(
const ::Font& font,
const std::string& text,
const ::Vector2& position,
const float fontSize,
const float spacing,
const ::Color& color) {
::DrawTextEx(font, text.c_str(), position, fontSize, spacing, color);
}
/**
* Draw text using font, color, position, origin, font size and spacing
*
* @see ::DrawTextPro
*/
static void Draw(
const ::Font& font,
const std::string& text,
const ::Vector2& position,
const ::Vector2& origin,
const float rotation,
const float fontSize,
const float spacing,
const ::Color& color) {
::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, color);
}
};
} // namespace raylib
using RText = raylib::Text;
#endif // RAYLIB_CPP_INCLUDE_TEXT_HPP_
+102
View File
@@ -0,0 +1,102 @@
#ifndef RAYLIB_CPP_INCLUDE_TEXTURE_HPP_
#define RAYLIB_CPP_INCLUDE_TEXTURE_HPP_
#include "./TextureUnmanaged.hpp"
namespace raylib {
/**
* Texture type
*
* The texture will be unloaded on object destruction. Use raylib::TextureUnmanaged if you're looking to not unload.
*
* @see raylib::TextureUnmanaged
*/
class Texture : public TextureUnmanaged {
public:
using TextureUnmanaged::TextureUnmanaged;
/**
* Explicitly forbid the copy constructor.
*/
Texture(const Texture&) = delete;
/**
* Explicitly forbid copy assignment.
*/
Texture& operator=(const Texture&) = delete;
/**
* Move constructor.
*/
Texture(Texture&& other) noexcept {
set(other);
other.id = 0;
other.width = 0;
other.height = 0;
other.mipmaps = 0;
other.format = 0;
}
/**
* On destruction, unload the Texture.
*/
~Texture() { Unload(); }
/**
* Move assignment.
*/
Texture& operator=(Texture&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.id = 0;
other.width = 0;
other.height = 0;
other.mipmaps = 0;
other.format = 0;
return *this;
}
/**
* Unload previous texture, then load texture from image data
*/
void Load(const ::Image& image) {
Unload();
TextureUnmanaged::Load(image);
}
/**
* Unload previous texture, then load cubemap from image.
* Multiple image cubemap layouts supported
*/
void Load(const ::Image& image, int layoutType) {
Unload();
TextureUnmanaged::Load(image, layoutType);
}
/**
* Unload previous texture, then load texture from file into GPU memory (VRAM)
*/
void Load(const std::string& fileName) {
Unload();
TextureUnmanaged::Load(fileName);
}
};
// Create the Texture aliases.
using Texture2D = Texture;
using TextureCubemap = Texture;
} // namespace raylib
using RTexture = raylib::Texture;
using RTexture2D = raylib::Texture2D;
using RTextureCubemap = raylib::TextureCubemap;
#endif // RAYLIB_CPP_INCLUDE_TEXTURE_HPP_
+347
View File
@@ -0,0 +1,347 @@
#ifndef RAYLIB_CPP_INCLUDE_TEXTUREUNMANAGED_HPP_
#define RAYLIB_CPP_INCLUDE_TEXTUREUNMANAGED_HPP_
#include <string>
#include "./Image.hpp"
#include "./Material.hpp"
#include "./RaylibException.hpp"
#include "./Vector2.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* A Texture that is not managed by C++ RAII.
*
* Make sure to Unload() this if needed, otherwise use raylib::Texture.
*
* @see raylib::Texture
*/
class TextureUnmanaged : public ::Texture {
public:
/**
* Default texture constructor.
*/
TextureUnmanaged() : ::Texture{0, 0, 0, 0, 0} {
// Nothing.
}
/**
* Move/Create a texture structure manually.
*/
TextureUnmanaged(
unsigned int id,
int width,
int height,
int mipmaps = 1,
int format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
: ::Texture{id, width, height, mipmaps, format} {
// Nothing.
}
/**
* Creates a texture object based on the given Texture struct data.
*/
TextureUnmanaged(const ::Texture& texture)
: ::Texture{texture.id, texture.width, texture.height, texture.mipmaps, texture.format} {
// Nothing.
}
/**
* Creates a texture from the given Image.
*
* @throws raylib::RaylibException Throws if failed to create the texture from the given image.
*/
TextureUnmanaged(const ::Image& image) { Load(image); }
/**
* Load cubemap from image, multiple image cubemap layouts supported.
*
* @throws raylib::RaylibException Throws if failed to create the texture from the given cubemap.
*
* @see LoadTextureCubemap()
*/
TextureUnmanaged(const ::Image& image, int layout) { Load(image, layout); }
/**
* Load texture from file into GPU memory (VRAM)
*
* @throws raylib::RaylibException Throws if failed to create the texture from the given file.
*/
TextureUnmanaged(const std::string& fileName) { Load(fileName); }
TextureUnmanaged(::Texture&& other) : ::Texture{other.id, other.width, other.height, other.mipmaps, other.format} {
// Nothing.
}
GETTER(unsigned int, Id, id)
GETTER(int, Width, width)
GETTER(int, Height, height)
GETTER(int, Mipmaps, mipmaps)
GETTER(int, Format, format)
TextureUnmanaged& operator=(const ::Texture& texture) {
set(texture);
return *this;
}
[[nodiscard]] std::string ToString() const { return TextFormat("Texture(id=%u, %dx%d)", id, width, height); }
operator std::string() const { return ToString(); }
/**
* Retrieve the width and height of the texture.
*/
RLCPP_NODISCARD Vector2 GetSize() const { return {static_cast<float>(width), static_cast<float>(height)}; }
/**
* Load texture from image data
*/
void Load(const ::Image& image) {
set(::LoadTextureFromImage(image));
if (!IsValid()) {
throw RaylibException("Failed to load Texture from Image");
}
}
/**
* Load cubemap from image, multiple image cubemap layouts supported
*/
void Load(const ::Image& image, int layoutType) {
set(::LoadTextureCubemap(image, layoutType));
if (!IsValid()) {
throw RaylibException("Failed to load Texture from Cubemap");
}
}
/**
* Load texture from file into GPU memory (VRAM)
*/
void Load(const std::string& fileName) {
set(::LoadTexture(fileName.c_str()));
if (!IsValid()) {
throw RaylibException("Failed to load Texture from file: " + fileName);
}
}
/**
* Unload texture from GPU memory (VRAM)
*/
void Unload() {
// Protect against calling UnloadTexture() twice.
if (id != 0) {
::UnloadTexture(*this);
id = 0;
}
}
/**
* Update GPU texture with new data
*/
TextureUnmanaged& Update(const void* pixels) {
::UpdateTexture(*this, pixels);
return *this;
}
/**
* Update GPU texture rectangle with new data
*/
TextureUnmanaged& Update(::Rectangle rec, const void* pixels) {
UpdateTextureRec(*this, rec, pixels);
return *this;
}
/**
* Get pixel data from GPU texture and return an Image
*/
RLCPP_NODISCARD ::Image GetData() const { return ::LoadImageFromTexture(*this); }
/**
* Get pixel data from GPU texture and return an Image
*/
operator Image() { return GetData(); }
/**
* Generate GPU mipmaps for a texture
*/
TextureUnmanaged& GenMipmaps() {
::GenTextureMipmaps(this);
return *this;
}
/**
* Set texture scaling filter mode
*/
TextureUnmanaged& SetFilter(int filterMode) {
::SetTextureFilter(*this, filterMode);
return *this;
}
/**
* Set texture wrapping mode
*/
TextureUnmanaged& SetWrap(int wrapMode) {
::SetTextureWrap(*this, wrapMode);
return *this;
}
/**
* Draw a Texture2D
*
* @see ::DrawTexture()
*/
void Draw(int posX = 0, int posY = 0, ::Color tint = {255, 255, 255, 255}) const {
::DrawTexture(*this, posX, posY, tint);
}
/**
* Draw a Texture2D with position defined as Vector2
*
* @see ::DrawTextureV()
*/
void Draw(::Vector2 position, ::Color tint = {255, 255, 255, 255}) const { ::DrawTextureV(*this, position, tint); }
/**
* Draw a Texture2D with extended parameters
*
* @see ::DrawTextureEx()
*/
void Draw(::Vector2 position, float rotation, float scale = 1.0f, ::Color tint = {255, 255, 255, 255}) const {
::DrawTextureEx(*this, position, rotation, scale, tint);
}
/**
* Draw a part of a texture defined by a rectangle
*
* @see ::DrawTextureRec()
*/
void Draw(::Rectangle sourceRec, ::Vector2 position = {0, 0}, ::Color tint = {255, 255, 255, 255}) const {
::DrawTextureRec(*this, sourceRec, position, tint);
}
/**
* Draw a part of a texture defined by a rectangle with 'pro' parameters
*
* @see ::DrawTexturePro()
*/
void Draw(
::Rectangle sourceRec,
::Rectangle destRec,
::Vector2 origin = {0, 0},
float rotation = 0,
::Color tint = {255, 255, 255, 255}) const {
::DrawTexturePro(*this, sourceRec, destRec, origin, rotation, tint);
}
/**
* Draws a texture (or part of it) that stretches or shrinks nicely
*
* @see ::DrawTextureNPatch()
*/
void Draw(
::NPatchInfo nPatchInfo,
::Rectangle destRec,
::Vector2 origin = {0, 0},
float rotation = 0,
::Color tint = {255, 255, 255, 255}) const {
::DrawTextureNPatch(*this, nPatchInfo, destRec, origin, rotation, tint);
}
/**
* Draw a billboard texture
*
* @see ::DrawBillboard()
*/
void
DrawBillboard(const ::Camera& camera, ::Vector3 position, float size, ::Color tint = {255, 255, 255, 255}) const {
::DrawBillboard(camera, *this, position, size, tint);
}
/**
* Draw a billboard texture defined by source
*
* @see ::DrawBillboardRec()
*/
void DrawBillboard(
const ::Camera& camera,
::Rectangle source,
::Vector3 position,
::Vector2 size,
::Color tint = {255, 255, 255, 255}) const {
DrawBillboardRec(camera, *this, source, position, size, tint);
}
/**
* Draw a billboard texture defined by source and rotation
*
* @see ::DrawBillboardPro()
*/
void DrawBillboard(
const ::Camera& camera,
::Rectangle source,
Vector3 position,
::Vector3 up,
Vector2 size,
Vector2 origin,
float rotation = 0.0f,
::Color tint = {255, 255, 255, 255}) const {
DrawBillboardPro(camera, *this, source, position, up, size, origin, rotation, tint);
}
/**
* Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...)
*/
TextureUnmanaged& SetMaterial(::Material* material, int mapType = MATERIAL_MAP_NORMAL) {
::SetMaterialTexture(material, mapType, *this);
return *this;
}
TextureUnmanaged& SetMaterial(const ::Material& material, int mapType = MATERIAL_MAP_NORMAL) {
::SetMaterialTexture(const_cast<::Material*>(&material), mapType, *this);
return *this;
}
/**
* Set texture and rectangle to be used on shapes drawing.
*/
TextureUnmanaged& SetShapes(const ::Rectangle& source) {
::SetShapesTexture(*this, source);
return *this;
}
/**
* Set shader uniform value for texture (sampler2d)
*/
TextureUnmanaged& SetShaderValue(const ::Shader& shader, int locIndex) {
::SetShaderValueTexture(shader, locIndex, *this);
return *this;
}
/**
* Determines whether or not the Texture has been loaded and is ready.
*
* @return True or false depending on whether the Texture has data.
*/
RLCPP_NODISCARD bool IsValid() const { return IsTextureValid(*this); }
protected:
void set(const ::Texture& texture) {
id = texture.id;
width = texture.width;
height = texture.height;
mipmaps = texture.mipmaps;
format = texture.format;
}
};
// Create the TextureUnmanaged aliases.
using Texture2DUnmanaged = TextureUnmanaged;
using TextureCubemapUnmanaged = TextureUnmanaged;
} // namespace raylib
using RTextureUnmanaged = raylib::TextureUnmanaged;
using RTexture2DUnmanaged = raylib::Texture2DUnmanaged;
using RTextureCubemapUnmanaged = raylib::TextureCubemapUnmanaged;
#endif // RAYLIB_CPP_INCLUDE_TEXTUREUNMANAGED_HPP_
+51
View File
@@ -0,0 +1,51 @@
#ifndef RAYLIB_CPP_INCLUDE_TOUCH_HPP_
#define RAYLIB_CPP_INCLUDE_TOUCH_HPP_
#include "./Functions.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Input-related functions: touch
*/
namespace Touch {
/**
* Get touch position X for touch point 0 (relative to screen size)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline int GetX() {
return ::GetTouchX();
}
/**
* Get touch position Y for touch point 0 (relative to screen size)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline int GetY() {
return ::GetTouchY();
}
/**
* Get touch position XY for a touch point index (relative to screen size)
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline Vector2 GetPosition(int index) {
return ::GetTouchPosition(index);
}
/**
* Get touch point identifier for given index
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline int GetPointId(int index) {
return ::GetTouchPointId(index);
}
/**
* Get number of touch points
*/
RLCPP_MAYBEUNUSED RLCPPAPI inline int GetPointCount() {
return ::GetTouchPointCount();
}
} // namespace Touch
} // namespace raylib
namespace RTouch = raylib::Touch;
#endif // RAYLIB_CPP_INCLUDE_TOUCH_HPP_
+396
View File
@@ -0,0 +1,396 @@
#ifndef RAYLIB_CPP_INCLUDE_VECTOR2_HPP_
#define RAYLIB_CPP_INCLUDE_VECTOR2_HPP_
#ifndef RAYLIB_CPP_NO_MATH
#include <cmath>
#endif
#include <string>
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
#include "./raymath.hpp"
namespace raylib {
/**
* Vector2 type
*/
class Vector2 : public ::Vector2 {
public:
constexpr Vector2(const ::Vector2& vec) : ::Vector2{vec.x, vec.y} {}
constexpr Vector2(float x = 0, float y = 0) : ::Vector2{x, y} {}
GETTERSETTER(float, X, x)
GETTERSETTER(float, Y, y)
/**
* Set the Vector2 to the same as the given Vector2.
*/
Vector2& operator=(const ::Vector2& vector2) {
set(vector2);
return *this;
}
/**
* Determine whether or not the vectors are equal.
*/
constexpr bool operator==(const ::Vector2& other) const { return x == other.x && y == other.y; }
/**
* Determines if the vectors are not equal.
*/
constexpr bool operator!=(const ::Vector2& other) const { return !(*this == other); }
RLCPP_NODISCARD std::string ToString() const { return TextFormat("Vector2(%f, %f)", x, y); }
operator std::string() const { return ToString(); }
#ifndef RAYLIB_CPP_NO_MATH
/**
* Add two vectors (v1 + v2)
*/
Vector2 Add(const ::Vector2& vector2) const { return Vector2Add(*this, vector2); }
/**
* Add two vectors (v1 + v2)
*/
Vector2 operator+(const ::Vector2& vector2) const { return Vector2Add(*this, vector2); }
/**
* Add two vectors (v1 + v2)
*/
Vector2& operator+=(const ::Vector2& vector2) {
set(Vector2Add(*this, vector2));
return *this;
}
/**
* Add vector and float value
*/
Vector2 Add(float value) const {
return Vector2AddValue(*this, value);
}
/**
* Add vector and float value
*/
Vector2 operator+(float value) const {
return Vector2AddValue(*this, value);
}
/**
* Add vector and float value
*/
Vector2& operator+=(float value) {
set(Vector2AddValue(*this, value));
return *this;
}
/**
* Subtract two vectors (v1 - v2)
*/
RLCPP_NODISCARD Vector2 Subtract(const ::Vector2& vector2) const { return Vector2Subtract(*this, vector2); }
/**
* Subtract two vectors (v1 - v2)
*/
Vector2 operator-(const ::Vector2& vector2) const { return Vector2Subtract(*this, vector2); }
/**
* Subtract two vectors (v1 - v2)
*/
Vector2& operator-=(const ::Vector2& vector2) {
set(Vector2Subtract(*this, vector2));
return *this;
}
/**
* Subtract vector by float value
*/
RLCPP_NODISCARD Vector2 Subtract(float value) const {
return Vector2SubtractValue(*this, value);
}
/**
* Subtract vector by float value
*/
Vector2 operator-(float value) const {
return Vector2SubtractValue(*this, value);
}
/**
* Subtract vector by float value
*/
Vector2& operator-=(float value) {
set(Vector2SubtractValue(*this, value));
return *this;
}
/**
* Negate vector
*/
RLCPP_NODISCARD Vector2 Negate() const { return Vector2Negate(*this); }
/**
* Negate vector
*/
Vector2 operator-() const { return Vector2Negate(*this); }
/**
* Multiply vector by vector
*/
RLCPP_NODISCARD Vector2 Multiply(const ::Vector2& vector2) const { return Vector2Multiply(*this, vector2); }
/**
* Multiply vector by vector
*/
Vector2 operator*(const ::Vector2& vector2) const { return Vector2Multiply(*this, vector2); }
/**
* Multiply vector by vector
*/
Vector2& operator*=(const ::Vector2& vector2) {
set(Vector2Multiply(*this, vector2));
return *this;
}
/**
* Scale vector (multiply by value)
*/
RLCPP_NODISCARD Vector2 Scale(const float scale) const { return Vector2Scale(*this, scale); }
/**
* Scale vector (multiply by value)
*/
Vector2 operator*(const float scale) const { return Vector2Scale(*this, scale); }
/**
* Scale vector (multiply by value)
*/
Vector2& operator*=(const float scale) {
set(Vector2Scale(*this, scale));
return *this;
}
/**
* Divide vector by vector
*/
RLCPP_NODISCARD Vector2 Divide(const ::Vector2& vector2) const { return Vector2Divide(*this, vector2); }
/**
* Divide vector by vector
*/
Vector2 operator/(const ::Vector2& vector2) const { return Vector2Divide(*this, vector2); }
/**
* Divide vector by vector
*/
Vector2& operator/=(const ::Vector2& vector2) {
set(Vector2Divide(*this, vector2));
return *this;
}
/**
* Divide vector by value
*/
RLCPP_NODISCARD Vector2 Divide(const float div) const { return ::Vector2{x / div, y / div}; }
/**
* Divide vector by value
*/
Vector2 operator/(const float div) const { return Divide(div); }
/**
* Divide vector by value
*/
Vector2& operator/=(const float div) {
this->x /= div;
this->y /= div;
return *this;
}
/**
* Normalize provided vector
*/
RLCPP_NODISCARD Vector2 Normalize() const { return Vector2Normalize(*this); }
/**
* Transforms a Vector2 by a given Matrix
*/
RLCPP_NODISCARD Vector2 Transform(::Matrix mat) const { return ::Vector2Transform(*this, mat); }
/**
* Calculate linear interpolation between two vectors
*/
RLCPP_NODISCARD Vector2 Lerp(const ::Vector2& vector2, float amount) const { return Vector2Lerp(*this, vector2, amount); }
/**
* Calculate reflected vector to normal
*/
RLCPP_NODISCARD Vector2 Reflect(const ::Vector2& normal) const { return Vector2Reflect(*this, normal); }
/**
* Rotate Vector by float in radians
*/
RLCPP_NODISCARD Vector2 Rotate(float angle) const { return Vector2Rotate(*this, angle); }
/**
* Move Vector towards target
*/
RLCPP_NODISCARD Vector2 MoveTowards(const ::Vector2& target, float maxDistance) const {
return Vector2MoveTowards(*this, target, maxDistance);
}
/**
* Invert the given vector
*/
RLCPP_NODISCARD Vector2 Invert() const { return ::Vector2Invert(*this); }
/**
* Clamp the components of the vector between
*/
RLCPP_NODISCARD Vector2 Clamp(::Vector2 min, ::Vector2 max) const { return ::Vector2Clamp(*this, min, max); }
/**
* // Clamp the magnitude of the vector between two min and max values
*/
RLCPP_NODISCARD Vector2 Clamp(float min, float max) const { return ::Vector2ClampValue(*this, min, max); }
/**
* Check whether two given vectors are almost equal
*/
RLCPP_NODISCARD int Equals(::Vector2 q) const { return ::Vector2Equals(*this, q); }
/**
* Calculate vector length
*/
RLCPP_NODISCARD float Length() const { return Vector2Length(*this); }
/**
* Calculate vector square length
*/
RLCPP_NODISCARD float LengthSqr() const { return Vector2LengthSqr(*this); }
/**
* Calculate two vectors dot product
*/
RLCPP_NODISCARD float DotProduct(const ::Vector2& vector2) const { return Vector2DotProduct(*this, vector2); }
/**
* Calculate distance between two vectors
*/
RLCPP_NODISCARD float Distance(const ::Vector2& vector2) const { return Vector2Distance(*this, vector2); }
/**
* Calculate square distance between two vectors
*/
RLCPP_NODISCARD float DistanceSqr(::Vector2 v2) const { return ::Vector2DistanceSqr(*this, v2); }
/**
* Calculate angle from two vectors in X-axis
*/
RLCPP_NODISCARD float Angle(const ::Vector2& vector2) const { return Vector2Angle(*this, vector2); }
/**
* Vector with components value 0.0f
*/
static Vector2 Zero() { return Vector2Zero(); }
/**
* Vector with components value 1.0f
*/
static Vector2 One() { return Vector2One(); }
#endif
void DrawPixel(::Color color = {0, 0, 0, 255}) const { ::DrawPixelV(*this, color); }
void DrawLine(::Vector2 endPos, ::Color color = {0, 0, 0, 255}) const { ::DrawLineV(*this, endPos, color); }
void DrawLine(::Vector2 endPos, float thick, ::Color color = {0, 0, 0, 255}) const {
::DrawLineEx(*this, endPos, thick, color);
}
void DrawLineBezier(::Vector2 endPos, float thick, ::Color color = {0, 0, 0, 255}) const {
::DrawLineBezier(*this, endPos, thick, color);
}
/**
* Draw a color-filled circle (Vector version)
*/
void DrawCircle(float radius, ::Color color = {0, 0, 0, 255}) const { ::DrawCircleV(*this, radius, color); }
void DrawRectangle(::Vector2 size, ::Color color = {0, 0, 0, 255}) const { ::DrawRectangleV(*this, size, color); }
void DrawPoly(int sides, float radius, float rotation, ::Color color = {0, 0, 0, 255}) const {
::DrawPoly(*this, sides, radius, rotation, color);
}
/**
* Check collision between two circles
*/
RLCPP_NODISCARD bool CheckCollisionCircle(float radius1, ::Vector2 center2, float radius2) const {
return ::CheckCollisionCircles(*this, radius1, center2, radius2);
}
/**
* Check collision between circle and rectangle
*/
RLCPP_NODISCARD bool CheckCollisionCircle(float radius, ::Rectangle rec) const {
return ::CheckCollisionCircleRec(*this, radius, rec);
}
/**
* Check if point is inside rectangle
*/
RLCPP_NODISCARD bool CheckCollision(::Rectangle rec) const { return ::CheckCollisionPointRec(*this, rec); }
/**
* Check if point is inside circle
*/
RLCPP_NODISCARD bool CheckCollision(::Vector2 center, float radius) const {
return ::CheckCollisionPointCircle(*this, center, radius);
}
/**
* Check if point is inside a triangle
*/
RLCPP_NODISCARD bool CheckCollision(::Vector2 p1, ::Vector2 p2, ::Vector2 p3) const {
return ::CheckCollisionPointTriangle(*this, p1, p2, p3);
}
/**
* Check the collision between two lines defined by two points each, returns collision point by reference
*/
bool
CheckCollisionLines(::Vector2 endPos1, ::Vector2 startPos2, ::Vector2 endPos2, ::Vector2* collisionPoint) const {
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]
*/
RLCPP_NODISCARD bool CheckCollisionPointLine(::Vector2 p1, ::Vector2 p2, int threshold = 1) const {
return ::CheckCollisionPointLine(*this, p1, p2, threshold);
}
protected:
void set(const ::Vector2& vec) {
x = vec.x;
y = vec.y;
}
};
} // namespace raylib
using RVector2 = raylib::Vector2;
#endif // RAYLIB_CPP_INCLUDE_VECTOR2_HPP_
+312
View File
@@ -0,0 +1,312 @@
#ifndef RAYLIB_CPP_INCLUDE_VECTOR3_HPP_
#define RAYLIB_CPP_INCLUDE_VECTOR3_HPP_
#ifndef RAYLIB_CPP_NO_MATH
#include <cmath>
#endif
#include <string>
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
#include "./raymath.hpp"
namespace raylib {
/**
* Vector3 type
*/
class Vector3 : public ::Vector3 {
public:
constexpr Vector3(const ::Vector3& vec) : ::Vector3{vec.x, vec.y, vec.z} {}
constexpr Vector3(float x = 0, float y = 0, float z = 0) : ::Vector3{x, y, z} {}
Vector3(::Color color) { set(ColorToHSV(color)); }
GETTERSETTER(float, X, x)
GETTERSETTER(float, Y, y)
GETTERSETTER(float, Z, z)
Vector3& operator=(const ::Vector3& vector3) {
set(vector3);
return *this;
}
constexpr bool operator==(const ::Vector3& other) const { return x == other.x && y == other.y && z == other.z; }
constexpr bool operator!=(const ::Vector3& other) const { return !(*this == other); }
RLCPP_NODISCARD std::string ToString() const { return TextFormat("Vector3(%f, %f, %f)", x, y, z); }
operator std::string() const { return ToString(); }
#ifndef RAYLIB_CPP_NO_MATH
/**
* Add two vectors
*/
RLCPP_NODISCARD Vector3 Add(const ::Vector3& vector3) const { return Vector3Add(*this, vector3); }
/**
* Add two vectors
*/
Vector3 operator+(const ::Vector3& vector3) const { return Vector3Add(*this, vector3); }
Vector3& operator+=(const ::Vector3& vector3) {
set(Vector3Add(*this, vector3));
return *this;
}
/**
* Add vector and float value
*/
RLCPP_NODISCARD Vector3 Add(float value) const {
return Vector3AddValue(*this, value);
}
/**
* Add vector and float value
*/
Vector3 operator+(float value) const {
return Vector3AddValue(*this, value);
}
Vector3& operator+=(float value) {
set(Vector3AddValue(*this, value));
return *this;
}
/**
* Subtract two vectors.
*/
RLCPP_NODISCARD Vector3 Subtract(const ::Vector3& vector3) const { return Vector3Subtract(*this, vector3); }
/**
* Subtract two vectors.
*/
Vector3 operator-(const ::Vector3& vector3) const { return Vector3Subtract(*this, vector3); }
Vector3& operator-=(const ::Vector3& vector3) {
set(Vector3Subtract(*this, vector3));
return *this;
}
/**
* Subtract vector by float value
*/
RLCPP_NODISCARD Vector3 Subtract(float value) const {
return Vector3SubtractValue(*this, value);
}
/**
* Subtract vector by float value
*/
Vector3 operator-(float value) const {
return Vector3SubtractValue(*this, value);
}
Vector3& operator-=(float value) {
set(Vector3SubtractValue(*this, value));
return *this;
}
/**
* Negate provided vector (invert direction)
*/
RLCPP_NODISCARD Vector3 Negate() const { return Vector3Negate(*this); }
/**
* Negate provided vector (invert direction)
*/
Vector3 operator-() const { return Vector3Negate(*this); }
/**
* Multiply vector by vector
*/
RLCPP_NODISCARD Vector3 Multiply(const ::Vector3& vector3) const { return Vector3Multiply(*this, vector3); }
/**
* Multiply vector by vector
*/
Vector3 operator*(const ::Vector3& vector3) const { return Vector3Multiply(*this, vector3); }
/**
* Multiply vector by vector
*/
Vector3& operator*=(const ::Vector3& vector3) {
set(Vector3Multiply(*this, vector3));
return *this;
}
/**
* Multiply vector by scalar
*/
RLCPP_NODISCARD Vector3 Scale(const float scaler) const { return Vector3Scale(*this, scaler); }
/**
* Multiply vector by scalar
*/
Vector3 operator*(const float scaler) const { return Vector3Scale(*this, scaler); }
/**
* Multiply vector by scalar
*/
Vector3& operator*=(const float scaler) {
set(Vector3Scale(*this, scaler));
return *this;
}
/**
* Divide vector by vector
*/
RLCPP_NODISCARD Vector3 Divide(const ::Vector3& vector3) const { return Vector3Divide(*this, vector3); }
/**
* Divide vector by vector
*/
Vector3 operator/(const ::Vector3& vector3) const { return Vector3Divide(*this, vector3); }
/**
* Divide vector by vector
*/
Vector3& operator/=(const ::Vector3& vector3) {
x /= vector3.x;
y /= vector3.y;
z /= vector3.z;
return *this;
}
/**
* Divide a vector by a value.
*/
RLCPP_NODISCARD Vector3 Divide(const float div) const { return ::Vector3{x / div, y / div, z / div}; }
/**
* Divide a vector by a value.
*/
Vector3 operator/(const float div) const { return Divide(div); }
/**
* Divide a vector by a value.
*/
Vector3& operator/=(const float div) {
x /= div;
y /= div;
z /= div;
return *this;
}
/**
* Calculate vector length
*/
RLCPP_NODISCARD float Length() const { return Vector3Length(*this); }
/**
* Calculate vector square length
*/
RLCPP_NODISCARD float LengthSqr() const { return Vector3LengthSqr(*this); }
RLCPP_NODISCARD Vector3 Normalize() const { return Vector3Normalize(*this); }
RLCPP_NODISCARD float DotProduct(const ::Vector3& vector3) const { return Vector3DotProduct(*this, vector3); }
RLCPP_NODISCARD float Distance(const ::Vector3& vector3) const { return Vector3Distance(*this, vector3); }
RLCPP_NODISCARD Vector3 Lerp(const ::Vector3& vector3, const float amount) const { return Vector3Lerp(*this, vector3, amount); }
RLCPP_NODISCARD Vector3 CrossProduct(const ::Vector3& vector3) const { return Vector3CrossProduct(*this, vector3); }
RLCPP_NODISCARD Vector3 Perpendicular() const { return Vector3Perpendicular(*this); }
RLCPP_NODISCARD Vector3 Project(const ::Vector3& vector3) const { return Vector3Project(*this, vector3); }
RLCPP_NODISCARD Vector3 Reject(const ::Vector3& vector3) const { return Vector3Reject(*this, vector3); }
void OrthoNormalize(::Vector3* vector3) { Vector3OrthoNormalize(this, vector3); }
RLCPP_NODISCARD Vector3 Transform(const ::Matrix& matrix) const { return Vector3Transform(*this, matrix); }
RLCPP_NODISCARD Vector3 RotateByQuaternion(const ::Quaternion& quaternion) const {
return Vector3RotateByQuaternion(*this, quaternion);
}
RLCPP_NODISCARD Vector3 Reflect(const ::Vector3& normal) const { return Vector3Reflect(*this, normal); }
RLCPP_NODISCARD Vector3 Min(const ::Vector3& vector3) const { return Vector3Min(*this, vector3); }
RLCPP_NODISCARD Vector3 Max(const ::Vector3& vector3) const { return Vector3Max(*this, vector3); }
RLCPP_NODISCARD Vector3 Barycenter(const ::Vector3& a, const ::Vector3& b, const ::Vector3& c) const {
return Vector3Barycenter(*this, a, b, c);
}
static Vector3 Zero() { return Vector3Zero(); }
static Vector3 One() { return Vector3One(); }
#endif
void DrawLine3D(const ::Vector3& endPos, ::Color color) const { ::DrawLine3D(*this, endPos, color); }
void DrawPoint3D(::Color color) const { ::DrawPoint3D(*this, color); }
void DrawCircle3D(float radius, const ::Vector3& rotationAxis, float rotationAngle, Color color) const {
::DrawCircle3D(*this, radius, rotationAxis, rotationAngle, color);
}
void DrawCube(float width, float height, float length, ::Color color) const {
::DrawCube(*this, width, height, length, color);
}
void DrawCube(const ::Vector3& size, ::Color color) const { ::DrawCubeV(*this, size, color); }
void DrawCubeWires(float width, float height, float length, ::Color color) const {
::DrawCubeWires(*this, width, height, length, color);
}
void DrawCubeWires(const ::Vector3& size, ::Color color) const { ::DrawCubeWiresV(*this, size, color); }
void DrawSphere(float radius, ::Color color) const { ::DrawSphere(*this, radius, color); }
void DrawSphere(float radius, int rings, int slices, ::Color color) const {
::DrawSphereEx(*this, radius, rings, slices, color);
}
void DrawSphereWires(float radius, int rings, int slices, ::Color color) const {
::DrawSphereWires(*this, radius, rings, slices, color);
}
void DrawCylinder(float radiusTop, float radiusBottom, float height, int slices, ::Color color) const {
::DrawCylinder(*this, radiusTop, radiusBottom, height, slices, color);
}
void DrawCylinderWires(float radiusTop, float radiusBottom, float height, int slices, ::Color color) const {
::DrawCylinderWires(*this, radiusTop, radiusBottom, height, slices, color);
}
void DrawPlane(const ::Vector2& size, ::Color color) const { ::DrawPlane(*this, size, color); }
/**
* Detect collision between two spheres
*/
RLCPP_NODISCARD bool CheckCollision(float radius1, const ::Vector3& center2, float radius2) const {
return CheckCollisionSpheres(*this, radius1, center2, radius2);
}
protected:
void set(const ::Vector3& vec) {
x = vec.x;
y = vec.y;
z = vec.z;
}
};
} // namespace raylib
using RVector3 = raylib::Vector3;
#endif // RAYLIB_CPP_INCLUDE_VECTOR3_HPP_
+308
View File
@@ -0,0 +1,308 @@
#ifndef RAYLIB_CPP_INCLUDE_VECTOR4_HPP_
#define RAYLIB_CPP_INCLUDE_VECTOR4_HPP_
#ifndef RAYLIB_CPP_NO_MATH
#include <cmath>
#include <utility>
#endif
#include <string>
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
#include "./raymath.hpp"
namespace raylib {
class Quaternion : public ::Quaternion {};
/**
* Vector4 type
*/
class Vector4 : public ::Vector4 {
public:
constexpr Vector4(const ::Vector4& vec) : ::Vector4{vec.x, vec.y, vec.z, vec.w} {}
explicit constexpr Vector4(const raylib::Quaternion quat) : ::Vector4{quat.x, quat.y, quat.z, quat.w} {}
explicit constexpr Vector4(const float x = 0, const float y = 0, const float z = 0, const float w = 0) : ::Vector4{x, y, z, w} {}
explicit constexpr Vector4(const ::Rectangle rectangle) : ::Vector4{rectangle.x, rectangle.y, rectangle.width, rectangle.height} {}
explicit Vector4(const ::Color color) { set(ColorNormalize(color)); }
GETTERSETTER(float, X, x)
GETTERSETTER(float, Y, y)
GETTERSETTER(float, Z, z)
GETTERSETTER(float, W, w)
Vector4& operator=(const ::Vector4& vector4) {
set(vector4);
return *this;
}
/*
* An exact value by value equality comparison.
* Due to floating point inaccuracies consider using Equals instead.
*/
constexpr bool operator==(const ::Vector4& other) const {
return x == other.x && y == other.y && z == other.z && w == other.w;
}
/*
* An exact value by value inequality comparison.
* Due to floating point inaccuracies consider using Equals instead.
*/
constexpr bool operator!=(const ::Vector4& other) const { return !(*this == other); }
RLCPP_NODISCARD constexpr ::Rectangle ToRectangle() const { return {x, y, z, w}; }
constexpr operator ::Rectangle() const { return {x, y, z, w}; }
RLCPP_NODISCARD std::string ToString() const { return ::TextFormat("Vector4(%f, %f, %f, %f)", x, y, z, w); }
operator std::string() const { return ToString(); }
#ifndef RAYLIB_CPP_NO_MATH
static Vector4 Zero() { return ::Vector4Zero(); }
static Vector4 One() { return ::Vector4One(); }
/**
* Add two vectors
*/
RLCPP_NODISCARD Vector4 Add(const ::Vector4& vector4) const { return ::Vector4Add(*this, vector4); }
/**
* Add two vectors
*/
Vector4 operator+(const ::Vector4& vector4) const { return ::Vector4Add(*this, vector4); }
Vector4& operator+=(const ::Vector4& vector4) {
set(::Vector4Add(*this, vector4));
return *this;
}
/**
* Add vector and float value
*/
RLCPP_NODISCARD Vector4 Add(const float value) const {
return ::Vector4AddValue(*this, value);
}
/**
* Add vector and float value
*/
Vector4 operator+(const float value) const {
return ::Vector4AddValue(*this, value);
}
/**
* Add vector and float value
*/
Vector4& operator+=(const float value) {
set(::Vector4AddValue(*this, value));
return *this;
}
/**
* Add vector and float value
*/
friend Vector4 operator+(const float lhs, const Vector4& rhs) { return rhs + lhs; }
/**
* Subtract two vectors.
*/
RLCPP_NODISCARD Vector4 Subtract(const ::Vector4& vector4) const { return ::Vector4Subtract(*this, vector4); }
/**
* Subtract two vectors.
*/
Vector4 operator-(const ::Vector4& vector4) const { return ::Vector4Subtract(*this, vector4); }
Vector4& operator-=(const ::Vector4& vector4) {
set(::Vector4Subtract(*this, vector4));
return *this;
}
/**
* Subtract vector by float value
*/
RLCPP_NODISCARD Vector4 Subtract(const float value) const {
return ::Vector4SubtractValue(*this, value);
}
/**
* Subtract vector by float value
*/
Vector4 operator-(const float value) const {
return ::Vector4SubtractValue(*this, value);
}
/**
* Subtract vector by float value
*/
Vector4& operator-=(const float value) {
set(::Vector4SubtractValue(*this, value));
return *this;
}
/**
* Subtract vector by float value
*/
friend Vector4 operator-(const float lhs, const Vector4& rhs) { return rhs - lhs; }
/**
* Negate provided vector
*/
RLCPP_NODISCARD Vector4 Negate() const { return ::Vector4Negate(*this); }
/**
* Negate provided vector
*/
Vector4 operator-() const { return ::Vector4Negate(*this); }
/**
* Multiply vector by vector
*/
RLCPP_NODISCARD Vector4 Multiply(const ::Vector4& other) const { return ::Vector4Multiply(*this, other); }
/**
* Multiply vector by vector
*/
Vector4 operator*(const ::Vector4& other) const { return ::Vector4Multiply(*this, other); }
/**
* Multiply vector by vector
*/
Vector4& operator*=(const ::Vector4& other) {
set(::Vector4Multiply(*this, other));
return *this;
}
/**
* Scale vector components by value (multiply)
*/
RLCPP_NODISCARD Vector4 Scale(const float scale) const { return ::Vector4Scale(*this, scale); }
/**
* Scale vector components by value (multiply)
*/
Vector4 operator*(const float scale) const { return ::Vector4Scale(*this, scale); }
/**
* Scale vector components by value (multiply)
*/
Vector4& operator*=(const float scale) {
set(::Vector4Scale(*this, scale));
return *this;
}
/**
* Scale vector components by value (multiply)
*/
friend Vector4 operator*(const float lhs, const Vector4& rhs) { return rhs * lhs; }
/**
* Divide vector by vector
*/
RLCPP_NODISCARD Vector4 Divide(const ::Vector4& vector4) const { return ::Vector4Divide(*this, vector4); }
/**
* Divide vector by vector
*/
Vector4 operator/(const ::Vector4& vector4) const { return ::Vector4Divide(*this, vector4); }
/**
* Divide vector by vector
*/
Vector4& operator/=(const ::Vector4& vector4) {
set(::Vector4Divide(*this, vector4));
return *this;
}
/**
* Divide vector components by value
*/
RLCPP_NODISCARD constexpr Vector4 Divide(const float div) const { return ::Vector4{x / div, y / div, z / div, w / div}; }
/**
* Divide vector components by value
*/
Vector4 operator/(const float div) const { return Divide(div); }
/**
* Divide vector components by value
*/
Vector4& operator/=(const float div) {
x /= div;
y /= div;
z /= div;
w /= div;
return *this;
}
/**
* Divide vector components by value
*/
constexpr friend Vector4 operator/(const float lhs, const Vector4& rhs) {
return Vector4{
lhs / rhs.x,
lhs / rhs.y,
lhs / rhs.z,
lhs / rhs.w
};
}
RLCPP_NODISCARD float Length() const { return ::Vector4Length(*this); }
RLCPP_NODISCARD float LengthSqr() const { return ::Vector4LengthSqr(*this); }
RLCPP_NODISCARD float DotProduct(const ::Vector4& v2) const { return ::Vector4DotProduct(*this, v2); }
RLCPP_NODISCARD float Distance(const ::Vector4& v2) const { return ::Vector4Distance(*this, v2); }
RLCPP_NODISCARD float DistanceSqr(const ::Vector4& v2) const { return ::Vector4DistanceSqr(*this, v2); }
RLCPP_NODISCARD Vector4 Normalize() const { return ::Vector4Normalize(*this); }
RLCPP_NODISCARD Vector4 Min(const ::Vector4& v2) const { return ::Vector4Min(*this, v2); }
RLCPP_NODISCARD Vector4 Max(const ::Vector4& v2) const { return ::Vector4Max(*this, v2); }
RLCPP_NODISCARD Vector4 Lerp(const ::Vector4& v2, const float amount) const { return ::Vector4Lerp(*this, v2, amount); }
RLCPP_NODISCARD Vector4 MoveTowards(const ::Vector4& target, const float maxDistance) const { return ::Vector4MoveTowards(*this, target, maxDistance); }
RLCPP_NODISCARD Vector4 Invert() const { return ::Vector4Invert(*this); }
/*
* Check whether two given vectors are almost equal
*/
RLCPP_NODISCARD bool Equals(const ::Vector4& other) const {
return static_cast<bool>(::Vector4Equals(*this, other));
}
#endif
RLCPP_NODISCARD Color ColorFromNormalized() const { return ::ColorFromNormalized(*this); }
operator Color() const { return ColorFromNormalized(); }
protected:
void set(const ::Vector4& vec4) {
x = vec4.x;
y = vec4.y;
z = vec4.z;
w = vec4.w;
}
};
} // namespace raylib
using RVector4 = raylib::Vector4;
#endif // RAYLIB_CPP_INCLUDE_VECTOR4_HPP_
+74
View File
@@ -0,0 +1,74 @@
#ifndef RAYLIB_CPP_INCLUDE_VRSTEREOCONFIG_HPP_
#define RAYLIB_CPP_INCLUDE_VRSTEREOCONFIG_HPP_
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* VR stereo config functions for VR simulator
*/
class VrStereoConfig : public ::VrStereoConfig {
public:
VrStereoConfig(const ::VrDeviceInfo& info) { Load(info); }
VrStereoConfig(const VrStereoConfig&) = delete;
VrStereoConfig& operator=(const VrStereoConfig&) = delete;
VrStereoConfig(VrStereoConfig&&) = default;
VrStereoConfig& operator=(VrStereoConfig&&) = default;
/**
* Load VR stereo config for VR simulator device parameters
*/
void Load(const ::VrDeviceInfo& info) { set(LoadVrStereoConfig(info)); }
/**
* Unload VR stereo config
*/
~VrStereoConfig() { Unload(); }
/**
* Begin stereo rendering
*/
VrStereoConfig& BeginMode() {
::BeginVrStereoMode(*this);
return *this;
}
/**
* End stereo rendering
*/
VrStereoConfig& EndMode() {
::EndVrStereoMode();
return *this;
}
/**
* Unload VR stereo config
*/
void Unload() { ::UnloadVrStereoConfig(*this); }
protected:
void set(const ::VrStereoConfig& config) {
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.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_
+74
View File
@@ -0,0 +1,74 @@
#ifndef RAYLIB_CPP_INCLUDE_WAVE_HPP_
#define RAYLIB_CPP_INCLUDE_WAVE_HPP_
#include "./WaveUnmanaged.hpp"
namespace raylib {
/**
* Wave type, defines audio wave data.
*
* The wave will be unloaded on object destruction. Use raylib::WaveUnmanaged if you're looking to not unload.
* Unlike other resource types, Wave supports value-copy semantics via WaveCopy().
*
* @see raylib::WaveUnmanaged
*/
class Wave : public WaveUnmanaged {
public:
using WaveUnmanaged::WaveUnmanaged;
Wave(const Wave& other) : WaveUnmanaged(other.Copy()) {}
Wave(Wave&& other) noexcept : WaveUnmanaged(other) {
other.frameCount = 0;
other.sampleRate = 0;
other.sampleSize = 0;
other.channels = 0;
other.data = nullptr;
}
Wave& operator=(const ::Wave& wave) {
Unload();
set(wave);
return *this;
}
Wave& operator=(const Wave& other) {
if (this == &other) {
return *this;
}
Unload();
set(other.Copy());
return *this;
}
Wave& operator=(Wave&& other) noexcept {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.frameCount = 0;
other.sampleRate = 0;
other.sampleSize = 0;
other.channels = 0;
other.data = nullptr;
return *this;
}
~Wave() { Unload(); }
void Load(const std::string& fileName) {
Unload();
WaveUnmanaged::Load(fileName);
}
void Load(const std::string& fileType, const unsigned char* fileData, int dataSize) {
Unload();
WaveUnmanaged::Load(fileType, fileData, dataSize);
}
};
} // namespace raylib
using RWave = raylib::Wave;
#endif // RAYLIB_CPP_INCLUDE_WAVE_HPP_
+178
View File
@@ -0,0 +1,178 @@
#ifndef RAYLIB_CPP_INCLUDE_WAVEUNMANAGED_HPP_
#define RAYLIB_CPP_INCLUDE_WAVEUNMANAGED_HPP_
#include <string>
#include "./RaylibException.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* A Wave that is not managed by C++ RAII.
*
* Make sure to Unload() this if needed, otherwise use raylib::Wave.
*
* @see raylib::Wave
*/
class WaveUnmanaged : public ::Wave {
public:
/**
* Creates a WaveUnmanaged from an existing Wave struct.
*/
WaveUnmanaged(const ::Wave& wave) : ::Wave(wave) {}
/**
* Creates a WaveUnmanaged from its components.
*/
WaveUnmanaged(
unsigned int frameCount = 0,
unsigned int sampleRate = 0,
unsigned int sampleSize = 0,
unsigned int channels = 0,
void* data = nullptr)
: ::Wave{frameCount, sampleRate, sampleSize, channels, data} {}
/**
* Load wave data from file.
*
* @throws raylib::RaylibException Throws if the Wave failed to load.
*/
WaveUnmanaged(const std::string& fileName) { Load(fileName); }
/**
* Load wave from memory buffer; fileType refers to extension: i.e. "wav".
*
* @throws raylib::RaylibException Throws if the Wave failed to load.
*/
WaveUnmanaged(const std::string& fileType, const unsigned char* fileData, int dataSize) {
Load(fileType, fileData, dataSize);
}
GETTER(unsigned int, FrameCount, frameCount)
GETTER(unsigned int, SampleRate, sampleRate)
GETTER(unsigned int, SampleSize, sampleSize)
GETTER(unsigned int, Channels, channels)
GETTER(void*, Data, data)
WaveUnmanaged& operator=(const ::Wave& wave) {
set(wave);
return *this;
}
[[nodiscard]] std::string ToString() const {
return TextFormat(
"Wave(frameCount=%u, sampleRate=%u, sampleSize=%u, channels=%u, data=%p)",
frameCount, sampleRate, sampleSize, channels, data
);
}
operator std::string() const { return ToString(); }
/**
* Load wave data from file.
*
* @throws raylib::RaylibException Throws if the Wave failed to load.
*/
void Load(const std::string& fileName) {
set(::LoadWave(fileName.c_str()));
if (!IsValid()) {
throw RaylibException("Failed to load Wave from file: " + fileName);
}
}
/**
* Load wave from memory buffer; fileType refers to extension: i.e. "wav".
*
* @throws raylib::RaylibException Throws if the Wave failed to load.
*/
void Load(const std::string& fileType, const unsigned char* fileData, int dataSize) {
set(::LoadWaveFromMemory(fileType.c_str(), fileData, dataSize));
if (!IsValid()) {
throw RaylibException("Failed to load Wave from file data of type: " + fileType);
}
}
/**
* Unload wave data.
*/
void Unload() {
// Protect against calling UnloadWave() twice.
if (data != nullptr) {
::UnloadWave(*this);
data = nullptr;
}
}
/**
* Copy a wave to a new wave.
*/
RLCPP_NODISCARD ::Wave Copy() const { return ::WaveCopy(*this); }
/**
* Crop a wave to defined samples range.
*/
WaveUnmanaged& Crop(int initSample, int finalSample) {
::WaveCrop(this, initSample, finalSample);
return *this;
}
/**
* Convert wave data to desired format.
*/
WaveUnmanaged& Format(int sampleRate, int sampleSize, int channels = 2) {
::WaveFormat(this, sampleRate, sampleSize, channels);
return *this;
}
/**
* Load samples data from wave as a floats array.
*/
float* LoadSamples() { return ::LoadWaveSamples(*this); }
/**
* Unload samples data loaded with LoadWaveSamples().
*/
static void UnloadSamples(float* samples) { ::UnloadWaveSamples(samples); }
/**
* Export wave data to file, returns true on success.
*/
bool Export(const std::string& fileName) { return ::ExportWave(*this, fileName.c_str()); }
/**
* Export wave sample data to code (.h), returns true on success.
*/
bool ExportAsCode(const std::string& fileName) { return ::ExportWaveAsCode(*this, fileName.c_str()); }
/**
* Load sound from wave data.
*/
::Sound LoadSound() { return ::LoadSoundFromWave(*this); }
/**
* Load sound from wave data.
*/
operator ::Sound() { return LoadSound(); }
/**
* Retrieve whether or not the Wave data has been loaded.
*
* @return True or false depending on whether the wave data has been loaded.
*/
RLCPP_NODISCARD bool IsValid() const { return ::IsWaveValid(*this); }
protected:
void set(const ::Wave& wave) {
frameCount = wave.frameCount;
sampleRate = wave.sampleRate;
sampleSize = wave.sampleSize;
channels = wave.channels;
data = wave.data;
}
};
} // namespace raylib
using RWaveUnmanaged = raylib::WaveUnmanaged;
#endif // RAYLIB_CPP_INCLUDE_WAVEUNMANAGED_HPP_
+474
View File
@@ -0,0 +1,474 @@
#ifndef RAYLIB_CPP_INCLUDE_WINDOW_HPP_
#define RAYLIB_CPP_INCLUDE_WINDOW_HPP_
#include <string>
#include "./RaylibException.hpp"
#include "./Vector2.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Window and Graphics Device Functions.
*/
class Window {
public:
/**
* Build a Window object, but defer the initialization. Ensure you call Init() manually.
*
* @see Init()
*/
Window() = default;
/**
* Initialize window and OpenGL context.
*
* @param width The width of the window.
* @param height The height of the window.
* @param title The desired title of the window.
* @param flags The ConfigFlags to set prior to initializing the window. See SetConfigFlags for more details.
* @param logLevel The the current threshold (minimum) log level
*
* @see ::SetConfigFlags()
* @see ConfigFlags
*
* @throws raylib::RaylibException Thrown if the window failed to initiate.
*/
Window(int width, int height, const std::string& title = "raylib", unsigned int flags = 0, TraceLogLevel logLevel = LOG_ALL) {
Init(width, height, title, flags, logLevel);
}
Window(const Window&) = delete;
Window& operator=(const Window&) = delete;
/**
* Close window and unload OpenGL context
*/
~Window() { Close(); }
[[nodiscard]] std::string ToString() const { return TextFormat("Window(%dx%d)", GetWidth(), GetHeight()); }
operator std::string() const { return ToString(); }
/**
* Initializes the window.
*
* @param width The width of the window.
* @param height The height of the window.
* @param title The desired title of the window.
* @param flags The ConfigFlags to set prior to initializing the window. See SetConfigFlags for more details.
*
* @see ::SetConfigFlags()
* @see ConfigFlags
*
* @throws raylib::RaylibException Thrown if the window failed to initiate.
*/
static void Init(int width = 800, int height = 450, const std::string& title = "raylib", unsigned int flags = 0, TraceLogLevel logLevel = LOG_ALL) {
if (flags != 0) {
::SetConfigFlags(flags);
}
::SetTraceLogLevel(logLevel);
::InitWindow(width, height, title.c_str());
if (!::IsWindowReady()) {
throw RaylibException("Failed to create Window");
}
}
/**
* Check if KEY_ESCAPE pressed or Close icon pressed
*/
static bool ShouldClose() { return ::WindowShouldClose(); }
/**
* Set a custom key to exit program (default is ESC)
*/
static void SetExitKey(int key) { ::SetExitKey(key); }
/**
* Close window and unload OpenGL context
*/
static void Close() {
if (::IsWindowReady()) {
::CloseWindow();
}
}
/**
* Check if cursor is on the current screen
*/
static bool IsCursorOnScreen() { return ::IsCursorOnScreen(); }
/**
* Check if cursor is not visible
*/
static bool IsCursorHidden() { return ::IsCursorHidden(); }
/**
* Hides cursor
*/
static void HideCursor() { ::HideCursor(); }
/**
* Shows cursor
*/
static void ShowCursor() { ::ShowCursor(); }
/**
* Check if window is currently fullscreen
*/
static bool IsFullscreen() { return ::IsWindowFullscreen(); }
/**
* Check if window is currently hidden
*/
static bool IsHidden() { return ::IsWindowHidden(); }
/**
* Check if window is currently minimized
*/
static bool IsMinimized() { return ::IsWindowMinimized(); }
/**
* Check if window is currently minimized
*/
static bool IsMaximized() { return ::IsWindowMaximized(); }
/**
* Check if window is currently focused
*/
static bool IsFocused() { return ::IsWindowFocused(); }
/**
* Check if window has been resized last frame
*/
static bool IsResized() { return ::IsWindowResized(); }
/**
* Check if one specific window flag is enabled
*/
static bool IsState(unsigned int flag) { return ::IsWindowState(flag); }
/**
* Set window configuration state using flags
*/
Window& SetState(unsigned int flag) {
::SetWindowState(flag);
return *this;
}
/**
* Clear window configuration state flags
*/
Window& ClearState(unsigned int flag) {
::ClearWindowState(flag);
return *this;
}
/**
* Clear window with given color.
*/
Window& ClearBackground(const ::Color& color = BLACK) {
::ClearBackground(color);
return *this;
}
/**
* Toggle window state: fullscreen/windowed
*/
Window& ToggleFullscreen() {
::ToggleFullscreen();
return *this;
}
/**
* Set whether or not the application should be fullscreen.
*/
Window& SetFullscreen(bool fullscreen) {
if (fullscreen) {
if (!IsFullscreen()) {
ToggleFullscreen();
}
}
else {
if (IsFullscreen()) {
ToggleFullscreen();
}
}
return *this;
}
/**
* Toggle window state: borderless/windowed
*/
Window& ToggleBorderless() {
::ToggleBorderlessWindowed();
return *this;
}
/**
* Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
*/
Window& Maximize() {
::MaximizeWindow();
return *this;
}
/**
* Set window state: minimized, if resizable (only PLATFORM_DESKTOP)
*/
Window& Minimize() {
::MinimizeWindow();
return *this;
}
/**
* Set window state: not minimized/maximized (only PLATFORM_DESKTOP)
*/
Window& Restore() {
::RestoreWindow();
return *this;
}
/**
* Set icon for window
*/
Window& SetIcon(const ::Image& image) {
::SetWindowIcon(image);
return *this;
}
/**
* Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)
*/
Window& SetIcons(Image* images, int count) {
::SetWindowIcons(images, count);
return *this;
}
/**
* Set title for window
*/
Window& SetTitle(const std::string& title) {
::SetWindowTitle(title.c_str());
return *this;
}
/**
* Set window position on screen
*/
Window& SetPosition(int x, int y) {
::SetWindowPosition(x, y);
return *this;
}
/**
* Set window position on screen
*/
Window& SetPosition(const ::Vector2& position) {
return SetPosition(static_cast<int>(position.x), static_cast<int>(position.y));
}
/**
* Set monitor for the current window
*/
Window& SetMonitor(int monitor) {
::SetWindowMonitor(monitor);
return *this;
}
/**
* Set window minimum dimensions
*/
Window& SetMinSize(int width, int height) {
::SetWindowMinSize(width, height);
return *this;
}
/**
* Set window minimum dimensions
*/
Window& SetMinSize(const ::Vector2& size) {
::SetWindowMinSize(static_cast<int>(size.x), static_cast<int>(size.y));
return *this;
}
/**
* Set window dimensions
*/
Window& SetSize(int width, int height) {
::SetWindowSize(width, height);
return *this;
}
/**
* Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
*/
Window& SetOpacity(float opacity) {
::SetWindowOpacity(opacity);
return *this;
}
/**
* Set window focused (only PLATFORM_DESKTOP)
*/
Window& SetFocused() {
::SetWindowFocused();
return *this;
}
/**
* Set window dimensions
*/
Window& SetSize(const ::Vector2& size) { return SetSize(static_cast<int>(size.x), static_cast<int>(size.y)); }
/**
* Get the screen's width and height.
*/
static Vector2 GetSize() { return {static_cast<float>(GetWidth()), static_cast<float>(GetHeight())}; }
/**
* Get native window handle
*/
static void* GetHandle() { return ::GetWindowHandle(); }
/**
* Setup canvas (framebuffer) to start drawing
*/
Window& BeginDrawing() {
::BeginDrawing();
return *this;
}
/**
* End canvas drawing and swap buffers (double buffering)
*/
Window& EndDrawing() {
::EndDrawing();
return *this;
}
/**
* Get current screen width
*/
static int GetWidth() { return ::GetScreenWidth(); }
/**
* Get current screen height
*/
static int GetHeight() { return ::GetScreenHeight(); }
/**
* Get current render width (it considers HiDPI)
*/
static int GetRenderWidth() { return ::GetRenderWidth(); }
/**
* Get current render height (it considers HiDPI)
*/
static int GetRenderHeight() { return ::GetRenderHeight(); }
/**
* Get window position XY on monitor
*/
static Vector2 GetPosition() { return ::GetWindowPosition(); }
/*
* Get current window monitor
*/
static int GetMonitor() { return ::GetCurrentMonitor(); }
/**
* Get window scale DPI factor
*/
static Vector2 GetScaleDPI() { return ::GetWindowScaleDPI(); }
/**
* Set clipboard text content
*/
static void SetClipboardText(const std::string& text) { ::SetClipboardText(text.c_str()); }
/**
* Get clipboard text content
*/
static std::string GetClipboardText() { return ::GetClipboardText(); }
/**
* Set target FPS (maximum)
*/
Window& SetTargetFPS(int fps) {
::SetTargetFPS(fps);
return *this;
}
/**
* Returns current FPS
*/
static int GetFPS() { return ::GetFPS(); }
/**
* Draw current FPS
*/
static void DrawFPS(int posX = 10, int posY = 10) { ::DrawFPS(posX, posY); }
/**
* Returns time in seconds for last frame drawn
*/
static float GetFrameTime() { return ::GetFrameTime(); }
/**
* Returns elapsed time in seconds since InitWindow()
*/
static double GetTime() { return ::GetTime(); }
/**
* Check if window has been initialized successfully
*/
static bool IsReady() { return ::IsWindowReady(); }
/**
* Sets the configuration flags for raylib.
*
* @param flags The ConfigFlags to apply to the configuration.
*
* @see ::SetConfigFlags
*/
static void SetConfigFlags(unsigned int flags) { ::SetConfigFlags(flags); }
/**
* Alternates between calling `BeginDrawing()` and `EndDrawing()`.
*
* @code
* while (window.Drawing()) {
* DrawRectangle();
* }
* @endcode
*
* @return True if we're within the `BeginDrawing()` scope.
*/
bool Drawing() {
if (m_drawing) {
EndDrawing();
m_drawing = false;
}
else {
BeginDrawing();
m_drawing = true;
}
return m_drawing;
}
protected:
/**
* Handles the internal drawing state for calling either `BeginDrawing()` or `EndDrawing()` from the `Drawing()` function.
*
* @see Drawing()
*/
bool m_drawing = false;
};
} // namespace raylib
using RWindow = raylib::Window;
#endif // RAYLIB_CPP_INCLUDE_WINDOW_HPP_
+38
View File
@@ -0,0 +1,38 @@
/**
* Utility for raylib-cpp.
*/
#ifndef RAYLIB_CPP_INCLUDE_RAYLIB_CPP_UTILS_HPP_
#define RAYLIB_CPP_INCLUDE_RAYLIB_CPP_UTILS_HPP_
#ifndef GETTER
/**
* A utility to build a get method on top of a property.
*
* @param type The type of the property.
* @param method The human-readable name for the method.
* @param name The machine-readable name of the property.
*/
#define GETTER(type, method, name) \
/** Retrieves the name value for the object. @return The name value of the object. */ \
type Get##method() const { \
return name; \
}
#endif
#ifndef GETTERSETTER
/**
* A utility to build get and set methods on top of a property.
*
* @param type The type of the property.
* @param method The human-readable name for the method.
* @param name The machine-readable name of the property.
*/
#define GETTERSETTER(type, method, name) \
GETTER(type, method, name) \
/** Sets the name value for the object. @param value The value of which to set name to. */ \
void Set##method(type value) { \
name = value; \
}
#endif
#endif // RAYLIB_CPP_INCLUDE_RAYLIB_CPP_UTILS_HPP_
+88
View File
@@ -0,0 +1,88 @@
/**
* [raylib-cpp](https://github.com/RobLoach/raylib-cpp) is a C++ wrapper library for raylib, a simple and easy-to-use library to enjoy videogames programming. This C++ header provides object-oriented wrappers around raylib's struct interfaces.
*
* @see raylib namespace for a list of all available classes.
* @mainpage raylib-cpp
* @include core_basic_window.cpp
* @author Rob Loach (RobLoach)
* @copyright zlib/libpng
*
* raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software:
*
* Copyright 2020 Rob Loach (RobLoach)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose, including commercial
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that you
* wrote the original software. If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
* as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef RAYLIB_CPP_INCLUDE_RAYLIB_CPP_HPP_
#define RAYLIB_CPP_INCLUDE_RAYLIB_CPP_HPP_
#include "./AudioDevice.hpp"
#include "./AudioStream.hpp"
#include "./AudioStreamUnmanaged.hpp"
#include "./AutomationEventList.hpp"
#include "./BoundingBox.hpp"
#include "./Camera2D.hpp"
#include "./Camera3D.hpp"
#include "./Color.hpp"
#include "./FileData.hpp"
#include "./FileText.hpp"
#include "./Font.hpp"
#include "./FontUnmanaged.hpp"
#include "./Functions.hpp"
#include "./Gamepad.hpp"
#include "./Image.hpp"
#include "./Keyboard.hpp"
#include "./Material.hpp"
#include "./MaterialUnmanaged.hpp"
#include "./Matrix.hpp"
#include "./Mesh.hpp"
#include "./Model.hpp"
#include "./ModelUnmanaged.hpp"
#include "./ModelAnimation.hpp"
#include "./Mouse.hpp"
#include "./Music.hpp"
#include "./MusicUnmanaged.hpp"
#include "./Ray.hpp"
#include "./RayCollision.hpp"
#include "./RaylibException.hpp"
#include "./Rectangle.hpp"
#include "./RenderTexture.hpp"
#include "./RenderTextureUnmanaged.hpp"
#include "./Shader.hpp"
#include "./Sound.hpp"
#include "./SoundUnmanaged.hpp"
#include "./Text.hpp"
#include "./Texture.hpp"
#include "./TextureUnmanaged.hpp"
#include "./Touch.hpp"
#include "./Vector2.hpp"
#include "./Vector3.hpp"
#include "./Vector4.hpp"
#include "./VrStereoConfig.hpp"
#include "./Wave.hpp"
#include "./WaveUnmanaged.hpp"
#include "./Window.hpp"
/**
* All raylib-cpp classes and functions appear in the raylib namespace.
*/
namespace raylib {
// Nothing.
} // namespace raylib
#endif // RAYLIB_CPP_INCLUDE_RAYLIB_CPP_HPP_
+61
View File
@@ -0,0 +1,61 @@
/**
* C++ header to wrap raylib.h.
*/
#ifndef RAYLIB_CPP_INCLUDE_RAYLIB_HPP_
#define RAYLIB_CPP_INCLUDE_RAYLIB_HPP_
#ifdef __cplusplus
extern "C" {
#endif
#ifndef RAYLIB_H_FILE
#define RAYLIB_H_FILE "raylib.h"
#endif
#include RAYLIB_H_FILE // NOLINT
#if !defined(RAYLIB_VERSION_MAJOR) || !defined(RAYLIB_VERSION_MINOR)
#error "raylib-cpp requires raylib >= 5"
#endif
#if RAYLIB_VERSION_MAJOR < 6
#error "raylib-cpp requires raylib >= 6"
#endif
#if RAYLIB_VERSION_MAJOR > 6
#error "raylib-cpp requires raylib ~6.0. Use the `next` branch for the next version of raylib."
#endif
#ifndef RLCPP_MAYBEUNUSED
# if defined(__has_cpp_attribute)
# if __has_cpp_attribute(maybe_unused) && __cplusplus >= 201703L
# define RLCPP_MAYBEUNUSED [[maybe_unused]]
# else
# define RLCPP_MAYBEUNUSED
# endif
# elif (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (__cplusplus >= 201703L)
# define RLCPP_MAYBEUNUSED [[maybe_unused]]
# else
# define RLCPP_MAYBEUNUSED
# endif
#endif
#ifndef RLCPP_NODISCARD
# if defined(__has_cpp_attribute)
# if __has_cpp_attribute(nodiscard) && __cplusplus >= 201703L
# define RLCPP_NODISCARD [[nodiscard]]
# else
# define RLCPP_NODISCARD
# endif
# elif (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (__cplusplus >= 201703L)
# define RLCPP_NODISCARD [[nodiscard]]
# else
# define RLCPP_NODISCARD
# endif
#endif
#ifdef __cplusplus
}
#endif
#endif // RAYLIB_CPP_INCLUDE_RAYLIB_HPP_
+30
View File
@@ -0,0 +1,30 @@
/**
* C++ header to wrap raymath.h.
*/
#ifndef RAYLIB_CPP_INCLUDE_RAYMATH_HPP_
#define RAYLIB_CPP_INCLUDE_RAYMATH_HPP_
#ifdef __cplusplus
extern "C" {
#endif
#ifndef RAYLIB_CPP_NO_MATH
#ifndef BUILD_RAYLIB_CPP_MODULES
#ifndef RAYMATH_STATIC_INLINE
#define RAYMATH_STATIC_INLINE
#endif
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push // These throw a warnings on visual studio, need to check if __GNUC__ is defined to use it.
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
#define RAYMATH_DISABLE_CPP_OPERATORS
#include "raymath.h" // NOLINT
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif // RAYLIB_CPP_INCLUDE_RAYMATH_HPP_