Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/en_us/2.2-IntegratedInterfaceOverview.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ Set controller options. Will be split into specific options in bindings.
- ScreenshotTargetShortSide
Set screenshot scaling short side to specified length

- ScreenshotTargetExpand
Scale screenshots to a reference resolution `(width, height)` using Unity Canvas Scaler **Expand** semantics: `scale = max(width / raw_width, height / raw_height)`. The scale is applied uniformly to both axes so the source aspect ratio is preserved and both output dimensions are >= the reference. No cropping, no non-uniform stretching. Mutually exclusive with `ScreenshotTargetLongSide` / `ScreenshotTargetShortSide`; setting any of them resets the others. Value is an `int32_t` array of length 2: `{ width, height }`.

- ScreenshotUseRawSize
No scaling for screenshots

Expand Down
7 changes: 5 additions & 2 deletions docs/en_us/3.3-ProjectInterfaceV2.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@ We have designated the version number for the independent release (January 30, 2
and `WlRoots` (Linux only).

- **display_short_side** `number`
The short side length of the default scaled resolution, used for screen adaptation. _Optional_, defaults to 720. Mutually exclusive with `display_long_side` and `display_raw`.
The short side length of the default scaled resolution, used for screen adaptation. _Optional_, defaults to 720. Mutually exclusive with `display_long_side`, `display_expand`, and `display_raw`.

- **display_long_side** `number`
The long side length of the default scaled resolution, used for screen adaptation. _Optional._ Mutually exclusive with `display_short_side` and `display_raw`.
The long side length of the default scaled resolution, used for screen adaptation. _Optional._ Mutually exclusive with `display_short_side`, `display_expand`, and `display_raw`.

- **display_expand** `[number, number]`
Reference resolution `[width, height]` with Unity Canvas Scaler "Expand" semantics: `scale = max(width / raw_width, height / raw_height)`, applied uniformly so the source aspect ratio is preserved and both output dimensions are >= the reference. _Optional._ Mutually exclusive with `display_short_side`, `display_long_side`, and `display_raw`.

- **display_raw** `boolean`
Whether to use the original resolution for screenshots without scaling. _Optional_, defaults to false. Mutually exclusive with scaled resolution settings.
Expand Down
3 changes: 3 additions & 0 deletions docs/zh_cn/2.2-集成接口一览.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@
- ScreenshotTargetShortSide
设置截图缩放短边到指定长度

- ScreenshotTargetExpand
以 Unity Canvas Scaler 的 **Expand** 语义按参考分辨率 `(width, height)` 缩放截图:`scale = max(width / raw_width, height / raw_height)`,等比缩放后两边均不小于参考;保持源宽高比,无裁剪、无非等比拉伸。与 `ScreenshotTargetLongSide` / `ScreenshotTargetShortSide` 互斥,设置任一会重置其他。值为长度 2 的 `int32_t` 数组 `{ width, height }`。

- ScreenshotUseRawSize
设置截图不缩放

Expand Down
7 changes: 5 additions & 2 deletions docs/zh_cn/3.3-ProjectInterfaceV2协议.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,13 @@
控制器类型,取值为 `Adb`、`Win32`(仅 Windows)、`MacOS`(仅 macOS)、`PlayCover`(仅 macOS)、`Gamepad`(仅 Windows)和 `WlRoots`(仅 Linux)。

- display_short_side `number`
默认缩放分辨率的短边长度,用于屏幕适配。可选,默认720。与`display_long_side`和`display_raw`互斥。
默认缩放分辨率的短边长度,用于屏幕适配。可选,默认720。与`display_long_side`、`display_expand`和`display_raw`互斥。

- display_long_side `number`
默认缩放分辨率的长边长度,用于屏幕适配。可选。与`display_short_side`和`display_raw`互斥。
默认缩放分辨率的长边长度,用于屏幕适配。可选。与`display_short_side`、`display_expand`和`display_raw`互斥。

- display_expand `[number, number]`
Unity Canvas Scaler 的 Expand 语义参考分辨率 `[width, height]`:`scale = max(width / raw_width, height / raw_height)`,保持源宽高比,输出两边均不小于参考。可选。与`display_short_side`、`display_long_side`和`display_raw`互斥。

- display_raw `boolean`
是否使用原始分辨率进行截图,不进行缩放。可选,默认false。与缩放分辨率设置互斥。
Expand Down
10 changes: 10 additions & 0 deletions include/MaaFramework/MaaDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ enum MaaCtrlOptionEnum
///
/// value: int32_t array of virtual key codes; val_size: sizeof(int32_t) * count
MaaCtrlOption_BackgroundManagedKeys = 7,

/// Scale screenshot to fit a reference (width, height) using Unity Canvas
/// Scaler "Expand" semantics: scale = max(W / raw_width, H / raw_height),
/// applied uniformly to both axes so the source aspect ratio is preserved
/// and both output dimensions are >= the reference (W, H).
/// Mutually exclusive with ScreenshotTargetLongSide / ScreenshotTargetShortSide;
/// setting any of these resets the others. Ignored when ScreenshotUseRawSize is true.
///
/// value: int32_t[2] = { width, height }; val_size: sizeof(int32_t) * 2
MaaCtrlOption_ScreenshotTargetExpand = 8,
};

