-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
543 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>(hWnd); | ||
|
||
std::shared_ptr<TouchInputBase> touch_unit = nullptr; | ||
std::shared_ptr<KeyInputBase> key_unit = nullptr; | ||
std::shared_ptr<ScreencapBase> 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<SendMessageToucher>(); | ||
break; | ||
default: | ||
LogWarn << "Unknown touch input type" << VAR(touch_type); | ||
break; | ||
} | ||
|
||
auto unit_mgr = std::make_unique<ControlUnitMgr>(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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
|
||
#include <meojson/json.hpp> | ||
|
||
#include "ControlUnit/Win32ControlUnitAPI.h" | ||
|
||
MAA_CTRL_UNIT_NS_BEGIN | ||
|
||
class ScreencapBase | ||
{ | ||
public: | ||
virtual ~ScreencapBase() = default; | ||
|
||
public: | ||
virtual std::optional<cv::Mat> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}) |
Oops, something went wrong.