1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Fixed layer changes getting lost on alt-tabbing away

UI fixes
This commit is contained in:
SpoinkyNL 2017-03-12 22:56:56 +01:00
parent e729cfb960
commit a71dc46071
10 changed files with 68 additions and 44 deletions

View File

@ -28,7 +28,7 @@ namespace Artemis
private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{ {
// Get rid of the keyboard hook in case of a crash, otherwise input freezes up system wide until Artemis is gone // Get rid of the keyboard hook in case of a crash, otherwise input freezes up system wide until Artemis is gone
KeyboardHook.Dispose(); KeyboardHook.Stop();
if (DoHandle) if (DoHandle)
{ {

View File

@ -35,7 +35,7 @@ namespace Artemis
Initialize(); Initialize();
BindSpecialValues(); BindSpecialValues();
KeyboardHook.SetupKeyboardHook(); KeyboardHook.Start();
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
} }
@ -43,7 +43,7 @@ namespace Artemis
private void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs) private void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
{ {
// Get rid of the keyboard hook in case of a crash, otherwise input freezes up system wide until Artemis is gone // Get rid of the keyboard hook in case of a crash, otherwise input freezes up system wide until Artemis is gone
KeyboardHook.Dispose(); KeyboardHook.Stop();
} }
private void BindSpecialValues() private void BindSpecialValues()

View File

@ -55,7 +55,7 @@ namespace Artemis.DeviceProviders.Corsair
Height = 7; Height = 7;
Width = 25; Width = 25;
Slug = "corsair-k95-rgb"; Slug = "corsair-k95-rgb";
PreviewSettings = new PreviewSettings(new Thickness(0, -15, 0, 0), Resources.k95); PreviewSettings = new PreviewSettings(new Thickness(12, -12, 12, 5), Resources.k95);
break; break;
case "K70 RGB": case "K70 RGB":
case "K70 RGB RAPIDFIRE": case "K70 RGB RAPIDFIRE":
@ -63,7 +63,7 @@ namespace Artemis.DeviceProviders.Corsair
Height = 7; Height = 7;
Width = 21; Width = 21;
Slug = "corsair-k70-rgb"; Slug = "corsair-k70-rgb";
PreviewSettings = new PreviewSettings(new Thickness(0, -25, 0, 0), Resources.k70); PreviewSettings = new PreviewSettings(new Thickness(12, -12, 12, 5), Resources.k70);
break; break;
case "K65 RGB": case "K65 RGB":
case "CGK65 RGB": case "CGK65 RGB":
@ -72,13 +72,13 @@ namespace Artemis.DeviceProviders.Corsair
Height = 7; Height = 7;
Width = 18; Width = 18;
Slug = "corsair-k65-rgb"; Slug = "corsair-k65-rgb";
PreviewSettings = new PreviewSettings(new Thickness(0, -30, 0, 0), Resources.k65); PreviewSettings = new PreviewSettings(new Thickness(12, -12, 12, 5), Resources.k65);
break; break;
case "STRAFE RGB": case "STRAFE RGB":
Height = 7; Height = 7;
Width = 22; Width = 22;
Slug = "corsair-strafe-rgb"; Slug = "corsair-strafe-rgb";
PreviewSettings = new PreviewSettings(new Thickness(0, -5, 0, 0), Resources.strafe); PreviewSettings = new PreviewSettings(new Thickness(12, -12, 12, 5), Resources.strafe);
break; break;
} }

View File

@ -24,7 +24,7 @@ namespace Artemis.DeviceProviders.Logitech
"If needed, you can select a different keyboard in Artemis under settings."; "If needed, you can select a different keyboard in Artemis under settings.";
Height = 7; Height = 7;
Width = 22; Width = 22;
PreviewSettings = new PreviewSettings(new Thickness(10, -70, 10, 50), Resources.g910); PreviewSettings = new PreviewSettings(new Thickness(20, -55, 20, 65), Resources.g910);
_generalSettings = SettingsProvider.Load<GeneralSettings>(); _generalSettings = SettingsProvider.Load<GeneralSettings>();
} }