typedef MaaOption MaaTaskerOption;
Expand Down
22 changes: 22 additions & 0 deletions source/MaaAgentClient/Client/AgentClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2481,6 +2481,28 @@ bool AgentClient::handle_controller_set_option(const json::value& j)
ret = controller->set_option(key, keys.data(), sizeof(int32_t) * keys.size());
break;
}
case MaaCtrlOption_ScreenshotTargetExpand: {
if (!req.value.is_array() || req.value.as_array().size() != 2) {
LogError << "ScreenshotTargetExpand value must be a 2-element array" << VAR(req.value.type_name());
break;
}
int32_t dims[2] = { 0, 0 };
const auto& arr = req.value.as_array();
bool ok = true;
for (size_t i = 0; i < 2; ++i) {
if (!arr[i].is_number()) {
LogError << "ScreenshotTargetExpand array element must be a number" << VAR(arr[i].type_name());
ok = false;
break;
}
dims[i] = static_cast<int32_t>(arr[i].as_integer());
Comment on lines +2493 to +2498

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): 当 expand 维度传入非整数数值时,行为可能会让人意外。

is_number() 会接受浮点值,但代码后面使用的是 as_integer() 并转换为 int32_t,这可能会产生静默截断。如果只接受整数尺寸,建议改为更严格的检查(例如使用 is_integer()(若可用),或者显式验证数值在 int32_t 范围内且没有小数部分),以避免令人意外的行为。

建议实现如下:

        int32_t dims[2] = { 0, 0 };
        const auto& arr = req.value.as_array();
        bool ok = true;
        for (size_t i = 0; i < 2; ++i) {
            if (!arr[i].is_integer()) {
                LogError << "ScreenshotTargetExpand array element must be an integer number"
                         << VAR(arr[i].type_name());
                ok = false;
                break;
            }

            const auto v = arr[i].as_integer();
            if (v < std::numeric_limits<int32_t>::min() || v > std::numeric_limits<int32_t>::max()) {
                LogError << "ScreenshotTargetExpand array element is out of int32_t range"
                         << VAR(v);
                ok = false;
                break;
            }

            dims[i] = static_cast<int32_t>(v);
        }
        if (!ok || dims[0] <= 0 || dims[1] <= 0) {

如果当前翻译单元中还未引入 std::numeric_limits,请在 source/MaaAgentClient/Client/AgentClient.cpp 顶部附近添加 #include <limits>
如果你使用的 JSON/值类型不提供 is_integer(),请用等价的检查替代(例如 is_int64(),或者结合 is_number() 与小数部分检查),并保持与所用 JSON 库 API 一致。

Original comment in English

suggestion (bug_risk): Potentially surprising behavior when a non-integer number is passed for expand dimensions.

is_number() allows floating-point values, but the code then uses as_integer() and casts to int32_t, which may silently truncate. If only integral dimensions are valid, consider a stricter check (e.g., is_integer() if available, or explicitly verifying the value is within int32_t range and has no fractional part) to avoid surprising behavior.

Suggested implementation:

        int32_t dims[2] = { 0, 0 };
        const auto& arr = req.value.as_array();
        bool ok = true;
        for (size_t i = 0; i < 2; ++i) {
            if (!arr[i].is_integer()) {
                LogError << "ScreenshotTargetExpand array element must be an integer number"
                         << VAR(arr[i].type_name());
                ok = false;
                break;
            }

            const auto v = arr[i].as_integer();
            if (v < std::numeric_limits<int32_t>::min() || v > std::numeric_limits<int32_t>::max()) {
                LogError << "ScreenshotTargetExpand array element is out of int32_t range"
                         << VAR(v);
                ok = false;
                break;
            }

            dims[i] = static_cast<int32_t>(v);
        }
        if (!ok || dims[0] <= 0 || dims[1] <= 0) {

If std::numeric_limits is not already available in this translation unit, add #include <limits> near the top of source/MaaAgentClient/Client/AgentClient.cpp.
If the JSON/value type you're using does not provide is_integer(), replace that call with an equivalent (e.g., is_int64() or a combination of is_number() and a fractional-part check) consistent with your JSON library’s API.

}
if (!ok || dims[0] <= 0 || dims[1] <= 0) {
break;
}
ret = controller->set_option(key, dims, sizeof(dims));
break;
}
default:
LogError << "unknown key" << VAR(req.key);
break;
Expand Down
13 changes: 13 additions & 0 deletions source/MaaAgentServer/RemoteInstance/RemoteController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ bool RemoteController::set_option(MaaCtrlOption key, MaaOptionValue value, MaaOp
break;
}

case MaaCtrlOption_ScreenshotTargetExpand: {
if (val_size != sizeof(int32_t) * 2) {
LogError << "invalid val_size for expand option" << VAR(key) << VAR(val_size);
return false;
}
auto* dims = reinterpret_cast<const int32_t*>(value);
json::array arr;
arr.emplace_back(dims[0]);
arr.emplace_back(dims[1]);
jvalue = std::move(arr);
break;
}

default:
LogError << "unknown key" << VAR(key);
return false;
Expand Down
40 changes: 40 additions & 0 deletions source/MaaFramework/Controller/ControllerAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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_ScreenshotTargetExpand:
return set_image_target_expand(value, val_size);
case MaaCtrlOption_ScreenshotUseRawSize:
return set_image_use_raw_size(value, val_size);
case MaaCtrlOption_MouseLockFollow:
Expand Down Expand Up @@ -1097,6 +1099,16 @@ bool ControllerAgent::calc_target_image_size()
return true;
}

