diff --git a/examples/core/core_drop_files.cpp b/examples/core/core_drop_files.cpp new file mode 100644 index 0000000..dea950f --- /dev/null +++ b/examples/core/core_drop_files.cpp @@ -0,0 +1,78 @@ +/******************************************************************************************* +* +* raylib [core] example - Windows drop files +* +* This example only works on platforms that support drag & drop (Windows, Linux, OSX, Html5?) +* +* This example has been created using raylib-cpp (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2020 Rob Loach (@RobLoach) +* +********************************************************************************************/ + +#include "raylib/raylib.hpp" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + raylib::Window w(screenWidth, screenHeight, "raylib [core] example - drop files"); + + // Create the Dropped Files collection object. + raylib::DroppedFiles droppedFiles; + + 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 (droppedFiles.IsFileDropped()) { + droppedFiles.Get(); + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // Check if there are files to process. + if (droppedFiles.empty()) { + DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY); + } + else { + DrawText("Dropped files:", 100, 40, 20, DARKGRAY); + + // Iterate through all the dropped files. + for (int i = 0; i < droppedFiles.size(); i++) { + if (i%2 == 0) + DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5f)); + else + DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f)); + + // Display the path to the dropped file. + DrawText(droppedFiles[i].c_str(), 120, 100 + 40*i, 10, GRAY); + } + + DrawText("Drop new files...", 100, 110 + 40 * droppedFiles.size(), 20, DARKGRAY); + } + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + // ClearDroppedFiles(); // Called for us. + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 1efec9f..ffb432a 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,10 +1,39 @@ add_library(raylib-cpp INTERFACE) -file(GLOB sources raylib/*.hpp) -set(RAYLIBCPP_HEADERS, ${sources}) +target_include_directories(raylib-cpp INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/) install(FILES - ${RAYLIBCPP_HEADERS} DESTINATION include/ + raylib/AudioDevice.hpp + raylib/AudioStream.hpp + raylib/BoundingBox.hpp + raylib/Camera2D.hpp + raylib/Camera3D.hpp + raylib/Color.hpp + raylib/DroppedFiles.hpp + raylib/Font.hpp + raylib/Gamepad.hpp + raylib/Image.hpp + raylib/Material.hpp + raylib/Matrix.hpp + raylib/Mesh.hpp + raylib/ModelAnimation.hpp + raylib/Model.hpp + raylib/Mouse.hpp + raylib/Music.hpp + raylib/RayHitInfo.hpp + raylib/Ray.hpp + raylib/raylib.hpp + raylib/Rectangle.hpp + raylib/RenderTexture2D.hpp + raylib/Shader.hpp + raylib/Sound.hpp + raylib/Texture2D.hpp + raylib/utils.hpp + raylib/Vector2.hpp + raylib/Vector3.hpp + raylib/Vector4.hpp + raylib/VrSimulator.hpp + raylib/Wave.hpp + raylib/Window.hpp + DESTINATION include/raylib ) - -target_include_directories(raylib-cpp INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/) diff --git a/include/raylib/DroppedFiles.hpp b/include/raylib/DroppedFiles.hpp new file mode 100644 index 0000000..258758a --- /dev/null +++ b/include/raylib/DroppedFiles.hpp @@ -0,0 +1,88 @@ +#ifndef RAYLIB_CPP_DROPPEDFILES_HPP_ +#define RAYLIB_CPP_DROPPEDFILES_HPP_ + +#include + +#ifdef __cplusplus +extern "C"{ +#endif +#include "raylib.h" +#ifdef __cplusplus +} +#endif + +namespace raylib { + class DroppedFiles { + protected: + char** m_files; + int m_count; + public: + DroppedFiles() { + Get(); + } + + /** + * Get the dropped files names. + */ + DroppedFiles& Get() { + m_files = ::GetDroppedFiles(&m_count); + return *this; + } + + /** + * Check if a file has been dropped into window. + */ + inline bool IsFileDropped() { + return ::IsFileDropped(); + } + + /** + * Clear dropped files paths buffer. + */ + inline DroppedFiles& Clear() { + ::ClearDroppedFiles(); + return *this; + } + + ~DroppedFiles() { + Clear(); + } + + inline std::string operator[](int pos) { + return at(pos); + } + + inline int Count() { + return m_count; + } + + inline int size() { + return m_count; + } + + inline bool empty() { + return m_count == 0; + } + + inline void clear() { + Clear(); + } + + inline std::string front() { + return at(0); + } + + inline std::string back() { + return at(m_count - 1); + } + + std::string at(int pos) { + if (m_files != NULL && pos < m_count && pos >= 0) { + return std::string(m_files[pos]); + } + return ""; + } + }; +} + +#endif diff --git a/include/raylib/raylib.hpp b/include/raylib/raylib.hpp index dfc0d32..21a84b6 100644 --- a/include/raylib/raylib.hpp +++ b/include/raylib/raylib.hpp @@ -7,6 +7,7 @@ #include "Camera2D.hpp" #include "Camera3D.hpp" #include "Color.hpp" +#include "DroppedFiles.hpp" #include "Font.hpp" #include "Gamepad.hpp" #include "Image.hpp" diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index a0d32c9..f203b59 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -6,3 +6,6 @@ target_link_libraries(libraylib-cpp PUBLIC raylib raylib-cpp) # Remove the "lib" at the beginning since it's already there. set_target_properties(libraylib-cpp PROPERTIES PREFIX "") + +# Set up the install directory. +install(TARGETS libraylib-cpp DESTINATION lib) diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt index 6ba1d28..e1c04be 100644 --- a/projects/CMake/CMakeLists.txt +++ b/projects/CMake/CMakeLists.txt @@ -28,7 +28,7 @@ if (NOT raylib-cpp_FOUND) FetchContent_Declare( raylib-cpp GIT_REPOSITORY https://github.com/RobLoach/raylib-cpp.git - GIT_TAG 64c39d6d6b1ab2f68cb3669b0a3ff57857d5cdf7 + GIT_TAG 27f7a59fd2e7fb2356d90e4f477e994475e8dbb8 ) FetchContent_GetProperties(raylib-cpp) if (NOT raylib-cpp_POPULATED) # Have we downloaded raylib yet? @@ -45,7 +45,7 @@ endif() set(PROJECT_NAME raylib-cpp-example) set(PROJECT_SOURCES main.cpp) add_executable(${PROJECT_NAME} ${PROJECT_SOURCES}) -#set(raylib_VERBOSE 1) +set(raylib_VERBOSE 1) target_link_libraries(${PROJECT_NAME} PUBLIC raylib raylib-cpp) # That's it! You should have an example executable that you can run. Have fun!