Merge pull request #86 from go-vgo/dep-pr

Add func PointInBounds() and Update vendor
This commit is contained in:
vz 2017-12-20 23:09:46 +08:00 committed by GitHub
commit fe2dc55988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 20 deletions

View File

@ -117,6 +117,18 @@ MMPoint aFindBitmap(MMBitmapRef bit_map, MMRect rect){
return point; return point;
} }
bool point_in_bounds(MMBitmapRef bitmap, MMPoint point){
if (!bitmap_ready(bitmap)) {
return NULL;
}
if (MMBitmapPointInBounds(bitmap, point)) {
return true;
}
return false;
}
MMBitmapRef bitmap_open(char *path, uint16_t ttype){ MMBitmapRef bitmap_open(char *path, uint16_t ttype){
// MMImageType type; // MMImageType type;
@ -146,7 +158,7 @@ char *bitmap_save(MMBitmapRef bitmap, char *path, uint16_t type){
if (saveMMBitmapToFile(bitmap, path, (MMImageType) type) != 0) { if (saveMMBitmapToFile(bitmap, path, (MMImageType) type) != 0) {
return "Could not save image to file."; return "Could not save image to file.";
} }
//destroyMMBitmap(bitmap); // destroyMMBitmap(bitmap);
return "ok"; return "ok";
} }

View File

@ -50,6 +50,9 @@ func main() {
fx, fy = robotgo.FindBitmap(bit, bitmap) fx, fy = robotgo.FindBitmap(bit, bitmap)
fmt.Println("FindBitmap------", fx, fy) fmt.Println("FindBitmap------", fx, fy)
abool := robotgo.PointInBounds(bitmap, 1, 2)
fmt.Println("point in bounds...", abool)
// returns new bitmap object created from a portion of another // returns new bitmap object created from a portion of another
bitpos := robotgo.GetPortion(bitmap, 10, 10, 11, 10) bitpos := robotgo.GetPortion(bitmap, 10, 10, 11, 10)
fmt.Println(bitpos) fmt.Println(bitpos)

View File

@ -162,6 +162,10 @@ func bitmap() {
fx, fy = robotgo.FindBitmap(bit, bitmap) fx, fy = robotgo.FindBitmap(bit, bitmap)
fmt.Println("FindBitmap------", fx, fy) fmt.Println("FindBitmap------", fx, fy)
// bitmap := robotgo.CaptureScreen(10, 20, 30, 40)
abool := robotgo.PointInBounds(bitmap, 1, 2)
fmt.Println("point in bounds...", abool)
// returns new bitmap object created from a portion of another // returns new bitmap object created from a portion of another
bitpos := robotgo.GetPortion(bitmap, 10, 10, 11, 10) bitpos := robotgo.GetPortion(bitmap, 10, 10, 11, 10)
fmt.Println(bitpos) fmt.Println(bitpos)

View File

@ -62,7 +62,7 @@ import (
) )
const ( const (
version string = "v0.47.0.442, Mount Cook!" version string = "v0.47.0.445, Mount Cook!"
) )
type ( type (
@ -165,7 +165,7 @@ func CaptureScreen(args ...int) C.MMBitmapRef {
// fmt.Println("err:::", e) // fmt.Println("err:::", e)
x = 0 x = 0
y = 0 y = 0
//Get screen size. // Get screen size.
var displaySize C.MMSize var displaySize C.MMSize
displaySize = C.getMainDisplaySize() displaySize = C.getMainDisplaySize()
w = displaySize.width w = displaySize.width
@ -286,7 +286,7 @@ func SaveCapture(spath string, args ...int) {
// MoveMouse move the mouse // MoveMouse move the mouse
func MoveMouse(x, y int) { func MoveMouse(x, y int) {
//C.size_t int // C.size_t int
cx := C.size_t(x) cx := C.size_t(x)
cy := C.size_t(y) cy := C.size_t(y)
C.aMoveMouse(cx, cy) C.aMoveMouse(cx, cy)
@ -483,8 +483,8 @@ func KeyTap(args ...interface{}) {
keyarr []string keyarr []string
num int num int
) )
// var ckeyarr []*C.char // var ckeyArr []*C.char
ckeyarr := make([](*_Ctype_char), 0) ckeyArr := make([](*_Ctype_char), 0)
Try(func() { Try(func() {
if reflect.TypeOf(args[1]) == reflect.TypeOf(keyarr) { if reflect.TypeOf(args[1]) == reflect.TypeOf(keyarr) {
@ -494,7 +494,7 @@ func KeyTap(args ...interface{}) {
num = len(keyarr) num = len(keyarr)
for i := 0; i < num; i++ { for i := 0; i < num; i++ {
ckeyarr = append(ckeyarr, (*C.char)(unsafe.Pointer(C.CString(keyarr[i])))) ckeyArr = append(ckeyArr, (*C.char)(unsafe.Pointer(C.CString(keyarr[i]))))
} }
} else { } else {
@ -519,7 +519,7 @@ func KeyTap(args ...interface{}) {
zkey := C.CString(args[0].(string)) zkey := C.CString(args[0].(string))
if akey == "" && len(keyarr) != 0 { if akey == "" && len(keyarr) != 0 {
C.aKey_Tap(zkey, (**_Ctype_char)(unsafe.Pointer(&ckeyarr[0])), C.int(num)) C.aKey_Tap(zkey, (**_Ctype_char)(unsafe.Pointer(&ckeyArr[0])), C.int(num))
} else { } else {
// zkey := C.CString(args[0]) // zkey := C.CString(args[0])
amod := C.CString(akey) amod := C.CString(akey)
@ -547,18 +547,18 @@ func KeyToggle(args ...string) string {
Try(func() { Try(func() {
adown = args[1] adown = args[1]
Try(func() { if len(args) > 2 {
amkey = args[2] amkey = args[2]
Try(func() { Try(func() {
amkeyt = args[3] amkeyt = args[3]
}, func(e interface{}) { }, func(e interface{}) {
// fmt.Println("err:::", e) // fmt.Println("err:::", e)
amkeyt = "null" amkeyt = "null"
}) })
}, func(e interface{}) { } else {
// fmt.Println("err:::", e)
amkey = "null" amkey = "null"
}) }
}, func(e interface{}) { }, func(e interface{}) {
// fmt.Println("err:::", e) // fmt.Println("err:::", e)
adown = "null" adown = "null"
@ -733,6 +733,16 @@ func FindBit(args ...interface{}) (int, int) {
return int(pos.x), int(pos.y) return int(pos.x), int(pos.y)
} }
// PointInBounds bitmap point in bounds
func PointInBounds(bitmap C.MMBitmapRef, x, y int) bool {
var point C.MMPoint
point.x = C.size_t(x)
point.y = C.size_t(y)
cbool := C.point_in_bounds(bitmap, point)
return bool(cbool)
}
// OpenBitmap open the bitmap // OpenBitmap open the bitmap
func OpenBitmap(args ...interface{}) C.MMBitmapRef { func OpenBitmap(args ...interface{}) C.MMBitmapRef {
path := C.CString(args[0].(string)) path := C.CString(args[0].(string))

View File

@ -5,6 +5,7 @@ package process
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"strings" "strings"
"syscall" "syscall"
"time" "time"
@ -407,7 +408,8 @@ func (p *Process) Terminate() error {
} }
func (p *Process) Kill() error { func (p *Process) Kill() error {
return common.ErrNotImplementedError process := os.Process{Pid: int(p.Pid)}
return process.Kill()
} }
func getFromSnapProcess(pid int32) (int32, int32, string, error) { func getFromSnapProcess(pid int32) (int32, int32, string, error) {

14
vendor/vendor.json vendored
View File

@ -59,14 +59,14 @@
{ {
"checksumSHA1": "jWpwWWcywJPNhKTYxi4RXds+amQ=", "checksumSHA1": "jWpwWWcywJPNhKTYxi4RXds+amQ=",
"path": "github.com/shirou/gopsutil/internal/common", "path": "github.com/shirou/gopsutil/internal/common",
"revision": "b8c456e53432efdbba4ee9e55d27f69cb2dcf1ee", "revision": "27389f01ec9364f60d6dba4fbe9751d3b7058d46",
"revisionTime": "2017-12-09T07:50:03Z" "revisionTime": "2017-12-14T06:29:47Z"
}, },
{ {
"checksumSHA1": "UuwHornIODuEq7fYnsZwdVgERLk=", "checksumSHA1": "UuwHornIODuEq7fYnsZwdVgERLk=",
"path": "github.com/shirou/gopsutil/mem", "path": "github.com/shirou/gopsutil/mem",
"revision": "a8bc26299477e53c4ca89f7ec60160a74d4c0890", "revision": "27389f01ec9364f60d6dba4fbe9751d3b7058d46",
"revisionTime": "2017-11-12T16:40:41Z" "revisionTime": "2017-12-14T06:29:47Z"
}, },
{ {
"checksumSHA1": "AiC1wzY1Rjxs7iitVBvn4YM886k=", "checksumSHA1": "AiC1wzY1Rjxs7iitVBvn4YM886k=",
@ -75,10 +75,10 @@
"revisionTime": "2017-11-12T16:40:41Z" "revisionTime": "2017-11-12T16:40:41Z"
}, },
{ {
"checksumSHA1": "v3USS/LSyBuVc/DMBV+GX4ikZ5M=", "checksumSHA1": "DRj2E2ZXWdb8UtaGLIDKa64IRHk=",
"path": "github.com/shirou/gopsutil/process", "path": "github.com/shirou/gopsutil/process",
"revision": "b8c456e53432efdbba4ee9e55d27f69cb2dcf1ee", "revision": "27389f01ec9364f60d6dba4fbe9751d3b7058d46",
"revisionTime": "2017-12-09T07:50:03Z" "revisionTime": "2017-12-14T06:29:47Z"
}, },
{ {
"checksumSHA1": "Nve7SpDmjsv6+rhkXAkfg/UQx94=", "checksumSHA1": "Nve7SpDmjsv6+rhkXAkfg/UQx94=",