From ea66ca107448cb0928164b9388353e4074b06898 Mon Sep 17 00:00:00 2001 From: MistEO Date: Fri, 17 Jan 2025 23:19:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20target=20offset=20=E9=99=90=E5=88=B6?= =?UTF-8?q?=E7=9F=A9=E5=BD=A2=E5=B0=BA=E5=AF=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/MaaFramework/Task/Component/Actuator.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/source/MaaFramework/Task/Component/Actuator.cpp b/source/MaaFramework/Task/Component/Actuator.cpp index 301aca48e..160801541 100644 --- a/source/MaaFramework/Task/Component/Actuator.cpp +++ b/source/MaaFramework/Task/Component/Actuator.cpp @@ -270,6 +270,10 @@ cv::Rect Actuator::get_target_rect(const MAA_RES_NS::Action::Target target, cons LogError << "tasker is null"; return {}; } + if (!tasker_->controller()) { + LogError << "controller is null"; + return {}; + } using namespace MAA_RES_NS::Action; @@ -295,10 +299,13 @@ cv::Rect Actuator::get_target_rect(const MAA_RES_NS::Action::Target target, cons return {}; } - return cv::Rect { raw.x + target.offset.x, - raw.y + target.offset.y, - raw.width + target.offset.width, - raw.height + target.offset.height }; + auto image = controller()->cached_image(); + int x = std::clamp(raw.x, 0, image.cols); + int y = std::clamp(raw.y, 0, image.rows); + int width = std::clamp(raw.width, 0, image.cols - x); + int height = std::clamp(raw.height, 0, image.rows - y); + + return cv::Rect(x, y, width, height); } MAA_CTRL_NS::ControllerAgent* Actuator::controller()