Skip to content

Commit

Permalink
Merge pull request #1 from VictorGrycuk/dev/1.2
Browse files Browse the repository at this point in the history
[v1.2] Add option to lock the magnifier in place, increase refresh rate
  • Loading branch information
VictorGrycuk authored Nov 30, 2020
2 parents 0cdd8a5 + 1f8ee5b commit 7341ebb
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 21 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Done using BarRaider's [Stream Deck Tools](https://github.com/BarRaider/streamde
- Turns a Stream Deck key into a screen magnifier
- Allows up to 32x zoom
- Press to start, press again to stop
- Refresh update is 1 second do to Stream Deck API limit
- Long press (+2 seconds) to lock the location, long press again to unlock it
- Refresh update is 10ms
- Optional crosshair

### Mover
Expand Down
Binary file modified images/magnifier.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/mover.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ internal static Bitmap ResizeImage(Image image, int width, int height)
return newImage;
}

internal static Image CopyFromScreen(int zoomLevel)
internal static Image CopyFromScreen(int zoomLevel, Point mouseLocation)
{
var endWidth = 144;
var endHeight = 144;
var cursorLocation = ScreenHelper.GetMouseLocation();
var startWidth = endWidth / zoomLevel;
var startHeight = endHeight / zoomLevel;
var xPos = Math.Max(0, cursorLocation.X - (startWidth / 2));
var yPos = Math.Max(0, cursorLocation.Y - (startHeight / 2));
var xPos = Math.Max(0, mouseLocation.X - (startWidth / 2));
var yPos = Math.Max(0, mouseLocation.Y - (startHeight / 2));
var img = new Bitmap(startWidth, startHeight);
using (var graphics = Graphics.FromImage(img))
{
Expand Down
53 changes: 38 additions & 15 deletions streamdeck-magnifier/streamdeck-magnifier/Magnifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,73 @@
using System;
using System.Threading.Tasks;
using System.Drawing;
using System.Timers;

namespace Magnifier
{
[PluginActionId("victorgrycuk.streamdeck.magnifier")]
public class Magnifier : PluginBase
{
private readonly MagnifierSettings settings;
private bool isRunning;
private readonly Timer Timer;
private bool isFixed;
private Point mouseLocation;
private DateTime dateTime;

public Magnifier(SDConnection connection, InitialPayload payload) : base(connection, payload)
{
settings = payload.Settings == null || payload.Settings.Count == 0
? MagnifierSettings.CreateDefaultSettings()
: payload.Settings.ToObject<MagnifierSettings>();

Timer = new Timer(10);
Timer.Elapsed += new ElapsedEventHandler(UpdateKey);
Timer.Enabled = false;
Timer.Start();
}

private void UpdateKey(object sender, ElapsedEventArgs e)
{
if (Timer.Enabled)
{
var location = isFixed ? mouseLocation : ScreenHelper.GetMouseLocation();
var img = ImageHelper.CopyFromScreen(settings.ZoomLevel, location);
img = ImageHelper.ResizeImage(img, 144, 144);

if (settings.UseCrosshair)
{
ImageHelper.DrawCrosshair(img);
}

Connection.SetImageAsync(img);
}
}

public override void Dispose()
{
Timer.Stop();
Timer.Dispose();
Logger.Instance.LogMessage(TracingLevel.INFO, $"Destructor called");
}

public override void KeyPressed(KeyPayload payload)
{
isRunning = !isRunning;
Timer.Enabled = !Timer.Enabled;
dateTime = DateTime.Now;
}

public override void KeyReleased(KeyPayload payload) { }

public override void OnTick()
public override void KeyReleased(KeyPayload payload)
{
if (isRunning)
if ((DateTime.Now - dateTime).TotalSeconds > 2)
{
var img = ImageHelper.CopyFromScreen(settings.ZoomLevel);
img = ImageHelper.ResizeImage(img, 144, 144);

if (settings.UseCrosshair)
{
ImageHelper.DrawCrosshair(img);
}

Connection.SetImageAsync(img);
mouseLocation = ScreenHelper.GetMouseLocation();
isFixed = !isFixed;
Timer.Enabled = true;
}
}

public override void OnTick() { }

public override void ReceivedSettings(ReceivedSettingsPayload payload)
{
Tools.AutoPopulateSettings(settings, payload.Settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
</div>
</div>
</div>
<details class="message">
<summary>Hold the key for 2+ seconds to lock it in place</summary>
</details>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion streamdeck-magnifier/streamdeck-magnifier/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"Description": "Converts a Stream Deck key into a screen magnifier, with up to 32x zoom.\nIncludes an option to move the mouse pixel by pixel for better precision.",
"Icon": "Images/magnifierIcon",
"URL": "https://github.com/VictorGrycuk/streamdeck-magnifier",
"Version": "1.1",
"Version": "1.2.1",
"CodePath": "streamdeck-magnifier",
"Category": "Magnifier",
"CategoryIcon": "Images/categoryIcon",
Expand Down

0 comments on commit 7341ebb

Please sign in to comment.