View File

@ -47,10 +47,9 @@ namespace Artemis.Managers
if (string.IsNullOrEmpty(_generalSettings.LastKeyboard) || _deviceManager.ChangingKeyboard) if (string.IsNullOrEmpty(_generalSettings.LastKeyboard) || _deviceManager.ChangingKeyboard)
return; return;
// If Artemis doesn't have focus, don't preview // If Artemis doesn't have focus, don't preview unless overwritten by KeepActive
var activePreview = PreviewViewModules.FirstOrDefault( var activePreview = PreviewViewModules.FirstOrDefault(vm => (vm.IsActive || vm.ProfileEditor.KeepActive) && vm.UsesProfileEditor && vm.ModuleModel.Settings.IsEnabled);
vm => vm.IsActive && vm.UsesProfileEditor && vm.ModuleModel.Settings.IsEnabled); if (activePreview != null && (activePreview.ProfileEditor.KeepActive || ActiveWindowHelper.MainWindowActive))
if (activePreview != null && ActiveWindowHelper.MainWindowActive)
EnsurePreviewActive(activePreview); EnsurePreviewActive(activePreview);
else else
EnsurePreviewInactive(); EnsurePreviewInactive();

View File

@ -13,9 +13,9 @@ namespace Artemis.Modules.Abstract
{ {
public abstract class ModuleViewModel : Screen public abstract class ModuleViewModel : Screen
{ {
private readonly GeneralSettings _generalSettings;
private readonly MainManager _mainManager; private readonly MainManager _mainManager;
private readonly ModuleManager _moduleManager; private readonly ModuleManager _moduleManager;
private readonly GeneralSettings _generalSettings;
private ModuleSettings _settings; private ModuleSettings _settings;
public ModuleViewModel(MainManager mainManager, ModuleModel moduleModel, IKernel kernel) public ModuleViewModel(MainManager mainManager, ModuleModel moduleModel, IKernel kernel)
@ -56,7 +56,8 @@ namespace Artemis.Modules.Abstract
get { return _settings; } get { return _settings; }
set set
{ {
if (Equals(value, _settings)) return; if (Equals(value, _settings))
return;
_settings = value; _settings = value;
NotifyOfPropertyChange(() => Settings); NotifyOfPropertyChange(() => Settings);
} }
@ -74,6 +75,9 @@ namespace Artemis.Modules.Abstract
} }
} }
/// <summary>
/// Indicates whether or not this module uses the profile editor
/// </summary>
public abstract bool UsesProfileEditor { get; } public abstract bool UsesProfileEditor { get; }
private void MainManagerOnEnabledChanged(object sender, EnabledChangedEventArgs e) private void MainManagerOnEnabledChanged(object sender, EnabledChangedEventArgs e)
@ -91,7 +95,7 @@ namespace Artemis.Modules.Abstract
private void UpdatedEnabledSetting() private void UpdatedEnabledSetting()
{ {
if (!ModuleModel.IsGeneral || (_moduleManager.ActiveModule != null && !_moduleManager.ActiveModule.IsGeneral || Settings.IsEnabled == IsModuleActive)) if (!ModuleModel.IsGeneral || _moduleManager.ActiveModule != null && !_moduleManager.ActiveModule.IsGeneral || Settings.IsEnabled == IsModuleActive)
return; return;
Settings.IsEnabled = IsModuleActive; Settings.IsEnabled = IsModuleActive;
@ -161,4 +165,4 @@ namespace Artemis.Modules.Abstract
ProfileEditor?.OnDeactivate(close); ProfileEditor?.OnDeactivate(close);
} }
} }
} }

View File

