forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/Lights/AmbLight.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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 Microsoft.UI; | ||
using Microsoft.UI.Composition; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Media; | ||
|
||
namespace Microsoft.CmdPal.UI.Controls; | ||
|
||
internal sealed partial class AmbLight : XamlLight | ||
{ | ||
private static readonly string Id = typeof(AmbLight).FullName!; | ||
|
||
protected override void OnConnected(UIElement newElement) | ||
{ | ||
var compositor = CompositionTarget.GetCompositorForCurrentThread(); | ||
|
||
// Create AmbientLight and set its properties | ||
var ambientLight = compositor.CreateAmbientLight(); | ||
ambientLight.Color = Colors.White; | ||
|
||
// Associate CompositionLight with XamlLight | ||
CompositionLight = ambientLight; | ||
|
||
// Add UIElement to the Light's Targets | ||
AddTargetElement(GetId(), newElement); | ||
} | ||
|
||
protected override void OnDisconnected(UIElement oldElement) | ||
{ | ||
// Dispose Light when it is removed from the tree | ||
RemoveTargetElement(GetId(), oldElement); | ||
CompositionLight.Dispose(); | ||
} | ||
|
||
protected override string GetId() => Id; | ||
} |
104 changes: 104 additions & 0 deletions
104
src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/Lights/HoverLight.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// 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.Numerics; | ||
using Microsoft.UI; | ||
using Microsoft.UI.Composition; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Hosting; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Media; | ||
|
||
namespace Microsoft.CmdPal.UI.Controls; | ||
|
||
internal sealed partial class HoverLight : XamlLight | ||
{ | ||
private ExpressionAnimation? _lightPositionExpression; | ||
private Vector3KeyFrameAnimation? _offsetAnimation; | ||
private static readonly string Id = typeof(HoverLight).FullName!; | ||
|
||
protected override void OnConnected(UIElement targetElement) | ||
{ | ||
var compositor = CompositionTarget.GetCompositorForCurrentThread(); | ||
|
||
// Create SpotLight and set its properties | ||
var spotLight = compositor.CreateSpotLight(); | ||
spotLight.InnerConeAngleInDegrees = 50f; | ||
spotLight.InnerConeColor = Colors.FloralWhite; | ||
spotLight.OuterConeColor = Colors.FloralWhite; | ||
spotLight.OuterConeAngleInDegrees = 20f; | ||
spotLight.ConstantAttenuation = 1f; | ||
spotLight.LinearAttenuation = 0.253f; | ||
spotLight.QuadraticAttenuation = 0.58f; | ||
|
||
// Associate CompositionLight with XamlLight | ||
CompositionLight = spotLight; | ||
|
||
// Define resting position Animation | ||
Vector3 restingPosition = new(200, 200, 400); | ||
var cbEasing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.3f, 0.7f), new Vector2(0.9f, 0.5f)); | ||
_offsetAnimation = compositor.CreateVector3KeyFrameAnimation(); | ||
_offsetAnimation.InsertKeyFrame(1, restingPosition, cbEasing); | ||
_offsetAnimation.Duration = TimeSpan.FromSeconds(0.5f); | ||
|
||
spotLight.Offset = restingPosition; | ||
|
||
// Define expression animation that relates light's offset to pointer position | ||
var hoverPosition = ElementCompositionPreview.GetPointerPositionPropertySet(targetElement); | ||
_lightPositionExpression = compositor.CreateExpressionAnimation("Vector3(hover.Position.X, hover.Position.Y, height)"); | ||
_lightPositionExpression.SetReferenceParameter("hover", hoverPosition); | ||
_lightPositionExpression.SetScalarParameter("height", 100.0f); | ||
|
||
// Configure pointer entered/ exited events | ||
targetElement.PointerMoved += TargetElement_PointerMoved; | ||
targetElement.PointerExited += TargetElement_PointerExited; | ||
|
||
// Add UIElement to the Light's Targets | ||
AddTargetElement(GetId(), targetElement); | ||
} | ||
|
||
private void MoveToRestingPosition() => | ||
|
||
// Start animation on SpotLight's Offset | ||
CompositionLight?.StartAnimation("Offset", _offsetAnimation); | ||
|
||
private void TargetElement_PointerMoved(object sender, PointerRoutedEventArgs e) | ||
{ | ||
if (CompositionLight != null) | ||
{ | ||
// touch input is still UI thread-bound as of the Creator's Update | ||
if (e.Pointer.PointerDeviceType == Microsoft.UI.Input.PointerDeviceType.Touch) | ||
{ | ||
var offset = e.GetCurrentPoint((UIElement)sender).Position.ToVector2(); | ||
|
||
if (CompositionLight is SpotLight light) | ||
{ | ||
light.Offset = new Vector3(offset.X, offset.Y, 15); | ||
} | ||
} | ||
else | ||
{ | ||
// Get the pointer's current position from the property and bind the SpotLight's X-Y Offset | ||
CompositionLight.StartAnimation("Offset", _lightPositionExpression); | ||
} | ||
} | ||
} | ||
|
||
private void TargetElement_PointerExited(object sender, PointerRoutedEventArgs e) => | ||
|
||
// Move to resting state when pointer leaves targeted UIElement | ||
MoveToRestingPosition(); | ||
|
||
protected override void OnDisconnected(UIElement oldElement) | ||
{ | ||
// Dispose Light and Composition resources when it is removed from the tree | ||
RemoveTargetElement(GetId(), oldElement); | ||
CompositionLight.Dispose(); | ||
|
||
_lightPositionExpression?.Dispose(); | ||
_offsetAnimation?.Dispose(); | ||
} | ||
|
||
protected override string GetId() => Id; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8b4e646
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@check-spelling-bot Report
🔴 Please review
See the 📜action log or 📝 job summary for details.
Unrecognized words (160)
Previously acknowledged words that are now absent
BODGY Emoji Infotip pef SYSTEMWOW VKey Wbemidl WIC 🫥Some files were automatically ignored 🙈
These sample patterns would exclude them:
You should consider adding them to:
File matching is via Perl regular expressions.
To check these files, more of their words need to be in the dictionary than not. You can use
patterns.txt
to exclude portions, add items to the dictionary (e.g. by adding them toallow.txt
), or fix typos.To accept these unrecognized words as correct and remove the previously acknowledged and now absent words and update file exclusions, you could run the following commands
... in a clone of the [email protected]:zadjii-msft/PowerToys.git repository
on the
niels9001/lights
branch (ℹ️ how do I use this?):Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary
This includes both expected items (1910) from .github/actions/spell-check/expect.txt and unrecognized words (160)
Consider adding them (in
.github/workflows/spelling2.yml
) foruses: check-spelling/[email protected]
in itswith
:To stop checking additional dictionaries, add (in
.github/workflows/spelling2.yml
) foruses: check-spelling/[email protected]
in itswith
:Pattern suggestions ✂️ (1)
You could add these patterns to
.github/actions/spell-check/patterns.txt
:Errors (5)
See the 📜action log or 📝 job summary for details.
See ❌ Event descriptions for more information.
If the flagged items are 🤯 false positives
If items relate to a ...
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txt
file matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^
refers to the file's path from the root of the repository, so^README\.md$
would exclude README.md (on whichever branch you're using).well-formed pattern.
If you can write a pattern that would match it,
try adding it to the
patterns.txt
file.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.