From 6960eae62f536267969ef38d47ab3dd3b432e316 Mon Sep 17 00:00:00 2001 From: MistEO Date: Sun, 12 Nov 2023 20:48:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Win32=20Controller=20=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 11 +- include/MaaFramework/Instance/MaaController.h | 4 + include/MaaFramework/MaaDef.h | 15 ++ source/CMakeLists.txt | 3 + .../Base}/ArgvWrapper.hpp | 2 +- source/MaaAdbControlUnit/Base/UnitBase.h | 2 +- source/MaaFramework/API/MaaController.cpp | 21 +++ source/MaaFramework/CMakeLists.txt | 3 + .../ControlUnitLibraryHolder.cpp | 47 ++++++ .../API/Win32ControlUnitAPI.cpp | 63 ++++++++ source/MaaWin32ControlUnit/Base/UnitBase.h | 43 ++++++ source/MaaWin32ControlUnit/CMakeLists.txt | 25 ++++ .../Manager/ControlUnitMgr.cpp | 139 ++++++++++++++++++ .../Manager/ControlUnitMgr.h | 57 +++++++ .../Touch/SendMessageToucher.cpp | 56 +++++++ .../Touch/SendMessageToucher.h | 25 ++++ .../include/ControlUnit/Win32ControlUnitAPI.h | 24 +++ .../include/Utils/ControlUnitLibraryHolder.h | 14 ++ 18 files changed, 543 insertions(+), 11 deletions(-) rename source/{include/Utils => MaaAdbControlUnit/Base}/ArgvWrapper.hpp (97%) create mode 100644 source/MaaWin32ControlUnit/API/Win32ControlUnitAPI.cpp create mode 100644 source/MaaWin32ControlUnit/Base/UnitBase.h create mode 100644 source/MaaWin32ControlUnit/CMakeLists.txt create mode 100644 source/MaaWin32ControlUnit/Manager/ControlUnitMgr.cpp create mode 100644 source/MaaWin32ControlUnit/Manager/ControlUnitMgr.h create mode 100644 source/MaaWin32ControlUnit/Touch/SendMessageToucher.cpp create mode 100644 source/MaaWin32ControlUnit/Touch/SendMessageToucher.h create mode 100644 source/include/ControlUnit/Win32ControlUnitAPI.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e6021942b..94421f86f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,8 @@ option(USE_MAADEPS "use third-party libraries built by MaaDeps" ON) option(WITH_ADB_CONTROLLER "build with adb controller" ON) option(WITH_THRIFT_CONTROLLER "build with thrift controller" ON) option(WITH_DBG_CONTROLLER "build with debugging controller" ON) +option(WITH_WIN32_CONTROLLER "build with win32 controller" ON) + option(WITH_GRPC "build with protobuf and grpc" ON) option(BUILD_GRPC_CLI "build grpc CLI exec" ON) @@ -43,20 +45,11 @@ include(${PROJECT_SOURCE_DIR}/cmake/utils.cmake) include(${PROJECT_SOURCE_DIR}/cmake/version.cmake) # include(${PROJECT_SOURCE_DIR}/cmake/nuget.cmake) -if (WITH_ADB_CONTROLLER) - add_compile_definitions(WITH_ADB_CONTROLLER) -endif() if(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE) include(${PROJECT_SOURCE_DIR}/cmake/thrift-gen.cmake) - add_compile_definitions(WITH_THRIFT_CONTROLLER) endif() -if (WITH_DBG_CONTROLLER) - add_compile_definitions(WITH_DBG_CONTROLLER) -endif() - if(WITH_GRPC) include(${PROJECT_SOURCE_DIR}/cmake/grpc-gen.cmake) - add_compile_definitions(WITH_GRPC) endif() find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs) diff --git a/include/MaaFramework/Instance/MaaController.h b/include/MaaFramework/Instance/MaaController.h index 54475f158..f2e4265b1 100644 --- a/include/MaaFramework/Instance/MaaController.h +++ b/include/MaaFramework/Instance/MaaController.h @@ -13,6 +13,10 @@ extern "C" MaaStringView adb_path, MaaStringView address, MaaAdbControllerType type, MaaStringView config, MaaControllerCallback callback, MaaCallbackTransparentArg callback_arg); + MaaControllerHandle MAA_FRAMEWORK_API MaaWin32ControllerCreate( // + void* hWnd, MaaWin32ControllerType type, MaaControllerCallback callback, + MaaCallbackTransparentArg callback_arg); + MaaControllerHandle MAA_FRAMEWORK_API MaaAdbControllerCreateV2( // MaaStringView adb_path, MaaStringView address, MaaAdbControllerType type, MaaStringView config, MaaStringView agent_path, MaaControllerCallback callback, MaaCallbackTransparentArg callback_arg); diff --git a/include/MaaFramework/MaaDef.h b/include/MaaFramework/MaaDef.h index 95e8eaac8..ec5a63e9b 100644 --- a/include/MaaFramework/MaaDef.h +++ b/include/MaaFramework/MaaDef.h @@ -165,6 +165,21 @@ enum MaaThriftControllerTypeEnum MaaThriftControllerType_UnixDomainSocket = 2, }; +#ifdef _WIN32 +typedef int32_t MaaWin32ControllerType; +enum MaaWin32ControllerTypeEnum +{ + MaaWin32Controller_Invalid = 0, + + MaaWin32ControllerType_Touch_SendMessage = 1, + MaaWin32ControllerType_Touch_Mask = 0xFF, + + MaaWin32ControllerType_Key_Mask = 0xFF00, + + MaaWin32ControllerType_Screencap_Mask = 0xFF0000, +}; +#endif + typedef void* MaaTransparentArg; typedef MaaTransparentArg MaaCallbackTransparentArg; diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 0541c77af..f8e462b8e 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -3,6 +3,9 @@ add_subdirectory(MaaUtils) if (WITH_ADB_CONTROLLER) add_subdirectory(MaaAdbControlUnit) endif(WITH_ADB_CONTROLLER) +if (WITH_WIN32_CONTROLLER) + add_subdirectory(MaaWin32ControlUnit) +endif(WITH_WIN32_CONTROLLER) if(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE) add_subdirectory(MaaThriftControlUnit) endif(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE) diff --git a/source/include/Utils/ArgvWrapper.hpp b/source/MaaAdbControlUnit/Base/ArgvWrapper.hpp similarity index 97% rename from source/include/Utils/ArgvWrapper.hpp rename to source/MaaAdbControlUnit/Base/ArgvWrapper.hpp index 92da0e47a..fbac0c27a 100644 --- a/source/include/Utils/ArgvWrapper.hpp +++ b/source/MaaAdbControlUnit/Base/ArgvWrapper.hpp @@ -3,7 +3,7 @@ #include #include -#include "StringMisc.hpp" +#include "Utils/StringMisc.hpp" MAA_NS_BEGIN diff --git a/source/MaaAdbControlUnit/Base/UnitBase.h b/source/MaaAdbControlUnit/Base/UnitBase.h index 739b622f5..121d1693a 100644 --- a/source/MaaAdbControlUnit/Base/UnitBase.h +++ b/source/MaaAdbControlUnit/Base/UnitBase.h @@ -2,10 +2,10 @@ #include +#include "Base/ArgvWrapper.hpp" #include "ControlUnit/AdbControlUnitAPI.h" #include "Platform/PlatformIO.h" #include "Screencap/ScreencapHelper.h" -#include "Utils/ArgvWrapper.hpp" MAA_CTRL_UNIT_NS_BEGIN diff --git a/source/MaaFramework/API/MaaController.cpp b/source/MaaFramework/API/MaaController.cpp index a67c0ca50..ad6e32b28 100644 --- a/source/MaaFramework/API/MaaController.cpp +++ b/source/MaaFramework/API/MaaController.cpp @@ -37,6 +37,27 @@ MaaControllerHandle MaaAdbControllerCreateV2( // return new MAA_CTRL_NS::GeneralControllerAgent(std::move(control_unit), callback, callback_arg); } +MaaControllerHandle MaaWin32ControllerCreate( // + void* hWnd, MaaWin32ControllerType type, MaaControllerCallback callback, MaaCallbackTransparentArg callback_arg) +{ + LogFunc << VAR_VOIDP(hWnd) << VAR(type) << VAR_VOIDP(callback) << VAR_VOIDP(callback_arg); + + if (!hWnd) { + LogError << "hWnd is nullptr"; + return nullptr; + } + + auto control_unit = + MAA_CTRL_NS::Win32ControlUnitLibraryHolder::create_control_unit(hWnd, type, callback, callback_arg); + + if (!control_unit) { + LogError << "Failed to create control unit"; + return nullptr; + } + + return new MAA_CTRL_NS::GeneralControllerAgent(std::move(control_unit), callback, callback_arg); +} + MaaControllerHandle MaaCustomControllerCreate( // MaaCustomControllerHandle handle, MaaTransparentArg handle_arg, MaaControllerCallback callback, MaaCallbackTransparentArg callback_arg) diff --git a/source/MaaFramework/CMakeLists.txt b/source/MaaFramework/CMakeLists.txt index 83db867ad..95091841d 100644 --- a/source/MaaFramework/CMakeLists.txt +++ b/source/MaaFramework/CMakeLists.txt @@ -22,6 +22,9 @@ add_dependencies(MaaFramework MaaUtils) if (WITH_ADB_CONTROLLER) add_dependencies(MaaFramework MaaAdbControlUnit) endif(WITH_ADB_CONTROLLER) +if (WITH_WIN32_CONTROLLER) + add_dependencies(MaaFramework MaaWin32ControlUnit) +endif(WITH_WIN32_CONTROLLER) if(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE) add_dependencies(MaaFramework MaaThriftControlUnit) endif(WITH_THRIFT_CONTROLLER AND NOT MAA_CROSSCOMPILE) diff --git a/source/MaaUtils/LibraryHolder/ControlUnitLibraryHolder.cpp b/source/MaaUtils/LibraryHolder/ControlUnitLibraryHolder.cpp index 28b52da5e..0e6d5067b 100644 --- a/source/MaaUtils/LibraryHolder/ControlUnitLibraryHolder.cpp +++ b/source/MaaUtils/LibraryHolder/ControlUnitLibraryHolder.cpp @@ -66,6 +66,53 @@ std::shared_ptr AdbControlUnitLibraryHolder::c return std::shared_ptr(control_unit_handle, destroy_control_unit); } +std::shared_ptr Win32ControlUnitLibraryHolder::create_control_unit( + void* hWnd, MaaWin32ControllerType type, MaaControllerCallback callback, MaaCallbackTransparentArg callback_arg) +{ + if (!hWnd) { + LogError << "hWnd is nullptr"; + return nullptr; + } + + if (!load_library(libname_)) { + LogError << "Failed to load library" << VAR(libname_); + return nullptr; + } + + check_version(version_func_name_); + + using create_control_unit_t = + MaaControlUnitHandle(void*, MaaWin32ControllerType, MaaControllerCallback, MaaCallbackTransparentArg); + + using destroy_control_unit_t = void(MaaControlUnitHandle); + + auto create_control_unit_func = get_function(create_func_name_); + if (!create_control_unit_func) { + LogError << "Failed to get function create_control_unit"; + return nullptr; + } + + auto destroy_control_unit_func = get_function(destroy_func_name_); + if (!destroy_control_unit_func) { + LogError << "Failed to get function destroy_control_unit"; + return nullptr; + } + + auto control_unit_handle = create_control_unit_func(hWnd, type, callback, callback_arg); + + if (!control_unit_handle) { + LogError << "Failed to create control unit"; + return nullptr; + } + + auto destroy_control_unit = [destroy_control_unit_func](MaaControlUnitHandle handle) { + destroy_control_unit_func(handle); + unload_library(); + }; + + return std::shared_ptr(control_unit_handle, destroy_control_unit); +} + std::shared_ptr DbgControlUnitLibraryHolder::create_control_unit( MaaDbgControllerType type, MaaStringView read_path) { diff --git a/source/MaaWin32ControlUnit/API/Win32ControlUnitAPI.cpp b/source/MaaWin32ControlUnit/API/Win32ControlUnitAPI.cpp new file mode 100644 index 000000000..c28c4bb5b --- /dev/null +++ b/source/MaaWin32ControlUnit/API/Win32ControlUnitAPI.cpp @@ -0,0 +1,63 @@ +#include "ControlUnit/Win32ControlUnitAPI.h" + +#include "Base/UnitBase.h" +#include "Manager/ControlUnitMgr.h" +#include "Touch/SendMessageToucher.h" +#include "Utils/Logger.h" +#include "Utils/SafeWindows.hpp" + +MaaStringView get_version() +{ +#pragma message("MaaWin32ControlUnit MAA_VERSION: " MAA_VERSION) + + return MAA_VERSION; +} + +MaaControlUnitHandle create_control_unit( // + void* hWnd, MaaWin32ControllerType type, MaaControllerCallback callback, MaaCallbackTransparentArg callback_arg) +{ + using namespace MAA_CTRL_UNIT_NS; + + LogFunc << VAR_VOIDP(hWnd) << VAR_VOIDP(callback) << VAR_VOIDP(callback_arg); + + if (!hWnd) { + LogError << "hWnd is nullptr"; + return nullptr; + } + HWND h_wnd = reinterpret_cast(hWnd); + + std::shared_ptr touch_unit = nullptr; + std::shared_ptr key_unit = nullptr; + std::shared_ptr screencap_unit = nullptr; + + auto touch_type = type & MaaWin32ControllerType_Touch_Mask; + // auto key_type = type & MaaWin32ControllerType_Key_Mask; + // auto screencap_type = type & MaaWin32ControllerType_Screencap_Mask; + + switch (touch_type) { + case MaaWin32ControllerType_Touch_SendMessage: + LogInfo << "touch_type: SendMessage"; + touch_unit = std::make_shared(); + break; + default: + LogWarn << "Unknown touch input type" << VAR(touch_type); + break; + } + + auto unit_mgr = std::make_unique(h_wnd, callback, callback_arg); + + unit_mgr->set_touch_input_obj(touch_unit); + unit_mgr->set_key_input_obj(key_unit); + unit_mgr->set_screencap_obj(screencap_unit); + + return unit_mgr.release(); +} + +void destroy_control_unit(MaaControlUnitHandle handle) +{ + LogFunc << VAR_VOIDP(handle); + + if (handle) { + delete handle; + } +} diff --git a/source/MaaWin32ControlUnit/Base/UnitBase.h b/source/MaaWin32ControlUnit/Base/UnitBase.h new file mode 100644 index 000000000..d4a3197eb --- /dev/null +++ b/source/MaaWin32ControlUnit/Base/UnitBase.h @@ -0,0 +1,43 @@ +#pragma once + +#include + +#include "ControlUnit/Win32ControlUnitAPI.h" + +MAA_CTRL_UNIT_NS_BEGIN + +class ScreencapBase +{ +public: + virtual ~ScreencapBase() = default; + +public: + virtual std::optional screencap() = 0; + +protected: +}; + +class TouchInputBase +{ +public: + virtual ~TouchInputBase() = default; + +public: + virtual bool click(int x, int y) = 0; + virtual bool swipe(int x1, int y1, int x2, int y2, int duration) = 0; + + virtual bool touch_down(int contact, int x, int y, int pressure) = 0; + virtual bool touch_move(int contact, int x, int y, int pressure) = 0; + virtual bool touch_up(int contact) = 0; +}; + +class KeyInputBase +{ +public: + virtual ~KeyInputBase() = default; + +public: + virtual bool press_key(int key) = 0; +}; + +MAA_CTRL_UNIT_NS_END diff --git a/source/MaaWin32ControlUnit/CMakeLists.txt b/source/MaaWin32ControlUnit/CMakeLists.txt new file mode 100644 index 000000000..cd364f659 --- /dev/null +++ b/source/MaaWin32ControlUnit/CMakeLists.txt @@ -0,0 +1,25 @@ +file(GLOB_RECURSE maa_win32_control_unit_src *.h *.hpp *.cpp) +file(GLOB_RECURSE maa_win32_control_unit_header ../include/ControlUnit/Win32ControlUnitAPI.h ../include/ControlUnit/ControlUnitAPI.h) + +add_library(MaaWin32ControlUnit SHARED ${maa_win32_control_unit_src} ${maa_win32_control_unit_header}) + +target_include_directories(MaaWin32ControlUnit PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include + ${CMAKE_CURRENT_SOURCE_DIR}/../../include) + +target_link_libraries(MaaWin32ControlUnit MaaUtils HeaderOnlyLibraries ${OpenCV_LIBS} ZLIB::ZLIB Boost::system) +if(WIN32) + target_link_libraries(MaaWin32ControlUnit ws2_32) +endif() + +target_compile_definitions(MaaWin32ControlUnit PRIVATE MAA_CONTROL_UNIT_EXPORTS) + +add_dependencies(MaaWin32ControlUnit MaaUtils) + +install( + TARGETS MaaWin32ControlUnit + RUNTIME DESTINATION bin + LIBRARY DESTINATION bin + #ARCHIVE DESTINATION lib + ) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${maa_win32_control_unit_src}) diff --git a/source/MaaWin32ControlUnit/Manager/ControlUnitMgr.cpp b/source/MaaWin32ControlUnit/Manager/ControlUnitMgr.cpp new file mode 100644 index 000000000..44913dc9e --- /dev/null +++ b/source/MaaWin32ControlUnit/Manager/ControlUnitMgr.cpp @@ -0,0 +1,139 @@ +#include "ControlUnitMgr.h" + +#include + +#include "MaaFramework/MaaMsg.h" +#include "Utils/Logger.h" + +MAA_CTRL_UNIT_NS_BEGIN + +ControlUnitMgr::ControlUnitMgr(HWND hWnd, MaaControllerCallback callback, MaaCallbackTransparentArg callback_arg) + : hWnd_(hWnd), notifier(callback, callback_arg) +{} + +bool ControlUnitMgr::find_device(std::vector& devices) +{ + std::ignore = devices; + + // TODO + return false; +} + +bool ControlUnitMgr::connect() +{ + // TODO + + return false; +} + +bool ControlUnitMgr::request_uuid(std::string& uuid) +{ + std::ignore = uuid; + + // TODO + return false; +} + +bool ControlUnitMgr::request_resolution(int& width, int& height) +{ + std::ignore = width; + std::ignore = height; + + // TODO + return false; +} + +bool ControlUnitMgr::start_app(const std::string& intent) +{ + // TODO + std::ignore = intent; + + return false; +} + +bool ControlUnitMgr::stop_app(const std::string& intent) +{ + // TODO + std::ignore = intent; + + return false; +} + +bool ControlUnitMgr::screencap(cv::Mat& image) +{ + if (!screencap_) { + LogError << "screencap_ is null"; + return false; + } + + auto opt = screencap_->screencap(); + if (!opt) { + LogError << "failed to screencap"; + return false; + } + + image = std::move(opt).value(); + return true; +} + +bool ControlUnitMgr::click(int x, int y) +{ + if (!touch_input_) { + LogError << "touch_input_ is null"; + return false; + } + + return touch_input_->click(x, y); +} + +bool ControlUnitMgr::swipe(int x1, int y1, int x2, int y2, int duration) +{ + if (!touch_input_) { + LogError << "touch_input_ is null"; + return false; + } + + return touch_input_->swipe(x1, y1, x2, y2, duration); +} + +bool ControlUnitMgr::touch_down(int contact, int x, int y, int pressure) +{ + if (!touch_input_) { + LogError << "touch_input_ is null"; + return false; + } + + return touch_input_->touch_down(contact, x, y, pressure); +} + +bool ControlUnitMgr::touch_move(int contact, int x, int y, int pressure) +{ + if (!touch_input_) { + LogError << "touch_input_ is null"; + return false; + } + + return touch_input_->touch_move(contact, x, y, pressure); +} + +bool ControlUnitMgr::touch_up(int contact) +{ + if (!touch_input_) { + LogError << "touch_input_ is null"; + return false; + } + + return touch_input_->touch_up(contact); +} + +bool ControlUnitMgr::press_key(int key) +{ + if (!key_input_) { + LogError << "key_input_ is null"; + return false; + } + + return key_input_->press_key(key); +} + +MAA_CTRL_UNIT_NS_END diff --git a/source/MaaWin32ControlUnit/Manager/ControlUnitMgr.h b/source/MaaWin32ControlUnit/Manager/ControlUnitMgr.h new file mode 100644 index 000000000..ffce757ec --- /dev/null +++ b/source/MaaWin32ControlUnit/Manager/ControlUnitMgr.h @@ -0,0 +1,57 @@ +#pragma once + +#include "ControlUnit/ControlUnitAPI.h" + +#include + +#include "Base/UnitBase.h" +#include "Utils/MessageNotifier.hpp" + +MAA_CTRL_UNIT_NS_BEGIN + +class ControlUnitMgr : public ControlUnitAPI +{ +public: + ControlUnitMgr(HWND hWnd, MaaControllerCallback callback, MaaCallbackTransparentArg callback_arg); + virtual ~ControlUnitMgr() override = default; + +public: // from ControlUnitAPI + virtual bool find_device(/*out*/ std::vector& devices) override; + + virtual bool connect() override; + + virtual bool request_uuid(/*out*/ std::string& uuid) override; + virtual bool request_resolution(/*out*/ int& width, /*out*/ int& height) override; + + virtual bool start_app(const std::string& intent) override; + virtual bool stop_app(const std::string& intent) override; + + virtual bool screencap(/*out*/ cv::Mat& image) override; + + virtual bool click(int x, int y) override; + virtual bool swipe(int x1, int y1, int x2, int y2, int duration) override; + + virtual bool touch_down(int contact, int x, int y, int pressure) override; + virtual bool touch_move(int contact, int x, int y, int pressure) override; + virtual bool touch_up(int contact) override; + + virtual bool press_key(int key) override; + +public: + bool parse(const json::value& config); + + void set_touch_input_obj(std::shared_ptr obj) { touch_input_ = std::move(obj); } + void set_key_input_obj(std::shared_ptr obj) { key_input_ = std::move(obj); } + void set_screencap_obj(std::shared_ptr obj) { screencap_ = std::move(obj); } + +private: + HWND hWnd_ = nullptr; + + MessageNotifier notifier; + + std::shared_ptr touch_input_ = nullptr; + std::shared_ptr key_input_ = nullptr; + std::shared_ptr screencap_ = nullptr; +}; + +MAA_CTRL_UNIT_NS_END diff --git a/source/MaaWin32ControlUnit/Touch/SendMessageToucher.cpp b/source/MaaWin32ControlUnit/Touch/SendMessageToucher.cpp new file mode 100644 index 000000000..c1b747be8 --- /dev/null +++ b/source/MaaWin32ControlUnit/Touch/SendMessageToucher.cpp @@ -0,0 +1,56 @@ +#include "SendMessageToucher.h" + +MAA_CTRL_UNIT_NS_BEGIN + +bool SendMessageToucher::click(int x, int y) +{ + // TODO + std::ignore = x; + std::ignore = y; + + return false; +} + +bool SendMessageToucher::swipe(int x1, int y1, int x2, int y2, int duration) +{ + // TODO + std::ignore = x1; + std::ignore = y1; + std::ignore = x2; + std::ignore = y2; + std::ignore = duration; + + return false; +} + +bool SendMessageToucher::touch_down(int contact, int x, int y, int pressure) +{ + // TODO + std::ignore = contact; + std::ignore = x; + std::ignore = y; + std::ignore = pressure; + + return false; +} + +bool SendMessageToucher::touch_move(int contact, int x, int y, int pressure) +{ + // TODO + std::ignore = contact; + std::ignore = x; + std::ignore = y; + std::ignore = pressure; + + return false; +} + +bool SendMessageToucher::touch_up(int contact) +{ + // TODO + std::ignore = contact; + + return false; +} + +MAA_CTRL_UNIT_NS_END diff --git a/source/MaaWin32ControlUnit/Touch/SendMessageToucher.h b/source/MaaWin32ControlUnit/Touch/SendMessageToucher.h new file mode 100644 index 000000000..b7dc5c3a5 --- /dev/null +++ b/source/MaaWin32ControlUnit/Touch/SendMessageToucher.h @@ -0,0 +1,25 @@ +#pragma once + +#include "ControlUnit/ControlUnitAPI.h" + +#include + +#include "Base/UnitBase.h" + +MAA_CTRL_UNIT_NS_BEGIN + +class SendMessageToucher : public TouchInputBase +{ +public: + virtual ~SendMessageToucher() override = default; + +public: // from TouchInputBase + virtual bool click(int x, int y) override; + virtual bool swipe(int x1, int y1, int x2, int y2, int duration) override; + + virtual bool touch_down(int contact, int x, int y, int pressure) override; + virtual bool touch_move(int contact, int x, int y, int pressure) override; + virtual bool touch_up(int contact) override; +}; + +MAA_CTRL_UNIT_NS_END diff --git a/source/include/ControlUnit/Win32ControlUnitAPI.h b/source/include/ControlUnit/Win32ControlUnitAPI.h new file mode 100644 index 000000000..cfad24bbb --- /dev/null +++ b/source/include/ControlUnit/Win32ControlUnitAPI.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +#include "ControlUnit/ControlUnitAPI.h" +#include "MaaFramework/MaaDef.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + MaaStringView MAA_CONTROL_UNIT_API get_version(); + + MaaControlUnitHandle MAA_CONTROL_UNIT_API create_control_unit( // + void* hWnd, MaaWin32ControllerType type, MaaControllerCallback callback, + MaaCallbackTransparentArg callback_arg); + + void MAA_CONTROL_UNIT_API destroy_control_unit(MaaControlUnitHandle handle); + +#ifdef __cplusplus +} +#endif diff --git a/source/include/Utils/ControlUnitLibraryHolder.h b/source/include/Utils/ControlUnitLibraryHolder.h index 2af3faf42..a626d6d24 100644 --- a/source/include/Utils/ControlUnitLibraryHolder.h +++ b/source/include/Utils/ControlUnitLibraryHolder.h @@ -23,6 +23,20 @@ class MAA_UTILS_API AdbControlUnitLibraryHolder : public LibraryHolder +{ +public: + static std::shared_ptr create_control_unit( // + void* hWnd, MaaWin32ControllerType type, MaaControllerCallback callback, + MaaCallbackTransparentArg callback_arg); + +private: + inline static const std::filesystem::path libname_ = MAA_NS::path("MaaWin32ControlUnit"); + inline static const std::string version_func_name_ = "get_version"; + inline static const std::string create_func_name_ = "create_control_unit"; + inline static const std::string destroy_func_name_ = "destroy_control_unit"; +}; + class MAA_UTILS_API DbgControlUnitLibraryHolder : public LibraryHolder { public: