Skip to content

Commit

Permalink
feat: MaaCtrlOption_ScreenshotUseRawSize
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Oct 29, 2024
1 parent c944363 commit be293a7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
16 changes: 10 additions & 6 deletions include/MaaFramework/MaaDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,22 @@ enum MaaCtrlOptionEnum
{
MaaCtrlOption_Invalid = 0,

/// Only one of long and short side can be set, and the other is automatically scaled according
/// to the aspect ratio.
/// Only one of long and short side can be set, and the other is automatically scaled according to the aspect ratio.
///
/// value: int, eg: 1920; val_size: sizeof(int)
/// value: int, eg: 1280; val_size: sizeof(int)
MaaCtrlOption_ScreenshotTargetLongSide = 1,

/// Only one of long and short side can be set, and the other is automatically scaled according
/// to the aspect ratio.
/// Only one of long and short side can be set, and the other is automatically scaled according to the aspect ratio.
///
/// value: int, eg: 1080; val_size: sizeof(int)
/// value: int, eg: 720; val_size: sizeof(int)
MaaCtrlOption_ScreenshotTargetShortSide = 2,

/// Screenshot use raw size without scaling.
/// Please note that this option may cause incorrect coordinates on user devices with different resolutions if scaling is not performed.
///
/// value: bool, eg: true; val_size: sizeof(bool)
MaaCtrlOption_ScreenshotUseRawSize = 3,

/// Dump all screenshots and actions
///
/// Recording will evaluate to true if any of this or
Expand Down
24 changes: 24 additions & 0 deletions source/MaaFramework/Controller/ControllerAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ bool ControllerAgent::set_option(MaaCtrlOption key, MaaOptionValue value, MaaOpt
return set_image_target_long_side(value, val_size);
case MaaCtrlOption_ScreenshotTargetShortSide:
return set_image_target_short_side(value, val_size);
case MaaCtrlOption_ScreenshotUseRawSize:
return set_image_use_raw_size(value, val_size);
case MaaCtrlOption_Recording:
return set_recording(value, val_size);

Expand Down Expand Up @@ -751,6 +753,13 @@ bool ControllerAgent::calc_target_image_size()
return false;
}

if (image_use_raw_size_) {
LogDebug << "image_use_raw_size_" << VAR(image_raw_width_) << VAR(image_raw_height_);
image_target_width_ = image_raw_width_;
image_target_height_ = image_raw_height_;
return true;
}

LogDebug << "Re-calc image target size:" << VAR(image_target_long_side_) << VAR(image_target_short_side_) << VAR(image_raw_width_)
<< VAR(image_raw_height_);

Expand Down Expand Up @@ -842,6 +851,21 @@ bool ControllerAgent::set_image_target_short_side(MaaOptionValue value, MaaOptio
return true;
}

bool ControllerAgent::set_image_use_raw_size(MaaOptionValue value, MaaOptionValueSize val_size)
{
LogDebug;

if (val_size != sizeof(bool)) {
LogError << "invalid value size: " << val_size;
return false;
}
image_use_raw_size_ = *reinterpret_cast<bool*>(value);

clear_target_image_size();

return true;
}

bool ControllerAgent::set_recording(MaaOptionValue value, MaaOptionValueSize val_size)
{
if (val_size != sizeof(recording_)) {
Expand Down
2 changes: 2 additions & 0 deletions source/MaaFramework/Controller/ControllerAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class ControllerAgent : public MaaController
private: // options
bool set_image_target_long_side(MaaOptionValue value, MaaOptionValueSize val_size);
bool set_image_target_short_side(MaaOptionValue value, MaaOptionValueSize val_size);
bool set_image_use_raw_size(MaaOptionValue value, MaaOptionValueSize val_size);
bool set_recording(MaaOptionValue value, MaaOptionValueSize val_size);

private:
Expand All @@ -201,6 +202,7 @@ class ControllerAgent : public MaaController
std::mutex image_mutex_;
cv::Mat image_;

bool image_use_raw_size_ = false;
int image_target_long_side_ = 0;
int image_target_short_side_ = 720;
int image_target_width_ = 0;
Expand Down
11 changes: 11 additions & 0 deletions source/binding/Python/maa/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ def set_screenshot_target_short_side(self, short_side: int) -> bool:
ctypes.sizeof(ctypes.c_int32),
)
)

def set_screenshot_use_raw_size(self, enable: bool) -> bool:
cbool = MaaBool(enable)
return bool(
Library.framework.MaaControllerSetOption(
self._handle,
MaaOption(MaaCtrlOptionEnum.ScreenshotUseRawSize),
ctypes.pointer(cbool),
ctypes.sizeof(MaaBool),
)
)

### private ###

Expand Down
7 changes: 6 additions & 1 deletion source/binding/Python/maa/define.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ class MaaCtrlOptionEnum:
# value: int, eg: 1080; val_size: sizeof(int)
ScreenshotTargetShortSide = 2

# Screenshot use raw size without scaling.
# Please note that this option may cause incorrect coordinates on user devices with different resolutions if scaling is not performed.
# value: bool, eg: true; val_size: sizeof(bool)
ScreenshotUseRawSize = 3

# Dump all screenshots and actions
# this option will || with MaaGlobalOptionEnum.Recording
# value: bool, eg: true; val_size: sizeof(bool)
Expand Down Expand Up @@ -328,7 +333,7 @@ class MaaCustomControllerCallbacks(ctypes.Structure):
("press_key", PressKeyFunc),
("input_text", InputTextFunc),
]


class Status:
_status: MaaStatusEnum
Expand Down

0 comments on commit be293a7

Please sign in to comment.