if (image_target_expand_width_ > 0 && image_target_expand_height_ > 0) {
double sx = static_cast<double>(image_target_expand_width_) / image_raw_width_;
double sy = static_cast<double>(image_target_expand_height_) / image_raw_height_;
double scale = std::max(sx, sy);
Comment on lines +1102 to +1105

@sourcery-ai sourcery-ai Bot May 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: 在这里使用 std::round 可能会破坏“尺寸 ≥ 参考尺寸”的保证;在 expand 模式下建议改用 ceil。

scale = max(W/raw_w, H/raw_h) 时,浮点误差加上 std::round 可能导致结果比预期小 1 个像素(例如 raw_w * scale 计算结果略低于理想值)。在计算缩放后的宽高时改为使用 std::ceil,可以始终保证满足“≥ 参考尺寸”的约定。

建议实现如下:

    if (image_target_expand_width_ > 0 && image_target_expand_height_ > 0) {
        double sx = static_cast<double>(image_target_expand_width_) / image_raw_width_;
        double sy = static_cast<double>(image_target_expand_height_) / image_raw_height_;
        double scale = std::max(sx, sy);
        image_target_width_ = static_cast<int>(std::ceil(image_raw_width_ * scale));
        image_target_height_ = static_cast<int>(std::ceil(image_raw_height_ * scale));
        LogInfo << "expand" << VAR(scale) << VAR(image_target_width_) << VAR(image_target_height_);
        return true;
    }

如果 source/MaaFramework/Controller/ControllerAgent.cpp 中尚未包含 <cmath>,请在其他标准库头文件附近添加:
#include <cmath>
以便使用 std::ceil

Original comment in English

suggestion: Using std::round here can violate the ">= reference size" guarantee; consider ceil for expand mode.

With scale = max(W/raw_w, H/raw_h), floating-point error plus std::round can yield dimensions 1 pixel smaller than guaranteed (e.g., raw_w * scale ends up just below the ideal value). Using std::ceil when computing the scaled width/height would consistently enforce the ">= reference" contract.

Suggested implementation:

    if (image_target_expand_width_ > 0 && image_target_expand_height_ > 0) {
        double sx = static_cast<double>(image_target_expand_width_) / image_raw_width_;
        double sy = static_cast<double>(image_target_expand_height_) / image_raw_height_;
        double scale = std::max(sx, sy);
        image_target_width_ = static_cast<int>(std::ceil(image_raw_width_ * scale));
        image_target_height_ = static_cast<int>(std::ceil(image_raw_height_ * scale));
        LogInfo << "expand" << VAR(scale) << VAR(image_target_width_) << VAR(image_target_height_);
        return true;
    }

If source/MaaFramework/Controller/ControllerAgent.cpp does not already include <cmath>, add:
#include <cmath>
near the other standard library includes so that std::ceil is available.

✅ Addressed in 4f27e6a: The expand branch now uses std::ceil for both dimensions and includes a comment explaining the reasoning, ensuring the scaled size always meets the “>= reference” guarantee as suggested.

@ZeroAd-06 ZeroAd-06 May 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(差点被带偏了

image_target_width_ = static_cast<int>(std::round(image_raw_width_ * scale));
image_target_height_ = static_cast<int>(std::round(image_raw_height_ * scale));
Comment on lines +1106 to +1107
LogInfo << "expand" << VAR(scale) << VAR(image_target_width_) << VAR(image_target_height_);
return true;
}

if (image_target_long_side_ == 0 && image_target_short_side_ == 0) {
LogError << "Invalid image target size";
return false;
Expand Down Expand Up @@ -1168,6 +1180,8 @@ bool ControllerAgent::set_image_target_long_side(MaaOptionValue value, MaaOption
}
image_target_long_side_ = *reinterpret_cast<const int32_t*>(value);
image_target_short_side_ = 0;
image_target_expand_width_ = 0;
image_target_expand_height_ = 0;

clear_target_image_size();

Expand All @@ -1185,13 +1199,39 @@ bool ControllerAgent::set_image_target_short_side(MaaOptionValue value, MaaOptio
}
image_target_long_side_ = 0;
image_target_short_side_ = *reinterpret_cast<const int32_t*>(value);
image_target_expand_width_ = 0;
image_target_expand_height_ = 0;

clear_target_image_size();

LogInfo << "image_target_height_ = " << image_target_short_side_;
return true;
}

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

if (val_size != sizeof(int32_t) * 2) {
LogError << "invalid value size: " << val_size;
return false;
}
auto* arr = reinterpret_cast<const int32_t*>(value);
if (arr[0] <= 0 || arr[1] <= 0) {
LogError << "invalid expand size" << VAR(arr[0]) << VAR(arr[1]);
return false;
}
image_target_expand_width_ = arr[0];
image_target_expand_height_ = arr[1];
image_target_long_side_ = 0;
image_target_short_side_ = 0;

clear_target_image_size();

LogInfo << VAR(image_target_expand_width_) << VAR(image_target_expand_height_);
return true;
}

