[New PowerToy] Add Screen Ruler module for measuring screen contents (#19701)

* [MeasureTool] initial commit

* [chore] clean up needless WindowsTargetPlatformVersion overrides from projects

* [MeasureTool] initial implementation

* Fix build errors

* Update vsconfig for needed Windows 10 SDK versions

* fix spellchecker

* another spellcheck fix

* more spellcheck errors

* Fix measurement being off by 1 on both ends

* UI fixes

* Add feet to crosses

* Remove anti-aliasing, as it's creating artifacts

* Use pixel tolerance from settings

* Tooltip updates

* Restore antialiasing to draw the tooltip

* remove comment for spell check

* Updated icons

* Icon updates

* Improve measurement accuracy and display

* Fix spellchecker

* Add less precise drawing on continuous warning

* Add setting for turning cross feet on

* Swap LMB/RMB for interaction

* Uncheck active tool's RadioButton when it exits

* activation hotkey toggles UI instead of just launching it

* track runner process and exit when it exits

* add proj ref

* toolbar is interactive during measurements

* always open toolbar on the main display

* refactor colors

* refactor edge detection & overlay ui

* refactor overlay ui even more

* simplify state structs

* multimonitor preparation: eliminate global state

* prepare for merge

* spelling

* proper thread termination + minor fixes

* multimonitor: launch tools on all monitors

* multimonitor support: track cursor position

* spell

* fix powertoys!

* ScreenSize -> Box

* add shadow effect for textbox

* spell

* fix debug mode

* dynamic text box size based on text layout metrics

* add mouse wheel to adjust pixel tolerance + per channel detection algorithm setting

* spelling

* fix per channel distance calculations

* update installer deps + spelling

* tool activation telemetry

* update assets and try to fix build

* use × instead of x

* allow multiple measurements with bounds tool with shift-click

* move #define DEBUG_OVERLAY in an appropriate space

* spell-checked

* update issue template + refactor text box drawing

* implement custom renderer and make × semiopaque

* spelling

* pass dpiScale to x renderer

* add sse2neon license

* update OOBE

* move license to NOTICE

* appropriate module preview image

* localization for AutomationPeer

* increase default pixel tolerance from 5 to 30

* add PowerToys.MeasureToolUI.exe to bugreport

* explicitly set texture dims

* clarify continuous capture description

* fix a real spelling error!

* cleanup

* clean up x2

* debug texture

* fix texture access

* fix saveasbitmap

* improve sum of all channel diffs method score calc

* optimize

* ContinuousCapture is enabled by default to avoid confusion

* build fix

* draw captured screen in a non continuous mode

* cast a spell...

* merge fix

* disable stroboscopic effect

* split global/perScreen measure state and minor improvements

* spelling

* fix comment

* primary monitor debug also active for the bounds tool

* dpi from rt for custom renderer

* add comment

* fix off by 1

* make backround convertion success for non continuous mode non-essential

* fix spelling

* overlay window covers taskbar

* fix CI

* revert taskbar covering

* fix CI

* fix ci again

* fix 2

* fix ci

* CI fix

* fix arm ci

* cleanup cursor convertion between coordinate spaces

* fix spelling

* Fix signing

* Fix MeasureToolUI version

* Fix core version

* fix race condition in system internals which happens during concurrent d3d/d2d resource creation

Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
Co-authored-by: Niels Laute <niels.laute@live.nl>
This commit is contained in:
Andrey Nekrasov
2022-08-27 02:17:20 +03:00
committed by GitHub
parent 2274e0c67d
commit 78d65a87cd
114 changed files with 5319 additions and 337 deletions

View File

@@ -271,6 +271,22 @@ namespace Microsoft.PowerToys.Settings.UI.Library
}
}
private bool measureTool = true;
[JsonPropertyName("Measure Tool")]
public bool MeasureTool
{
get => measureTool;
set
{
if (measureTool != value)
{
LogTelemetryEvent(value);
measureTool = value;
}
}
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);

View File

