diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index ed6e16421..a36fa3fac 100644 --- a/src/Artemis.Core/Artemis.Core.csproj +++ b/src/Artemis.Core/Artemis.Core.csproj @@ -43,9 +43,9 @@ - - - + + + diff --git a/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj b/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj index 9607a10d8..21c5abd88 100644 --- a/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj +++ b/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj @@ -16,11 +16,11 @@ - - + + - - + + diff --git a/src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj b/src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj index e674a2ad6..9e2fc0938 100644 --- a/src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj +++ b/src/Artemis.UI.MacOS/Artemis.UI.MacOS.csproj @@ -15,11 +15,11 @@ - - + + - - + + diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj index 0c4439627..36817bd6b 100644 --- a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj +++ b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj @@ -10,17 +10,17 @@ - + - - - + + + - - + + - + diff --git a/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml b/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml index 0c571239e..5802bd188 100644 --- a/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml +++ b/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml @@ -6,25 +6,27 @@ xmlns:sharedControls="clr-namespace:Artemis.UI.Shared.Controls" xmlns:attachedProperties="clr-namespace:Artemis.UI.Shared.AttachedProperties" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="Artemis.UI.Shared.Controls.DraggableNumberBox"> + x:Class="Artemis.UI.Shared.Controls.DraggableNumberBox" + Focusable="True"> - - - - + { UpdateDisplayTextBox(); @@ -78,7 +79,19 @@ public partial class HotkeyBox : UserControl private void InputServiceOnKeyboardKeyUp(object? sender, ArtemisKeyboardKeyEventArgs e) { if (e.Modifiers == KeyboardModifierKey.None) - Dispatcher.UIThread.Post(() => FocusManager.Instance?.Focus(null)); + Dispatcher.UIThread.Post(ClearFocus); + } + + private void ClearFocus() + { + InputElement? element = this.FindAncestorOfType(); + if (element == null) + return; + + bool wasFocusable = element.Focusable; + element.Focusable = true; + element.Focus(); + element.Focusable = wasFocusable; } private void UpdateDisplayTextBox() @@ -96,7 +109,7 @@ public partial class HotkeyBox : UserControl private void Button_OnClick(object? sender, RoutedEventArgs e) { Hotkey = null; - FocusManager.Instance?.Focus(null); + ClearFocus(); UpdateDisplayTextBox(); } diff --git a/src/Artemis.UI.Shared/ReactiveAppWindow.cs b/src/Artemis.UI.Shared/ReactiveAppWindow.cs index 58f4ad820..a751f4ee6 100644 --- a/src/Artemis.UI.Shared/ReactiveAppWindow.cs +++ b/src/Artemis.UI.Shared/ReactiveAppWindow.cs @@ -48,7 +48,7 @@ public class ReactiveAppWindow : AppWindow, IViewFor whe return; TransparencyBackgroundFallback = Brushes.Transparent; - TransparencyLevelHint = WindowTransparencyLevel.Mica; + TransparencyLevelHint = new[] {WindowTransparencyLevel.Mica}; TryEnableMicaEffect(); } diff --git a/src/Artemis.UI.Shared/Utilities.cs b/src/Artemis.UI.Shared/Utilities.cs index cb2d58992..832e07b75 100644 --- a/src/Artemis.UI.Shared/Utilities.cs +++ b/src/Artemis.UI.Shared/Utilities.cs @@ -1,7 +1,5 @@ using System; -using System.ComponentModel; using System.Reactive.Linq; -using System.Reactive.Subjects; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Input.Platform; @@ -14,12 +12,9 @@ namespace Artemis.UI.Shared; /// public static class UI { - private static readonly BehaviorSubject KeyBindingsEnabledSubject = new(false); - static UI() { - if (KeyboardDevice.Instance != null) - KeyboardDevice.Instance.PropertyChanged += InstanceOnPropertyChanged; + KeyBindingsEnabled = InputElement.GotFocusEvent.Raised.Select(e => e.Item2.Source is not TextBox).StartWith(true); } /// @@ -35,15 +30,5 @@ public static class UI /// /// Gets a boolean indicating whether hotkeys are to be disabled. /// - public static IObservable KeyBindingsEnabled { get; } = KeyBindingsEnabledSubject.AsObservable(); - - private static void InstanceOnPropertyChanged(object? sender, PropertyChangedEventArgs e) - { - if (KeyboardDevice.Instance == null || e.PropertyName != nameof(KeyboardDevice.FocusedElement)) - return; - - bool enabled = KeyboardDevice.Instance.FocusedElement is not TextBox; - if (KeyBindingsEnabledSubject.Value != enabled) - KeyBindingsEnabledSubject.OnNext(enabled); - } + public static IObservable KeyBindingsEnabled { get; } } \ No newline at end of file diff --git a/src/Artemis.UI.Windows/Artemis.UI.Windows.csproj b/src/Artemis.UI.Windows/Artemis.UI.Windows.csproj index bdea0536c..3910a5e65 100644 --- a/src/Artemis.UI.Windows/Artemis.UI.Windows.csproj +++ b/src/Artemis.UI.Windows/Artemis.UI.Windows.csproj @@ -21,12 +21,12 @@ - - + + - - - + + + diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index ce2eaaf18..8a469b41c 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -15,25 +15,25 @@ - - - + + + - - - + + + - + - - + + - - + + diff --git a/src/Artemis.UI/Behaviors/SimpleContextDragBehavior.cs b/src/Artemis.UI/Behaviors/SimpleContextDragBehavior.cs index bd3845bfa..b23346427 100644 --- a/src/Artemis.UI/Behaviors/SimpleContextDragBehavior.cs +++ b/src/Artemis.UI/Behaviors/SimpleContextDragBehavior.cs @@ -103,8 +103,9 @@ public class SimpleContextDragBehavior : Behavior private void AssociatedObject_PointerPressed(object? sender, PointerPressedEventArgs e) { + IFocusManager? focusManager = TopLevel.GetTopLevel(AssociatedObject)?.FocusManager; PointerPointProperties properties = e.GetCurrentPoint(AssociatedObject).Properties; - if (!properties.IsLeftButtonPressed || FocusManager.Instance?.Current is TextBox) + if (!properties.IsLeftButtonPressed || focusManager?.GetFocusedElement() is TextBox) return; if (e.Source is not Control control || AssociatedObject?.DataContext != control.DataContext) return; @@ -130,8 +131,9 @@ public class SimpleContextDragBehavior : Behavior private async void AssociatedObject_PointerMoved(object? sender, PointerEventArgs e) { + IFocusManager? focusManager = TopLevel.GetTopLevel(AssociatedObject)?.FocusManager; PointerPointProperties properties = e.GetCurrentPoint(AssociatedObject).Properties; - if (!properties.IsLeftButtonPressed || FocusManager.Instance?.Current is TextBox) + if (!properties.IsLeftButtonPressed || focusManager?.GetFocusedElement() is TextBox) return; if (_triggerEvent is null) diff --git a/src/Artemis.UI/DefaultTypes/PropertyInput/StringPropertyInputView.axaml.cs b/src/Artemis.UI/DefaultTypes/PropertyInput/StringPropertyInputView.axaml.cs index 1ef4838a8..9063787d5 100644 --- a/src/Artemis.UI/DefaultTypes/PropertyInput/StringPropertyInputView.axaml.cs +++ b/src/Artemis.UI/DefaultTypes/PropertyInput/StringPropertyInputView.axaml.cs @@ -1,5 +1,4 @@ using Avalonia.Input; -using Avalonia.Markup.Xaml; using Avalonia.ReactiveUI; namespace Artemis.UI.DefaultTypes.PropertyInput; @@ -16,6 +15,6 @@ public partial class StringPropertyInputView : ReactiveUserControl - + diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/VisualEditor/VisualEditorView.axaml.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/VisualEditor/VisualEditorView.axaml.cs index 3fb88d5c5..87e7b3b2e 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/VisualEditor/VisualEditorView.axaml.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/VisualEditor/VisualEditorView.axaml.cs @@ -63,7 +63,12 @@ public partial class VisualEditorView : ReactiveUserControl - diff --git a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.axaml.cs b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.axaml.cs index 833a56e20..73b747355 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.axaml.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.axaml.cs @@ -5,7 +5,6 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.PanAndZoom; using Avalonia.Input; -using Avalonia.Markup.Xaml; using Avalonia.Media; using Avalonia.ReactiveUI; @@ -30,7 +29,7 @@ public partial class SurfaceEditorView : ReactiveUserControl { - private Canvas? _container; + private readonly DispatcherTimer _updateTimer; private bool _dragging; + private Canvas? _container; private Border? _pinPoint; - private PinViewRenderLoopTaks _renderLoopTask; + + public PinView() + { + _updateTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(16), DispatcherPriority.Render, UpdatePosition); + } protected void InitializePin(Border pinPoint) { _pinPoint = pinPoint; _pinPoint.PointerMoved += PinPointOnPointerMoved; _pinPoint.PointerReleased += PinPointOnPointerReleased; - _pinPoint.PropertyChanged += PinPointOnPropertyChanged; - _renderLoopTask = new PinViewRenderLoopTaks(this); } - - private void PinPointOnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e) - { - Console.WriteLine(e); - } - + private void PinPointOnPointerMoved(object? sender, PointerEventArgs e) { if (ViewModel == null || _container == null || _pinPoint == null) @@ -74,19 +72,17 @@ public class PinView : ReactiveUserControl /// protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { - base.OnAttachedToVisualTree(e); _container = this.FindAncestorOfType(); - AvaloniaLocator.Current.GetRequiredService().Add(_renderLoopTask); + _updateTimer.Start(); } /// protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) { - base.OnDetachedFromVisualTree(e); - AvaloniaLocator.Current.GetRequiredService().Remove(_renderLoopTask); + _updateTimer.Stop(); } - public void UpdatePosition() + public void UpdatePosition(object? sender, EventArgs eventArgs) { if (_container == null || _pinPoint == null || ViewModel == null) return; @@ -97,25 +93,4 @@ public class PinView : ReactiveUserControl } #endregion -} - -public class PinViewRenderLoopTaks : IRenderLoopTask -{ - private readonly PinView _pinView; - - public PinViewRenderLoopTaks(PinView pinView) - { - _pinView = pinView; - } - - public void Update(TimeSpan time) - { - _pinView.UpdatePosition(); - } - - public void Render() - { - } - - public bool NeedsUpdate => true; } \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Artemis.VisualScripting.csproj b/src/Artemis.VisualScripting/Artemis.VisualScripting.csproj index 2a69a2d53..c0e7a1bec 100644 --- a/src/Artemis.VisualScripting/Artemis.VisualScripting.csproj +++ b/src/Artemis.VisualScripting/Artemis.VisualScripting.csproj @@ -8,9 +8,9 @@ - - - + + +