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

View File

@@ -1,9 +1,9 @@
root = true
[*]
indent_style = space
indent_style = tabs
charset = utf-8
end_of_line = lf
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
trim_trailing_whitespace = true

View File

@@ -1,14 +1,19 @@
cmake_minimum_required(VERSION 3.11)
project (raylib-cpp)
option(BUILD_EXAMPLES "Examples" TRUE)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
configure_file(${CMAKE_SOURCE_DIR}/cmake/CTestCustom.cmake ${CMAKE_BINARY_DIR})
include_directories(include)
add_subdirectory(examples)
add_subdirectory(include)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
include(CTest)
enable_testing()
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
endif()

View File

@@ -28,7 +28,7 @@ int main(int argc, char* argv[])
EndDrawing();
}
// No need to call CloseWindow()!
// No need to call CloseWindow().
return 0;
}

View File

@@ -1,27 +1,34 @@
find_package(Raylib)
add_executable(core_basic_window core/core_basic_window.cpp)
target_link_libraries(core_basic_window raylib)
# Get the sources together
set(example_dirs audio core text textures)
set(example_sources)
set(example_resources)
add_executable(core_input_mouse core/core_input_mouse.cpp)
target_link_libraries(core_input_mouse raylib)
foreach(example_dir ${example_dirs})
file(GLOB sources ${example_dir}/*.cpp)
list(APPEND example_sources ${sources})
add_executable(textures_image_loading textures/textures_image_loading.cpp)
target_link_libraries(textures_image_loading raylib)
add_executable(textures_image_drawing textures/textures_image_drawing.cpp)
target_link_libraries(textures_image_drawing raylib)
configure_file(textures/resources/raylib_logo.png resources/cat.png COPYONLY)
configure_file(textures/resources/raylib_logo.png resources/custom_jupiter_crash.png COPYONLY)
configure_file(textures/resources/raylib_logo.png resources/parrots.png COPYONLY)
configure_file(textures/resources/raylib_logo.png resources/raylib_logo.png COPYONLY)
# Any any resources
file(GLOB resources ${example_dir}/resources/*)
list(APPEND example_resources ${resources})
endforeach()
add_executable(text_raylib_fonts text/text_raylib_fonts.cpp)
configure_file(text/resources/fonts/alagard.png resources/fonts/alagard.png COPYONLY)
configure_file(text/resources/fonts/alpha_beta.png resources/fonts/alpha_beta.png COPYONLY)
configure_file(text/resources/fonts/jupiter_crash.png resources/fonts/jupiter_crash.png COPYONLY)
configure_file(text/resources/fonts/mecha.png resources/fonts/mecha.png COPYONLY)
configure_file(text/resources/fonts/pixantiqua.png resources/fonts/pixantiqua.png COPYONLY)
configure_file(text/resources/fonts/pixelplay.png resources/fonts/pixelplay.png COPYONLY)
configure_file(text/resources/fonts/romulus.png resources/fonts/romulus.png COPYONLY)
configure_file(text/resources/fonts/setback.png resources/fonts/setback.png COPYONLY)
target_link_libraries(text_raylib_fonts raylib)
# Do each example
foreach(example_source ${example_sources})
# Create the basename for the example
get_filename_component(example_name ${example_source} NAME)
string(REPLACE ".cpp" "${OUTPUT_EXT}" example_name ${example_name})
# Setup the example
add_executable(${example_name} ${example_source})
target_link_libraries(${example_name} PUBLIC raylib-cpp raylib)
string(REGEX MATCH ".*/.*/" resources_dir ${example_source})
string(APPEND resources_dir "resources")
endforeach()
file(COPY ${example_resources} DESTINATION "resources/")

View File

@@ -0,0 +1,54 @@
/*******************************************************************************************
*
* raylib [audio] example - Sound loading and playing
*
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib/raylib.hpp"
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
raylib::Window w(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
raylib::AudioDevice audiodevice(); // Initialize audio device
raylib::Sound fxWav("resources/sound.wav"); // Load WAV audio file
raylib::Sound fxOgg("resources/tanatana.ogg"); // Load OGG audio file
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_SPACE)) fxWav.Play(); // Play WAV sound
if (IsKeyPressed(KEY_ENTER)) fxOgg.Play(); // Play OGG sound
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
return 0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -28,6 +28,7 @@ int main()
int screenWidth = 800;
int screenHeight = 450;
raylib::Color background(RAYWHITE);
raylib::Color textColor(LIGHTGRAY);
raylib::Window w(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
@@ -45,13 +46,13 @@ int main()
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(background);
background.ClearBackground();
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
textColor.DrawText("Congrats! You created your first window!", 190, 200, 20);
EndDrawing();
//----------------------------------------------------------------------------------
}
return 0;
}
}

View File

@@ -21,7 +21,9 @@ int main()
raylib::Window w(screenWidth, screenHeight, "raylib [core] example - mouse input");
raylib::Vector2 ballPosition(-100.0f, -100.0f);
raylib::Color background(RAYWHITE);
raylib::Color ballColor(DARKBLUE);
raylib::Color textColor(DARKGRAY);
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//---------------------------------------------------------------------------------------
@@ -42,15 +44,15 @@ int main()
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
background.ClearBackground();
DrawCircleV(ballPosition, 40, ballColor);
ballPosition.DrawCircle(40, ballColor);
DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
textColor.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20);
EndDrawing();
//----------------------------------------------------------------------------------
}
return 0;
}
}

View File

@@ -0,0 +1,60 @@
/*******************************************************************************************
*
* raylib [core] example - Generate random values
*
* This example has been created using raylib 1.1 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib/raylib.hpp"
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
raylib::Window w(screenWidth, screenHeight, "raylib [core] example - generate random values");
int framesCounter = 0; // Variable used to count frames
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!w.ShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
framesCounter++;
// Every two seconds (120 frames) a new random value is generated
if (((framesCounter/120)%2) == 1)
{
randValue = GetRandomValue(-8, 5);
framesCounter = 0;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON);
DrawText(FormatText("%i", randValue), 360, 180, 80, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
return 0;
}

View File

@@ -23,6 +23,8 @@ int main(void)
const int screenHeight = 450;
raylib::Window w(screenWidth, screenHeight, "raylib [textures] example - image drawing");
raylib::Color background(RAYWHITE);
raylib::Color darkGray(DARKGRAY);
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
raylib::Image cat("resources/cat.png"); // Load image in CPU memory (RAM)
@@ -63,13 +65,13 @@ int main(void)
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
background.ClearBackground();
texture.Draw(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, WHITE);
DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, texture.width, texture.height, DARKGRAY);
darkGray.DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, texture.width, texture.height);
DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, DARKGRAY);
DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, DARKGRAY);
darkGray.DrawText("We are drawing only one texture from various images composed!", 240, 350, 10);
darkGray.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10);
EndDrawing();
//----------------------------------------------------------------------------------

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

View File

@@ -30,14 +30,8 @@ endmacro()
find_package(Raylib)
list(APPEND SOURCES catch.hpp raylib_test.cpp)
list(APPEND LIBS raylib)
list(APPEND LIBS raylib-cpp raylib)
add_executable(raylib_test ${SOURCES})
target_include_directories(raylib_test PUBLIC
${raylib_SOURCE_DIR}/src
)
target_link_libraries(raylib_test ${LIBS})
ADD_CATCH_TESTS(raylib_test)

View File

@@ -4,13 +4,18 @@
#include "raylib/raylib.hpp"
#include "catch.hpp"
TEST_CASE("raylib_test functions work", "[raylib_test]" ) {
raylib::Vector2 vec(50, 100);
CHECK(vec.getX() == 50.0f);
TEST_CASE("raylib_test", "[raylib_test]" ) {
SECTION("Vector2") {
raylib::Vector2 vec(50, 100);
CHECK(vec.getX() == vec.x);
}
CHECK(raylib::Window::IsReady() == false);
SECTION("Window") {
CHECK(raylib::Window::IsReady() == false);
}
raylib::Color c(RED);
int redInt = c.ToInt();
CHECK(redInt == ColorToInt(RED));
}
SECTION("Color") {
raylib::Color c(RED);
CHECK(c.ToInt() == ColorToInt(RED));
}
}