Files
MaaAssistantArknights/MeoAssistance/WinMacro.h
2021-08-20 16:24:04 +08:00

61 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <string>
#include <random>
#include <optional>
#include <Windows.h>
#include "AsstDef.h"
namespace cv {
class Mat;
}
namespace asst {
class WinMacro
{
public:
WinMacro(const EmulatorInfo& info, HandleType type);
~WinMacro() = default;
bool captured() const noexcept;
bool resizeWindow(int Width, int Height);
bool resizeWindow(); // by configer
bool showWindow();
bool hideWindow();
bool click(const Point& p);
bool click(const Rect& rect);
bool swipe(const Point& p1, const Point& p2);
bool swipe(const Rect& r1, const Rect& r2);
void setControlScale(double scale, bool real = false);
cv::Mat getImage(const Rect& rect); // 通过Win32 Api对窗口截图
cv::Mat getAdbImage(); // 通过Adb截图会高清一点但是比较慢通过adb pull出来有io操作
Rect getWindowRect();
const EmulatorInfo& getEmulatorInfo() const noexcept { return m_emulator_info; }
const HandleType& getHandleType() const noexcept { return m_handle_type; }
static double getScreenScale();
private:
bool findHandle();
std::optional<std::string> callCmd(const std::string& cmd, bool use_pipe = true);
Point randPointInRect(const Rect& rect);
const EmulatorInfo m_emulator_info;
const HandleType m_handle_type;
HWND m_handle = NULL;
bool m_is_adb = false;
std::string m_click_cmd; // adb点击命令不是adb的句柄用不到这个
std::string m_swipe_cmd; // adb滑动命令不是adb的句柄用不到这个
std::string m_screencap_cmd; // adb截图命令不是adb的句柄用不到这个
std::string m_pullscreen_cmd; // adb拉取截图命令不是adb的句柄用不到这个
const std::string m_adb_screen_filename;
std::minstd_rand m_rand_engine;
int m_width = 0;
int m_height = 0;
//int m_x_offset = 0;
//int m_y_offset = 0;
double m_control_scale = 1;
};
}