mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 14:43:55 +00:00
Update CaptureScreen() use the scaled and some code
This commit is contained in:
parent
0a69ed90af
commit
e433e36e8a
151
robotgo.go
151
robotgo.go
@ -221,25 +221,15 @@ func GetMouseColor() string {
|
|||||||
return GetPixelColor(x, y)
|
return GetPixelColor(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScaleX get the primary display horizontal DPI scale factor
|
// SysScale get the sys scale (x11 todo)
|
||||||
func ScaleX() int {
|
|
||||||
return int(C.scale_x())
|
|
||||||
}
|
|
||||||
|
|
||||||
// SysScale get the sys scale
|
|
||||||
func SysScale() float64 {
|
func SysScale() float64 {
|
||||||
s := C.sys_scale()
|
s := C.sys_scale()
|
||||||
return float64(s)
|
return float64(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scaled return x * sys_scale
|
// Scaled get the screen scaled size
|
||||||
func Scaled(x int) int {
|
func Scaled(x int) int {
|
||||||
return int(float64(x) * SysScale())
|
return int(float64(x) * ScaleF())
|
||||||
}
|
|
||||||
|
|
||||||
// ScaleY get primary display vertical DPI scale factor
|
|
||||||
func ScaleY() int {
|
|
||||||
return int(C.scale_y())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetScreenSize get the screen size
|
// GetScreenSize get the screen size
|
||||||
@ -259,49 +249,16 @@ func GetScreenRect(displayId ...int) Rect {
|
|||||||
rect := C.getScreenRect(C.int32_t(display))
|
rect := C.getScreenRect(C.int32_t(display))
|
||||||
return Rect{
|
return Rect{
|
||||||
Point{
|
Point{
|
||||||
X: int(rect.origin.x),
|
X: Scaled(int(rect.origin.x)),
|
||||||
Y: int(rect.origin.y),
|
Y: Scaled(int(rect.origin.y)),
|
||||||
},
|
},
|
||||||
Size{
|
Size{
|
||||||
W: int(rect.size.w),
|
W: Scaled(int(rect.size.w)),
|
||||||
H: int(rect.size.h),
|
H: Scaled(int(rect.size.h)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale get the screen scale
|
|
||||||
func Scale() int {
|
|
||||||
dpi := map[int]int{
|
|
||||||
0: 100,
|
|
||||||
// DPI Scaling Level
|
|
||||||
96: 100,
|
|
||||||
120: 125,
|
|
||||||
144: 150,
|
|
||||||
168: 175,
|
|
||||||
192: 200,
|
|
||||||
216: 225,
|
|
||||||
// Custom DPI
|
|
||||||
240: 250,
|
|
||||||
288: 300,
|
|
||||||
384: 400,
|
|
||||||
480: 500,
|
|
||||||
}
|
|
||||||
|
|
||||||
x := ScaleX()
|
|
||||||
return dpi[x]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scale0 return ScaleX() / 0.96
|
|
||||||
func Scale0() int {
|
|
||||||
return int(float64(ScaleX()) / 0.96)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mul mul the scale
|
|
||||||
func Mul(x int) int {
|
|
||||||
s := Scale()
|
|
||||||
return x * s / 100
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetScaleSize get the screen scale size
|
// GetScaleSize get the screen scale size
|
||||||
func GetScaleSize() (int, int) {
|
func GetScaleSize() (int, int) {
|
||||||
x, y := GetScreenSize()
|
x, y := GetScreenSize()
|
||||||
@ -309,26 +266,6 @@ func GetScaleSize() (int, int) {
|
|||||||
return int(float64(x) * f), int(float64(y) * f)
|
return int(float64(x) * f), int(float64(y) * f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetXDisplayName set XDisplay name (Linux)
|
|
||||||
func SetXDisplayName(name string) string {
|
|
||||||
cname := C.CString(name)
|
|
||||||
str := C.set_XDisplay_name(cname)
|
|
||||||
|
|
||||||
gstr := C.GoString(str)
|
|
||||||
C.free(unsafe.Pointer(cname))
|
|
||||||
|
|
||||||
return gstr
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetXDisplayName get XDisplay name (Linux)
|
|
||||||
func GetXDisplayName() string {
|
|
||||||
name := C.get_XDisplay_name()
|
|
||||||
gname := C.GoString(name)
|
|
||||||
C.free(unsafe.Pointer(name))
|
|
||||||
|
|
||||||
return gname
|
|
||||||
}
|
|
||||||
|
|
||||||
// CaptureScreen capture the screen return bitmap(c struct),
|
// CaptureScreen capture the screen return bitmap(c struct),
|
||||||
// use `defer robotgo.FreeBitmap(bitmap)` to free the bitmap
|
// use `defer robotgo.FreeBitmap(bitmap)` to free the bitmap
|
||||||
//
|
//
|
||||||
@ -342,13 +279,12 @@ func CaptureScreen(args ...int) C.MMBitmapRef {
|
|||||||
w = C.int32_t(args[2])
|
w = C.int32_t(args[2])
|
||||||
h = C.int32_t(args[3])
|
h = C.int32_t(args[3])
|
||||||
} else {
|
} else {
|
||||||
x = 0
|
rect := GetScreenRect()
|
||||||
y = 0
|
|
||||||
|
|
||||||
// Get the main screen size.
|
x = C.int32_t(rect.X)
|
||||||
displaySize := C.getMainDisplaySize()
|
y = C.int32_t(rect.Y)
|
||||||
w = displaySize.w
|
w = C.int32_t(rect.W)
|
||||||
h = displaySize.h
|
h = C.int32_t(rect.H)
|
||||||
}
|
}
|
||||||
|
|
||||||
bit := C.capture_screen(x, y, w, h)
|
bit := C.capture_screen(x, y, w, h)
|
||||||
@ -402,6 +338,69 @@ func ToRGBA(bit C.MMBitmapRef) *image.RGBA {
|
|||||||
return ToRGBAGo(bmp1)
|
return ToRGBAGo(bmp1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetXDisplayName set XDisplay name (Linux)
|
||||||
|
func SetXDisplayName(name string) string {
|
||||||
|
cname := C.CString(name)
|
||||||
|
str := C.set_XDisplay_name(cname)
|
||||||
|
|
||||||
|
gstr := C.GoString(str)
|
||||||
|
C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
|
return gstr
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetXDisplayName get XDisplay name (Linux)
|
||||||
|
func GetXDisplayName() string {
|
||||||
|
name := C.get_XDisplay_name()
|
||||||
|
gname := C.GoString(name)
|
||||||
|
C.free(unsafe.Pointer(name))
|
||||||
|
|
||||||
|
return gname
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScaleX get the primary display horizontal DPI scale factor, drop
|
||||||
|
func ScaleX() int {
|
||||||
|
return int(C.scale_x())
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScaleY get primary display vertical DPI scale factor, drop
|
||||||
|
func ScaleY() int {
|
||||||
|
return int(C.scale_y())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale get the screen scale (only windows old), drop
|
||||||
|
func Scale() int {
|
||||||
|
dpi := map[int]int{
|
||||||
|
0: 100,
|
||||||
|
// DPI Scaling Level
|
||||||
|
96: 100,
|
||||||
|
120: 125,
|
||||||
|
144: 150,
|
||||||
|
168: 175,
|
||||||
|
192: 200,
|
||||||
|
216: 225,
|
||||||
|
// Custom DPI
|
||||||
|
240: 250,
|
||||||
|
288: 300,
|
||||||
|
384: 400,
|
||||||
|
480: 500,
|
||||||
|
}
|
||||||
|
|
||||||
|
x := ScaleX()
|
||||||
|
return dpi[x]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale0 return ScaleX() / 0.96, drop
|
||||||
|
func Scale0() int {
|
||||||
|
return int(float64(ScaleX()) / 0.96)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mul mul the scale, drop
|
||||||
|
func Mul(x int) int {
|
||||||
|
s := Scale()
|
||||||
|
return x * s / 100
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
.___ ___. ______ __ __ _______. _______
|
.___ ___. ______ __ __ _______. _______
|
||||||
| \/ | / __ \ | | | | / || ____|
|
| \/ | / __ \ | | | | / || ____|
|
||||||
|
@ -39,19 +39,20 @@ double sys_scale() {
|
|||||||
return pixelWidth / targetWidth;
|
return pixelWidth / targetWidth;
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
|
|
||||||
double xres;
|
// double xres;
|
||||||
Display *dpy;
|
// Display *dpy;
|
||||||
|
|
||||||
char *displayname = NULL;
|
// char *displayname = NULL;
|
||||||
int scr = 0; /* Screen number */
|
// int scr = 0; /* Screen number */
|
||||||
|
|
||||||
dpy = XOpenDisplay (displayname);
|
// dpy = XOpenDisplay (displayname);
|
||||||
xres = ((((double) DisplayWidth(dpy, scr)) * 25.4) /
|
// xres = ((((double) DisplayWidth(dpy, scr)) * 25.4) /
|
||||||
((double) DisplayWidthMM(dpy, scr)));
|
// ((double) DisplayWidthMM(dpy, scr)));
|
||||||
|
|
||||||
XCloseDisplay (dpy);
|
// XCloseDisplay (dpy);
|
||||||
|
|
||||||
return xres + 0.5;
|
// return xres / 96.0;
|
||||||
|
return 1.0;
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
double s = scaleX() / 96.0;
|
double s = scaleX() / 96.0;
|
||||||
return s;
|
return s;
|
||||||
|
Loading…
Reference in New Issue
Block a user