bool ControllerAgent::set_image_use_raw_size(MaaOptionValue value, MaaOptionValueSize val_size)
{
LogDebug;
Expand Down
3 changes: 3 additions & 0 deletions source/MaaFramework/Controller/ControllerAgent.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,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_target_expand(MaaOptionValue value, MaaOptionValueSize val_size);
bool set_image_use_raw_size(MaaOptionValue value, MaaOptionValueSize val_size);
bool set_mouse_lock_follow_option(MaaOptionValue value, MaaOptionValueSize val_size);
bool set_screenshot_resize_method(MaaOptionValue value, MaaOptionValueSize val_size);
Expand All @@ -307,6 +308,8 @@ class ControllerAgent : public MaaController
bool image_use_raw_size_ = false;
int image_target_long_side_ = 0;
int image_target_short_side_ = 720;
int image_target_expand_width_ = 0;
int image_target_expand_height_ = 0;
int image_target_width_ = 0;
int image_target_height_ = 0;
int image_raw_width_ = 0;
Expand Down
1 change: 1 addition & 0 deletions source/MaaPiCli/Impl/Configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ std::optional<RuntimeParam> Configurator::generate_runtime() const
// 设置分辨率配置
runtime.display_config.short_side = controller.display_short_side;
runtime.display_config.long_side = controller.display_long_side;
runtime.display_config.expand = controller.display_expand;
runtime.display_config.raw = controller.display_raw;

std::vector<InterfaceData::Agent> agents = std::visit(
Expand Down
4 changes: 4 additions & 0 deletions source/MaaPiCli/Impl/Runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ bool Runner::run(const RuntimeParam& param)
MaaBool raw = true;
MaaControllerSetOption(controller_handle, MaaCtrlOption_ScreenshotUseRawSize, &raw, sizeof(raw));
}
else if (param.display_config.expand.has_value()) {
int32_t expand[2] = { param.display_config.expand->at(0), param.display_config.expand->at(1) };
MaaControllerSetOption(controller_handle, MaaCtrlOption_ScreenshotTargetExpand, expand, sizeof(expand));
}
else if (param.display_config.long_side.has_value()) {
int long_side = param.display_config.long_side.value();
MaaControllerSetOption(controller_handle, MaaCtrlOption_ScreenshotTargetLongSide, &long_side, sizeof(long_side));
Expand Down
9 changes: 9 additions & 0 deletions source/binding/NodeJS/src/apis/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ void ControllerImpl::set_screenshot_target_short_side(int32_t value)
}
}

