use system cursor position for zoom when cursor is invisible (e.g. dragging).
This commit is contained in:
@@ -20,15 +20,19 @@ public class Loupe : MonoBehaviour
|
|||||||
uddTexture_.monitorId = uDesktopDuplication.Manager.cursorMonitorId;
|
uddTexture_.monitorId = uDesktopDuplication.Manager.cursorMonitorId;
|
||||||
|
|
||||||
// To get other monitor textures, set dirty flag.
|
// To get other monitor textures, set dirty flag.
|
||||||
foreach (var monitor in uDesktopDuplication.Manager.monitors) {
|
foreach (var target in uDesktopDuplication.Manager.monitors) {
|
||||||
monitor.CreateTexture();
|
target.CreateTexture();
|
||||||
monitor.shouldBeUpdated = true;
|
target.shouldBeUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var x = (float)uddTexture_.monitor.cursorX / uddTexture_.monitor.width;
|
var monitor = uddTexture_.monitor;
|
||||||
var y = (float)uddTexture_.monitor.cursorY / uddTexture_.monitor.height;
|
var cursorX = monitor.isCursorVisible ? monitor.cursorX : monitor.systemCursorX;
|
||||||
|
var cursorY = monitor.isCursorVisible ? monitor.cursorY : monitor.systemCursorY;
|
||||||
|
|
||||||
|
var x = (float)cursorX / monitor.width;
|
||||||
|
var y = (float)cursorY / monitor.height;
|
||||||
var w = 1f / zoom;
|
var w = 1f / zoom;
|
||||||
var h = w / aspect * uddTexture_.monitor.aspect;
|
var h = w / aspect * monitor.aspect;
|
||||||
x = Mathf.Clamp(x - w / 2, 0f, 1f - w);
|
x = Mathf.Clamp(x - w / 2, 0f, 1f - w);
|
||||||
y = Mathf.Clamp(y - h / 2, 0f, 1f - h);
|
y = Mathf.Clamp(y - h / 2, 0f, 1f - h);
|
||||||
uddTexture_.clipPos = new Vector2(x, y);
|
uddTexture_.clipPos = new Vector2(x, y);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace uDesktopDuplication
|
namespace uDesktopDuplication
|
||||||
{
|
{
|
||||||
@@ -157,6 +158,24 @@ public class Monitor
|
|||||||
get { return Lib.GetCursorY(id); }
|
get { return Lib.GetCursorY(id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int systemCursorX
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var p = Utility.GetCursorPos();
|
||||||
|
return p.x - left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int systemCursorY
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var p = Utility.GetCursorPos();
|
||||||
|
return p.y - top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int cursorShapeWidth
|
public int cursorShapeWidth
|
||||||
{
|
{
|
||||||
get { return Lib.GetCursorShapeWidth(id); }
|
get { return Lib.GetCursorShapeWidth(id); }
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace uDesktopDuplication
|
||||||
|
{
|
||||||
|
|
||||||
|
public struct MousePoint
|
||||||
|
{
|
||||||
|
public int x;
|
||||||
|
public int y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Utility
|
||||||
|
{
|
||||||
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
public static extern bool GetCursorPos(out MousePoint point);
|
||||||
|
|
||||||
|
public static MousePoint GetCursorPos()
|
||||||
|
{
|
||||||
|
MousePoint p;
|
||||||
|
if (!GetCursorPos(out p)) {
|
||||||
|
p.x = -1;
|
||||||
|
p.y = -1;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6c7e8da181b03ce4fb343ffa33cbb929
|
||||||
|
timeCreated: 1478934399
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user