@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class MeasureToolProperties
{
public MeasureToolProperties()
{
ActivationShortcut = new HotkeySettings(true, false, false, true, 0x4D);
PixelTolerance = new IntProperty(30);
ContinuousCapture = true;
DrawFeetOnCross = true;
PerColorChannelEdgeDetection = false;
MeasureCrossColor = new StringProperty("#FF4500");
}
public HotkeySettings ActivationShortcut { get; set; }
[JsonConverter(typeof(BoolPropertyJsonConverter))]
public bool ContinuousCapture { get; set; }
[JsonConverter(typeof(BoolPropertyJsonConverter))]
public bool DrawFeetOnCross { get; set; }
[JsonConverter(typeof(BoolPropertyJsonConverter))]
public bool PerColorChannelEdgeDetection { get; set; }
public IntProperty PixelTolerance { get; set; }
public StringProperty MeasureCrossColor { get; set; }
public override string ToString() => JsonSerializer.Serialize(this);
}
}

View File

@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class MeasureToolSettings : BasePTModuleSettings, ISettingsConfig
{
public const string ModuleName = "Measure Tool";
[JsonPropertyName("properties")]
public MeasureToolProperties Properties { get; set; }
public MeasureToolSettings()
{
Properties = new MeasureToolProperties();
Version = "1";
Name = ModuleName;
}
public string GetModuleName()
=> Name;
// This can be utilized in the future if the settings.json file is to be modified/deleted.
public bool UpgradeSettingsConfiguration()
=> false;
}
}

View File

@@ -0,0 +1,170 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.CompilerServices;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{
public class MeasureToolViewModel : Observable
{
private ISettingsUtils SettingsUtils { get; set; }
private GeneralSettings GeneralSettingsConfig { get; set; }
private MeasureToolSettings Settings { get; set; }
public MeasureToolViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<MeasureToolSettings> measureToolSettingsRepository, Func<string, int> ipcMSGCallBackFunc)
{
SettingsUtils = settingsUtils;
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
}
GeneralSettingsConfig = settingsRepository.SettingsConfig;
if (measureToolSettingsRepository == null)
{
throw new ArgumentNullException(nameof(measureToolSettingsRepository));
}
Settings = measureToolSettingsRepository.SettingsConfig;
SendConfigMSG = ipcMSGCallBackFunc;
}
public bool IsEnabled
{
get => GeneralSettingsConfig.Enabled.MeasureTool;
set
{
if (GeneralSettingsConfig.Enabled.MeasureTool != value)
{
GeneralSettingsConfig.Enabled.MeasureTool = value;
OnPropertyChanged(nameof(IsEnabled));
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
SendConfigMSG(outgoing.ToString());
NotifyPropertyChanged();
}
}
}
public bool ContinuousCapture
{
get
{
return Settings.Properties.ContinuousCapture;
}
set
{
if (Settings.Properties.ContinuousCapture != value)
{
Settings.Properties.ContinuousCapture = value;
NotifyPropertyChanged();
}
}
}
public bool DrawFeetOnCross
{
get
{
return Settings.Properties.DrawFeetOnCross;
}
set
{
if (Settings.Properties.DrawFeetOnCross != value)
{
Settings.Properties.DrawFeetOnCross = value;
NotifyPropertyChanged();
}
}
}
public string CrossColor
{
get
{
return Settings.Properties.MeasureCrossColor.Value;
}
set
{
value = (value != null) ? SettingsUtilities.ToRGBHex(value) : "#FF4500";
if (!value.Equals(Settings.Properties.MeasureCrossColor.Value, StringComparison.OrdinalIgnoreCase))
{
Settings.Properties.MeasureCrossColor.Value = value;
NotifyPropertyChanged();
}
}
}
public bool PerColorChannelEdgeDetection
{
get
{
return Settings.Properties.PerColorChannelEdgeDetection;
}
set
{
if (Settings.Properties.PerColorChannelEdgeDetection != value)
{
Settings.Properties.PerColorChannelEdgeDetection = value;
NotifyPropertyChanged();
}
}
}
public int PixelTolerance
{
get
{
return Settings.Properties.PixelTolerance.Value;
}
set
{
if (Settings.Properties.PixelTolerance.Value != value)
{
Settings.Properties.PixelTolerance.Value = value;
NotifyPropertyChanged();
}
}
}
public HotkeySettings ActivationShortcut
{
get
{
return Settings.Properties.ActivationShortcut;
}
set
{
if (Settings.Properties.ActivationShortcut != value)
{
Settings.Properties.ActivationShortcut = value;
NotifyPropertyChanged();
}
}
}
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
OnPropertyChanged(propertyName);
SettingsUtils.SaveSettings(Settings.ToJsonString(), MeasureToolSettings.ModuleName);
}
private Func<string, int> SendConfigMSG { get; }
}
}