Skip to content

Commit

Permalink
feat: MaaCtrlOption_ScreenshotUseRawSize
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwlin committed Oct 30, 2024
1 parent 3c1d23c commit c33ddf6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
36 changes: 26 additions & 10 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Controller interface {

SetScreenshotTargetLongSide(targetLongSide int) bool
SetScreenshotTargetShortSide(targetShortSide int) bool
SetScreenshotUseRawSize(enabled bool) bool
SetRecording(recording bool) bool

PostConnect() *Job
Expand Down Expand Up @@ -280,18 +281,20 @@ type ctrlOption int32
const (
ctrlOptionInvalid ctrlOption = 0

// ctrlOptionScreenshotTargetLongSide Only one of long and short side can be set, and the other is automatically scaled according
// to the aspect ratio.
// ctrlOptionScreenshotTargetLongSide specifies that only the long side can be set, and the short side
// is automatically scaled according to the aspect ratio.
ctrlOptionScreenshotTargetLongSide ctrlOption = 1

// ctrlOptionScreenshotTargetShortSide Only one of long and short side can be set, and the other is automatically scaled according
// to the aspect ratio.
// ctrlOptionScreenshotTargetShortSide specifies that only the short side can be set, and the long side
// is automatically scaled according to the aspect ratio.
ctrlOptionScreenshotTargetShortSide ctrlOption = 2

// ctrlOptionRecording Dump all screenshots and actions
//
// Recording will evaluate to true if any of this or
// MaaGlobalOptionEnum::MaaGlobalOption_Recording is true.
// ctrlOptionScreenshotUseRawSize specifies that the screenshot uses the raw size without scaling.
// Note that this option may cause incorrect coordinates on user devices with different resolutions if scaling is not performed.
ctrlOptionScreenshotUseRawSize ctrlOption = 3

/// ctrlOptionRecording indicates that all screenshots and actions should be dumped.
// Recording will evaluate to true if either this or MaaGlobalOptionEnum::MaaGlobalOption_Recording is true.
ctrlOptionRecording ctrlOption = 5
)

Expand All @@ -303,7 +306,7 @@ func (c *controller) setOption(key ctrlOption, value unsafe.Pointer, valSize uin
// SetScreenshotTargetLongSide sets screenshot target long side.
// Only one of long and short side can be set, and the other is automatically scaled according to the aspect ratio.
//
// eg: 1920
// eg: 1280
func (c *controller) SetScreenshotTargetLongSide(targetLongSide int) bool {
targetLongSide32 := int32(targetLongSide)
return c.setOption(
Expand All @@ -316,7 +319,7 @@ func (c *controller) SetScreenshotTargetLongSide(targetLongSide int) bool {
// SetScreenshotTargetShortSide sets screenshot target short side.
// Only one of long and short side can be set, and the other is automatically scaled according to the aspect ratio.
//
// eg: 1080
// eg: 720
func (c *controller) SetScreenshotTargetShortSide(targetShortSide int) bool {
targetShortSide32 := int32(targetShortSide)
return c.setOption(
Expand All @@ -326,6 +329,19 @@ func (c *controller) SetScreenshotTargetShortSide(targetShortSide int) bool {
)
}

// SetScreenshotUseRawSize sets whether the screenshot uses the raw size without scaling.
func (c *controller) SetScreenshotUseRawSize(enabled bool) bool {
var cEnabled uint8
if enabled {
cEnabled = 1
}
return c.setOption(
ctrlOptionScreenshotUseRawSize,
unsafe.Pointer(&cEnabled),
unsafe.Sizeof(cEnabled),
)
}

// SetRecording sets whether to dump all screenshots and actions.
func (c *controller) SetRecording(enabled bool) bool {
var cEnabled uint8
Expand Down
26 changes: 26 additions & 0 deletions controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,32 @@ func TestController_SetScreenshotTargetShortSide(t *testing.T) {
require.True(t, got)
}

func TestController_SetScreenshotUseRawSize(t *testing.T) {
testCases := []struct {
name string
enabled bool
expected bool
}{
{
name: "enabled true",
enabled: true,
},
{
name: "enabled false",
enabled: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
got := ctrl.SetScreenshotUseRawSize(tc.enabled)
require.True(t, got)
})
}
}

func TestController_SetRecording(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
Expand Down

0 comments on commit c33ddf6

Please sign in to comment.