From b3ac975c5f287f2bff7f84a9f1fbbbbc77e7abf7 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Mon, 18 Apr 2016 18:21:42 +0200 Subject: [PATCH] You can now see selected layers that are behind other layers. Selecting a layer also selects it in the list now. --- Artemis/Artemis/Artemis.csproj | 46 +- .../BindableSelectedItemBehavior.cs | 8 +- Artemis/Artemis/Managers/MainManager.cs | 4 +- Artemis/Artemis/Models/Profiles/LayerModel.cs | 4 +- .../Artemis/Models/Profiles/ProfileModel.cs | 30 + .../Games/CounterStrike/CounterStrikeModel.cs | 2 - .../CounterStrike/CounterStrikeViewModel.cs | 11 +- Artemis/Artemis/Resources/Icons.xaml | 2528 +++++++++-------- Artemis/Artemis/Utilities/ColorHelpers.cs | 17 + .../ViewModels/ProfileEditorViewModel.cs | 132 +- Artemis/Artemis/Views/ProfileEditorView.xaml | 36 +- Artemis/Artemis/packages.config | 11 +- 12 files changed, 1435 insertions(+), 1394 deletions(-) diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 621405501..d286cf8ae 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -120,10 +120,6 @@ - - ..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll - True - ..\packages\Autofac.4.0.0-rc1-177\lib\net45\Autofac.dll True @@ -152,12 +148,8 @@ ..\packages\CUE.NET.1.0.2.2\lib\net45\CUE.NET.dll True - - ..\packages\ExpressionEvaluator.2.0.4.0\lib\net40\ExpressionEvaluator.dll - True - - ..\packages\Hardcodet.NotifyIcon.Wpf.1.0.5\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll + ..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll True @@ -180,11 +172,7 @@ True - ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll - True - - - ..\packages\Screna.0.1.3\lib\Screna.dll + ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True @@ -231,28 +219,28 @@ - - ..\packages\Extended.Wpf.Toolkit.2.6\lib\net40\Xceed.Wpf.AvalonDock.dll + + ..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.AvalonDock.dll True - - ..\packages\Extended.Wpf.Toolkit.2.6\lib\net40\Xceed.Wpf.AvalonDock.Themes.Aero.dll + + ..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.AvalonDock.Themes.Aero.dll True - - ..\packages\Extended.Wpf.Toolkit.2.6\lib\net40\Xceed.Wpf.AvalonDock.Themes.Metro.dll + + ..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.AvalonDock.Themes.Metro.dll True - - ..\packages\Extended.Wpf.Toolkit.2.6\lib\net40\Xceed.Wpf.AvalonDock.Themes.VS2010.dll + + ..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.AvalonDock.Themes.VS2010.dll True - - ..\packages\Extended.Wpf.Toolkit.2.6\lib\net40\Xceed.Wpf.DataGrid.dll + + ..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.DataGrid.dll True - - ..\packages\Extended.Wpf.Toolkit.2.6\lib\net40\Xceed.Wpf.Toolkit.dll + + ..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.Toolkit.dll True @@ -538,14 +526,13 @@ - - PreserveNewest + @@ -553,9 +540,10 @@ + + - SettingsSingleFileGenerator Offsets.Designer.cs diff --git a/Artemis/Artemis/ItemBehaviours/BindableSelectedItemBehavior.cs b/Artemis/Artemis/ItemBehaviours/BindableSelectedItemBehavior.cs index 5e84d4502..a09841ed5 100644 --- a/Artemis/Artemis/ItemBehaviours/BindableSelectedItemBehavior.cs +++ b/Artemis/Artemis/ItemBehaviours/BindableSelectedItemBehavior.cs @@ -37,13 +37,13 @@ namespace Artemis.ItemBehaviours set { SetValue(SelectedItemProperty, value); } } - public static readonly DependencyProperty SelectedItemProperty = - DependencyProperty.Register("SelectedItem", typeof (object), typeof (BindableSelectedItemBehavior), - new UIPropertyMetadata(null, OnSelectedItemChanged)); + public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register("SelectedItem", + typeof (object), typeof (BindableSelectedItemBehavior), new UIPropertyMetadata(null, OnSelectedItemChanged)); private static void OnSelectedItemChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { - var item = e.NewValue as TreeViewItem; + var item = ((BindableSelectedItemBehavior) sender).AssociatedObject + .ItemContainerGenerator.ContainerFromItem(e.NewValue) as TreeViewItem; item?.SetValue(TreeViewItem.IsSelectedProperty, true); } diff --git a/Artemis/Artemis/Managers/MainManager.cs b/Artemis/Artemis/Managers/MainManager.cs index 745b91b15..381795d2e 100644 --- a/Artemis/Artemis/Managers/MainManager.cs +++ b/Artemis/Artemis/Managers/MainManager.cs @@ -50,8 +50,8 @@ namespace Artemis.Managers GameStateWebServer.Start(); // Start the named pipe - //PipeServer = new PipeServer(); - //PipeServer.Start("artemis"); + PipeServer = new PipeServer(); + PipeServer.Start("artemis"); } public PipeServer PipeServer { get; set; } diff --git a/Artemis/Artemis/Models/Profiles/LayerModel.cs b/Artemis/Artemis/Models/Profiles/LayerModel.cs index 6f357c5f2..8eccf4c17 100644 --- a/Artemis/Artemis/Models/Profiles/LayerModel.cs +++ b/Artemis/Artemis/Models/Profiles/LayerModel.cs @@ -11,7 +11,7 @@ namespace Artemis.Models.Profiles public class LayerModel { [XmlIgnore] private readonly LayerDrawer _drawer; - private bool _mustDraw; + [XmlIgnore] private bool _mustDraw; public LayerModel() { @@ -30,7 +30,7 @@ namespace Artemis.Models.Profiles public LayerType LayerType { get; set; } public bool Enabled { get; set; } public LayerPropertiesModel UserProps { get; set; } - + public List Children { get; set; } public List LayerConditions { get; set; } public List LayerProperties { get; set; } diff --git a/Artemis/Artemis/Models/Profiles/ProfileModel.cs b/Artemis/Artemis/Models/Profiles/ProfileModel.cs index 829620054..d6e3b5cbc 100644 --- a/Artemis/Artemis/Models/Profiles/ProfileModel.cs +++ b/Artemis/Artemis/Models/Profiles/ProfileModel.cs @@ -1,5 +1,8 @@ using System.Collections.Generic; using System.Windows.Media; +using System.Xml.Serialization; +using Artemis.Utilities; +using CUE.NET.Helper; namespace Artemis.Models.Profiles { @@ -42,5 +45,32 @@ namespace Artemis.Models.Profiles return hashCode; } } + + /// + /// Adds a new layer with default settings to the profile + /// + /// The newly added layer + public LayerModel AddLayer() + { + var layer = new LayerModel + { + Name = "New layer", + Enabled = true, + LayerType = LayerType.KeyboardRectangle, + UserProps = new LayerPropertiesModel + { + Brush = new SolidColorBrush(ColorHelpers.GetRandomRainbowMediaColor()), + Animation = LayerAnimation.None, + Height = 1, + Width = 1, + X = 0, + Y = 0, + Opacity = 1 + } + }; + + Layers.Add(layer); + return layer; + } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs index 381a7fd44..b1f65f050 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs @@ -89,8 +89,6 @@ namespace Artemis.Modules.Games.CounterStrike if (!jsonString.Contains("Counter-Strike: Global Offensive")) return; - Debug.WriteLine("Received data"); - // Parse the JSON GameDataModel = JsonConvert.DeserializeObject(jsonString); } diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs index b823d1212..982bb1136 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeViewModel.cs @@ -1,4 +1,5 @@ -using System.IO; +using System.ComponentModel; +using System.IO; using System.Windows.Forms; using Artemis.Managers; using Artemis.Properties; @@ -22,10 +23,16 @@ namespace Artemis.Modules.Games.CounterStrike PlaceConfigFile(); ProfileEditor = new ProfileEditorViewModel(MainManager, GameModel); - + ProfileEditor.PropertyChanged += ProfileUpdater; GameModel.Profile = ProfileEditor.SelectedProfile; } + private void ProfileUpdater(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == "SelectedProfile") + GameModel.Profile = ProfileEditor.SelectedProfile; + } + public ProfileEditorViewModel ProfileEditor { get; set; } public static string Name => "CS:GO"; diff --git a/Artemis/Artemis/Resources/Icons.xaml b/Artemis/Artemis/Resources/Icons.xaml index b35e272ed..be35c7a5f 100644 --- a/Artemis/Artemis/Resources/Icons.xaml +++ b/Artemis/Artemis/Resources/Icons.xaml @@ -1,2633 +1,2641 @@  - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -2640,275 +2648,275 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -2921,507 +2929,507 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -3442,507 +3450,507 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -3952,1180 +3960,1180 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/Artemis/Artemis/Utilities/ColorHelpers.cs b/Artemis/Artemis/Utilities/ColorHelpers.cs index e40064582..bdefa0ec5 100644 --- a/Artemis/Artemis/Utilities/ColorHelpers.cs +++ b/Artemis/Artemis/Utilities/ColorHelpers.cs @@ -28,6 +28,23 @@ namespace Artemis.Utilities return returnColor; } + public static System.Windows.Media.Color GetRandomRainbowMediaColor() + { + var colors = new List(); + var rand = new Random(); + for (var i = 0; i < 3; i++) + colors.Add((byte) rand.Next(0, 256)); + + var highest = colors.Max(); + var lowest = colors.Min(); + colors[colors.FindIndex(c => c == highest)] = 255; + colors[colors.FindIndex(c => c == lowest)] = 0; + + var returnColor = System.Windows.Media.Color.FromArgb(255, colors[0], colors[1], colors[2]); + + return returnColor; + } + public static Color ShiftColor(Color c, int shiftAmount) { int newRed = c.R; diff --git a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs index fd95a7da6..c6ce8f0ac 100644 --- a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs +++ b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs @@ -30,8 +30,8 @@ namespace Artemis.ViewModels private LayerEditorViewModel _editorVm; private Cursor _keyboardPreviewCursor; private BindableCollection _layers; - private BindableCollection _profileModels; - private bool _resizeSourceRect; + private BindableCollection _profiles; + private bool _resizing; private LayerModel _selectedLayer; private ProfileModel _selectedProfile; @@ -40,7 +40,7 @@ namespace Artemis.ViewModels _mainManager = mainManager; _gameModel = gameModel; - ProfileModels = new BindableCollection(); + Profiles = new BindableCollection(); Layers = new BindableCollection(); _mainManager.Events.Subscribe(this); @@ -48,14 +48,14 @@ namespace Artemis.ViewModels LoadProfiles(); } - public BindableCollection ProfileModels + public BindableCollection Profiles { - get { return _profileModels; } + get { return _profiles; } set { - if (Equals(value, _profileModels)) return; - _profileModels = value; - NotifyOfPropertyChange(() => ProfileModels); + if (Equals(value, _profiles)) return; + _profiles = value; + NotifyOfPropertyChange(() => Profiles); } } @@ -101,7 +101,7 @@ namespace Artemis.ViewModels { get { - if (_selectedProfile == null) + if (_selectedProfile == null || ActiveKeyboard == null) return null; var keyboardRect = ActiveKeyboard.KeyboardRectangle(4); @@ -112,18 +112,21 @@ namespace Artemis.ViewModels drawingContext.PushClip(new RectangleGeometry(keyboardRect)); drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, keyboardRect); - // Get the selection color - var penColor = (Color)ThemeManager.DetectAppStyle(Application.Current).Item2.Resources["AccentColor"]; - var pen = new Pen(new SolidColorBrush(penColor), 0.4); - - // Draw the layer + // Draw the layers foreach (var layerModel in _selectedProfile.Layers) - { layerModel.DrawPreview(drawingContext); - if (layerModel != SelectedLayer || !layerModel.Enabled) - continue; - - var layerRect = layerModel.UserProps.GetRect(); + + // Get the selection color + var color = (Color) ThemeManager.DetectAppStyle(Application.Current).Item2.Resources["AccentColor"]; + var pen = new Pen(new SolidColorBrush(color), 0.4); + + // Draw the selection outline and resize indicator + if (SelectedLayer != null && SelectedLayer.Enabled) + { + var layerRect = SelectedLayer.UserProps.GetRect(); + // Deflate the rect so that the border is drawn on the inside + layerRect.Inflate(-0.2, -0.2); + // Draw an outline around the selected layer drawingContext.DrawRectangle(null, pen, layerRect); // Draw a resize indicator in the bottom-right @@ -153,7 +156,7 @@ namespace Artemis.ViewModels { using (var memory = new MemoryStream()) { - if (ActiveKeyboard?.PreviewSettings == null || ActiveKeyboard?.PreviewSettings.Image == null) + if (ActiveKeyboard?.PreviewSettings.Image == null) return null; ActiveKeyboard.PreviewSettings.Image.Save(memory, ImageFormat.Png); memory.Position = 0; @@ -194,23 +197,21 @@ namespace Artemis.ViewModels private void PreviewRefresher(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName == "SelectedLayer" || e.PropertyName == "ProfileTree") + if (e.PropertyName != "KeyboardPreview") NotifyOfPropertyChange(() => KeyboardPreview); } private void LoadProfiles() { - ProfileModels.Clear(); - ProfileModels.AddRange(ProfileProvider.GetAll(_gameModel)); - SelectedProfile = ProfileModels.FirstOrDefault(); + Profiles.Clear(); + Profiles.AddRange(ProfileProvider.GetAll(_gameModel)); + SelectedProfile = Profiles.FirstOrDefault(); } public async void AddProfile() { - var name = - await - _mainManager.DialogService.ShowInputDialog("Add new profile", - "Please provide a profile name unique to this game and keyboard."); + var name = await _mainManager.DialogService.ShowInputDialog("Add new profile", + "Please provide a profile name unique to this game and keyboard."); if (name.Length < 1) { _mainManager.DialogService.ShowMessageBox("Invalid profile name", "Please provide a valid profile name"); @@ -223,12 +224,11 @@ namespace Artemis.ViewModels KeyboardName = ActiveKeyboard.Name, GameName = _gameModel.Name }; + if (ProfileProvider.GetAll().Contains(profile)) { - var overwrite = - await - _mainManager.DialogService.ShowQuestionMessageBox("Overwrite existing profile", - "A profile with this name already exists for this game. Would you like to overwrite it?"); + var overwrite = await _mainManager.DialogService.ShowQuestionMessageBox("Overwrite existing profile", + "A profile with this name already exists for this game. Would you like to overwrite it?"); if (!overwrite.Value) return; } @@ -247,8 +247,7 @@ namespace Artemis.ViewModels public void LayerEditor(LayerModel layer) { IWindowManager manager = new WindowManager(); - _editorVm = new LayerEditorViewModel(ActiveKeyboard, SelectedProfile, - layer); + _editorVm = new LayerEditorViewModel(ActiveKeyboard, SelectedProfile, layer); dynamic settings = new ExpandoObject(); settings.Title = "Artemis | Edit " + layer.Name; @@ -258,7 +257,6 @@ namespace Artemis.ViewModels public void SetSelectedLayer(LayerModel layer) { SelectedLayer = layer; - NotifyOfPropertyChange(() => KeyboardPreview); } public void AddLayer() @@ -266,23 +264,19 @@ namespace Artemis.ViewModels if (_selectedProfile == null) return; - var layer = new LayerModel - { - Name = "Layer " + (_selectedProfile.Layers.Count + 1), - LayerType = LayerType.KeyboardRectangle, - UserProps = new LayerPropertiesModel - { - Brush = new SolidColorBrush(Colors.Red), - Animation = LayerAnimation.None, - Height = 1, - Width = 1, - X = 0, - Y = 0, - Opacity = 1 - } - }; - SelectedProfile.Layers.Add(layer); + var layer = SelectedProfile.AddLayer(); Layers.Add(layer); + + SelectedLayer = layer; + } + + public void RemoveLayer() + { + if (_selectedProfile == null || _selectedLayer == null) + return; + + SelectedProfile.Layers.Remove(_selectedLayer); + Layers.Remove(_selectedLayer); } public void MouseDownKeyboardPreview(MouseButtonEventArgs e) @@ -294,17 +288,17 @@ namespace Artemis.ViewModels public void MouseUpKeyboardPreview(MouseButtonEventArgs e) { var timeSinceDown = DateTime.Now - _downTime; - if (timeSinceDown.TotalMilliseconds < 500) - { - var pos = e.GetPosition((Image) e.OriginalSource); - var x = pos.X/((double) ActiveKeyboard.PreviewSettings.Width/ActiveKeyboard.Width); - var y = pos.Y/((double) ActiveKeyboard.PreviewSettings.Height/ActiveKeyboard.Height); + if (!(timeSinceDown.TotalMilliseconds < 500)) + return; - var hoverLayer = SelectedProfile.Layers.Where(l => l.Enabled) - .FirstOrDefault(l => l.UserProps.GetRect(1).Contains(x, y)); - if (hoverLayer != null) - SelectedLayer = hoverLayer; - } + var pos = e.GetPosition((Image) e.OriginalSource); + var x = pos.X/((double) ActiveKeyboard.PreviewSettings.Width/ActiveKeyboard.Width); + var y = pos.Y/((double) ActiveKeyboard.PreviewSettings.Height/ActiveKeyboard.Height); + + var hoverLayer = SelectedProfile.Layers.Where(l => l.Enabled) + .FirstOrDefault(l => l.UserProps.GetRect(1).Contains(x, y)); + if (hoverLayer != null) + SelectedLayer = hoverLayer; } public void MouseMoveKeyboardPreview(MouseEventArgs e) @@ -327,11 +321,11 @@ namespace Artemis.ViewModels // Turn the mouse pointer into a hand if hovering over an active layer if (hoverLayer == SelectedLayer) { - var layerRect = hoverLayer.UserProps.GetRect(1); - if (Math.Sqrt(Math.Pow(x - layerRect.BottomRight.X, 2) + Math.Pow(y - layerRect.BottomRight.Y, 2)) < 0.6) - KeyboardPreviewCursor = Cursors.SizeNWSE; - else - KeyboardPreviewCursor = Cursors.SizeAll; + var rect = hoverLayer.UserProps.GetRect(1); + KeyboardPreviewCursor = + Math.Sqrt(Math.Pow(x - rect.BottomRight.X, 2) + Math.Pow(y - rect.BottomRight.Y, 2)) < 0.6 + ? Cursors.SizeNWSE + : Cursors.SizeAll; } else KeyboardPreviewCursor = Cursors.Hand; @@ -358,16 +352,16 @@ namespace Artemis.ViewModels _draggingLayerOffset = new Point(x - SelectedLayer.UserProps.X, y - SelectedLayer.UserProps.Y); _draggingLayer = hoverLayer; if (Math.Sqrt(Math.Pow(x - layerRect.BottomRight.X, 2) + Math.Pow(y - layerRect.BottomRight.Y, 2)) < 0.6) - _resizeSourceRect = true; + _resizing = true; else - _resizeSourceRect = false; + _resizing = false; } if (_draggingLayerOffset == null || _draggingLayer == null || (_draggingLayer != SelectedLayer)) return; // If no setup or reset was done, handle the actual dragging action - if (_resizeSourceRect) + if (_resizing) { _draggingLayer.UserProps.Width = (int) Math.Round(x - _draggingLayer.UserProps.X); _draggingLayer.UserProps.Height = (int) Math.Round(y - _draggingLayer.UserProps.Y); diff --git a/Artemis/Artemis/Views/ProfileEditorView.xaml b/Artemis/Artemis/Views/ProfileEditorView.xaml index a6ea8ed89..76061656c 100644 --- a/Artemis/Artemis/Views/ProfileEditorView.xaml +++ b/Artemis/Artemis/Views/ProfileEditorView.xaml @@ -3,8 +3,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:Artemis.Views" - xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls" xmlns:cal="http://www.caliburnproject.org" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:itemBehaviours="clr-namespace:Artemis.ItemBehaviours" @@ -28,13 +26,10 @@ - - -