diff --git a/dl/base/dl_range_every.h b/dl/base/dl_range_every.h index 584fd4ac..7f927b8e 100644 --- a/dl/base/dl_range_every.h +++ b/dl/base/dl_range_every.h @@ -233,11 +233,10 @@ void Erase(C& container, const V& v) ++iter; } } - /** - * @brief 移除容器所有元素都等于某值 - * @param[in] c 操作的容器 - * @param[in] v 要比较的值 +* @brief 移除容器所有元素都等于某值 +* @param[in] c 操作的容器 +* @param[in] v 要比较的值 */ template [[nodiscard]] @@ -290,6 +289,20 @@ void Replace(C& c, const V& v, const V& v_new) iter = v_new; } } +/** +* @brief 替换容器所有元素都等于某值 +* @param[in] c 操作的容器 +* @param[in] v 要替换的值 +* @param[in] v_new 新值 +*/ +template +[[nodiscard]] +C Replace(const C& c, const V& v, const V& v_new) +{ + C ret = c; + Replace(ret, v, v_new); + return ret; +} /** * @brief 对容器每个元素进行delete操作 diff --git a/dl/base/dl_string.h b/dl/base/dl_string.h index 3280f01a..dd950835 100644 --- a/dl/base/dl_string.h +++ b/dl/base/dl_string.h @@ -387,6 +387,15 @@ inline void CvtPathSeparator(std::string& path) { Every::Replace(path, '\\', '/'); } +/** +* @brief 路径斜杠统一为/ +* @param[in] path 路径 +*/ +[[nodiscard]] +inline std::string CvtPathSeparator(std::string_view path) +{ + return Every::Replace(std::string{ path }, '\\', '/'); +} /** * @brief 换行符统一为\n diff --git a/dl/system/dl_system.cpp b/dl/system/dl_system.cpp index 8fc9f873..ba782d5d 100644 --- a/dl/system/dl_system.cpp +++ b/dl/system/dl_system.cpp @@ -108,6 +108,11 @@ static void CallbackScroll(GLFWwindow* window, double dx, double dy) //log_test("滚动操作:{}, {}", dx, -dy); } +void CallbackDrop(GLFWwindow* window, int count, const char** paths) +{ + for (int i = 0; i < count; ++i) + g_system->_add_drop_file(String::CvtPathSeparator(paths[i])); +} System::System() : _funcInit{ nullptr }, @@ -159,6 +164,9 @@ void System::Start(const ParamWindow& param) glfwSetMouseButtonCallback(_imp->_window, CallbackMouseButton); // 设置滚动回调 glfwSetScrollCallback(_imp->_window, CallbackScroll); + // 拖入文件回调 + glfwSetDropCallback(_imp->_window, CallbackDrop); + #elif DL_PLATFORM == DL_PLATFORM_ANDROID _imp->_window = new GLFWwindow; _imp->_monitor = new GLFWmonitor; diff --git a/dl/system/dl_system.h b/dl/system/dl_system.h index 555caa79..d5cc3c9d 100644 --- a/dl/system/dl_system.h +++ b/dl/system/dl_system.h @@ -13,6 +13,7 @@ #ifndef DL_DISABLE_RENDER #include +#include #include "dl_type.h" #include "base/dl_type_user.h" @@ -123,6 +124,27 @@ public: */ std::string GetClipboardString(); + /** + * @brief 清空拖入文件列表 + */ + void ClearDropFile() + { + _vecDropFile.clear(); + } + /** + * @brief 返回拖入文件列表 + */ + const std::vector& GetDropFile() + { + return _vecDropFile; + } + + //! 内部调用 + void _add_drop_file(std::string_view str) + { + _vecDropFile.push_back(std::string{ str }); + } + SystemImp* GetImp() { return _imp; } private: SystemImp* _imp; @@ -131,6 +153,8 @@ private: CursorMode _cursorMode; bool _bCursorModeChange; + + std::vector _vecDropFile; }; extern System* g_system; }