@ -12,7 +12,7 @@ namespace Artemis.Utilities.Keyboard
private static IKeyboardMouseEvents _globalHook; private static IKeyboardMouseEvents _globalHook;
public static void SetupKeyboardHook() public static void Start()
{ {
_globalHook = Hook.GlobalEvents(); _globalHook = Hook.GlobalEvents();
_globalHook.KeyDown += GlobalHookOnKeyDown; _globalHook.KeyDown += GlobalHookOnKeyDown;
@ -21,6 +21,19 @@ namespace Artemis.Utilities.Keyboard
_globalHook.MouseUp += GlobalHookOnMouseUp; _globalHook.MouseUp += GlobalHookOnMouseUp;
} }
public static void Stop()
{
if (_globalHook == null)
return;
_globalHook.KeyDown -= GlobalHookOnKeyDown;
_globalHook.KeyUp -= GlobalHookOnKeyUp;
_globalHook.MouseDown -= GlobalHookOnMouseDown;
_globalHook.MouseUp -= GlobalHookOnMouseUp;
_globalHook.Dispose();
_globalHook = null;
}
private static async void GlobalHookOnMouseDown(object sender, MouseEventArgs e) private static async void GlobalHookOnMouseDown(object sender, MouseEventArgs e)
{ {
await Task.Factory.StartNew(() => { MouseDownCallback?.Invoke(e); }); await Task.Factory.StartNew(() => { MouseDownCallback?.Invoke(e); });
@ -45,18 +58,5 @@ namespace Artemis.Utilities.Keyboard
public static event KeyCallbackHandler KeyUpCallback; public static event KeyCallbackHandler KeyUpCallback;
public static event MouseCallbackHandler MouseDownCallback; public static event MouseCallbackHandler MouseDownCallback;
public static event MouseCallbackHandler MouseUpCallback; public static event MouseCallbackHandler MouseUpCallback;
public static void Dispose()
{
if (_globalHook == null)
return;
_globalHook.KeyDown -= GlobalHookOnKeyDown;
_globalHook.KeyUp -= GlobalHookOnKeyUp;
_globalHook.MouseDown -= GlobalHookOnMouseDown;
_globalHook.MouseUp -= GlobalHookOnMouseUp;
_globalHook.Dispose();
_globalHook = null;
}
} }
} }

View File

