Skip to content

Commit

Permalink
use system cursor position for zoom when cursor is invisible (e.g. dr…
Browse files Browse the repository at this point in the history
…agging).
  • Loading branch information
hecomi committed Nov 12, 2016
1 parent 1eb821b commit a0edc1a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Assets/uDesktopDuplication/Examples/Scripts/Loupe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ void Update()
uddTexture_.monitorId = uDesktopDuplication.Manager.cursorMonitorId;

// To get other monitor textures, set dirty flag.
foreach (var monitor in uDesktopDuplication.Manager.monitors) {
monitor.CreateTexture();
monitor.shouldBeUpdated = true;
foreach (var target in uDesktopDuplication.Manager.monitors) {
target.CreateTexture();
target.shouldBeUpdated = true;
}

var x = (float)uddTexture_.monitor.cursorX / uddTexture_.monitor.width;
var y = (float)uddTexture_.monitor.cursorY / uddTexture_.monitor.height;
var monitor = uddTexture_.monitor;
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 h = w / aspect * uddTexture_.monitor.aspect;
var h = w / aspect * monitor.aspect;
x = Mathf.Clamp(x - w / 2, 0f, 1f - w);
y = Mathf.Clamp(y - h / 2, 0f, 1f - h);
uddTexture_.clipPos = new Vector2(x, y);
Expand Down
19 changes: 19 additions & 0 deletions Assets/uDesktopDuplication/Scripts/Monitor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using System.Runtime.InteropServices;

namespace uDesktopDuplication
{
Expand Down Expand Up @@ -157,6 +158,24 @@ public int cursorY
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
{
get { return Lib.GetCursorShapeWidth(id); }
Expand Down
30 changes: 30 additions & 0 deletions Assets/uDesktopDuplication/Scripts/Utility.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
12 changes: 12 additions & 0 deletions Assets/uDesktopDuplication/Scripts/Utility.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0edc1a

Please sign in to comment.