Skip to content

Commit

Permalink
fix: Rect constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwlin committed Sep 23, 2024
1 parent 4d30b20 commit fe62b41
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (ctx *Context) runAction(entry, override string, box Rect, recognitionDetai
cOverride := C.CString(override)
defer C.free(unsafe.Pointer(cOverride))
rectBuf := buffer.NewRectBuffer()
rectBuf.Set(box)
rectBuf.Set(box.toBufferRect())
defer rectBuf.Destroy()
cRecognitionDetail := C.CString(recognitionDetail)
defer C.free(unsafe.Pointer(cRecognitionDetail))
Expand Down
2 changes: 1 addition & 1 deletion custom_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func _MaaCustomActionCallbackAgent(
CustomActionName: C.GoString(customActionName),
CustomActionParam: C.GoString(customActionParam),
RecognitionDetail: recognitionDetail,
Box: curBoxRectBuffer.Get(),
Box: toMaaRect(curBoxRectBuffer.Get()),
},
)
if ok {
Expand Down
4 changes: 2 additions & 2 deletions custom_recognition.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ func _MaaCustomRecognitionCallbackAgent(
CustomRecognizerName: C.GoString(customRecognizerName),
CustomRecognitionParam: C.GoString(customRecognitionParam),
Img: imgImg,
Roi: buffer.NewRectBufferByHandle(unsafe.Pointer(roi)).Get(),
Roi: toMaaRect(buffer.NewRectBufferByHandle(unsafe.Pointer(roi)).Get()),
},
)
if ok {
box := ret.Box
outBoxRect := buffer.NewRectBufferByHandle(unsafe.Pointer(outBox))
outBoxRect.Set(box)
outBoxRect.Set(box.toBufferRect())
outDetailString := buffer.NewStringBufferByHandle(unsafe.Pointer(outDetail))
outDetailString.Set(ret.Detail)
return C.uint8_t(1)
Expand Down
4 changes: 0 additions & 4 deletions internal/buffer/rect_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ type Rect struct {
X, Y, W, H int32
}

func (r Rect) ToInts() [4]int32 {
return [4]int32{r.X, r.Y, r.W, r.H}
}

type RectBuffer struct {
handle *C.MaaRect
}
Expand Down
26 changes: 25 additions & 1 deletion rect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,28 @@ package maa

import "github.com/MaaXYZ/maa-framework-go/internal/buffer"

type Rect = buffer.Rect
type Rect struct {
X, Y, W, H int32
}

func (r Rect) ToInts() [4]int32 {
return [4]int32{r.X, r.Y, r.W, r.H}
}

func (r Rect) toBufferRect() buffer.Rect {
return buffer.Rect{
X: r.X,
Y: r.Y,
W: r.W,
H: r.H,
}
}

func toMaaRect(rect buffer.Rect) Rect {
return Rect{
X: rect.X,
Y: rect.Y,
W: rect.W,
H: rect.H,
}
}

0 comments on commit fe62b41

Please sign in to comment.