@ -47,12 +47,12 @@ namespace Artemis.ViewModels
{ {
private readonly DeviceManager _deviceManager; private readonly DeviceManager _deviceManager;
private readonly MetroDialogService _dialogService; private readonly MetroDialogService _dialogService;
private KeybindModel _copyKeybind;
private KeybindModel _pasteKeybind;
private readonly LoopManager _loopManager; private readonly LoopManager _loopManager;
private readonly ModuleModel _moduleModel; private readonly ModuleModel _moduleModel;
private readonly KeybindModel _copyKeybind;
private ImageSource _keyboardPreview; private ImageSource _keyboardPreview;
private ObservableCollection<LayerModel> _layers; private ObservableCollection<LayerModel> _layers;
private readonly KeybindModel _pasteKeybind;
private ObservableCollection<string> _profileNames; private ObservableCollection<string> _profileNames;
private bool _saving; private bool _saving;
private LayerModel _selectedLayer; private LayerModel _selectedLayer;
@ -198,19 +198,19 @@ namespace Artemis.ViewModels
} }
} }
public ImageSource KeyboardImage => ImageUtilities.BitmapToBitmapImage( public ImageSource KeyboardImage => ImageUtilities.BitmapToBitmapImage(_deviceManager.ActiveKeyboard?.PreviewSettings.Image ?? Resources.none);
_deviceManager.ActiveKeyboard?.PreviewSettings.Image ?? Resources.none);
public ProfileModel SelectedProfile => _moduleModel?.ProfileModel; public ProfileModel SelectedProfile => _moduleModel?.ProfileModel;
public PreviewSettings? PreviewSettings => _deviceManager.ActiveKeyboard?.PreviewSettings; public PreviewSettings? PreviewSettings => _deviceManager.ActiveKeyboard?.PreviewSettings;
public bool ProfileSelected => SelectedProfile != null; public bool ProfileSelected => SelectedProfile != null;
public bool LayerSelected => SelectedProfile != null && SelectedLayer != null; public bool LayerSelected => SelectedProfile != null && SelectedLayer != null;
public bool EditorEnabled => SelectedProfile != null && !SelectedProfile.IsDefault && _deviceManager.ActiveKeyboard != null;
public bool EditorEnabled => SelectedProfile != null && !SelectedProfile.IsDefault &&
_deviceManager.ActiveKeyboard != null;
public bool LuaButtonVisible => !_moduleModel.IsOverlay; public bool LuaButtonVisible => !_moduleModel.IsOverlay;
/// <summary>
/// Set to true to keep the preview active if using the profile editor
/// </summary>
public bool KeepActive { get; set; }
#endregion #endregion
#region Layers #region Layers
@ -228,8 +228,10 @@ namespace Artemis.ViewModels
if (SelectedLayer == null) if (SelectedLayer == null)
return; return;
KeepActive = true;
ProfileEditorModel.EditLayer(SelectedLayer, _moduleModel.DataModel); ProfileEditorModel.EditLayer(SelectedLayer, _moduleModel.DataModel);
UpdateLayerList(SelectedLayer); UpdateLayerList(SelectedLayer);
KeepActive = false;
} }
public void EditLayer(LayerModel layerModel) public void EditLayer(LayerModel layerModel)
@ -237,8 +239,10 @@ namespace Artemis.ViewModels
if (layerModel == null) if (layerModel == null)
return; return;
KeepActive = true;
ProfileEditorModel.EditLayer(layerModel, _moduleModel.DataModel); ProfileEditorModel.EditLayer(layerModel, _moduleModel.DataModel);
UpdateLayerList(layerModel); UpdateLayerList(layerModel);
KeepActive = false;
} }
public LayerModel AddLayer() public LayerModel AddLayer()
@ -284,6 +288,7 @@ namespace Artemis.ViewModels
if (layer == null) if (layer == null)
return; return;
KeepActive = true;
var newName = await _dialogService.ShowInputDialog("Rename layer", "Please enter a name for the layer", var newName = await _dialogService.ShowInputDialog("Rename layer", "Please enter a name for the layer",
new MetroDialogSettings {DefaultText = layer.Name}); new MetroDialogSettings {DefaultText = layer.Name});
@ -293,6 +298,7 @@ namespace Artemis.ViewModels
layer.Name = newName; layer.Name = newName;
UpdateLayerList(layer); UpdateLayerList(layer);
KeepActive = false;
} }
/// <summary> /// <summary>
@ -340,7 +346,9 @@ namespace Artemis.ViewModels
return; return;
if (SelectedLayer != null) if (SelectedLayer != null)
{
SelectedLayer.InsertAfter(layerModel); SelectedLayer.InsertAfter(layerModel);
}
else else
{ {
SelectedProfile.Layers.Add(layerModel); SelectedProfile.Layers.Add(layerModel);
@ -630,7 +638,7 @@ namespace Artemis.ViewModels
if (_draggingLayer != null) if (_draggingLayer != null)
return; return;
var pos = e.GetPosition((Image) e.OriginalSource); var pos = GetScaledPosition(e);
var hoverLayer = GetLayers().Where(l => l.MustDraw()).FirstOrDefault(l => l.Properties.PropertiesRect(1).Contains(pos.X, pos.Y)); var hoverLayer = GetLayers().Where(l => l.MustDraw()).FirstOrDefault(l => l.Properties.PropertiesRect(1).Contains(pos.X, pos.Y));
if (hoverLayer != null) if (hoverLayer != null)
@ -646,7 +654,7 @@ namespace Artemis.ViewModels
if (SelectedProfile == null) if (SelectedProfile == null)
return; return;
var pos = e.GetPosition((Image) e.OriginalSource); var pos = GetScaledPosition(e);
var hoverLayer = GetLayers().Where(l => l.MustDraw()).FirstOrDefault(l => l.Properties.PropertiesRect(1).Contains(pos.X, pos.Y)); var hoverLayer = GetLayers().Where(l => l.MustDraw()).FirstOrDefault(l => l.Properties.PropertiesRect(1).Contains(pos.X, pos.Y));
HandleDragging(e, pos.X, pos.Y, hoverLayer); HandleDragging(e, pos.X, pos.Y, hoverLayer);
@ -671,6 +679,18 @@ namespace Artemis.ViewModels
} }
} }
private Point GetScaledPosition(MouseEventArgs e)
{
var sourceImage = (Image) e.OriginalSource;
var pos = e.GetPosition(sourceImage);
// Scale the X and Y position down to match the keyboard's physical size and thus the layer positions
pos.X = pos.X * (SelectedProfile.Width / sourceImage.ActualWidth);
pos.Y = pos.Y * (SelectedProfile.Height / sourceImage.ActualHeight);
return pos;
}
public Cursor KeyboardPreviewCursor public Cursor KeyboardPreviewCursor
{ {
get { return _keyboardPreviewCursor; } get { return _keyboardPreviewCursor; }

View File

@ -35,8 +35,9 @@
<Grid> <Grid>
<Image Grid.Column="0" Grid.Row="0" Source="{Binding Path=KeyboardImage}" MinHeight="10" MinWidth="10" Stretch="Uniform" /> <Image Grid.Column="0" Grid.Row="0" Source="{Binding Path=KeyboardImage}" MinHeight="10" MinWidth="10" Stretch="Uniform" />
<Image Grid.Column="0" Grid.Row="0" Source="{Binding Path=KeyboardPreview}" Opacity="0.8" Stretch="Uniform" Cursor="{Binding Path=KeyboardPreviewCursor}" <Image Grid.Column="0" Grid.Row="0" Source="{Binding Path=KeyboardPreview}" Opacity="0.8" Stretch="Uniform" Cursor="{Binding Path=KeyboardPreviewCursor}"
IsEnabled="{Binding Path=EditorEnabled, Mode=OneWay}" Margin="{Binding Path=PreviewSettings.Margin}" IsEnabled="{Binding Path=EditorEnabled, Mode=OneWay}" Margin="{Binding Path=PreviewSettings.Margin}" cal:Message.Attach="
cal:Message.Attach="[Event MouseMove] = [Action MouseMoveKeyboardPreview($eventArgs)]; [Event MouseDown] = [Action MouseDownKeyboardPreview($eventArgs)]; [Event MouseMove] = [Action MouseMoveKeyboardPreview($eventArgs)];
[Event MouseDown] = [Action MouseDownKeyboardPreview($eventArgs)];
[Event MouseUp] = [Action MouseUpKeyboardPreview($eventArgs)]" /> [Event MouseUp] = [Action MouseUpKeyboardPreview($eventArgs)]" />
</Grid> </Grid>
</Border> </Border>

View File

@ -10,7 +10,7 @@
xmlns:tb="http://www.hardcodet.net/taskbar" xmlns:tb="http://www.hardcodet.net/taskbar"
dialogs:DialogParticipation.Register="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}" dialogs:DialogParticipation.Register="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}"
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:ShellViewModel}" mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:ShellViewModel}"
Title="Artemis" Height="800" Width="1210" MinHeight="600" MinWidth="600" GlowBrush="{DynamicResource AccentColorBrush}" Icon="../logo.ico"> Title="Artemis" Height="800" Width="1210" ResizeMode="NoResize" GlowBrush="{DynamicResource AccentColorBrush}" Icon="../logo.ico">
<!-- Bit of extra code to use a different icon than in the taskbar --> <!-- Bit of extra code to use a different icon than in the taskbar -->
<Controls:MetroWindow.Resources> <Controls:MetroWindow.Resources>
<DrawingImage x:Key="BowIcon"> <DrawingImage x:Key="BowIcon">