#ifndef IMGUI_CWIDGET_H #define IMGUI_CWIDGET_H #include "CApplication.h" #define C_Key1 std::placeholders::_1 #define C_Key2 std::placeholders::_2 namespace CTL { class GUI_Widget : public GUI_Application{ virtual void onInit(){}; virtual void onParent(){}; void KeyEventHandler(); GLFWimage Icon[2] = { 0 }; // 全局变量,用于跟踪鼠标状态和窗口移动 int mouseInitialX = 0; int mouseInitialY = 0; int windowLastX = 0; int windowLastY = 0; #ifdef _WIN32 POINT dragStartPos; RECT r1; HICON hicon; #elif __linxu__ #endif ImVec2 MouseXY,XY; bool mouseButtonPressed = false,Iconbool = false,Framequeue = false,Funlook = true; double damping = 0.5; // 阻尼系数,用于平滑移动 int Round = 0,FrameTime = 10; unsigned char* datas{};int width = 1024, height = 800, nrChannels = 0; GUI_Application* application = nullptr; std::function task_Click_L; std::function task_Click_R; std::function task_Click_M; std::function Fun_Close; std::function Fun_onInit; std::function Fun_onParent; std::function Fun_ReSize; std::function DefaultKeyFun; std::thread AB; std::thread ABC; std::thread ABCD; std::queue> funcQueue; std::mutex funcMutex; public: #ifdef _WIN32 #elif __linux__ #endif void SetSize(HSize size); void SetPosition(HPos position); void SetOpacity(int opacity); HPos GetPosition(); HSize GetSize(); bool SetIcon(const unsigned char* Mem,const int MemSize); bool SetIcon(const char* path); void MouseWindow(); void SetRound(int x); void SetBackground(RGBA rgba); RGBA GetBackground(); void SetNoFrame(); void SetDamping(float d); void Close(); void SetCenter(); void SetNewFrameTime(int ms); void SetWindowTitle(std::string title); public: explicit GUI_Widget(GUI_Widget* parent = nullptr); //------------------------------------------------------------------ virtual void Show(GUI_Application* pApplication = nullptr); unsigned char* LoadIMGMemory(char const *filename, int *x, int *y, int *comp, int req_comp); unsigned char* LoadIMGMemory(const unsigned char *buffer, int len, int *x, int *y, int *comp, int req_comp); bool IsWindowFlag = true; //------------------------------------------------------------------ template bool Close_Click(Func&& fun, Args&&... args); template bool Click(ImGuiMouseButton Mouse,Func&& fun, Args&&... args); template bool SetOnInit(Func&& fun); template bool SetOnParent(Func&& fun); template bool ReSizeClick(Func&& fun, Args&&... args); template bool SetKeyboardClick(Func&& fun, Args&&... args); template void InvokeMethod(Func&& fun, Args&&... args); }; template inline bool GUI_Widget::Close_Click(Func&& fun, Args&&... args){ Fun_Close = std::bind(std::forward(fun), std::forward(args)...); return true; } template inline bool GUI_Widget::Click(ImGuiMouseButton Mouse,Func&& fun, Args&&... args){ if (Mouse == IMBN::ImGuiMouseButton_Left) { task_Click_L = std::bind(std::forward(fun), std::forward(args)...); } else if (Mouse == IMBN::ImGuiMouseButton_Right) { task_Click_R = std::bind(std::forward(fun), std::forward(args)...); } else if (Mouse == IMBN::ImGuiMouseButton_Middle) { task_Click_M = std::bind(std::forward(fun), std::forward(args)...); } return true; } template inline bool GUI_Widget::SetOnParent(Func&& fun) { Fun_onParent = std::bind(std::forward(fun)); return true; } template inline bool GUI_Widget::SetOnInit(Func&& fun) { Fun_onInit = std::bind(std::forward(fun)); return true; } template inline bool GUI_Widget::ReSizeClick(Func&& fun, Args&&... args){ Fun_ReSize = std::bind(std::forward(fun), std::forward(args)...); return true; } template inline bool GUI_Widget::SetKeyboardClick(Func&& fun, Args&&... args){ DefaultKeyFun = std::bind(std::forward(fun), std::forward(args)...); return true; } template inline void GUI_Widget::InvokeMethod(Func&& fun, Args&&... args){ if(Framequeue){ std::this_thread::sleep_for(std::chrono::milliseconds(16)); if(funcMutex.try_lock()){ //Funlook = false; funcQueue.push(std::bind(std::forward(fun), std::forward(args)...)); funcMutex.unlock(); } } } } #endif