diff --git a/.editorconfig b/.editorconfig index ae9fa0b..26e932e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 \ No newline at end of file +trim_trailing_whitespace = true diff --git a/CMakeLists.txt b/CMakeLists.txt index 156964b..abd80f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() \ No newline at end of file +endif() diff --git a/README.md b/README.md index ccafe10..9ba2eda 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ int main(int argc, char* argv[]) EndDrawing(); } - // No need to call CloseWindow()! + // No need to call CloseWindow(). return 0; } diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 71bdba7..d75c99e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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) \ No newline at end of file + +# 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/") diff --git a/examples/audio/audio_sound_loading.cpp b/examples/audio/audio_sound_loading.cpp new file mode 100644 index 0000000..6c3dced --- /dev/null +++ b/examples/audio/audio_sound_loading.cpp @@ -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; +} diff --git a/examples/audio/resources/chiptun1.mod b/examples/audio/resources/chiptun1.mod new file mode 100644 index 0000000..00d1688 Binary files /dev/null and b/examples/audio/resources/chiptun1.mod differ diff --git a/examples/audio/resources/coin.wav b/examples/audio/resources/coin.wav new file mode 100644 index 0000000..6007509 Binary files /dev/null and b/examples/audio/resources/coin.wav differ diff --git a/examples/audio/resources/guitar_noodling.ogg b/examples/audio/resources/guitar_noodling.ogg new file mode 100644 index 0000000..f502204 Binary files /dev/null and b/examples/audio/resources/guitar_noodling.ogg differ diff --git a/examples/audio/resources/mini1111.xm b/examples/audio/resources/mini1111.xm new file mode 100644 index 0000000..a185c1a Binary files /dev/null and b/examples/audio/resources/mini1111.xm differ diff --git a/examples/audio/resources/sound.wav b/examples/audio/resources/sound.wav new file mode 100644 index 0000000..b5d01c9 Binary files /dev/null and b/examples/audio/resources/sound.wav differ diff --git a/examples/audio/resources/spring.wav b/examples/audio/resources/spring.wav new file mode 100644 index 0000000..c7fbf1b Binary files /dev/null and b/examples/audio/resources/spring.wav differ diff --git a/examples/audio/resources/tanatana.flac b/examples/audio/resources/tanatana.flac new file mode 100644 index 0000000..dfe735c Binary files /dev/null and b/examples/audio/resources/tanatana.flac differ diff --git a/examples/audio/resources/tanatana.ogg b/examples/audio/resources/tanatana.ogg new file mode 100644 index 0000000..90b1795 Binary files /dev/null and b/examples/audio/resources/tanatana.ogg differ diff --git a/examples/audio/resources/weird.wav b/examples/audio/resources/weird.wav new file mode 100644 index 0000000..101029c Binary files /dev/null and b/examples/audio/resources/weird.wav differ diff --git a/examples/core/core_basic_window.cpp b/examples/core/core_basic_window.cpp index 776ea73..9a78f1f 100644 --- a/examples/core/core_basic_window.cpp +++ b/examples/core/core_basic_window.cpp @@ -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; -} \ No newline at end of file +} diff --git a/examples/core/core_input_mouse.cpp b/examples/core/core_input_mouse.cpp index 0a60217..6782423 100644 --- a/examples/core/core_input_mouse.cpp +++ b/examples/core/core_input_mouse.cpp @@ -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; -} \ No newline at end of file +} diff --git a/examples/core/core_random_values.cpp b/examples/core/core_random_values.cpp new file mode 100644 index 0000000..2922b4e --- /dev/null +++ b/examples/core/core_random_values.cpp @@ -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; +} diff --git a/examples/textures/textures_image_drawing.cpp b/examples/textures/textures_image_drawing.cpp index 20612a6..aecb869 100644 --- a/examples/textures/textures_image_drawing.cpp +++ b/examples/textures/textures_image_drawing.cpp @@ -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(); //---------------------------------------------------------------------------------- diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000..e830ffd --- /dev/null +++ b/include/CMakeLists.txt @@ -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}/) diff --git a/include/raylib/AudioDevice.hpp b/include/raylib/AudioDevice.hpp index 8536197..e8113f0 100644 --- a/include/raylib/AudioDevice.hpp +++ b/include/raylib/AudioDevice.hpp @@ -28,6 +28,10 @@ namespace raylib { static bool IsReady() { return IsAudioDeviceReady(); } + + void SetVolume(float volume) { + SetMasterVolume(volume); + } }; } diff --git a/include/raylib/AudioStream.hpp b/include/raylib/AudioStream.hpp new file mode 100644 index 0000000..3f754ed --- /dev/null +++ b/include/raylib/AudioStream.hpp @@ -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 diff --git a/include/raylib/BoundingBox.hpp b/include/raylib/BoundingBox.hpp index c3f320d..4e85fa6 100644 --- a/include/raylib/BoundingBox.hpp +++ b/include/raylib/BoundingBox.hpp @@ -49,4 +49,4 @@ namespace raylib { }; } -#endif \ No newline at end of file +#endif diff --git a/include/raylib/Camera2D.hpp b/include/raylib/Camera2D.hpp index 3d51860..7b1a84c 100644 --- a/include/raylib/Camera2D.hpp +++ b/include/raylib/Camera2D.hpp @@ -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 \ No newline at end of file +#endif diff --git a/include/raylib/Camera.hpp b/include/raylib/Camera3D.hpp similarity index 75% rename from include/raylib/Camera.hpp rename to include/raylib/Camera3D.hpp index 1179c73..5741357 100644 --- a/include/raylib/Camera.hpp +++ b/include/raylib/Camera3D.hpp @@ -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 \ No newline at end of file +#endif diff --git a/include/raylib/Color.hpp b/include/raylib/Color.hpp index d901f09..ba7d17e 100644 --- a/include/raylib/Color.hpp +++ b/include/raylib/Color.hpp @@ -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 \ No newline at end of file +#endif diff --git a/include/raylib/Font.hpp b/include/raylib/Font.hpp index 2235066..3764723 100644 --- a/include/raylib/Font.hpp +++ b/include/raylib/Font.hpp @@ -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); } - }; } diff --git a/include/raylib/Gamepad.hpp b/include/raylib/Gamepad.hpp index f77f249..5aa8de2 100644 --- a/include/raylib/Gamepad.hpp +++ b/include/raylib/Gamepad.hpp @@ -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() { diff --git a/include/raylib/Image.hpp b/include/raylib/Image.hpp index 6b7184e..481ebc0 100644 --- a/include/raylib/Image.hpp +++ b/include/raylib/Image.hpp @@ -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); + } + }; } diff --git a/include/raylib/Material.hpp b/include/raylib/Material.hpp index 7b17f99..6e9f57e 100644 --- a/include/raylib/Material.hpp +++ b/include/raylib/Material.hpp @@ -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); diff --git a/include/raylib/Mesh.hpp b/include/raylib/Mesh.hpp index 897f45b..32c845d 100644 --- a/include/raylib/Mesh.hpp +++ b/include/raylib/Mesh.hpp @@ -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); } - - - - - - }; } diff --git a/include/raylib/Music.hpp b/include/raylib/Music.hpp new file mode 100644 index 0000000..8195383 --- /dev/null +++ b/include/raylib/Music.hpp @@ -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 diff --git a/include/raylib/Rectangle.hpp b/include/raylib/Rectangle.hpp index 6f9d281..3e9a27f 100644 --- a/include/raylib/Rectangle.hpp +++ b/include/raylib/Rectangle.hpp @@ -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 \ No newline at end of file +#endif diff --git a/include/raylib/Sound.hpp b/include/raylib/Sound.hpp new file mode 100644 index 0000000..36285d4 --- /dev/null +++ b/include/raylib/Sound.hpp @@ -0,0 +1,79 @@ +#ifndef RAYLIB_CPP_SOUND_HPP_ +#define RAYLIB_CPP_SOUND_HPP_ + +#include + +#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 diff --git a/include/raylib/Vector2.hpp b/include/raylib/Vector2.hpp index 2827c0f..adff393 100644 --- a/include/raylib/Vector2.hpp +++ b/include/raylib/Vector2.hpp @@ -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 \ No newline at end of file +#endif diff --git a/include/raylib/Vector3.hpp b/include/raylib/Vector3.hpp index e5df1ce..4139adc 100644 --- a/include/raylib/Vector3.hpp +++ b/include/raylib/Vector3.hpp @@ -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); + } }; } diff --git a/include/raylib/Vector4.hpp b/include/raylib/Vector4.hpp index c467206..4ed9a79 100644 --- a/include/raylib/Vector4.hpp +++ b/include/raylib/Vector4.hpp @@ -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; diff --git a/include/raylib/Wave.hpp b/include/raylib/Wave.hpp new file mode 100644 index 0000000..3166606 --- /dev/null +++ b/include/raylib/Wave.hpp @@ -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 diff --git a/include/raylib/Window.hpp b/include/raylib/Window.hpp index 8947048..6515078 100644 --- a/include/raylib/Window.hpp +++ b/include/raylib/Window.hpp @@ -33,6 +33,13 @@ namespace raylib { return IsWindowReady(); }; + void BeginDrawing() { + ::BeginDrawing(); + } + void EndDrawing() { + ::EndDrawing(); + } + }; } diff --git a/include/raylib/raylib.hpp b/include/raylib/raylib.hpp index c24f7e4..2ae3f8a 100644 --- a/include/raylib/raylib.hpp +++ b/include/raylib/raylib.hpp @@ -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 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9958eb2..0986d27 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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) diff --git a/tests/raylib_test.cpp b/tests/raylib_test.cpp index fa9250d..c5cb226 100644 --- a/tests/raylib_test.cpp +++ b/tests/raylib_test.cpp @@ -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)); -} \ No newline at end of file + SECTION("Color") { + raylib::Color c(RED); + CHECK(c.ToInt() == ColorToInt(RED)); + } +}