void ControllerImpl::set_screenshot_target_expand(std::tuple<int32_t, int32_t> value)
{
int32_t arr[2] = { std::get<0>(value), std::get<1>(value) };
if (!MaaControllerSetOption(controller, MaaCtrlOption_ScreenshotTargetExpand, arr, sizeof(arr))) {
throw maajs::MaaError { "Controller set screenshot_target_expand failed" };
}
}

void ControllerImpl::set_screenshot_use_raw_size(bool value)
{
if (!MaaControllerSetOption(controller, MaaCtrlOption_ScreenshotUseRawSize, &value, sizeof(value))) {
Expand Down Expand Up @@ -372,6 +380,7 @@ void ControllerImpl::init_proto(maajs::ObjectType proto, maajs::FunctionType)
MAA_BIND_FUNC(proto, "remove_sink", ControllerImpl::remove_sink);
MAA_BIND_SETTER(proto, "screenshot_target_long_side", ControllerImpl::set_screenshot_target_long_side);
MAA_BIND_SETTER(proto, "screenshot_target_short_side", ControllerImpl::set_screenshot_target_short_side);
MAA_BIND_SETTER(proto, "screenshot_target_expand", ControllerImpl::set_screenshot_target_expand);
MAA_BIND_SETTER(proto, "screenshot_use_raw_size", ControllerImpl::set_screenshot_use_raw_size);
MAA_BIND_SETTER(proto, "screenshot_resize_method", ControllerImpl::set_screenshot_resize_method);
MAA_BIND_FUNC(proto, "clear_sinks", ControllerImpl::clear_sinks);
Expand Down
1 change: 1 addition & 0 deletions source/binding/NodeJS/src/apis/controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ declare global {

set screenshot_target_long_side(value: number)
set screenshot_target_short_side(value: number)
set screenshot_target_expand(value: [number, number])
set screenshot_use_raw_size(value: boolean)
set screenshot_resize_method(value: number)

Expand Down
1 change: 1 addition & 0 deletions source/binding/NodeJS/src/apis/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct ControllerImpl : public maajs::NativeClassBase
void clear_sinks();
void set_screenshot_target_long_side(int32_t value);
void set_screenshot_target_short_side(int32_t value);
void set_screenshot_target_expand(std::tuple<int32_t, int32_t> value);
void set_screenshot_use_raw_size(bool value);
void set_screenshot_resize_method(int32_t value);
maajs::ValueType post_connection(maajs::ValueType self, maajs::EnvType env);
Expand Down
24 changes: 24 additions & 0 deletions source/binding/Python/maa/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,30 @@ def set_screenshot_target_short_side(self, short_side: int) -> bool:
)
)

def set_screenshot_target_expand(self, width: int, height: int) -> bool:
"""以 Unity Canvas Scaler 的 Expand 语义按参考分辨率缩放截图 /
Scale screenshot to reference (width, height) using Unity Expand semantics

scale = max(width / raw_width, height / raw_height),保持源宽高比,
输出两边均 >= 参考。与长/短边模式互斥。

Args:
width: 参考宽 / Reference width
height: 参考高 / Reference height

Returns:
bool: 是否成功 / Whether successful
"""
arr = (ctypes.c_int32 * 2)(width, height)
return bool(
Library.framework().MaaControllerSetOption(
self._handle,
MaaOption(MaaCtrlOptionEnum.ScreenshotTargetExpand),
arr,
ctypes.sizeof(arr),
)
)

def set_screenshot_use_raw_size(self, enable: bool) -> bool:
"""设置截图不缩放 / Set screenshot use raw size without scaling

Expand Down
8 changes: 8 additions & 0 deletions source/binding/Python/maa/define.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ class MaaCtrlOptionEnum(IntEnum):
# value: int32_t array of virtual key codes; val_size: sizeof(int32_t) * count
BackgroundManagedKeys = 7

# Scale screenshot to fit a reference (width, height) using Unity Canvas
# Scaler "Expand" semantics: scale = max(W / raw_width, H / raw_height),
# applied uniformly so the source aspect ratio is preserved and both
# output dimensions are >= the reference (W, H).
# Mutually exclusive with ScreenshotTargetLongSide / ScreenshotTargetShortSide.
# value: int32_t[2] = (width, height); val_size: sizeof(int32_t) * 2
ScreenshotTargetExpand = 8


class MaaInferenceDeviceEnum(IntEnum):
CPU = -2
Expand Down
8 changes: 6 additions & 2 deletions source/include/ProjectInterface/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <unordered_map>
#include <variant>
#include <vector>
#include <array>

#include <meojson/json.hpp>

Expand Down Expand Up @@ -82,9 +83,10 @@ struct InterfaceData
// 是否需要管理员权限(例如某些 Win32 输入方式需要更高权限)
bool permission_required = false;

// 分辨率设置,三者互斥
// 分辨率设置,四者互斥
std::optional<int> display_short_side; // 默认720
std::optional<int> display_long_side;
std::optional<std::array<int, 2>> display_expand; // [width, height], Unity Canvas Scaler "Expand" 语义
bool display_raw = false;

// 附加资源路径,在 resource.path 加载完成后额外加载
Expand All @@ -107,6 +109,7 @@ struct InterfaceData
MEO_OPT permission_required,
MEO_OPT display_short_side,
MEO_OPT display_long_side,
MEO_OPT display_expand,
MEO_OPT display_raw,
MEO_OPT attach_resource_path,
MEO_OPT option,
Expand Down Expand Up @@ -436,11 +439,12 @@ struct Configuration

struct RuntimeParam
{
// 分辨率设置,三者互斥
// 分辨率设置,四者互斥
struct DisplayConfig
{
std::optional<int> short_side; // 默认720
std::optional<int> long_side;
std::optional<std::array<int, 2>> expand; // [width, height], Unity Canvas Scaler "Expand" 语义
bool raw = false;
};

Expand Down
12 changes: 11 additions & 1 deletion tools/interface.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,17 @@
"display_long_side": {
"type": "number",
"title": "长边分辨率",
"description": "默认缩放分辨率的长边长度,用于屏幕适配。与 display_short_side 和 display_raw 互斥"
"description": "默认缩放分辨率的长边长度,用于屏幕适配。与 display_short_side、display_expand 和 display_raw 互斥"
},
"display_expand": {
"type": "array",
"items": {
"type": "number"
},
"minItems": 2,
"maxItems": 2,
"title": "Unity Expand 参考分辨率",
"description": "按 Unity Canvas Scaler 的 Expand 语义缩放:scale = max(width / raw_width, height / raw_height),保持源宽高比,输出两边均不小于参考。格式 [width, height]。与 display_short_side、display_long_side 和 display_raw 互斥"
},
"display_raw": {
"type": "boolean",
Expand Down
Loading