This commit is contained in:
Rob Loach
2019-08-10 14:53:47 -04:00
parent a7856d72f3
commit 14acffeb46
41 changed files with 677 additions and 81 deletions

10
include/CMakeLists.txt Normal file
View File

@@ -0,0 +1,10 @@
add_library(raylib-cpp INTERFACE)
file(GLOB sources raylib/*.cpp)
set(RAYLIBCPP_HEADERS, ${sources})
install(FILES
${RAYLIBCPP_HEADERS} DESTINATION include/
)
target_include_directories(raylib-cpp INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/)

View File

@@ -28,6 +28,10 @@ namespace raylib {
static bool IsReady() {
return IsAudioDeviceReady();
}
void SetVolume(float volume) {
SetMasterVolume(volume);
}
};
}

View File

@@ -0,0 +1,78 @@
#ifndef RAYLIB_CPP_AUDIOSTREAM_HPP_
#define RAYLIB_CPP_AUDIOSTREAM_HPP_
#include "raylib.h"
#include "utils.hpp"
namespace raylib {
class AudioStream : public ::AudioStream {
public:
AudioStream(::AudioStream music) {
set(music);
};
AudioStream(unsigned int SampleRate, unsigned int SampleSize, unsigned int Channels) {
set(InitAudioStream(SampleRate, SampleSize, Channels));
}
~AudioStream() {
Close();
}
inline void set(::AudioStream stream) {
sampleRate = stream.sampleRate;
sampleSize = stream.sampleSize;
channels = stream.channels;
buffer = stream.buffer;
}
GETTERSETTER(unsigned int,SampleRate,sampleRate)
GETTERSETTER(unsigned int,SampleSize,sampleSize)
GETTERSETTER(unsigned int,Channels,channels)
AudioStream& operator=(const ::AudioStream& stream) {
set(stream);
return *this;
}
AudioStream& operator=(const AudioStream& stream) {
set(stream);
return *this;
}
void Update(const void *data, int samplesCount) {
UpdateAudioStream(*this, data, samplesCount);
}
void Close() {
CloseAudioStream(*this);
}
bool IsAudioBufferProcessed() {
return ::IsAudioBufferProcessed(*this);
}
void Play() {
PlayAudioStream(*this);
}
void Pause() {
PauseAudioStream(*this);
}
void Resume() {
ResumeAudioStream(*this);
}
bool IsPlaying() {
IsAudioStreamPlaying(*this);
}
void Stop() {
StopAudioStream(*this);
}
void SetVolume(float volume) {
SetAudioStreamVolume(*this, volume);
}
void SetPitch(float pitch) {
SetAudioStreamPitch(*this, pitch);
}
};
}
#endif

View File

@@ -49,4 +49,4 @@ namespace raylib {
};
}
#endif
#endif

View File

@@ -42,7 +42,7 @@ namespace raylib {
GETTERSETTER(float,Zoom,zoom)
Camera2D& operator=(const ::Camera2D& camera) {
set(color);
set(camera);
return *this;
}
@@ -54,4 +54,4 @@ namespace raylib {
};
}
#endif
#endif

View File

@@ -6,9 +6,9 @@
#include "utils.hpp"
namespace raylib {
class Camera : public ::Camera {
class Camera3D : public ::Camera3D {
public:
Camera(::Vector3 positionValue, ::Vector3 targetValue, ::Vector3 upValue, float fovyValue = 0, int typeValue = 0) {
Camera3D(::Vector3 positionValue, ::Vector3 targetValue, ::Vector3 upValue, float fovyValue = 0, int typeValue = 0) {
position = positionValue;
target = targetValue;
up = upValue;
@@ -16,7 +16,7 @@ namespace raylib {
type = typeValue;
};
inline void set(const ::Camera& camera) {
inline void set(const ::Camera3D& camera) {
position = camera.position;
target = camera.target;
up = camera.up;
@@ -24,7 +24,7 @@ namespace raylib {
type = camera.type;
}
inline void set(const Camera& camera) {
inline void set(const Camera3D& camera) {
position = camera.position;
target = camera.target;
up = camera.up;
@@ -61,19 +61,19 @@ namespace raylib {
GETTERSETTER(float,Fovy,fovy)
GETTERSETTER(int,Type,type)
Camera& operator=(const ::Camera& camera) {
Camera3D& operator=(const ::Camera3D& camera) {
set(camera);
return *this;
}
Camera& operator=(const Camera& camera) {
Camera3D& operator=(const Camera3D& camera) {
set(camera);
return *this;
}
};
typedef Camera Camera3D;
typedef Camera3D Camera;
}
#endif
#endif

View File

@@ -51,6 +51,8 @@ namespace raylib {
return ::ColorToInt(*this);
}
operator int() const { return ::ColorToInt(*this); }
Color Fade(float alpha) {
Color a;
a.set(::Fade(*this, alpha));
@@ -80,7 +82,23 @@ namespace raylib {
return *this;
}
void ClearBackground() {
::ClearBackground(*this);
}
void DrawPixel(int x, int y) {
::DrawPixel(x, y, *this);
}
void DrawPixel(::Vector2 pos) {
::DrawPixelV(pos, *this);
}
void DrawText(const std::string& text, int posX, int posY, int fontSize) {
::DrawText(text.c_str(), posX, posY, fontSize, *this);
}
};
}
#endif
#endif

View File

@@ -70,10 +70,15 @@ namespace raylib {
return *this;
}
void DrawTextEx(const std::string& text, ::Vector2 position, float fontSize, float spacing, ::Color color) {
::DrawTextEx(*this, text.c_str(), position, fontSize, spacing, color);
void DrawText(const std::string& text, ::Vector2 position, float fontSize, float spacing, ::Color tint) {
DrawTextEx(*this, text.c_str(), position, fontSize, spacing, tint);
}
void DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing, bool wordWrap, ::Color tint) {
DrawTextRec(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint);
}
void DrawText(const std::string& text, ::Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, int selectStart, int selectLength, ::Color selectText, Color selectBack) {
DrawTextRecEx(*this, text.c_str(), rec, fontSize, spacing, wordWrap, tint, selectStart, selectLength, selectText, selectBack);
}
};
}

View File

@@ -20,6 +20,11 @@ namespace raylib {
GETTERSETTER(int,Number,number)
Gamepad& operator=(const Gamepad& gamepad) {
set(gamepad);
return *this;
}
operator int() const { return number; }
bool IsAvailable() {

View File

@@ -30,6 +30,16 @@ namespace raylib {
Unload();
};
Image& operator=(const ::Image& image) {
set(image);
return *this;
}
Image& operator=(const Image& image) {
set(image);
return *this;
}
inline void set(::Image image) {
data = image.data;
width = image.width;
@@ -92,13 +102,38 @@ namespace raylib {
void DrawTextEx(::Vector2 position, ::Font font, const std::string& text, float fontSize, float spacing, ::Color color){
ImageDrawTextEx(this, position, font, text.c_str(), fontSize, spacing, color);
}
void FlipVertical(){
void FlipVertical() {
ImageFlipVertical(this);
}
void FlipHorizontal(){
void FlipHorizontal() {
ImageFlipHorizontal(this);
}
void RotateCW() {
ImageRotateCW(this);
}
void RotateCCW() {
ImageRotateCCW(this);
}
void ColorTint(::Color color) {
ImageColorTint(this, color);
}
void ColorInvert() {
ImageColorInvert(this);
}
void ColorGrayscale() {
ImageColorGrayscale(this);
}
void ColorContrast(float contrast) {
ImageColorContrast(this, contrast);
}
void ColorBrightness(int brightness) {
ImageColorBrightness(this, brightness);
}
void ColorReplace(::Color color, ::Color replace) {
ImageColorReplace(this, color, replace);
}
};
}

View File

@@ -27,6 +27,16 @@ namespace raylib {
GETTERSETTER(::Shader,Shader,shader)
Material& operator=(const ::Material& material) {
set(material);
return *this;
}
Material& operator=(const Material& material) {
set(material);
return *this;
}
void Unload() {
UnloadMaterial(*this);

View File

@@ -54,7 +54,7 @@ namespace raylib {
BoundingBox GetBoundingBox() {
return BoundingBox(MeshBoundingBox(*this));
}
void Tangents() {
MeshTangents(this);
}
@@ -62,12 +62,6 @@ namespace raylib {
void Binormals() {
MeshBinormals(this);
}
};
}

91
include/raylib/Music.hpp Normal file
View File

@@ -0,0 +1,91 @@
#ifndef RAYLIB_CPP_MUSIC_HPP_
#define RAYLIB_CPP_MUSIC_HPP_
#include "raylib.h"
#include "utils.hpp"
namespace raylib {
class Music : public ::Music {
public:
Music(::Music music) {
set(music);
};
Music(const std::string& fileName) {
set(LoadMusicStream(fileName.c_str()));
}
~Music() {
Unload();
}
inline void set(::Music music) {
ctxType = music.ctxType;
ctxData = music.ctxData;
sampleCount = music.sampleCount;
sampleLeft = music.sampleLeft;
loopCount = music.loopCount;
stream = music.stream;
}
GETTERSETTER(int,CtxType,ctxType)
GETTERSETTER(unsigned int,SampleCount,sampleCount)
GETTERSETTER(unsigned int,SampleLeft,sampleLeft)
GETTERSETTER(unsigned int,LoopCount,loopCount)
Music& operator=(const ::Music& music) {
set(music);
return *this;
}
Music& operator=(const Music& music) {
set(music);
return *this;
}
void Unload() {
UnloadMusicStream(*this);
}
void Play() {
PlayMusicStream(*this);
}
void Update() {
UpdateMusicStream(*this);
}
void Stop() {
StopMusicStream(*this);
}
void Pause() {
PauseMusicStream(*this);
}
void Resume() {
ResumeMusicStream(*this);
}
bool IsPlaying() {
return IsMusicPlaying(*this);
}
void SetVolume(float volume) {
SetMusicVolume(*this, volume);
}
void SetPitch(float pitch) {
SetMusicPitch(*this, pitch);
}
void SetLoopCount(int count) {
SetMusicLoopCount(*this, count);
}
float GetTimeLength() {
return GetMusicTimeLength(*this);
}
float GetTimePlayed() {
return GetMusicTimePlayed(*this);
}
};
}
#endif

View File

@@ -29,6 +29,17 @@ namespace raylib {
GETTERSETTER(float,Width,width)
GETTERSETTER(float,Height,height)
Rectangle& operator=(const ::Rectangle& rect) {
set(rect);
return *this;
}
Rectangle& operator=(const Rectangle& rect) {
set(rect);
return *this;
}
void Draw(::Color color) {
DrawRectangle(x, y, width, height, color);
}
@@ -38,4 +49,4 @@ namespace raylib {
};
}
#endif
#endif

79
include/raylib/Sound.hpp Normal file
View File

@@ -0,0 +1,79 @@
#ifndef RAYLIB_CPP_SOUND_HPP_
#define RAYLIB_CPP_SOUND_HPP_
#include <string>
#include "raylib.h"
#include "utils.hpp"
namespace raylib {
class Sound : public ::Sound {
public:
Sound(::Sound vec) {
set(vec);
};
Sound(const std::string& fileName) {
set(LoadSound(fileName.c_str()));
};
Sound(::Wave wave) {
set(LoadSoundFromWave(wave));
};
~Sound() {
Unload();
}
inline void set(::Sound sound) {
sampleCount = sound.sampleCount;
stream = sound.stream;
}
GETTERSETTER(unsigned int,SampleCount,sampleCount)
GETTERSETTER(::AudioStream,Stream,stream)
void Update(const void *data, int sampleCount) {
UpdateSound(*this, data, sampleCount);
}
void Unload() {
UnloadSound(*this);
}
void Play() {
PlaySound(*this);
}
void Stop() {
StopSound(*this);
}
void Pause() {
PauseSound(*this);
}
void Resume() {
ResumeSound(*this);
}
void PlayMulti() {
PlaySoundMulti(*this);
}
void StopMulti() {
StopSoundMulti();
}
bool IsPlaying() {
return IsSoundPlaying(*this);
}
void SetVolume(float volume) {
SetSoundVolume(*this, volume);
}
void SetPitch(float pitch) {
SetSoundPitch(*this, pitch);
}
};
}
#endif

View File

@@ -21,7 +21,31 @@ namespace raylib {
GETTERSETTER(float,X,x)
GETTERSETTER(float,Y,y)
void DrawPixel(::Color color) {
DrawPixelV(*this, color);
}
void DrawLine(::Vector2 endPos, ::Color color) {
DrawLineV(*this, endPos, color);
}
void DrawLine(::Vector2 endPos, float thick, ::Color color) {
DrawLineEx(*this, endPos, thick, color);
}
void DrawCircle(float radius, ::Color color) {
DrawCircleV(*this, radius, color);
}
void DrawRectangle(::Vector2 size, ::Color color) {
DrawRectangleV(*this, size, color);
}
void DrawPoly(int sides, float radius, float rotation, ::Color color) {
::DrawPoly(*this, sides, radius, rotation, color);
}
};
}
#endif
#endif

View File

@@ -15,6 +15,10 @@ namespace raylib {
y = Y;
z = Z;
};
Vector3(::Color color) {
set(ColorToHSV(color));
}
inline void set(::Vector3 vec) {
x = vec.x;
y = vec.y;
@@ -24,6 +28,10 @@ namespace raylib {
GETTERSETTER(float,X,x)
GETTERSETTER(float,Y,y)
GETTERSETTER(float,Z,z)
void DrawGizmo() {
::DrawGizmo(*this);
}
};
}

View File

@@ -18,6 +18,10 @@ namespace raylib {
w = W;
};
Vector4(::Color color) {
set(ColorNormalize(color));
}
inline void set(::Vector4 vec4) {
x = vec4.x;
y = vec4.y;

79
include/raylib/Wave.hpp Normal file
View File

@@ -0,0 +1,79 @@
#ifndef RAYLIB_CPP_WAVE_HPP_
#define RAYLIB_CPP_WAVE_HPP_
#include "raylib.h"
#include "utils.hpp"
namespace raylib {
class Wave : public ::Wave {
public:
Wave(::Wave wave) {
set(wave);
};
Wave(unsigned int SampleCount = 0, unsigned int SampleRate = 0, unsigned int SampleSize = 0, unsigned int Channels = 0) {
sampleCount = SampleCount;
sampleRate = SampleRate;
sampleSize = SampleSize;
channels = Channels;
};
Wave(const std::string& fileName) {
set(LoadWave(fileName.c_str()));
}
~Wave() {
Unload();
}
inline void set(::Wave wave) {
sampleCount = wave.sampleCount;
sampleRate = wave.sampleRate;
sampleSize = wave.sampleSize;
channels = wave.channels;
data = wave.data;
}
GETTERSETTER(unsigned int,X,sampleCount)
GETTERSETTER(unsigned int,Y,sampleRate)
GETTERSETTER(unsigned int,Z,sampleSize)
GETTERSETTER(unsigned int,W,channels)
GETTERSETTER(void*,Data,data)
void Format(int SampleRate = 0, int SampleSize = 0, int Channels = 2) {
WaveFormat(this, SampleRate, SampleSize, Channels);
}
Wave Copy() {
return WaveCopy(*this);
}
void Crop(int initSample, int finalSample) {
WaveCrop(this, initSample, finalSample);
}
void Export(const std::string& fileName) {
ExportWave(*this, fileName.c_str());
}
void ExportAsCode(const std::string& fileName) {
ExportWaveAsCode(*this, fileName.c_str());
}
void Unload() {
if (data != NULL) {
UnloadWave(*this);
data = NULL;
}
}
Sound LoadSound() {
return LoadSoundFromWave(*this);
}
float* GetData() {
return GetWaveData(*this);
}
};
}
#endif

View File

@@ -33,6 +33,13 @@ namespace raylib {
return IsWindowReady();
};
void BeginDrawing() {
::BeginDrawing();
}
void EndDrawing() {
::EndDrawing();
}
};
}

View File

@@ -2,24 +2,28 @@
#define RAYLIB_CPP_RAYLIB_CPP_HPP_
#include "AudioDevice.hpp"
#include "AudioStream.hpp"
#include "BoundingBox.hpp"
#include "Camera.hpp"
#include "Camera2D.hpp"
#include "Camera3D.hpp"
#include "Color.hpp"
#include "Font.hpp"
#include "Gamepad.hpp"
#include "Image.hpp"
#include "Material.hpp"
#include "Mesh.hpp"
#include "Music.hpp"
#include "Ray.hpp"
#include "RayHitInfo.hpp"
#include "Rectangle.hpp"
#include "RenderTexture2D.hpp"
#include "Shader.hpp"
#include "Sound.hpp"
#include "Texture2D.hpp"
#include "Vector2.hpp"
#include "Vector3.hpp"
#include "Vector4.hpp"
#include "Wave.hpp"
#include "Window.hpp"
#endif