From 30662036a42b3d44446f39c444a6e82b9ba4fc91 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Thu, 17 Nov 2016 18:48:44 +0100 Subject: [PATCH 01/17] Another for #198 because I suck --- Artemis/Artemis/Dialogs/MarkdownDialog.xaml.cs | 2 -- Artemis/Artemis/Services/MetroDialogService.cs | 14 ++++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Artemis/Artemis/Dialogs/MarkdownDialog.xaml.cs b/Artemis/Artemis/Dialogs/MarkdownDialog.xaml.cs index 3d6b1d7e6..3b9c69bed 100644 --- a/Artemis/Artemis/Dialogs/MarkdownDialog.xaml.cs +++ b/Artemis/Artemis/Dialogs/MarkdownDialog.xaml.cs @@ -16,8 +16,6 @@ namespace Artemis.Dialogs public static readonly DependencyProperty MarkdownProperty = DependencyProperty.Register("Markdown", typeof(string), typeof(MarkdownDialog), new PropertyMetadata(default(string))); - - public MarkdownDialog(MetroWindow parentWindow) { ParentWindow = parentWindow; diff --git a/Artemis/Artemis/Services/MetroDialogService.cs b/Artemis/Artemis/Services/MetroDialogService.cs index 2591e7a0a..ea3ad5686 100644 --- a/Artemis/Artemis/Services/MetroDialogService.cs +++ b/Artemis/Artemis/Services/MetroDialogService.cs @@ -60,13 +60,15 @@ namespace Artemis.Services if (window == null) return; - var dialog = new MarkdownDialog(window) + window.Dispatcher.Invoke(() => { - Markdown = markdown, - Title = title - }; - - window.Dispatcher.Invoke(() => window.ShowMetroDialogAsync(dialog)); + var dialog = new MarkdownDialog(window) + { + Markdown = markdown, + Title = title + }; + return window.ShowMetroDialogAsync(dialog); + }); } public override async Task ShowQuestionMessageBox(string title, string message) From 1330b547d7ff1d04ddb93429b40de84f5dca7e25 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Thu, 17 Nov 2016 23:32:32 +0100 Subject: [PATCH 02/17] Fix Strafe rendering --- .../Corsair/CorsairKeyboards.cs | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs index a1840dcbe..530bc88b4 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs @@ -100,28 +100,30 @@ namespace Artemis.DeviceProviders.Corsair /// public override void DrawBitmap(Bitmap bitmap) { - var image = ImageUtilities.ResizeImage(bitmap, Width, Height); - - // For STRAFE, stretch the image on row 2. - if (_keyboard.DeviceInfo.Model == "STRAFE RGB") + using (var image = ImageUtilities.ResizeImage(bitmap, Width, Height)) { - using (var strafeBitmap = new Bitmap(22, 8)) + // For STRAFE, stretch the image on row 2. + if (_keyboard.DeviceInfo.Model == "STRAFE RGB") { - using (var g = Graphics.FromImage(strafeBitmap)) + using (var strafeBitmap = new Bitmap(22, 8)) { - g.DrawImage(image, new Point(0, 0)); - g.DrawImage(image, new Rectangle(0, 3, 22, 7), new Rectangle(0, 2, 22, 7), GraphicsUnit.Pixel); - } + using (var g = Graphics.FromImage(strafeBitmap)) + { + g.DrawImage(image, new Point(0, 0)); + g.DrawImage(image, new Rectangle(0, 3, 22, 7), new Rectangle(0, 2, 22, 7), + GraphicsUnit.Pixel); - image.Dispose(); - image = strafeBitmap; + _keyboardBrush.Image = strafeBitmap; + _keyboard.Update(); + } + } + } + else + { + _keyboardBrush.Image = image; + _keyboard.Update(); } } - - _keyboardBrush.Image = image; - _keyboard.Update(); - - image.Dispose(); } public override KeyMatch? GetKeyPosition(Keys keyCode) @@ -144,7 +146,7 @@ namespace Artemis.DeviceProviders.Corsair return null; var center = cueLed.LedRectangle.GetCenter(); - return new KeyMatch(keyCode, (int) (center.X*widthMultiplier),(int) (center.Y*heightMultiplier)); + return new KeyMatch(keyCode, (int) (center.X*widthMultiplier), (int) (center.Y*heightMultiplier)); } } } \ No newline at end of file From 590d6991feac50a7927288b3c9f020d0c752c612 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Sun, 20 Nov 2016 10:13:59 +0100 Subject: [PATCH 03/17] Fixed crash on WebServer start failure for #200 Added Sombra (and Ana) for #201 --- .../Modules/Games/Overwatch/OverwatchDataModel.cs | 4 +++- .../Modules/Games/Overwatch/OverwatchModel.cs | 15 ++++++++++----- Artemis/Artemis/Properties/AssemblyInfo.cs | 4 ++-- .../Utilities/GameState/GameStateWebServer.cs | 4 ++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Artemis/Artemis/Modules/Games/Overwatch/OverwatchDataModel.cs b/Artemis/Artemis/Modules/Games/Overwatch/OverwatchDataModel.cs index 5d0353154..4a0cdd3a1 100644 --- a/Artemis/Artemis/Modules/Games/Overwatch/OverwatchDataModel.cs +++ b/Artemis/Artemis/Modules/Games/Overwatch/OverwatchDataModel.cs @@ -46,6 +46,8 @@ namespace Artemis.Modules.Games.Overwatch Lúcio, Mercy, Symmetra, - Zenyatta + Zenyatta, + Ana, + Sombra } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/Overwatch/OverwatchModel.cs b/Artemis/Artemis/Modules/Games/Overwatch/OverwatchModel.cs index 45bd862fc..e2dfab716 100644 --- a/Artemis/Artemis/Modules/Games/Overwatch/OverwatchModel.cs +++ b/Artemis/Artemis/Modules/Games/Overwatch/OverwatchModel.cs @@ -10,14 +10,16 @@ using Artemis.Profiles.Layers.Models; using Artemis.Services; using Artemis.Utilities; using Artemis.Utilities.DataReaders; +using Artemis.ViewModels; using Microsoft.Win32; namespace Artemis.Modules.Games.Overwatch { public class OverwatchModel : GameModel { - private readonly PipeServer _pipeServer; + private readonly DebugViewModel _debugViewModel; private readonly MetroDialogService _dialogService; + private readonly PipeServer _pipeServer; private DateTime _characterChange; private string _lastMessage; // Using sticky values on these since they can cause flickering @@ -27,11 +29,13 @@ namespace Artemis.Modules.Games.Overwatch private DateTime _ultimateReady; private DateTime _ultimateUsed; - public OverwatchModel(DeviceManager deviceManager, PipeServer pipeServer, MetroDialogService dialogService) + public OverwatchModel(DeviceManager deviceManager, PipeServer pipeServer, MetroDialogService dialogService, + DebugViewModel debugViewModel) : base(deviceManager, SettingsProvider.Load(), new OverwatchDataModel()) { _pipeServer = pipeServer; _dialogService = dialogService; + _debugViewModel = debugViewModel; Name = "Overwatch"; ProcessName = "Overwatch"; Scale = 4; @@ -70,7 +74,9 @@ namespace Artemis.Modules.Games.Overwatch new CharacterColor {Character = OverwatchCharacter.Lúcio, Color = Color.FromRgb(34, 142, 2)}, new CharacterColor {Character = OverwatchCharacter.Mercy, Color = Color.FromRgb(243, 226, 106)}, new CharacterColor {Character = OverwatchCharacter.Symmetra, Color = Color.FromRgb(46, 116, 148)}, - new CharacterColor {Character = OverwatchCharacter.Zenyatta, Color = Color.FromRgb(248, 218, 26)} + new CharacterColor {Character = OverwatchCharacter.Zenyatta, Color = Color.FromRgb(248, 218, 26)}, + new CharacterColor {Character = OverwatchCharacter.Ana, Color = Color.FromRgb(16, 36, 87)}, + new CharacterColor {Character = OverwatchCharacter.Sombra, Color = Color.FromRgb(20, 5, 101)} }; } @@ -127,8 +133,7 @@ namespace Artemis.Modules.Games.Overwatch if (colors == null) return; - // TODO: Get the debug viewmodel and update the color array - //_events.PublishOnUIThread(new RazerColorArrayChanged(colors)); + _debugViewModel.UpdateRazerDisplay(colors); // Determine general game state ParseGameSate(gameDataModel, colors); diff --git a/Artemis/Artemis/Properties/AssemblyInfo.cs b/Artemis/Artemis/Properties/AssemblyInfo.cs index dfbd5b140..a7dab2921 100644 --- a/Artemis/Artemis/Properties/AssemblyInfo.cs +++ b/Artemis/Artemis/Properties/AssemblyInfo.cs @@ -53,8 +53,8 @@ using System.Windows; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.0.2")] -[assembly: AssemblyFileVersion("1.5.0.2")] +[assembly: AssemblyVersion("1.5.0.4")] +[assembly: AssemblyFileVersion("1.5.0.4")] [assembly: InternalsVisibleTo("Artemis.Tests")] [assembly: InternalsVisibleTo("Artemis.Explorables")] diff --git a/Artemis/Artemis/Utilities/GameState/GameStateWebServer.cs b/Artemis/Artemis/Utilities/GameState/GameStateWebServer.cs index 85dd34ed5..f8b4e5bae 100644 --- a/Artemis/Artemis/Utilities/GameState/GameStateWebServer.cs +++ b/Artemis/Artemis/Utilities/GameState/GameStateWebServer.cs @@ -49,9 +49,9 @@ namespace Artemis.Utilities.GameState { _listener.Start(); } - catch (HttpListenerException e) + catch (Exception e) { - _logger.Error(e, "Couldn't start the webserver on port {0}.", Port); + _logger.Error(e, "Couldn't start the webserver on port {0}. Try selecting a different port", Port); Running = false; return; } From 33094731aabbb55ef05d9c567617fce86267a479 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Wed, 30 Nov 2016 14:43:20 +0100 Subject: [PATCH 04/17] Simplified layer render pipeline --- .../Layers/Animations/GrowAnimation.cs | 32 ++- .../Layers/Animations/NoneAnimation.cs | 4 +- .../Layers/Animations/PulseAnimation.cs | 32 ++- .../Layers/Animations/SlideDownAnimation.cs | 31 +-- .../Layers/Animations/SlideLeftAnimation.cs | 30 +-- .../Layers/Animations/SlideRightAnimation.cs | 31 +-- .../Layers/Animations/SlideUpAnimation.cs | 27 ++- .../Layers/Conditions/DataModelCondition.cs | 6 +- .../Layers/Conditions/EventCondition.cs | 14 +- .../Layers/Interfaces/ILayerAnimation.cs | 4 +- .../Layers/Interfaces/ILayerCondition.cs | 2 +- .../Profiles/Layers/Interfaces/ILayerType.cs | 10 +- .../Layers/Models/DynamicPropertiesModel.cs | 58 +++--- .../Layers/Models/EventPropertiesModel.cs | 8 +- .../Profiles/Layers/Models/LayerModel.cs | 194 ++++++++++++++---- .../Layers/Models/LayerPropertiesModel.cs | 5 +- .../Types/AmbientLight/AmbientLightType.cs | 12 +- .../Profiles/Layers/Types/Audio/AudioType.cs | 10 +- .../Layers/Types/Folder/FolderType.cs | 2 +- .../Layers/Types/Generic/GenericType.cs | 24 +-- .../Layers/Types/Headset/HeadsetType.cs | 22 +- .../Layers/Types/KeyPress/KeyPressType.cs | 4 +- .../Layers/Types/Keyboard/KeyboardType.cs | 36 ++-- .../Types/KeyboardGif/KeyboardGifType.cs | 31 ++- .../Profiles/Layers/Types/Mouse/MouseType.cs | 22 +- .../Layers/Types/Mousemat/MousematType.cs | 25 +-- .../Artemis/Profiles/Lua/LuaLayerWrapper.cs | 116 ++++++++--- .../ViewModels/Profiles/ProfileViewModel.cs | 10 +- 28 files changed, 464 insertions(+), 338 deletions(-) diff --git a/Artemis/Artemis/Profiles/Layers/Animations/GrowAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/GrowAnimation.cs index 56cd8958d..0d5144150 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/GrowAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/GrowAnimation.cs @@ -1,5 +1,4 @@ using System; -using System.Windows; using System.Windows.Media; using Artemis.Profiles.Layers.Interfaces; using Artemis.Profiles.Layers.Models; @@ -8,16 +7,16 @@ namespace Artemis.Profiles.Layers.Animations { public class GrowAnimation : ILayerAnimation { - public string Name { get; } = "Grow"; + public string Name => "Grow"; public void Update(LayerModel layerModel, bool updateAnimations) { // TODO: Generic implementation // Reset animation progress if layer wasn't drawn for 100ms if ((new TimeSpan(0, 0, 0, 0, 100) < DateTime.Now - layerModel.LastRender) && updateAnimations) - layerModel.Properties.AnimationProgress = 0; + layerModel.AnimationProgress = 0; - var progress = layerModel.Properties.AnimationProgress; + var progress = layerModel.AnimationProgress; if (MustExpire(layerModel)) progress = 0; @@ -25,43 +24,42 @@ namespace Artemis.Profiles.Layers.Animations // If not previewing, store the animation progress in the actual model for the next frame if (updateAnimations) - layerModel.Properties.AnimationProgress = progress; + layerModel.AnimationProgress = progress; } - public void Draw(LayerPropertiesModel props, LayerPropertiesModel applied, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { - if (applied?.Brush == null) + if (layerModel.Brush == null) return; - const int scale = 4; // Set up variables for this frame - var rect = applied.Contain - ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale) - : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale); + var rect = layerModel.Properties.Contain + ? layerModel.LayerRect() + : layerModel.Properties.PropertiesRect(); - var clip = new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale); + var clip = layerModel.LayerRect(); // Take an offset of 4 to allow layers to slightly leave their bounds - var progress = (6.0 - props.AnimationProgress)*10.0; + var progress = (6.0 - layerModel.AnimationProgress)*10.0; if (progress < 0) { // Can't meddle with the original brush because it's frozen. - var brush = applied.Brush.Clone(); + var brush = layerModel.Brush.Clone(); brush.Opacity = 1 + 0.025*progress; if (brush.Opacity < 0) brush.Opacity = 0; if (brush.Opacity > 1) brush.Opacity = 1; - applied.Brush = brush; + layerModel.Brush = brush; } rect.Inflate(-rect.Width/100.0*progress, -rect.Height/100.0*progress); clip.Inflate(-clip.Width/100.0*progress, -clip.Height/100.0*progress); c.PushClip(new RectangleGeometry(clip)); - c.DrawRectangle(applied.Brush, null, rect); + c.DrawRectangle(layerModel.Brush, null, rect); c.Pop(); } - public bool MustExpire(LayerModel layer) => layer.Properties.AnimationProgress > 10; + public bool MustExpire(LayerModel layer) => layer.AnimationProgress > 10; } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Animations/NoneAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/NoneAnimation.cs index 3bbe7d9d1..0d0e759ea 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/NoneAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/NoneAnimation.cs @@ -6,13 +6,13 @@ namespace Artemis.Profiles.Layers.Animations { public class NoneAnimation : ILayerAnimation { - public string Name { get; } = "None"; + public string Name => "None"; public void Update(LayerModel layerModel, bool updateAnimations) { } - public void Draw(LayerPropertiesModel props, LayerPropertiesModel applied, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { } diff --git a/Artemis/Artemis/Profiles/Layers/Animations/PulseAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/PulseAnimation.cs index ee7c0a131..669452134 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/PulseAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/PulseAnimation.cs @@ -1,5 +1,4 @@ using System; -using System.Windows; using System.Windows.Media; using Artemis.Profiles.Layers.Interfaces; using Artemis.Profiles.Layers.Models; @@ -8,16 +7,16 @@ namespace Artemis.Profiles.Layers.Animations { public class PulseAnimation : ILayerAnimation { - public string Name { get; } = "Pulse"; + public string Name => "Pulse"; public void Update(LayerModel layerModel, bool updateAnimations) { // TODO: Generic implementation // Reset animation progress if layer wasn't drawn for 100ms if ((new TimeSpan(0, 0, 0, 0, 100) < DateTime.Now - layerModel.LastRender) && updateAnimations) - layerModel.Properties.AnimationProgress = 0; + layerModel.AnimationProgress = 0; - var progress = layerModel.Properties.AnimationProgress; + var progress = layerModel.AnimationProgress; if (MustExpire(layerModel)) progress = 0; @@ -25,32 +24,31 @@ namespace Artemis.Profiles.Layers.Animations // If not previewing, store the animation progress in the actual model for the next frame if (updateAnimations) - layerModel.Properties.AnimationProgress = progress; + layerModel.AnimationProgress = progress; } - public void Draw(LayerPropertiesModel props, LayerPropertiesModel applied, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { - if (applied.Brush == null) + if (layerModel.Brush == null) return; - const int scale = 4; // Set up variables for this frame - var rect = applied.Contain - ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale) - : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale); + var rect = layerModel.Properties.Contain + ? layerModel.LayerRect() + : layerModel.Properties.PropertiesRect(); - var clip = new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale); + var clip = layerModel.LayerRect(); // Can't meddle with the original brush because it's frozen. - var brush = applied.Brush.Clone(); - brush.Opacity = (Math.Sin(props.AnimationProgress*Math.PI) + 1)*(props.Opacity/2); - applied.Brush = brush; + var brush = layerModel.Brush.Clone(); + brush.Opacity = (Math.Sin(layerModel.AnimationProgress*Math.PI) + 1)*(layerModel.Opacity/2); + layerModel.Brush = brush; c.PushClip(new RectangleGeometry(clip)); - c.DrawRectangle(applied.Brush, null, rect); + c.DrawRectangle(layerModel.Brush, null, rect); c.Pop(); } - public bool MustExpire(LayerModel layer) => layer.Properties.AnimationProgress > 2; + public bool MustExpire(LayerModel layer) => layer.AnimationProgress > 2; } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Animations/SlideDownAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/SlideDownAnimation.cs index 23b176656..81a7cbca8 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/SlideDownAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/SlideDownAnimation.cs @@ -7,45 +7,46 @@ namespace Artemis.Profiles.Layers.Animations { public class SlideDownAnimation : ILayerAnimation { - public string Name { get; } = "Slide down"; + public string Name => "Slide down"; public void Update(LayerModel layerModel, bool updateAnimations) { - var progress = layerModel.Properties.AnimationProgress; + var progress = layerModel.AnimationProgress; if (MustExpire(layerModel)) progress = 0; progress = progress + layerModel.Properties.AnimationSpeed*2; // If not previewing, store the animation progress in the actual model for the next frame if (updateAnimations) - layerModel.Properties.AnimationProgress = progress; + layerModel.AnimationProgress = progress; } - public void Draw(LayerPropertiesModel props, LayerPropertiesModel applied, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { - if (applied.Brush == null) + if (layerModel.Brush == null) return; - const int scale = 4; // Set up variables for this frame - var rect = applied.Contain - ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale) - : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale); + var rect = layerModel.Properties.Contain + ? layerModel.LayerRect() + : layerModel.Properties.PropertiesRect(); - var s1 = new Rect(new Point(rect.X, rect.Y + props.AnimationProgress), new Size(rect.Width, rect.Height)); - var s2 = new Rect(new Point(s1.X, s1.Y - rect.Height), new Size(rect.Width, rect.Height + .5)); + var s1 = new Rect(new Point(rect.X, rect.Y + layerModel.AnimationProgress), + new Size(rect.Width, rect.Height)); + var s2 = new Rect(new Point(s1.X, s1.Y - rect.Height), + new Size(rect.Width, rect.Height + .5)); - var clip = new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale); + var clip = layerModel.LayerRect(); c.PushClip(new RectangleGeometry(clip)); - c.DrawRectangle(applied.Brush, null, s1); - c.DrawRectangle(applied.Brush, null, s2); + c.DrawRectangle(layerModel.Brush, null, s1); + c.DrawRectangle(layerModel.Brush, null, s2); c.Pop(); } public bool MustExpire(LayerModel layer) { - return layer.Properties.AnimationProgress + layer.Properties.AnimationSpeed*2 >= layer.Properties.Height*4; + return layer.AnimationProgress + layer.Properties.AnimationSpeed*2 >= layer.Properties.Height*4; } } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Animations/SlideLeftAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/SlideLeftAnimation.cs index 7394deee4..8f64ddae0 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/SlideLeftAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/SlideLeftAnimation.cs @@ -7,46 +7,46 @@ namespace Artemis.Profiles.Layers.Animations { public class SlideLeftAnimation : ILayerAnimation { - public string Name { get; } = "Slide left"; + public string Name => "Slide left"; public void Update(LayerModel layerModel, bool updateAnimations) { - var progress = layerModel.Properties.AnimationProgress; + var progress = layerModel.AnimationProgress; if (MustExpire(layerModel)) progress = 0; progress = progress + layerModel.Properties.AnimationSpeed*2; // If not previewing, store the animation progress in the actual model for the next frame if (updateAnimations) - layerModel.Properties.AnimationProgress = progress; + layerModel.AnimationProgress = progress; } - public void Draw(LayerPropertiesModel props, LayerPropertiesModel applied, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { - if (applied.Brush == null) + if (layerModel.Brush == null) return; - const int scale = 4; // Set up variables for this frame - var rect = applied.Contain - ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale) - : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale); + var rect = layerModel.Properties.Contain + ? layerModel.LayerRect() + : layerModel.Properties.PropertiesRect(); - var s1 = new Rect(new Point(rect.X - props.AnimationProgress, rect.Y), + var s1 = new Rect(new Point(rect.X - layerModel.AnimationProgress, rect.Y), new Size(rect.Width + .5, rect.Height)); - var s2 = new Rect(new Point(s1.X + rect.Width, rect.Y), new Size(rect.Width, rect.Height)); + var s2 = new Rect(new Point(s1.X + rect.Width, rect.Y), + new Size(rect.Width, rect.Height)); - var clip = new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale); + var clip = layerModel.LayerRect(); c.PushClip(new RectangleGeometry(clip)); - c.DrawRectangle(applied.Brush, null, s1); - c.DrawRectangle(applied.Brush, null, s2); + c.DrawRectangle(layerModel.Brush, null, s1); + c.DrawRectangle(layerModel.Brush, null, s2); c.Pop(); } public bool MustExpire(LayerModel layer) { - return layer.Properties.AnimationProgress + layer.Properties.AnimationSpeed*2 >= layer.Properties.Width*4; + return layer.AnimationProgress + layer.Properties.AnimationSpeed*2 >= layer.Properties.Width*4; } } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Animations/SlideRightAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/SlideRightAnimation.cs index 83352d26c..6f99d7b3e 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/SlideRightAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/SlideRightAnimation.cs @@ -7,45 +7,46 @@ namespace Artemis.Profiles.Layers.Animations { public class SlideRightAnimation : ILayerAnimation { - public string Name { get; } = "Slide right"; + public string Name => "Slide right"; public void Update(LayerModel layerModel, bool updateAnimations) { - var progress = layerModel.Properties.AnimationProgress; + var progress = layerModel.AnimationProgress; if (MustExpire(layerModel)) progress = 0; progress = progress + layerModel.Properties.AnimationSpeed*2; // If not previewing, store the animation progress in the actual model for the next frame if (updateAnimations) - layerModel.Properties.AnimationProgress = progress; + layerModel.AnimationProgress = progress; } - public void Draw(LayerPropertiesModel props, LayerPropertiesModel applied, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { - if (applied.Brush == null) + if (layerModel.Brush == null) return; - const int scale = 4; // Set up variables for this frame - var rect = applied.Contain - ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale) - : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale); + var rect = layerModel.Properties.Contain + ? layerModel.LayerRect() + : layerModel.Properties.PropertiesRect(); - var s1 = new Rect(new Point(rect.X + props.AnimationProgress, rect.Y), new Size(rect.Width, rect.Height)); - var s2 = new Rect(new Point(s1.X - rect.Width, rect.Y), new Size(rect.Width + .5, rect.Height)); + var s1 = new Rect(new Point(rect.X + layerModel.AnimationProgress, rect.Y), + new Size(rect.Width, rect.Height)); + var s2 = new Rect(new Point(s1.X - rect.Width, rect.Y), + new Size(rect.Width + .5, rect.Height)); - var clip = new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale); + var clip = layerModel.LayerRect(); c.PushClip(new RectangleGeometry(clip)); - c.DrawRectangle(applied.Brush, null, s1); - c.DrawRectangle(applied.Brush, null, s2); + c.DrawRectangle(layerModel.Brush, null, s1); + c.DrawRectangle(layerModel.Brush, null, s2); c.Pop(); } public bool MustExpire(LayerModel layer) { - return layer.Properties.AnimationProgress + layer.Properties.AnimationSpeed*2 >= layer.Properties.Width*4; + return layer.AnimationProgress + layer.Properties.AnimationSpeed*2 >= layer.Properties.Width*4; } } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Animations/SlideUpAnimation.cs b/Artemis/Artemis/Profiles/Layers/Animations/SlideUpAnimation.cs index 651fb88b2..14de66902 100644 --- a/Artemis/Artemis/Profiles/Layers/Animations/SlideUpAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Animations/SlideUpAnimation.cs @@ -7,46 +7,45 @@ namespace Artemis.Profiles.Layers.Animations { public class SlideUpAnimation : ILayerAnimation { - public string Name { get; } = "Slide up"; + public string Name => "Slide up"; public void Update(LayerModel layerModel, bool updateAnimations) { - var progress = layerModel.Properties.AnimationProgress; + var progress = layerModel.AnimationProgress; if (MustExpire(layerModel)) progress = 0; progress = progress + layerModel.Properties.AnimationSpeed*2; // If not previewing, store the animation progress in the actual model for the next frame if (updateAnimations) - layerModel.Properties.AnimationProgress = progress; + layerModel.AnimationProgress = progress; } - public void Draw(LayerPropertiesModel props, LayerPropertiesModel applied, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { - if (applied.Brush == null) + if (layerModel.Brush == null) return; - const int scale = 4; // Set up variables for this frame - var rect = applied.Contain - ? new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale) - : new Rect(props.X*scale, props.Y*scale, props.Width*scale, props.Height*scale); + var rect = layerModel.Properties.Contain + ? layerModel.LayerRect() + : layerModel.Properties.PropertiesRect(); - var s1 = new Rect(new Point(rect.X, rect.Y - props.AnimationProgress), + var s1 = new Rect(new Point(rect.X, rect.Y - layerModel.AnimationProgress), new Size(rect.Width, rect.Height + .5)); var s2 = new Rect(new Point(s1.X, s1.Y + rect.Height), new Size(rect.Width, rect.Height)); - var clip = new Rect(applied.X*scale, applied.Y*scale, applied.Width*scale, applied.Height*scale); + var clip = layerModel.LayerRect(); c.PushClip(new RectangleGeometry(clip)); - c.DrawRectangle(applied.Brush, null, s1); - c.DrawRectangle(applied.Brush, null, s2); + c.DrawRectangle(layerModel.Brush, null, s1); + c.DrawRectangle(layerModel.Brush, null, s2); c.Pop(); } public bool MustExpire(LayerModel layer) { - return layer.Properties.AnimationProgress + layer.Properties.AnimationSpeed*2 >= layer.Properties.Height*4; + return layer.AnimationProgress + layer.Properties.AnimationSpeed*2 >= layer.Properties.Height*4; } } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Conditions/DataModelCondition.cs b/Artemis/Artemis/Profiles/Layers/Conditions/DataModelCondition.cs index ec73555e0..3572d0e74 100644 --- a/Artemis/Artemis/Profiles/Layers/Conditions/DataModelCondition.cs +++ b/Artemis/Artemis/Profiles/Layers/Conditions/DataModelCondition.cs @@ -7,11 +7,11 @@ namespace Artemis.Profiles.Layers.Conditions { public class DataModelCondition : ILayerCondition { - public bool ConditionsMet(LayerModel layer, IDataModel dataModel) + public bool ConditionsMet(LayerModel layerModel, IDataModel dataModel) { - lock (layer.Properties.Conditions) + lock (layerModel.Properties.Conditions) { - return layer.Properties.Conditions.All(cm => cm.ConditionMet(dataModel)); + return layerModel.Properties.Conditions.All(cm => cm.ConditionMet(dataModel)); } } } diff --git a/Artemis/Artemis/Profiles/Layers/Conditions/EventCondition.cs b/Artemis/Artemis/Profiles/Layers/Conditions/EventCondition.cs index 0f2ae4d53..04ea65aa8 100644 --- a/Artemis/Artemis/Profiles/Layers/Conditions/EventCondition.cs +++ b/Artemis/Artemis/Profiles/Layers/Conditions/EventCondition.cs @@ -7,17 +7,17 @@ namespace Artemis.Profiles.Layers.Conditions { public class EventCondition : ILayerCondition { - public bool ConditionsMet(LayerModel layer, IDataModel dataModel) + public bool ConditionsMet(LayerModel layerModel, IDataModel dataModel) { - lock (layer.Properties.Conditions) + lock (layerModel.Properties.Conditions) { - var conditionsMet = layer.Properties.Conditions.All(cm => cm.ConditionMet(dataModel)); - layer.EventProperties.Update(layer, conditionsMet); + var conditionsMet = layerModel.Properties.Conditions.All(cm => cm.ConditionMet(dataModel)); + layerModel.EventProperties.Update(layerModel, conditionsMet); - if (conditionsMet && layer.EventProperties.CanTrigger) - layer.EventProperties.TriggerEvent(layer); + if (conditionsMet && layerModel.EventProperties.CanTrigger) + layerModel.EventProperties.TriggerEvent(layerModel); - return layer.EventProperties.MustDraw; + return layerModel.EventProperties.MustDraw; } } } diff --git a/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerAnimation.cs b/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerAnimation.cs index e5554a8d3..f5d1c45c0 100644 --- a/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerAnimation.cs +++ b/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerAnimation.cs @@ -10,7 +10,7 @@ namespace Artemis.Profiles.Layers.Interfaces string Name { get; } void Update(LayerModel layerModel, bool updateAnimations); - void Draw(LayerPropertiesModel props, LayerPropertiesModel applied, DrawingContext c); - bool MustExpire(LayerModel layer); + void Draw(LayerModel layerModel, DrawingContext c); + bool MustExpire(LayerModel layerModel); } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerCondition.cs b/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerCondition.cs index 56588ad8d..8fd7422ae 100644 --- a/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerCondition.cs +++ b/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerCondition.cs @@ -5,6 +5,6 @@ namespace Artemis.Profiles.Layers.Interfaces { public interface ILayerCondition { - bool ConditionsMet(LayerModel layer, IDataModel dataModel); + bool ConditionsMet(LayerModel layerModel, IDataModel dataModel); } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerType.cs b/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerType.cs index ee840be41..4b38d1a6d 100644 --- a/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerType.cs +++ b/Artemis/Artemis/Profiles/Layers/Interfaces/ILayerType.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Windows.Media; +using System.Windows.Media; using Artemis.Models.Interfaces; using Artemis.Profiles.Layers.Abstract; using Artemis.Profiles.Layers.Models; @@ -38,9 +37,9 @@ namespace Artemis.Profiles.Layers.Interfaces /// /// Draws the layer /// - /// The layer to draw + /// The layer to draw /// The drawing context to draw with - void Draw(LayerModel layer, DrawingContext c); + void Draw(LayerModel layerModel, DrawingContext c); /// /// Updates the provided layer layerModel according to this type @@ -61,7 +60,8 @@ namespace Artemis.Profiles.Layers.Interfaces /// /// The layer editor VM this type resides in /// The current viewmodel - LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel, LayerPropertiesViewModel layerPropertiesViewModel); + LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel, + LayerPropertiesViewModel layerPropertiesViewModel); } public enum DrawType diff --git a/Artemis/Artemis/Profiles/Layers/Models/DynamicPropertiesModel.cs b/Artemis/Artemis/Profiles/Layers/Models/DynamicPropertiesModel.cs index 8cbf2ca6c..1063f71aa 100644 --- a/Artemis/Artemis/Profiles/Layers/Models/DynamicPropertiesModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Models/DynamicPropertiesModel.cs @@ -37,15 +37,15 @@ namespace Artemis.Profiles.Layers.Models /// public LayerPropertyOptions LayerPropertyOptions { get; set; } - internal void ApplyProperty(IDataModel dataModel, LayerPropertiesModel properties) + internal void ApplyProperty(IDataModel dataModel, LayerModel layerModel) { if (LayerPropertyType == LayerPropertyType.PercentageOf) - ApplyPercentageOf(dataModel, properties, PercentageSource); + ApplyPercentageOf(dataModel, layerModel, PercentageSource); if (LayerPropertyType == LayerPropertyType.PercentageOfProperty) - ApplyPercentageOfProperty(dataModel, properties); + ApplyPercentageOfProperty(dataModel, layerModel); } - private void ApplyPercentageOf(IDataModel dataModel, LayerPropertiesModel properties, float src) + private void ApplyPercentageOf(IDataModel dataModel, LayerModel layerModel, float src) { if (GameProperty == null) return; @@ -54,61 +54,61 @@ namespace Artemis.Profiles.Layers.Models var percentage = gameProperty/src; if (LayerProperty == "Width") - ApplyWidth(properties, percentage); + ApplyWidth(layerModel, percentage); else if (LayerProperty == "Height") - ApplyHeight(properties, percentage); + ApplyHeight(layerModel, percentage); else if (LayerProperty == "Opacity") - ApplyOpacity(properties, percentage); + ApplyOpacity(layerModel, percentage); } - private void ApplyWidth(LayerPropertiesModel properties, float percentage) + private void ApplyWidth(LayerModel layerModel, float percentage) { - var newWidth = Math.Round(percentage*(float) properties.Width, 2); - var difference = properties.Width - newWidth; + var newWidth = Math.Round(percentage*(float) layerModel.Width, 2); + var difference = layerModel.Width - newWidth; if (newWidth < 0) newWidth = 0; - properties.Width = newWidth; + layerModel.Width = newWidth; // Apply the right to left option if (LayerPropertyOptions == LayerPropertyOptions.RightToLeft) - properties.X = properties.X + difference; + layerModel.X = layerModel.X + difference; } - private void ApplyHeight(LayerPropertiesModel properties, float percentage) + private void ApplyHeight(LayerModel layerModel, float percentage) { - var newHeight = Math.Round(percentage*(float) properties.Height, 2); - var difference = properties.Height - newHeight; + var newHeight = Math.Round(percentage*(float) layerModel.Height, 2); + var difference = layerModel.Height - newHeight; if (newHeight < 0) newHeight = 0; - properties.Height = newHeight; + layerModel.Height = newHeight; if (LayerPropertyOptions == LayerPropertyOptions.Downwards) - properties.Y = properties.Y + difference; + layerModel.Y = layerModel.Y + difference; } - private void ApplyOpacity(LayerPropertiesModel properties, float percentage) + private void ApplyOpacity(LayerModel layerModel, float percentage) { - properties.Opacity = percentage*(float) properties.Opacity; - if (properties.Opacity < 0.0) - properties.Opacity = 0.0; - if (properties.Opacity > 1.0) - properties.Opacity = 1.0; + layerModel.Opacity = percentage*(float) layerModel.Opacity; + if (layerModel.Opacity < 0.0) + layerModel.Opacity = 0.0; + if (layerModel.Opacity > 1.0) + layerModel.Opacity = 1.0; // Apply the inverse/decrease option if (LayerPropertyOptions == LayerPropertyOptions.Decrease) - properties.Opacity = 1.0 - properties.Opacity; + layerModel.Opacity = 1.0 - layerModel.Opacity; - var brush = properties.Brush.Clone(); - brush.Opacity = properties.Opacity; - properties.Brush = brush; + var brush = layerModel.Brush.Clone(); + brush.Opacity = layerModel.Opacity; + layerModel.Brush = brush; } - private void ApplyPercentageOfProperty(IDataModel dataModel, LayerPropertiesModel properties) + private void ApplyPercentageOfProperty(IDataModel dataModel, LayerModel layerModel) { var value = dataModel.GetPropValue(PercentageProperty); - ApplyPercentageOf(dataModel, properties, value); + ApplyPercentageOf(dataModel, layerModel, value); } } diff --git a/Artemis/Artemis/Profiles/Layers/Models/EventPropertiesModel.cs b/Artemis/Artemis/Profiles/Layers/Models/EventPropertiesModel.cs index b13f3487a..d145bf7ae 100644 --- a/Artemis/Artemis/Profiles/Layers/Models/EventPropertiesModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Models/EventPropertiesModel.cs @@ -1,6 +1,4 @@ using System; -using System.Threading; -using System.Threading.Tasks; using Newtonsoft.Json; namespace Artemis.Profiles.Layers.Models @@ -20,6 +18,8 @@ namespace Artemis.Profiles.Layers.Models [JsonIgnore] public bool MustDraw { get; set; } + public DateTime EventCanTriggerTime { get; set; } + /// /// Resets the event's properties and triggers it /// @@ -42,11 +42,9 @@ namespace Artemis.Profiles.Layers.Models CanTrigger = false; MustDraw = true; EventTriggerTime = DateTime.Now; - layer.Properties.AnimationProgress = 0.0; + layer.AnimationProgress = 0.0; } - public DateTime EventCanTriggerTime { get; set; } - /// /// Gets whether the event should stop diff --git a/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs b/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs index e3bd0b529..f0da902c0 100644 --- a/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Windows; using System.Windows.Media; using Artemis.Models.Interfaces; using Artemis.Profiles.Layers.Animations; @@ -24,38 +25,9 @@ namespace Artemis.Profiles.Layers.Models GifImage = new GifImage(model.GifFile); } - public ILayerType LayerType { get; set; } - public ILayerCondition LayerCondition { get; set; } - public ILayerAnimation LayerAnimation { get; set; } - - public string Name { get; set; } - public int Order { get; set; } - - public bool Enabled { get; set; } - public bool Expanded { get; set; } - public bool IsEvent { get; set; } - public LayerPropertiesModel Properties { get; set; } - public EventPropertiesModel EventProperties { get; set; } - public ChildItemCollection Children { get; } - - [JsonIgnore] - public LayerPropertiesModel AppliedProperties { get; set; } - [JsonIgnore] public ImageSource LayerImage => LayerType.DrawThumbnail(this); - [JsonIgnore] - public LayerModel Parent { get; internal set; } - - [JsonIgnore] - public ProfileModel Profile { get; internal set; } - - [JsonIgnore] - public GifImage GifImage { get; set; } - - [JsonIgnore] - public DateTime LastRender { get; set; } - /// /// Checks whether this layers conditions are met. /// If they are met and this layer is an event, this also triggers that event. @@ -68,19 +40,53 @@ namespace Artemis.Profiles.Layers.Models return Enabled && LayerCondition.ConditionsMet(this, dataModel); } + /// + /// Update the layer + /// + /// + /// + /// public void Update(IDataModel dataModel, bool preview, bool updateAnimations) { LayerType.Update(this, dataModel, preview); LayerAnimation?.Update(this, updateAnimations); - + LastRender = DateTime.Now; } + /// + /// Applies the saved properties to the current properties + /// + /// Include advanced properties (opacity, brush) + public void ApplyProperties(bool advanced) + { + X = Properties.X; + Y = Properties.Y; + Width = Properties.Width; + Height = Properties.Height; + + if (!advanced) + return; + + Opacity = Properties.Opacity; + Brush = Properties.Brush; + } + + /// + /// Draw the layer using the provided context + /// + /// + /// + /// + /// public void Draw(IDataModel dataModel, DrawingContext c, bool preview, bool updateAnimations) { LayerType.Draw(this, c); } + /// + /// Tells the current layer type to setup the layer's LayerProperties + /// public void SetupProperties() { LayerType.SetupProperties(this); @@ -97,6 +103,9 @@ namespace Artemis.Profiles.Layers.Models } } + /// + /// Ensures all child layers have a unique order + /// public void FixOrder() { Children.Sort(l => l.Order); @@ -163,18 +172,30 @@ namespace Artemis.Profiles.Layers.Models }; } + /// + /// Insert this layer before the given layer + /// + /// public void InsertBefore(LayerModel source) { source.Order = Order; Insert(source); } + /// + /// Insert this layer after the given layer + /// + /// public void InsertAfter(LayerModel source) { source.Order = Order + 1; Insert(source); } + /// + /// Insert the layer as a sibling + /// + /// private void Insert(LayerModel source) { if (Parent != null) @@ -197,11 +218,15 @@ namespace Artemis.Profiles.Layers.Models } } + public Rect LayerRect(int scale = 4) + { + return new Rect(X* scale, Y* scale, Width*scale, Height*scale); + } + /// /// Generates a flat list containing all layers that must be rendered on the keyboard, /// the first mouse layer to be rendered and the first headset layer to be rendered /// - /// The game data model to base the conditions on /// Instance of said game data model /// Whether or not to ignore anything but keyboards /// @@ -227,6 +252,105 @@ namespace Artemis.Profiles.Layers.Models return layers; } + public void SetupCondition() + { + if (IsEvent && !(LayerCondition is EventCondition)) + LayerCondition = new EventCondition(); + else if (!IsEvent && !(LayerCondition is DataModelCondition)) + LayerCondition = new DataModelCondition(); + } + + #region Properties + + #region Layer type properties + + public ILayerType LayerType { get; set; } + public ILayerCondition LayerCondition { get; set; } + public ILayerAnimation LayerAnimation { get; set; } + + #endregion + + #region Generic properties + + public string Name { get; set; } + public int Order { get; set; } + public bool Enabled { get; set; } + public bool Expanded { get; set; } + public bool IsEvent { get; set; } + public LayerPropertiesModel Properties { get; set; } + public EventPropertiesModel EventProperties { get; set; } + + #endregion + + #region Relational properties + + public ChildItemCollection Children { get; } + + [JsonIgnore] + public LayerModel Parent { get; internal set; } + + [JsonIgnore] + public ProfileModel Profile { get; internal set; } + + #endregion + + #region Render properties + + [JsonIgnore] private Brush _brush; + + [JsonIgnore] + public double X { get; set; } + + [JsonIgnore] + public double Y { get; set; } + + [JsonIgnore] + public double Width { get; set; } + + [JsonIgnore] + public double Height { get; set; } + + [JsonIgnore] + public double Opacity { get; set; } + + [JsonIgnore] + public Brush Brush + { + get { return _brush; } + set + { + if (value == null) + { + _brush = null; + return; + } + + if (value.IsFrozen) + { + _brush = value; + return; + } + + // Clone the brush off of the UI thread and freeze it + var cloned = value.Dispatcher.Invoke(value.CloneCurrentValue); + cloned.Freeze(); + _brush = cloned; + } + } + + [JsonIgnore] + public double AnimationProgress { get; set; } + + [JsonIgnore] + public GifImage GifImage { get; set; } + + [JsonIgnore] + public DateTime LastRender { get; set; } + + #endregion + + #endregion + #region IChildItem Members LayerModel IChildItem.Parent @@ -242,13 +366,5 @@ namespace Artemis.Profiles.Layers.Models } #endregion - - public void SetupCondition() - { - if (IsEvent && !(LayerCondition is EventCondition)) - LayerCondition = new EventCondition(); - else if (!IsEvent && !(LayerCondition is DataModelCondition)) - LayerCondition = new DataModelCondition(); - } } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Models/LayerPropertiesModel.cs b/Artemis/Artemis/Profiles/Layers/Models/LayerPropertiesModel.cs index a6eb1ea34..9dc878e84 100644 --- a/Artemis/Artemis/Profiles/Layers/Models/LayerPropertiesModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Models/LayerPropertiesModel.cs @@ -38,9 +38,6 @@ namespace Artemis.Profiles.Layers.Models public List Conditions { get; set; } = new List(); public List DynamicProperties { get; set; } = new List(); - [JsonIgnore] - public double AnimationProgress { get; set; } - [JsonConverter(typeof(BrushJsonConverter))] public Brush Brush { @@ -66,7 +63,7 @@ namespace Artemis.Profiles.Layers.Models } } - public Rect GetRect(int scale = 4) + public Rect PropertiesRect(int scale = 4) { return new Rect(X*scale, Y*scale, Width*scale, Height*scale); } diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightType.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightType.cs index 6e75cd928..8f2db0e42 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightType.cs @@ -71,14 +71,14 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight (BitmapSource.Create(width, height, 96, 96, ScreenCaptureManager.LastCapturePixelFormat, null, _lastData, stride), new Rect(0, 0, width, height))); } - public void Draw(LayerModel layer, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { - Rect rect = new Rect(layer.Properties.X * 4, - layer.Properties.Y * 4, - layer.Properties.Width * 4, - layer.Properties.Height * 4); + Rect rect = new Rect(layerModel.Properties.X * 4, + layerModel.Properties.Y * 4, + layerModel.Properties.Width * 4, + layerModel.Properties.Height * 4); - c.DrawRectangle(((AmbientLightPropertiesModel)layer.Properties).AmbientLightBrush, null, rect); + c.DrawRectangle(((AmbientLightPropertiesModel)layerModel.Properties).AmbientLightBrush, null, rect); } public ImageSource DrawThumbnail(LayerModel layer) diff --git a/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs b/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs index a3de34dbf..d2f795d52 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs @@ -72,7 +72,7 @@ namespace Artemis.Profiles.Layers.Types.Audio return image; } - public void Draw(LayerModel layer, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { lock (SpectrumData) { @@ -84,10 +84,10 @@ namespace Artemis.Profiles.Layers.Types.Audio var oldX = audioLayer.Properties.X; var oldY = audioLayer.Properties.Y; - audioLayer.Properties.Width = layer.Properties.Width; - audioLayer.Properties.Height = layer.Properties.Height; - audioLayer.Properties.X = layer.Properties.X; - audioLayer.Properties.Y = layer.Properties.Y; + audioLayer.Properties.Width = layerModel.Properties.Width; + audioLayer.Properties.Height = layerModel.Properties.Height; + audioLayer.Properties.X = layerModel.Properties.X; + audioLayer.Properties.Y = layerModel.Properties.Y; audioLayer.LayerType.Draw(audioLayer, c); audioLayer.Properties.Width = oldWidth; diff --git a/Artemis/Artemis/Profiles/Layers/Types/Folder/FolderType.cs b/Artemis/Artemis/Profiles/Layers/Types/Folder/FolderType.cs index 7856f0e40..0e7d533e4 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Folder/FolderType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Folder/FolderType.cs @@ -29,7 +29,7 @@ namespace Artemis.Profiles.Layers.Types.Folder return image; } - public void Draw(LayerModel layer, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { } diff --git a/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericType.cs b/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericType.cs index f2c5a880c..39d9c016d 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericType.cs @@ -32,24 +32,21 @@ namespace Artemis.Profiles.Layers.Types.Generic return image; } - public void Draw(LayerModel layer, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { // If an animation is present, let it handle the drawing - if (layer.LayerAnimation != null && !(layer.LayerAnimation is NoneAnimation)) + if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation)) { - layer.LayerAnimation.Draw(layer.Properties, layer.AppliedProperties, c); + layerModel.LayerAnimation.Draw(layerModel, c); return; } // Otherwise draw the rectangle with its applied dimensions and brush - var rect = new Rect(layer.AppliedProperties.X*4, - layer.AppliedProperties.Y*4, - layer.AppliedProperties.Width*4, - layer.AppliedProperties.Height*4); - + var rect = layerModel.LayerRect(); + // Can't meddle with the original brush because it's frozen. - var brush = layer.AppliedProperties.Brush.Clone(); - brush.Opacity = layer.AppliedProperties.Opacity; + var brush = layerModel.Brush.Clone(); + brush.Opacity = layerModel.Opacity; c.PushClip(new RectangleGeometry(rect)); c.DrawRectangle(brush, null, rect); @@ -65,15 +62,14 @@ namespace Artemis.Profiles.Layers.Types.Generic layerModel.Properties.Y = 0; layerModel.Properties.Contain = true; - layerModel.AppliedProperties = new SimplePropertiesModel(layerModel.Properties); + layerModel.ApplyProperties(false); if (isPreview || dataModel == null) return; // If not previewing, apply dynamic properties according to datamodel - var props = (SimplePropertiesModel) layerModel.AppliedProperties; - foreach (var dynamicProperty in props.DynamicProperties) - dynamicProperty.ApplyProperty(dataModel, layerModel.AppliedProperties); + foreach (var dynamicProperty in layerModel.Properties.DynamicProperties) + dynamicProperty.ApplyProperty(dataModel, layerModel); } public void SetupProperties(LayerModel layerModel) diff --git a/Artemis/Artemis/Profiles/Layers/Types/Headset/HeadsetType.cs b/Artemis/Artemis/Profiles/Layers/Types/Headset/HeadsetType.cs index 4ac2c43b7..673066b9e 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Headset/HeadsetType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Headset/HeadsetType.cs @@ -30,24 +30,21 @@ namespace Artemis.Profiles.Layers.Types.Headset return image; } - public void Draw(LayerModel layer, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { // If an animation is present, let it handle the drawing - if (layer.LayerAnimation != null && !(layer.LayerAnimation is NoneAnimation)) + if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation)) { - layer.LayerAnimation.Draw(layer.Properties, layer.AppliedProperties, c); + layerModel.LayerAnimation.Draw(layerModel, c); return; } // Otherwise draw the rectangle with its applied dimensions and brush - var rect = new Rect(layer.AppliedProperties.X*4, - layer.AppliedProperties.Y*4, - layer.AppliedProperties.Width*4, - layer.AppliedProperties.Height*4); + var rect = layerModel.LayerRect(); // Can't meddle with the original brush because it's frozen. - var brush = layer.AppliedProperties.Brush.Clone(); - brush.Opacity = layer.AppliedProperties.Opacity; + var brush = layerModel.Brush.Clone(); + brush.Opacity = layerModel.Opacity; c.PushClip(new RectangleGeometry(rect)); c.DrawRectangle(brush, null, rect); @@ -63,15 +60,14 @@ namespace Artemis.Profiles.Layers.Types.Headset layerModel.Properties.Y = 0; layerModel.Properties.Contain = true; - layerModel.AppliedProperties = new SimplePropertiesModel(layerModel.Properties); + layerModel.ApplyProperties(true); if (isPreview || dataModel == null) return; // If not previewing, apply dynamic properties according to datamodel - var props = (SimplePropertiesModel) layerModel.AppliedProperties; - foreach (var dynamicProperty in props.DynamicProperties) - dynamicProperty.ApplyProperty(dataModel, layerModel.AppliedProperties); + foreach (var dynamicProperty in layerModel.Properties.DynamicProperties) + dynamicProperty.ApplyProperty(dataModel, layerModel); } public void SetupProperties(LayerModel layerModel) diff --git a/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs b/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs index dfbf75ac8..4ba37b0e5 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs @@ -49,7 +49,7 @@ namespace Artemis.Profiles.Layers.Types.KeyPress return image; } - public void Draw(LayerModel layer, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { lock (_keyPressLayers) { @@ -67,7 +67,7 @@ namespace Artemis.Profiles.Layers.Types.KeyPress layerModel.Properties.Y = 0; layerModel.Properties.Contain = true; - layerModel.AppliedProperties = new KeyPressPropertiesModel(layerModel.Properties); + layerModel.ApplyProperties(true); _layerModel = layerModel; diff --git a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs index 4be6789ee..6de7dc6d7 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Windows; +using System.Windows; using System.Windows.Media; using Artemis.Models.Interfaces; using Artemis.Profiles.Layers.Abstract; @@ -34,32 +33,26 @@ namespace Artemis.Profiles.Layers.Types.Keyboard return image; } - public void Draw(LayerModel layer, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { // If an animation is present, let it handle the drawing - if (layer.LayerAnimation != null && !(layer.LayerAnimation is NoneAnimation)) + if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation)) { - layer.LayerAnimation.Draw(layer.Properties, layer.AppliedProperties, c); + layerModel.LayerAnimation.Draw(layerModel, c); return; } // Otherwise draw the rectangle with its layer.AppliedProperties dimensions and brush - var rect = layer.AppliedProperties.Contain - ? new Rect(layer.AppliedProperties.X*4, - layer.AppliedProperties.Y*4, - layer.AppliedProperties.Width*4, - layer.AppliedProperties.Height*4) - : new Rect(layer.Properties.X*4, - layer.Properties.Y*4, - layer.Properties.Width*4, - layer.Properties.Height*4); + var rect = layerModel.Properties.Contain + ? layerModel.LayerRect() + : new Rect(layerModel.Properties.X*4, layerModel.Properties.Y*4, + layerModel.Properties.Width*4, layerModel.Properties.Height*4); - var clip = new Rect(layer.AppliedProperties.X*4, layer.AppliedProperties.Y*4, - layer.AppliedProperties.Width*4, layer.AppliedProperties.Height*4); + var clip = layerModel.LayerRect(); // Can't meddle with the original brush because it's frozen. - var brush = layer.AppliedProperties.Brush.Clone(); - brush.Opacity = layer.AppliedProperties.Opacity; + var brush = layerModel.Brush.Clone(); + brush.Opacity = layerModel.Opacity; c.PushClip(new RectangleGeometry(clip)); c.DrawRectangle(brush, null, rect); @@ -68,14 +61,13 @@ namespace Artemis.Profiles.Layers.Types.Keyboard public void Update(LayerModel layerModel, IDataModel dataModel, bool isPreview = false) { - layerModel.AppliedProperties = new KeyboardPropertiesModel(layerModel.Properties); + layerModel.ApplyProperties(true); if (isPreview || dataModel == null) return; // If not previewing, apply dynamic properties according to datamodel - var keyboardProps = (KeyboardPropertiesModel) layerModel.AppliedProperties; - foreach (var dynamicProperty in keyboardProps.DynamicProperties) - dynamicProperty.ApplyProperty(dataModel, layerModel.AppliedProperties); + foreach (var dynamicProperty in layerModel.Properties.DynamicProperties) + dynamicProperty.ApplyProperty(dataModel, layerModel); } public void SetupProperties(LayerModel layerModel) diff --git a/Artemis/Artemis/Profiles/Layers/Types/KeyboardGif/KeyboardGifType.cs b/Artemis/Artemis/Profiles/Layers/Types/KeyboardGif/KeyboardGifType.cs index dc44e356c..37e88de84 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/KeyboardGif/KeyboardGifType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/KeyboardGif/KeyboardGifType.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Drawing; +using System.Drawing; using System.IO; using System.Windows; using System.Windows.Media; @@ -31,28 +30,25 @@ namespace Artemis.Profiles.Layers.Types.KeyboardGif return image; } - public void Draw(LayerModel layer, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { - var props = (KeyboardPropertiesModel) layer.Properties; + var props = (KeyboardPropertiesModel) layerModel.Properties; if (string.IsNullOrEmpty(props.GifFile)) return; if (!File.Exists(props.GifFile)) return; // Only reconstruct GifImage if the underlying source has changed - if (layer.GifImage == null) - layer.GifImage = new GifImage(props.GifFile); - if (layer.GifImage.Source != props.GifFile) - layer.GifImage = new GifImage(props.GifFile); + if (layerModel.GifImage == null) + layerModel.GifImage = new GifImage(props.GifFile); + if (layerModel.GifImage.Source != props.GifFile) + layerModel.GifImage = new GifImage(props.GifFile); - var rect = new Rect(layer.AppliedProperties.X*4, - layer.AppliedProperties.Y*4, - layer.AppliedProperties.Width*4, - layer.AppliedProperties.Height*4); + var rect = new Rect(layerModel.X*4, layerModel.Y*4, layerModel.Width*4, layerModel.Height*4); - lock (layer.GifImage) + lock (layerModel.GifImage) { - var draw = layer.GifImage.GetNextFrame(); + var draw = layerModel.GifImage.GetNextFrame(); using (var drawBitmap = new Bitmap(draw)) { c.DrawImage(ImageUtilities.BitmapToBitmapImage(drawBitmap), rect); @@ -62,14 +58,13 @@ namespace Artemis.Profiles.Layers.Types.KeyboardGif public void Update(LayerModel layerModel, IDataModel dataModel, bool isPreview = false) { - layerModel.AppliedProperties = new KeyboardPropertiesModel(layerModel.Properties); + layerModel.ApplyProperties(true); if (isPreview) return; // If not previewing, apply dynamic properties according to datamodel - var keyboardProps = (KeyboardPropertiesModel) layerModel.AppliedProperties; - foreach (var dynamicProperty in keyboardProps.DynamicProperties) - dynamicProperty.ApplyProperty(dataModel, layerModel.AppliedProperties); + foreach (var dynamicProperty in layerModel.Properties.DynamicProperties) + dynamicProperty.ApplyProperty(dataModel, layerModel); } public void SetupProperties(LayerModel layerModel) diff --git a/Artemis/Artemis/Profiles/Layers/Types/Mouse/MouseType.cs b/Artemis/Artemis/Profiles/Layers/Types/Mouse/MouseType.cs index f6267e5e4..1f8ac9f4a 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Mouse/MouseType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Mouse/MouseType.cs @@ -32,24 +32,21 @@ namespace Artemis.Profiles.Layers.Types.Mouse return image; } - public void Draw(LayerModel layer, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { // If an animation is present, let it handle the drawing - if (layer.LayerAnimation != null && !(layer.LayerAnimation is NoneAnimation)) + if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation)) { - layer.LayerAnimation.Draw(layer.Properties, layer.AppliedProperties, c); + layerModel.LayerAnimation.Draw(layerModel, c); return; } // Otherwise draw the rectangle with its applied dimensions and brush - var rect = new Rect(layer.AppliedProperties.X*4, - layer.AppliedProperties.Y*4, - layer.AppliedProperties.Width*4, - layer.AppliedProperties.Height*4); + var rect = layerModel.LayerRect(); // Can't meddle with the original brush because it's frozen. - var brush = layer.AppliedProperties.Brush.Clone(); - brush.Opacity = layer.AppliedProperties.Opacity; + var brush = layerModel.Brush.Clone(); + brush.Opacity = layerModel.Opacity; c.PushClip(new RectangleGeometry(rect)); c.DrawRectangle(brush, null, rect); @@ -65,15 +62,14 @@ namespace Artemis.Profiles.Layers.Types.Mouse layerModel.Properties.Y = 0; layerModel.Properties.Contain = true; - layerModel.AppliedProperties = new SimplePropertiesModel(layerModel.Properties); + layerModel.ApplyProperties(true); if (isPreview || dataModel == null) return; // If not previewing, apply dynamic properties according to datamodel - var props = (SimplePropertiesModel) layerModel.AppliedProperties; - foreach (var dynamicProperty in props.DynamicProperties) - dynamicProperty.ApplyProperty(dataModel, layerModel.AppliedProperties); + foreach (var dynamicProperty in layerModel.Properties.DynamicProperties) + dynamicProperty.ApplyProperty(dataModel, layerModel); } public void SetupProperties(LayerModel layerModel) diff --git a/Artemis/Artemis/Profiles/Layers/Types/Mousemat/MousematType.cs b/Artemis/Artemis/Profiles/Layers/Types/Mousemat/MousematType.cs index adba069f8..91f2cec9c 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Mousemat/MousematType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Mousemat/MousematType.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Windows; using System.Windows.Media; using Artemis.Models.Interfaces; @@ -30,24 +29,21 @@ namespace Artemis.Profiles.Layers.Types.Mousemat return image; } - public void Draw(LayerModel layer, DrawingContext c) + public void Draw(LayerModel layerModel, DrawingContext c) { // If an animation is present, let it handle the drawing - if (layer.LayerAnimation != null && !(layer.LayerAnimation is NoneAnimation)) + if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation)) { - layer.LayerAnimation.Draw(layer.Properties, layer.AppliedProperties, c); + layerModel.LayerAnimation.Draw(layerModel, c); return; } // Otherwise draw the rectangle with its applied dimensions and brush - var rect = new Rect(layer.AppliedProperties.X*4, - layer.AppliedProperties.Y*4, - layer.AppliedProperties.Width*4, - layer.AppliedProperties.Height*4); + var rect = layerModel.LayerRect(); // Can't meddle with the original brush because it's frozen. - var brush = layer.AppliedProperties.Brush.Clone(); - brush.Opacity = layer.AppliedProperties.Opacity; + var brush = layerModel.Brush.Clone(); + brush.Opacity = layerModel.Opacity; c.PushClip(new RectangleGeometry(rect)); c.DrawRectangle(brush, null, rect); @@ -63,15 +59,14 @@ namespace Artemis.Profiles.Layers.Types.Mousemat layerModel.Properties.Y = 0; layerModel.Properties.Contain = true; - layerModel.AppliedProperties = new SimplePropertiesModel(layerModel.Properties); + layerModel.ApplyProperties(true); if (isPreview || dataModel == null) return; // If not previewing, apply dynamic properties according to datamodel - var props = (SimplePropertiesModel) layerModel.AppliedProperties; - foreach (var dynamicProperty in props.DynamicProperties) - dynamicProperty.ApplyProperty(dataModel, layerModel.AppliedProperties); + foreach (var dynamicProperty in layerModel.Properties.DynamicProperties) + dynamicProperty.ApplyProperty(dataModel, layerModel); } public void SetupProperties(LayerModel layerModel) diff --git a/Artemis/Artemis/Profiles/Lua/LuaLayerWrapper.cs b/Artemis/Artemis/Profiles/Lua/LuaLayerWrapper.cs index 661bf928f..f9d9dffc5 100644 --- a/Artemis/Artemis/Profiles/Lua/LuaLayerWrapper.cs +++ b/Artemis/Artemis/Profiles/Lua/LuaLayerWrapper.cs @@ -19,8 +19,9 @@ namespace Artemis.Profiles.Lua public LuaLayerWrapper(LayerModel layerModel) { _layerModel = layerModel; + SavedProperties = new LuaLayerProperties(layerModel); - // Triger an update to fill up the AppliedProperties + // Triger an update to fill up the Properties _layerModel.Update(new ProfilePreviewDataModel(), true, false); } @@ -63,73 +64,120 @@ namespace Artemis.Profiles.Lua #endregion - #region Advanced layer properties + #region Render layer properties public double X { - get { return _layerModel.AppliedProperties.X; } - set { _layerModel.AppliedProperties.X = value; } + get { return _layerModel.X; } + set { _layerModel.X = value; } } public double Y { - get { return _layerModel.AppliedProperties.Y; } - set { _layerModel.AppliedProperties.Y = value; } + get { return _layerModel.Y; } + set { _layerModel.Y = value; } } public double Width { - get { return _layerModel.AppliedProperties.Width; } - set { _layerModel.AppliedProperties.Width = value; } + get { return _layerModel.Width; } + set { _layerModel.Width = value; } } public double Height { - get { return _layerModel.AppliedProperties.Height; } - set { _layerModel.AppliedProperties.Height = value; } - } - - public bool Contain - { - get { return _layerModel.AppliedProperties.Contain; } - set { _layerModel.AppliedProperties.Contain = value; } + get { return _layerModel.Height; } + set { _layerModel.Height = value; } } public double Opacity { - get { return _layerModel.AppliedProperties.Opacity; } - set { _layerModel.AppliedProperties.Opacity = value; } - } - - public double AnimationSpeed - { - get { return _layerModel.AppliedProperties.AnimationSpeed; } - set { _layerModel.AppliedProperties.AnimationSpeed = value; } + get { return _layerModel.Opacity; } + set { _layerModel.Opacity = value; } } public double AnimationProgress { - get { return _layerModel.AppliedProperties.AnimationProgress; } - set { _layerModel.AppliedProperties.AnimationProgress = value; } + get { return _layerModel.AnimationProgress; } + set { _layerModel.AnimationProgress = value; } } - public string BrushType => _layerModel.AppliedProperties.Brush?.GetType().Name; + #endregion + + #region Advanced layer properties + + public LuaLayerProperties SavedProperties { get; set; } + + public string BrushType => _layerModel.Properties.Brush?.GetType().Name; public LuaBrush Brush { get { - if (_layerModel.AppliedProperties.Brush is SolidColorBrush) - return new LuaSolidColorBrush(_layerModel.AppliedProperties.Brush); - if (_layerModel.AppliedProperties.Brush is LinearGradientBrush) - return new LuaLinearGradientBrush(_layerModel.AppliedProperties.Brush); - if (_layerModel.AppliedProperties.Brush is RadialGradientBrush) - return new LuaRadialGradientBrush(_layerModel.AppliedProperties.Brush); + if (_layerModel.Properties.Brush is SolidColorBrush) + return new LuaSolidColorBrush(_layerModel.Properties.Brush); + if (_layerModel.Properties.Brush is LinearGradientBrush) + return new LuaLinearGradientBrush(_layerModel.Properties.Brush); + if (_layerModel.Properties.Brush is RadialGradientBrush) + return new LuaRadialGradientBrush(_layerModel.Properties.Brush); return null; } - set { _layerModel.AppliedProperties.Brush = value?.Brush; } + set { _layerModel.Properties.Brush = value?.Brush; } } #endregion } + + [MoonSharpUserData] + public class LuaLayerProperties + { + private readonly LayerModel _layerModel; + + public LuaLayerProperties(LayerModel layerModel) + { + _layerModel = layerModel; + } + + public double X + { + get { return _layerModel.Properties.X; } + set { _layerModel.Properties.X = value; } + } + + public double Y + { + get { return _layerModel.Properties.Y; } + set { _layerModel.Properties.Y = value; } + } + + public double Width + { + get { return _layerModel.Properties.Width; } + set { _layerModel.Properties.Width = value; } + } + + public double Height + { + get { return _layerModel.Properties.Height; } + set { _layerModel.Properties.Height = value; } + } + + public bool Contain + { + get { return _layerModel.Properties.Contain; } + set { _layerModel.Properties.Contain = value; } + } + + public double Opacity + { + get { return _layerModel.Properties.Opacity; } + set { _layerModel.Properties.Opacity = value; } + } + + public double AnimationSpeed + { + get { return _layerModel.Properties.AnimationSpeed; } + set { _layerModel.Properties.AnimationSpeed = value; } + } + } } \ No newline at end of file diff --git a/Artemis/Artemis/ViewModels/Profiles/ProfileViewModel.cs b/Artemis/Artemis/ViewModels/Profiles/ProfileViewModel.cs index fe7fdc0c5..47605c4f7 100644 --- a/Artemis/Artemis/ViewModels/Profiles/ProfileViewModel.cs +++ b/Artemis/Artemis/ViewModels/Profiles/ProfileViewModel.cs @@ -97,7 +97,7 @@ namespace Artemis.ViewModels.Profiles // Draw the selection outline and resize indicator if (SelectedLayer != null && SelectedLayer.MustDraw()) { - var layerRect = SelectedLayer.Properties.GetRect(); + var layerRect = SelectedLayer.Properties.PropertiesRect(); // Deflate the rect so that the border is drawn on the inside layerRect.Inflate(-0.2, -0.2); @@ -227,7 +227,7 @@ namespace Artemis.ViewModels.Profiles var y = pos.Y/((double) keyboard.PreviewSettings.Height/keyboard.Height); var hoverLayer = GetLayers().Where(l => l.MustDraw()) - .FirstOrDefault(l => l.Properties.GetRect(1).Contains(x, y)); + .FirstOrDefault(l => l.Properties.PropertiesRect(1).Contains(x, y)); if (hoverLayer != null) SelectedLayer = hoverLayer; @@ -247,7 +247,7 @@ namespace Artemis.ViewModels.Profiles var x = pos.X/((double) keyboard.PreviewSettings.Width/keyboard.Width); var y = pos.Y/((double) keyboard.PreviewSettings.Height/keyboard.Height); var hoverLayer = GetLayers().Where(l => l.MustDraw()) - .FirstOrDefault(l => l.Properties.GetRect(1).Contains(x, y)); + .FirstOrDefault(l => l.Properties.PropertiesRect(1).Contains(x, y)); HandleDragging(e, x, y, hoverLayer); @@ -260,7 +260,7 @@ namespace Artemis.ViewModels.Profiles // Turn the mouse pointer into a hand if hovering over an active layer if (hoverLayer == SelectedLayer) { - var rect = hoverLayer.Properties.GetRect(1); + var rect = hoverLayer.Properties.PropertiesRect(1); KeyboardPreviewCursor = Math.Sqrt(Math.Pow(x - rect.BottomRight.X, 2) + Math.Pow(y - rect.BottomRight.Y, 2)) < 0.6 ? Cursors.SizeNWSE @@ -305,7 +305,7 @@ namespace Artemis.ViewModels.Profiles // Setup the dragging state on mouse press if (_draggingLayerOffset == null && hoverLayer != null && e.LeftButton == MouseButtonState.Pressed) { - var layerRect = hoverLayer.Properties.GetRect(1); + var layerRect = hoverLayer.Properties.PropertiesRect(1); _draggingLayerOffset = new Point(x - SelectedLayer.Properties.X, y - SelectedLayer.Properties.Y); _draggingLayer = hoverLayer; From 188e1ddfe4f0830b7460359b8a8e0168aa2871fd Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Wed, 30 Nov 2016 14:47:16 +0100 Subject: [PATCH 05/17] Resharper cleanup layer modules --- .../AmbienceCreator/AmbienceCreatorExtend.cs | 64 ++++++++------- .../AmbienceCreator/AmbienceCreatorMirror.cs | 71 +++++++++-------- .../AmbientLight/AmbienceCreator/AvgColor.cs | 20 ++--- .../AmbienceCreator/IAmbienceCreator.cs | 5 +- .../AmbientLightPropertiesModel.cs | 22 +++--- .../AmbientLightPropertiesView.xaml | 29 ++++--- .../AmbientLightPropertiesView.xaml.cs | 2 +- .../AmbientLightPropertiesViewModel.cs | 8 +- .../Types/AmbientLight/AmbientLightType.cs | 54 +++++++------ .../Helper/CheckboxEnumFlagHelper.cs | 22 +++--- .../AmbientLight/Model/AmbienceCreatorType.cs | 8 +- .../Model/BlackBarDetectionMode.cs | 4 +- .../Model/Extensions/AvgColorExtension.cs | 22 +++--- .../Model/Extensions/EnumExtension.cs | 8 +- .../Model/Extensions/PixelDataExtension.cs | 78 ++++++++++--------- .../Types/AmbientLight/Model/FlipMode.cs | 2 +- .../AmbientLight/Model/ScreenCaptureMode.cs | 5 +- .../Types/AmbientLight/Model/SmoothMode.cs | 14 ++-- .../ScreenCapturing/DX9ScreenCapture.cs | 36 ++++----- .../ScreenCapturing/IScreenCapture.cs | 4 +- .../ScreenCapturing/ScreenCaptureManager.cs | 21 ++--- .../Profiles/Layers/Types/Audio/AudioType.cs | 2 +- .../Layers/Types/Folder/FolderType.cs | 5 +- .../Types/Generic/GenericPropertiesView.xaml | 53 +++++++------ .../Layers/Types/Generic/GenericType.cs | 7 +- .../Layers/Types/Headset/HeadsetType.cs | 5 +- .../Layers/Types/KeyPress/KeyPressType.cs | 2 +- .../Keyboard/KeyboardPropertiesView.xaml | 2 +- .../Layers/Types/Keyboard/KeyboardType.cs | 2 +- .../Types/KeyboardGif/KeyboardGifType.cs | 2 +- .../Profiles/Layers/Types/Mouse/MouseType.cs | 5 +- .../Layers/Types/Mousemat/MousematType.cs | 2 +- 32 files changed, 312 insertions(+), 274 deletions(-) diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/AmbienceCreatorExtend.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/AmbienceCreatorExtend.cs index c8abd06b7..eecff9753 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/AmbienceCreatorExtend.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/AmbienceCreatorExtend.cs @@ -9,34 +9,40 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator #region Methods public byte[] GetAmbience(byte[] pixels, int sourceWidth, int sourceHeight, - int targetWidth, int targetHeight, - AmbientLightPropertiesModel settings) + int targetWidth, int targetHeight, + AmbientLightPropertiesModel settings) { - AvgColor[] colors = new AvgColor[targetWidth]; - for (int i = 0; i < colors.Length; i++) + var colors = new AvgColor[targetWidth]; + for (var i = 0; i < colors.Length; i++) colors[i] = new AvgColor(); - int offsetLeft = settings.OffsetLeft + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left) - ? pixels.DetectBlackBarLeft(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) + var offsetLeft = settings.OffsetLeft + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left) + ? pixels.DetectBlackBarLeft(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, + settings.OffsetTop, settings.OffsetBottom) : 0); - int offsetRight = settings.OffsetRight + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right) - ? pixels.DetectBlackBarRight(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) - : 0); - int offsetTop = settings.OffsetTop + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top) - ? pixels.DetectBlackBarTop(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) - : 0); - int offsetBottom = settings.OffsetBottom + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Bottom) - ? pixels.DetectBlackBarBottom(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) + var offsetRight = settings.OffsetRight + + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right) + ? pixels.DetectBlackBarRight(sourceWidth, sourceHeight, settings.OffsetLeft, + settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) + : 0); + var offsetTop = settings.OffsetTop + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top) + ? pixels.DetectBlackBarTop(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, + settings.OffsetTop, settings.OffsetBottom) : 0); + var offsetBottom = settings.OffsetBottom + + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Bottom) + ? pixels.DetectBlackBarBottom(sourceWidth, sourceHeight, settings.OffsetLeft, + settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) + : 0); - int effectiveSourceWidth = sourceWidth - offsetLeft - offsetRight; - int effectiveSourceHeight = sourceHeight - offsetTop - offsetBottom; + var effectiveSourceWidth = sourceWidth - offsetLeft - offsetRight; + var effectiveSourceHeight = sourceHeight - offsetTop - offsetBottom; - int relevantSourceHeight = (int)Math.Round(effectiveSourceHeight * (settings.MirroredAmount / 100.0)); - int relevantOffsetTop = sourceHeight - offsetBottom - relevantSourceHeight; + var relevantSourceHeight = (int) Math.Round(effectiveSourceHeight*(settings.MirroredAmount/100.0)); + var relevantOffsetTop = sourceHeight - offsetBottom - relevantSourceHeight; - double widthPixels = effectiveSourceWidth / (double)targetWidth; - double heightPixels = relevantSourceHeight / (double)targetHeight; + var widthPixels = effectiveSourceWidth/(double) targetWidth; + var heightPixels = relevantSourceHeight/(double) targetHeight; if (widthPixels <= 0 || heightPixels <= 0 || (relevantSourceHeight + relevantOffsetTop > sourceHeight) || effectiveSourceWidth > sourceWidth) @@ -45,13 +51,13 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator return colors.ToBGRArray(); } - int increment = Math.Max(1, Math.Min(20, settings.Downsampling)); - for (int y = 0; y < relevantSourceHeight; y += increment) + var increment = Math.Max(1, Math.Min(20, settings.Downsampling)); + for (var y = 0; y < relevantSourceHeight; y += increment) { - int targetWidthIndex = 0; - double widthCounter = widthPixels; + var targetWidthIndex = 0; + var widthCounter = widthPixels; - for (int x = 0; x < effectiveSourceWidth; x += increment) + for (var x = 0; x < effectiveSourceWidth; x += increment) { if (x >= widthCounter) { @@ -59,10 +65,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator targetWidthIndex++; } - int colorsOffset = targetWidthIndex; - int sourceOffset = ((((relevantOffsetTop + y) * sourceWidth) + offsetLeft + x) * 4); + var colorsOffset = targetWidthIndex; + var sourceOffset = ((relevantOffsetTop + y)*sourceWidth + offsetLeft + x)*4; - AvgColor color = colors[colorsOffset]; + var color = colors[colorsOffset]; color.AddB(pixels[sourceOffset]); color.AddG(pixels[sourceOffset + 1]); color.AddR(pixels[sourceOffset + 2]); @@ -76,4 +82,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator #endregion } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/AmbienceCreatorMirror.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/AmbienceCreatorMirror.cs index 3d4569eed..a659eb9a6 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/AmbienceCreatorMirror.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/AmbienceCreatorMirror.cs @@ -9,43 +9,50 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator #region Methods public byte[] GetAmbience(byte[] pixels, int sourceWidth, int sourceHeight, - int targetWidth, int targetHeight, - AmbientLightPropertiesModel settings) + int targetWidth, int targetHeight, + AmbientLightPropertiesModel settings) { - AvgColor[] colors = new AvgColor[targetWidth * targetHeight]; - for (int i = 0; i < colors.Length; i++) + var colors = new AvgColor[targetWidth*targetHeight]; + for (var i = 0; i < colors.Length; i++) colors[i] = new AvgColor(); - int offsetLeft = settings.OffsetLeft + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left) - ? pixels.DetectBlackBarLeft(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) + var offsetLeft = settings.OffsetLeft + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left) + ? pixels.DetectBlackBarLeft(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, + settings.OffsetTop, settings.OffsetBottom) : 0); - int offsetRight = settings.OffsetRight + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right) - ? pixels.DetectBlackBarRight(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) - : 0); - int offsetTop = settings.OffsetTop + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top) - ? pixels.DetectBlackBarTop(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) - : 0); - int offsetBottom = settings.OffsetBottom + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Bottom) - ? pixels.DetectBlackBarBottom(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) + var offsetRight = settings.OffsetRight + + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right) + ? pixels.DetectBlackBarRight(sourceWidth, sourceHeight, settings.OffsetLeft, + settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) + : 0); + var offsetTop = settings.OffsetTop + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top) + ? pixels.DetectBlackBarTop(sourceWidth, sourceHeight, settings.OffsetLeft, settings.OffsetRight, + settings.OffsetTop, settings.OffsetBottom) : 0); + var offsetBottom = settings.OffsetBottom + + (settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Bottom) + ? pixels.DetectBlackBarBottom(sourceWidth, sourceHeight, settings.OffsetLeft, + settings.OffsetRight, settings.OffsetTop, settings.OffsetBottom) + : 0); - int effectiveSourceWidth = sourceWidth - offsetLeft - offsetRight; - int effectiveSourceHeight = sourceHeight - offsetTop - offsetBottom; + var effectiveSourceWidth = sourceWidth - offsetLeft - offsetRight; + var effectiveSourceHeight = sourceHeight - offsetTop - offsetBottom; - int relevantSourceHeight = (int)Math.Round(effectiveSourceHeight * (settings.MirroredAmount / 100.0)); - int relevantOffsetTop = sourceHeight - offsetBottom - relevantSourceHeight; + var relevantSourceHeight = (int) Math.Round(effectiveSourceHeight*(settings.MirroredAmount/100.0)); + var relevantOffsetTop = sourceHeight - offsetBottom - relevantSourceHeight; - double widthPixels = effectiveSourceWidth / (double)targetWidth; - double heightPixels = relevantSourceHeight / (double)targetHeight; + var widthPixels = effectiveSourceWidth/(double) targetWidth; + var heightPixels = relevantSourceHeight/(double) targetHeight; - if (widthPixels <= 0 || heightPixels <= 0 || (relevantSourceHeight + relevantOffsetTop > sourceHeight) || effectiveSourceWidth > sourceWidth) + if (widthPixels <= 0 || heightPixels <= 0 || (relevantSourceHeight + relevantOffsetTop > sourceHeight) || + effectiveSourceWidth > sourceWidth) return colors.ToBGRArray(); - int targetHeightIndex = 0; - double heightCounter = heightPixels; + var targetHeightIndex = 0; + var heightCounter = heightPixels; - int increment = Math.Max(1, Math.Min(20, settings.Downsampling)); - for (int y = 0; y < relevantSourceHeight; y += increment) + var increment = Math.Max(1, Math.Min(20, settings.Downsampling)); + for (var y = 0; y < relevantSourceHeight; y += increment) { if (y >= heightCounter) { @@ -53,10 +60,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator targetHeightIndex++; } - int targetWidthIndex = 0; - double widthCounter = widthPixels; + var targetWidthIndex = 0; + var widthCounter = widthPixels; - for (int x = 0; x < effectiveSourceWidth; x += increment) + for (var x = 0; x < effectiveSourceWidth; x += increment) { if (x >= widthCounter) { @@ -64,10 +71,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator targetWidthIndex++; } - int colorsOffset = (targetHeightIndex * targetWidth) + targetWidthIndex; - int sourceOffset = ((((relevantOffsetTop + y) * sourceWidth) + offsetLeft + x) * 4); + var colorsOffset = targetHeightIndex*targetWidth + targetWidthIndex; + var sourceOffset = ((relevantOffsetTop + y)*sourceWidth + offsetLeft + x)*4; - AvgColor color = colors[colorsOffset]; + var color = colors[colorsOffset]; color.AddB(pixels[sourceOffset]); color.AddG(pixels[sourceOffset + 1]); color.AddR(pixels[sourceOffset + 2]); @@ -80,4 +87,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.AmbienceCreator #endregion } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/AvgColor.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/AvgColor.cs index 9cef78a27..8c6a60e9b 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/AvgColor.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/AvgColor.cs @@ -4,16 +4,16 @@ { #region Properties & Fields - private int _rCount = 0; - private int _r = 0; - private int _gCount = 0; - private int _g = 0; - private int _bCount = 0; - private int _b = 0; + private int _rCount; + private int _r; + private int _gCount; + private int _g; + private int _bCount; + private int _b; - public byte R => (byte)(_rCount > 0 ? (_r / _rCount) : 0); - public byte G => (byte)(_gCount > 0 ? (_g / _gCount) : 0); - public byte B => (byte)(_bCount > 0 ? (_b / _bCount) : 0); + public byte R => (byte) (_rCount > 0 ? _r/_rCount : 0); + public byte G => (byte) (_gCount > 0 ? _g/_gCount : 0); + public byte B => (byte) (_bCount > 0 ? _b/_bCount : 0); #endregion @@ -39,4 +39,4 @@ #endregion } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/IAmbienceCreator.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/IAmbienceCreator.cs index df84941bd..8492a0ea2 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/IAmbienceCreator.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbienceCreator/IAmbienceCreator.cs @@ -2,6 +2,7 @@ { public interface IAmbienceCreator { - byte[] GetAmbience(byte[] pixels, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, AmbientLightPropertiesModel settings); + byte[] GetAmbience(byte[] pixels, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, + AmbientLightPropertiesModel settings); } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesModel.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesModel.cs index 5579ae504..c548b3077 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesModel.cs @@ -7,6 +7,16 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight { public class AmbientLightPropertiesModel : LayerPropertiesModel { + #region Constructors + + public AmbientLightPropertiesModel(LayerPropertiesModel properties) + : base(properties) + { + Brush = new SolidColorBrush(Color.FromRgb(0, 0, 0)); + } + + #endregion + #region Properties & Fields //HACK DarthAffe 30.10.2016: The 'normal' Brush-Property destoys the profile since Drawing-Brushes cannot be deserialized. @@ -28,15 +38,5 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight public FlipMode FlipMode { get; set; } = FlipMode.Vertical; #endregion - - #region Constructors - - public AmbientLightPropertiesModel(LayerPropertiesModel properties) - : base(properties) - { - Brush = new SolidColorBrush(Color.FromRgb(0, 0, 0)); - } - - #endregion } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesView.xaml b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesView.xaml index 78a0e2118..8201fe8d9 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesView.xaml +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesView.xaml @@ -1,14 +1,14 @@  @@ -51,7 +51,8 @@ - @@ -65,12 +66,14 @@ - + Value="{Binding Path=LayerModel.Properties.MirroredAmount, Mode=TwoWay}" + Margin="10,12,10,2" Height="24" /> + + Value="{Binding Path=LayerModel.Properties.Downsampling, Mode=TwoWay}" + Margin="10,12,10,2" Height="24" /> + Value="{Binding Path=LayerModel.Properties.OffsetLeft, Mode=TwoWay}" + Margin="10,12,10,2" Height="24" /> + Value="{Binding Path=LayerModel.Properties.OffsetRight, Mode=TwoWay}" + Margin="10,12,10,2" Height="24" /> + Value="{Binding Path=LayerModel.Properties.OffsetTop, Mode=TwoWay}" Margin="10,12,10,2" + Height="24" /> + Value="{Binding Path=LayerModel.Properties.OffsetBottom, Mode=TwoWay}" + Margin="10,12,10,2" Height="24" /> - + \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesView.xaml.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesView.xaml.cs index f85eca5c2..a7539b649 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesView.xaml.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesView.xaml.cs @@ -9,4 +9,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight InitializeComponent(); } } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesViewModel.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesViewModel.cs index 4926ff2c4..7e71757d0 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesViewModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightPropertiesViewModel.cs @@ -9,15 +9,17 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight public AmbientLightPropertiesViewModel(LayerEditorViewModel editorVm) : base(editorVm) - { } + { + } #endregion #region Methods public override void ApplyProperties() - { } + { + } #endregion } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightType.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightType.cs index 8f2db0e42..c176040f9 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/AmbientLightType.cs @@ -26,13 +26,11 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight public bool ShowInEdtor => true; public DrawType DrawType => DrawType.Keyboard; - [JsonIgnore] - private AmbienceCreatorType? _lastAmbienceCreatorType = null; - [JsonIgnore] - private IAmbienceCreator _lastAmbienceCreator; + [JsonIgnore] private AmbienceCreatorType? _lastAmbienceCreatorType; - [JsonIgnore] - private byte[] _lastData; + [JsonIgnore] private IAmbienceCreator _lastAmbienceCreator; + + [JsonIgnore] private byte[] _lastData; #endregion @@ -56,36 +54,39 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight public void Update(LayerModel layerModel, IDataModel dataModel, bool isPreview = false) { - AmbientLightPropertiesModel properties = layerModel?.Properties as AmbientLightPropertiesModel; + var properties = layerModel?.Properties as AmbientLightPropertiesModel; if (properties == null) return; - int width = (int)Math.Round(properties.Width); - int height = (int)Math.Round(properties.Height); + var width = (int) Math.Round(properties.Width); + var height = (int) Math.Round(properties.Height); - byte[] data = ScreenCaptureManager.GetLastScreenCapture(); - byte[] newData = GetAmbienceCreator(properties).GetAmbience(data, ScreenCaptureManager.LastCaptureWidth, ScreenCaptureManager.LastCaptureHeight, width, height, properties); + var data = ScreenCaptureManager.GetLastScreenCapture(); + var newData = GetAmbienceCreator(properties) + .GetAmbience(data, ScreenCaptureManager.LastCaptureWidth, ScreenCaptureManager.LastCaptureHeight, width, + height, properties); _lastData = _lastData?.Blend(newData, properties.SmoothMode) ?? newData; - int stride = (width * ScreenCaptureManager.LastCapturePixelFormat.BitsPerPixel + 7) / 8; + var stride = (width*ScreenCaptureManager.LastCapturePixelFormat.BitsPerPixel + 7)/8; properties.AmbientLightBrush = new DrawingBrush(new ImageDrawing - (BitmapSource.Create(width, height, 96, 96, ScreenCaptureManager.LastCapturePixelFormat, null, _lastData, stride), new Rect(0, 0, width, height))); + (BitmapSource.Create(width, height, 96, 96, ScreenCaptureManager.LastCapturePixelFormat, null, _lastData, + stride), new Rect(0, 0, width, height))); } public void Draw(LayerModel layerModel, DrawingContext c) { - Rect rect = new Rect(layerModel.Properties.X * 4, - layerModel.Properties.Y * 4, - layerModel.Properties.Width * 4, - layerModel.Properties.Height * 4); + var rect = new Rect(layerModel.Properties.X*4, + layerModel.Properties.Y*4, + layerModel.Properties.Width*4, + layerModel.Properties.Height*4); - c.DrawRectangle(((AmbientLightPropertiesModel)layerModel.Properties).AmbientLightBrush, null, rect); + c.DrawRectangle(((AmbientLightPropertiesModel) layerModel.Properties).AmbientLightBrush, null, rect); } public ImageSource DrawThumbnail(LayerModel layer) { - Rect thumbnailRect = new Rect(0, 0, 18, 18); - DrawingVisual visual = new DrawingVisual(); - using (DrawingContext c = visual.RenderOpen()) + var thumbnailRect = new Rect(0, 0, 18, 18); + var visual = new DrawingVisual(); + using (var c = visual.RenderOpen()) c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.ambilight), thumbnailRect); return new DrawingImage(visual.Drawing); @@ -99,12 +100,15 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight _lastAmbienceCreatorType = properties.AmbienceCreatorType; switch (properties.AmbienceCreatorType) { - case AmbienceCreatorType.Mirror: return _lastAmbienceCreator = new AmbienceCreatorMirror(); - case AmbienceCreatorType.Extend: return _lastAmbienceCreator = new AmbienceCreatorExtend(); - default: throw new InvalidEnumArgumentException(); + case AmbienceCreatorType.Mirror: + return _lastAmbienceCreator = new AmbienceCreatorMirror(); + case AmbienceCreatorType.Extend: + return _lastAmbienceCreator = new AmbienceCreatorExtend(); + default: + throw new InvalidEnumArgumentException(); } } #endregion } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Helper/CheckboxEnumFlagHelper.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Helper/CheckboxEnumFlagHelper.cs index 6ba6a423c..b6157ad68 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Helper/CheckboxEnumFlagHelper.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Helper/CheckboxEnumFlagHelper.cs @@ -8,10 +8,13 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper public class CheckboxEnumFlagHelper { #region DependencyProperties + // ReSharper disable InconsistentNaming public static readonly DependencyProperty FlagsProperty = DependencyProperty.RegisterAttached( - "Flags", typeof(Enum), typeof(CheckboxEnumFlagHelper), new FrameworkPropertyMetadata(default(Enum), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, FlagsChanged)); + "Flags", typeof(Enum), typeof(CheckboxEnumFlagHelper), + new FrameworkPropertyMetadata(default(Enum), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, + FlagsChanged)); public static void SetFlags(DependencyObject element, Enum value) { @@ -20,7 +23,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper public static Enum GetFlags(DependencyObject element) { - return (Enum)element.GetValue(FlagsProperty); + return (Enum) element.GetValue(FlagsProperty); } public static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached( @@ -33,10 +36,11 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper public static Enum GetValue(DependencyObject element) { - return (Enum)element.GetValue(ValueProperty); + return (Enum) element.GetValue(ValueProperty); } // ReSharper restore InconsistentNaming + #endregion #region Methods @@ -50,7 +54,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper private static void ValueChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { - CheckBox checkbox = dependencyObject as CheckBox; + var checkbox = dependencyObject as CheckBox; if (checkbox == null) return; checkbox.Checked -= UpdateSource; @@ -69,17 +73,17 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper { if (checkbox == null) return; - Enum value = GetValue(checkbox); + var value = GetValue(checkbox); checkbox.IsChecked = value != null && (flags?.HasFlag(value) ?? false); } private static void UpdateSource(object sender, RoutedEventArgs routedEventArgs) { - CheckBox checkbox = sender as CheckBox; + var checkbox = sender as CheckBox; if (checkbox == null) return; - Enum flags = GetFlags(checkbox); - Enum value = GetValue(checkbox); + var flags = GetFlags(checkbox); + var value = GetValue(checkbox); if (value == null) return; if (checkbox.IsChecked ?? false) @@ -90,4 +94,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Helper #endregion } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/AmbienceCreatorType.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/AmbienceCreatorType.cs index 8f7f389e4..209d8c785 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/AmbienceCreatorType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/AmbienceCreatorType.cs @@ -4,10 +4,8 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model { public enum AmbienceCreatorType { - [Description("Mirror")] - Mirror, + [Description("Mirror")] Mirror, - [Description("Extend")] - Extend + [Description("Extend")] Extend } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/BlackBarDetectionMode.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/BlackBarDetectionMode.cs index 31a3cfbfc..905c58d23 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/BlackBarDetectionMode.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/BlackBarDetectionMode.cs @@ -9,6 +9,6 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model Left = 1 << 0, Right = 1 << 1, Top = 1 << 2, - Bottom = 1 << 3, + Bottom = 1 << 3 } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/Extensions/AvgColorExtension.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/Extensions/AvgColorExtension.cs index 449072211..225b118b7 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/Extensions/AvgColorExtension.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/Extensions/AvgColorExtension.cs @@ -23,10 +23,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions public static AvgColor[] ExtendHeight(this AvgColor[] colors, int height) { - AvgColor[] extended = new AvgColor[colors.Length * height]; + var extended = new AvgColor[colors.Length*height]; - for (int i = 0; i < height; i++) - Array.Copy(colors, 0, extended, i * colors.Length, colors.Length); + for (var i = 0; i < height; i++) + Array.Copy(colors, 0, extended, i*colors.Length, colors.Length); return extended; } @@ -35,9 +35,9 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions { if (colors == null || width <= 0) return colors; - AvgColor[] flipped = new AvgColor[colors.Length]; + var flipped = new AvgColor[colors.Length]; for (int i = 0, j = colors.Length - width; i < colors.Length; i += width, j -= width) - for (int k = 0; k < width; ++k) + for (var k = 0; k < width; ++k) flipped[i + k] = colors[j + k]; return flipped; @@ -47,8 +47,8 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions { if (colors == null || width <= 0) return colors; - AvgColor[] flipped = new AvgColor[colors.Length]; - for (int i = 0; i < colors.Length; i += width) + var flipped = new AvgColor[colors.Length]; + for (var i = 0; i < colors.Length; i += width) for (int j = 0, k = width - 1; j < width; ++j, --k) flipped[i + j] = colors[i + k]; @@ -57,9 +57,9 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions public static byte[] ToBGRArray(this AvgColor[] colors) { - byte[] newData = new byte[colors.Length * 3]; - int counter = 0; - foreach (AvgColor color in colors) + var newData = new byte[colors.Length*3]; + var counter = 0; + foreach (var color in colors) { newData[counter++] = color.B; newData[counter++] = color.G; @@ -71,4 +71,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions #endregion } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/Extensions/EnumExtension.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/Extensions/EnumExtension.cs index 65f1ea6f9..e39c2a03d 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/Extensions/EnumExtension.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/Extensions/EnumExtension.cs @@ -10,17 +10,17 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions { if (e == null || value == null || t == null) return e; - int eValue = Convert.ToInt32(e); - int valueValue = Convert.ToInt32(value); + var eValue = Convert.ToInt32(e); + var valueValue = Convert.ToInt32(value); if (set) eValue |= valueValue; else eValue &= ~valueValue; - return (Enum)Enum.ToObject(t, eValue); + return (Enum) Enum.ToObject(t, eValue); } #endregion } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/Extensions/PixelDataExtension.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/Extensions/PixelDataExtension.cs index 5fa442669..a315a3965 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/Extensions/PixelDataExtension.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/Extensions/PixelDataExtension.cs @@ -6,17 +6,18 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions { #region Methods - public static int DetectBlackBarLeft(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, int offsetTop, int offsetBottom) + public static int DetectBlackBarLeft(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, + int offsetTop, int offsetBottom) { - int bottomBorder = height - offsetBottom; - int rightBorder = width - offsetRight; + var bottomBorder = height - offsetBottom; + var rightBorder = width - offsetRight; - int blackBarWidth = 0; - for (int x = rightBorder - 1; x >= offsetLeft; x--) + var blackBarWidth = 0; + for (var x = rightBorder - 1; x >= offsetLeft; x--) { - for (int y = offsetTop; y < bottomBorder; y++) + for (var y = offsetTop; y < bottomBorder; y++) { - int offset = ((y * width) + x) * 4; + var offset = (y*width + x)*4; if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15) return blackBarWidth; } @@ -26,17 +27,18 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions return width; } - public static int DetectBlackBarRight(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, int offsetTop, int offsetBottom) + public static int DetectBlackBarRight(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, + int offsetTop, int offsetBottom) { - int bottomBorder = height - offsetBottom; - int rightBorder = width - offsetRight; + var bottomBorder = height - offsetBottom; + var rightBorder = width - offsetRight; - int blackBarWidth = 0; - for (int x = offsetLeft; x < rightBorder; x++) + var blackBarWidth = 0; + for (var x = offsetLeft; x < rightBorder; x++) { - for (int y = offsetTop; y < bottomBorder; y++) + for (var y = offsetTop; y < bottomBorder; y++) { - int offset = ((y * width) + x) * 4; + var offset = (y*width + x)*4; if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15) return blackBarWidth; } @@ -46,17 +48,18 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions return width; } - public static int DetectBlackBarTop(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, int offsetTop, int offsetBottom) + public static int DetectBlackBarTop(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, + int offsetTop, int offsetBottom) { - int bottomBorder = height - offsetBottom; - int rightBorder = width - offsetRight; + var bottomBorder = height - offsetBottom; + var rightBorder = width - offsetRight; - int blackBarHeight = 0; - for (int y = offsetTop; y < bottomBorder; y++) + var blackBarHeight = 0; + for (var y = offsetTop; y < bottomBorder; y++) { - for (int x = offsetLeft; x < rightBorder; x++) + for (var x = offsetLeft; x < rightBorder; x++) { - int offset = ((y * width) + x) * 4; + var offset = (y*width + x)*4; if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15) return blackBarHeight; } @@ -66,17 +69,18 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions return height; } - public static int DetectBlackBarBottom(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, int offsetTop, int offsetBottom) + public static int DetectBlackBarBottom(this byte[] pixels, int width, int height, int offsetLeft, + int offsetRight, int offsetTop, int offsetBottom) { - int bottomBorder = height - offsetBottom; - int rightBorder = width - offsetRight; + var bottomBorder = height - offsetBottom; + var rightBorder = width - offsetRight; - int blackBarHeight = 0; - for (int y = bottomBorder - 1; y >= offsetTop; y--) + var blackBarHeight = 0; + for (var y = bottomBorder - 1; y >= offsetTop; y--) { - for (int x = offsetLeft; x < rightBorder; x++) + for (var x = offsetLeft; x < rightBorder; x++) { - int offset = ((y * width) + x) * 4; + var offset = (y*width + x)*4; if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15) return blackBarHeight; } @@ -89,23 +93,25 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model.Extensions public static byte[] Blend(this byte[] pixels, byte[] blendPixels, SmoothMode smoothMode) { if (smoothMode == SmoothMode.None || pixels.Length != blendPixels.Length) return blendPixels; - - double percentage = smoothMode == SmoothMode.Low? 0.25: (smoothMode == SmoothMode.Medium ? 0.075 : 0.025 /*high*/); - byte[] blended = new byte[pixels.Length]; + var percentage = smoothMode == SmoothMode.Low + ? 0.25 + : (smoothMode == SmoothMode.Medium ? 0.075 : 0.025 /*high*/); - for (int i = 0; i < blended.Length; i++) - blended[i] = GetIntColor((blendPixels[i] / 255.0) * percentage + (pixels[i] / 255.0) * (1 - percentage)); + var blended = new byte[pixels.Length]; + + for (var i = 0; i < blended.Length; i++) + blended[i] = GetIntColor(blendPixels[i]/255.0*percentage + pixels[i]/255.0*(1 - percentage)); return blended; } private static byte GetIntColor(double d) { - double calcF = Math.Max(0, Math.Min(1, d)); - return (byte)(calcF.Equals(1) ? 255 : calcF * 256); + var calcF = Math.Max(0, Math.Min(1, d)); + return (byte) (calcF.Equals(1) ? 255 : calcF*256); } #endregion } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/FlipMode.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/FlipMode.cs index 540617a5e..eee9666b2 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/FlipMode.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/FlipMode.cs @@ -9,4 +9,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model Vertical = 1 << 0, Horizontal = 1 << 1 } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/ScreenCaptureMode.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/ScreenCaptureMode.cs index 23213b13e..dd37f813e 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/ScreenCaptureMode.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/ScreenCaptureMode.cs @@ -4,7 +4,6 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model { public enum ScreenCaptureMode { - [Description("DirectX 9")] - DirectX9 + [Description("DirectX 9")] DirectX9 } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/SmoothMode.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/SmoothMode.cs index 19c2bd3fd..222bf0037 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/SmoothMode.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/Model/SmoothMode.cs @@ -4,16 +4,12 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.Model { public enum SmoothMode { - [Description("None")] - None, + [Description("None")] None, - [Description("Low")] - Low, + [Description("Low")] Low, - [Description("Medium")] - Medium, + [Description("Medium")] Medium, - [Description("High")] - High + [Description("High")] High } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/ScreenCapturing/DX9ScreenCapture.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/ScreenCapturing/DX9ScreenCapture.cs index 5833fda07..13c8c02c3 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/ScreenCapturing/DX9ScreenCapture.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/ScreenCapturing/DX9ScreenCapture.cs @@ -2,25 +2,12 @@ using System.Runtime.InteropServices; using System.Windows.Forms; using System.Windows.Media; -using SharpDX; using SharpDX.Direct3D9; namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing { public class DX9ScreenCapture : IScreenCapture { - #region Properties & Fields - - private Device _device; - private Surface _surface; - private byte[] _buffer; - - public int Width { get; } - public int Height { get; } - public PixelFormat PixelFormat => PixelFormats.Bgr24; - - #endregion - #region Constructors public DX9ScreenCapture() @@ -28,26 +15,39 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing Width = Screen.PrimaryScreen.Bounds.Width; Height = Screen.PrimaryScreen.Bounds.Height; - PresentParameters presentParams = new PresentParameters(Width, Height) + var presentParams = new PresentParameters(Width, Height) { Windowed = true, SwapEffect = SwapEffect.Discard }; - _device = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, presentParams); + _device = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, + CreateFlags.SoftwareVertexProcessing, presentParams); _surface = Surface.CreateOffscreenPlain(_device, Width, Height, Format.A8R8G8B8, Pool.Scratch); - _buffer = new byte[Width * Height * 4]; + _buffer = new byte[Width*Height*4]; } #endregion + #region Properties & Fields + + private readonly Device _device; + private readonly Surface _surface; + private readonly byte[] _buffer; + + public int Width { get; } + public int Height { get; } + public PixelFormat PixelFormat => PixelFormats.Bgr24; + + #endregion + #region Methods public byte[] CaptureScreen() { _device.GetFrontBufferData(0, _surface); - DataRectangle dr = _surface.LockRectangle(LockFlags.None); + var dr = _surface.LockRectangle(LockFlags.None); Marshal.Copy(dr.DataPointer, _buffer, 0, _buffer.Length); _surface.UnlockRectangle(); @@ -62,4 +62,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing #endregion } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/ScreenCapturing/IScreenCapture.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/ScreenCapturing/IScreenCapture.cs index 343d1c2ba..1acdfbadb 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/ScreenCapturing/IScreenCapture.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/ScreenCapturing/IScreenCapture.cs @@ -10,9 +10,9 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing PixelFormat PixelFormat { get; } /// - /// As Pixel-Data BGRA + /// As Pixel-Data BGRA /// /// The Pixel-Data byte[] CaptureScreen(); } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/ScreenCapturing/ScreenCaptureManager.cs b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/ScreenCapturing/ScreenCaptureManager.cs index 92fe05ef5..35182634e 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/ScreenCapturing/ScreenCaptureManager.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/AmbientLight/ScreenCapturing/ScreenCaptureManager.cs @@ -14,13 +14,14 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing private static Thread _worker; private static DateTime _lastCaptureAccess; private static volatile byte[] _lastScreenCapture; - private static volatile bool _isRunning = false; + private static volatile bool _isRunning; - private static ScreenCaptureMode? _lastScreenCaptureMode = null; + private static ScreenCaptureMode? _lastScreenCaptureMode; private static IScreenCapture _screenCapture; public static double StandByTime { get; set; } = 3; - public static double UpdateRate { get; set; } = 1.0 / 20.0; // DarthAffe 29.10.2016: I think 20 FPS should be enough as default + public static double UpdateRate { get; set; } = 1.0/20.0; + // DarthAffe 29.10.2016: I think 20 FPS should be enough as default public static ScreenCaptureMode ScreenCaptureMode { get; set; } = ScreenCaptureMode.DirectX9; public static int LastCaptureWidth { get; private set; } @@ -41,8 +42,10 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing _lastScreenCaptureMode = ScreenCaptureMode; switch (ScreenCaptureMode) { - case ScreenCaptureMode.DirectX9: return _screenCapture = new DX9ScreenCapture(); - default: throw new InvalidEnumArgumentException(); + case ScreenCaptureMode.DirectX9: + return _screenCapture = new DX9ScreenCapture(); + default: + throw new InvalidEnumArgumentException(); } } @@ -59,7 +62,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing { while ((DateTime.Now - _lastCaptureAccess).TotalSeconds < StandByTime) { - DateTime lastCapture = DateTime.Now; + var lastCapture = DateTime.Now; try { CaptureScreen(); @@ -69,7 +72,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing Debug.WriteLine("[CaptureLoop]: " + ex.Message); } - int sleep = (int)((UpdateRate - (DateTime.Now - lastCapture).TotalSeconds) * 1000); + var sleep = (int) ((UpdateRate - (DateTime.Now - lastCapture).TotalSeconds)*1000); if (sleep > 0) Thread.Sleep(sleep); } @@ -83,7 +86,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing private static void CaptureScreen() { - IScreenCapture screenCapture = GetScreenCapture(); + var screenCapture = GetScreenCapture(); _lastScreenCapture = screenCapture.CaptureScreen(); LastCaptureWidth = screenCapture.Width; @@ -113,4 +116,4 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing #endregion } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs b/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs index d2f795d52..b64983c10 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs @@ -21,11 +21,11 @@ namespace Artemis.Profiles.Layers.Types.Audio { internal class AudioType : ILayerType { + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private readonly List _audioLayers = new List(); private readonly MMDevice _device; private readonly SampleAggregator _sampleAggregator = new SampleAggregator(1024); private readonly WasapiLoopbackCapture _waveIn; - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private int _lines; private AudioPropertiesModel _previousSettings; diff --git a/Artemis/Artemis/Profiles/Layers/Types/Folder/FolderType.cs b/Artemis/Artemis/Profiles/Layers/Types/Folder/FolderType.cs index 0e7d533e4..c9f289373 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Folder/FolderType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Folder/FolderType.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Windows; +using System.Windows; using System.Windows.Media; using Artemis.Models.Interfaces; using Artemis.Profiles.Layers.Abstract; @@ -13,7 +12,7 @@ namespace Artemis.Profiles.Layers.Types.Folder { public class FolderType : ILayerType { - public string Name { get; } = "Folder"; + public string Name => "Folder"; public bool ShowInEdtor { get; } = false; // FolderType pretents to be a keyboard so it's children get drawn public DrawType DrawType { get; } = DrawType.Keyboard; diff --git a/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericPropertiesView.xaml b/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericPropertiesView.xaml index c31f063c2..b5fe8174c 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericPropertiesView.xaml +++ b/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericPropertiesView.xaml @@ -1,12 +1,13 @@  + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + 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:ncore="http://schemas.ncore.com/wpf/xaml/colorbox" + xmlns:ObjectModel="clr-namespace:System.Collections.ObjectModel;assembly=System" + x:Class="Artemis.Profiles.Layers.Types.Generic.GenericPropertiesView" + mc:Ignorable="d" + d:DesignHeight="600" d:DesignWidth="500"> @@ -24,10 +25,10 @@ + VerticalAlignment="Center" + Height="18" /> + Height="22"> @@ -37,33 +38,41 @@ + VerticalAlignment="Center" Height="18" /> + TickPlacement="None" TickFrequency="0.05" + Value="{Binding LayerModel.Properties.AnimationSpeed, Mode=TwoWay}" Minimum="0.05" Maximum="3" + SmallChange="0" IsSnapToTickEnabled="True" Margin="10,12,10,2" Height="24" /> + VerticalAlignment="Top" Height="18" Width="130" /> - + BorderThickness="1" SnapsToDevicePixels="True" ToolTip="Click to edit"> + \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericType.cs b/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericType.cs index 39d9c016d..77ccd3b69 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Generic/GenericType.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Windows; using System.Windows.Media; using Artemis.Models.Interfaces; @@ -15,7 +14,7 @@ namespace Artemis.Profiles.Layers.Types.Generic { public class GenericType : ILayerType { - public string Name { get; } = "Generic (Logitech)"; + public string Name => "Generic (Logitech)"; public bool ShowInEdtor { get; } = false; public DrawType DrawType { get; } = DrawType.Generic; @@ -43,7 +42,7 @@ namespace Artemis.Profiles.Layers.Types.Generic // Otherwise draw the rectangle with its applied dimensions and brush var rect = layerModel.LayerRect(); - + // Can't meddle with the original brush because it's frozen. var brush = layerModel.Brush.Clone(); brush.Opacity = layerModel.Opacity; diff --git a/Artemis/Artemis/Profiles/Layers/Types/Headset/HeadsetType.cs b/Artemis/Artemis/Profiles/Layers/Types/Headset/HeadsetType.cs index 673066b9e..cbf75c0d4 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Headset/HeadsetType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Headset/HeadsetType.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Windows; using System.Windows.Media; using Artemis.Models.Interfaces; @@ -15,7 +14,7 @@ namespace Artemis.Profiles.Layers.Types.Headset { public class HeadsetType : ILayerType { - public string Name { get; } = "Headset"; + public string Name => "Headset"; public bool ShowInEdtor { get; } = false; public DrawType DrawType { get; } = DrawType.Headset; diff --git a/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs b/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs index 4ba37b0e5..0bed586e0 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/KeyPress/KeyPressType.cs @@ -32,7 +32,7 @@ namespace Artemis.Profiles.Layers.Types.KeyPress public RadialGradientBrush TempBrush { get; set; } - public string Name { get; } = "Keyboard - Key press"; + public string Name => "Keyboard - Key press"; public bool ShowInEdtor { get; } = false; public DrawType DrawType { get; } = DrawType.Keyboard; diff --git a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardPropertiesView.xaml b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardPropertiesView.xaml index 85ee67746..9e582617b 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardPropertiesView.xaml +++ b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardPropertiesView.xaml @@ -60,7 +60,7 @@ VerticalAlignment="Top" Height="18" Width="130" /> - + diff --git a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs index 6de7dc6d7..8fbc1ddf7 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardType.cs @@ -11,7 +11,7 @@ namespace Artemis.Profiles.Layers.Types.Keyboard { public class KeyboardType : ILayerType { - public string Name { get; } = "Keyboard"; + public string Name => "Keyboard"; public bool ShowInEdtor { get; } = true; public DrawType DrawType { get; } = DrawType.Keyboard; diff --git a/Artemis/Artemis/Profiles/Layers/Types/KeyboardGif/KeyboardGifType.cs b/Artemis/Artemis/Profiles/Layers/Types/KeyboardGif/KeyboardGifType.cs index 37e88de84..dd524577b 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/KeyboardGif/KeyboardGifType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/KeyboardGif/KeyboardGifType.cs @@ -15,7 +15,7 @@ namespace Artemis.Profiles.Layers.Types.KeyboardGif { internal class KeyboardGifType : ILayerType { - public string Name { get; } = "Keyboard - GIF"; + public string Name => "Keyboard - GIF"; public bool ShowInEdtor { get; } = true; public DrawType DrawType { get; } = DrawType.Keyboard; diff --git a/Artemis/Artemis/Profiles/Layers/Types/Mouse/MouseType.cs b/Artemis/Artemis/Profiles/Layers/Types/Mouse/MouseType.cs index 1f8ac9f4a..b8a58f535 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Mouse/MouseType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Mouse/MouseType.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Windows; using System.Windows.Media; using Artemis.Models.Interfaces; @@ -15,7 +14,7 @@ namespace Artemis.Profiles.Layers.Types.Mouse { public class MouseType : ILayerType { - public string Name { get; } = "Mouse"; + public string Name => "Mouse"; public bool ShowInEdtor { get; } = false; public DrawType DrawType { get; } = DrawType.Mouse; diff --git a/Artemis/Artemis/Profiles/Layers/Types/Mousemat/MousematType.cs b/Artemis/Artemis/Profiles/Layers/Types/Mousemat/MousematType.cs index 91f2cec9c..e9b24af82 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Mousemat/MousematType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Mousemat/MousematType.cs @@ -14,7 +14,7 @@ namespace Artemis.Profiles.Layers.Types.Mousemat { public class MousematType : ILayerType { - public string Name { get; } = "Mousemat"; + public string Name => "Mousemat"; public bool ShowInEdtor { get; } = false; public DrawType DrawType { get; } = DrawType.Mousemat; From 31b51e561a02b9cf2a74857ab39bc3fce3580b1d Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Wed, 30 Nov 2016 16:22:19 +0100 Subject: [PATCH 06/17] Added Tweening but the library uses too much CPU with many layers --- Artemis/Artemis/Artemis.csproj | 5 + .../Profiles/Layers/Models/LayerModel.cs | 15 ++- .../Profiles/Layers/Models/TweenModel.cs | 94 +++++++++++++++++++ .../Profiles/Layers/Types/Audio/AudioType.cs | 27 ++++-- Artemis/Artemis/packages.config | 1 + 5 files changed, 131 insertions(+), 11 deletions(-) create mode 100644 Artemis/Artemis/Profiles/Layers/Models/TweenModel.cs diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 198390572..1d77f6b3f 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -127,6 +127,10 @@ LocalIntranet + + ..\packages\Betwixt.1.4.1\lib\net35\Betwixt.dll + True + ..\packages\Caliburn.Micro.Core.3.0.1\lib\net45\Caliburn.Micro.dll True @@ -403,6 +407,7 @@ + diff --git a/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs b/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs index f0da902c0..f7c833247 100644 --- a/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs @@ -19,7 +19,7 @@ namespace Artemis.Profiles.Layers.Models public LayerModel() { Children = new ChildItemCollection(this); - + TweenModel = new TweenModel(this, 200); var model = Properties as KeyboardPropertiesModel; if (model != null) GifImage = new GifImage(model.GifFile); @@ -27,6 +27,8 @@ namespace Artemis.Profiles.Layers.Models [JsonIgnore] public ImageSource LayerImage => LayerType.DrawThumbnail(this); + [JsonIgnore] + public TweenModel TweenModel { get; set; } /// /// Checks whether this layers conditions are met. @@ -51,6 +53,8 @@ namespace Artemis.Profiles.Layers.Models LayerType.Update(this, dataModel, preview); LayerAnimation?.Update(this, updateAnimations); + TweenModel.Update(); + LastRender = DateTime.Now; } @@ -220,7 +224,14 @@ namespace Artemis.Profiles.Layers.Models public Rect LayerRect(int scale = 4) { - return new Rect(X* scale, Y* scale, Width*scale, Height*scale); + var width = Width; + var height = Height; + if (width < 0) + width = 0; + if (height < 0) + height = 0; + + return new Rect(X * scale, Y * scale, width * scale, height * scale); } /// diff --git a/Artemis/Artemis/Profiles/Layers/Models/TweenModel.cs b/Artemis/Artemis/Profiles/Layers/Models/TweenModel.cs new file mode 100644 index 000000000..47e68220d --- /dev/null +++ b/Artemis/Artemis/Profiles/Layers/Models/TweenModel.cs @@ -0,0 +1,94 @@ +using System; +using Betwixt; + +namespace Artemis.Profiles.Layers.Models +{ + public class TweenModel + { + private readonly LayerModel _layerModel; + private float _height; + private Tweener _heightTweener; + private float _opacity; + private Tweener _opacityTweener; + private float _width; + private Tweener _widthTweener; + private float _x; + private Tweener _xTweener; + private float _y; + private Tweener _yTweener; + + public TweenModel(LayerModel layerModel, double defaultDuration) + { + _layerModel = layerModel; + + XDuration = defaultDuration; + YDuration = defaultDuration; + WidthDuration = defaultDuration; + HeightDuration = defaultDuration; + OpacityDuration = defaultDuration; + + XFunc = Ease.Quad.InOut; + YFunc = Ease.Quad.InOut; + WidthFunc = Ease.Quad.InOut; + HeightFunc = Ease.Quad.InOut; + OpacityFunc = Ease.Quad.InOut; + + _xTweener = new Tweener(0, (float) layerModel.X, XDuration, XFunc); + _yTweener = new Tweener(0, (float) layerModel.Y, YDuration, YFunc); + _widthTweener = new Tweener(0, (float) layerModel.Width, WidthDuration, WidthFunc); + _heightTweener = new Tweener(0, (float) layerModel.Height, HeightDuration, HeightFunc); + _opacityTweener = new Tweener(0, (float) layerModel.Opacity, OpacityDuration, OpacityFunc); + + StoreCurrentValues(); + } + + public double XDuration { get; set; } + public double YDuration { get; set; } + public double WidthDuration { get; set; } + public double HeightDuration { get; set; } + public double OpacityDuration { get; set; } + + public EaseFunc XFunc { get; set; } + public EaseFunc YFunc { get; set; } + public EaseFunc WidthFunc { get; set; } + public EaseFunc HeightFunc { get; set; } + public EaseFunc OpacityFunc { get; set; } + + private void StoreCurrentValues() + { + _x = (float) _layerModel.X; + _y = (float) _layerModel.Y; + _width = (float) _layerModel.Width; + _height = (float) _layerModel.Height; + _opacity = (float) _layerModel.Opacity; + } + + public void Update() + { + if (Math.Abs(_layerModel.X - _x) > 0.001) + _xTweener = new Tweener(_x, (float) _layerModel.X, XDuration, XFunc); + if (Math.Abs(_layerModel.Y - _y) > 0.001) + _yTweener = new Tweener(_y, (float) _layerModel.Y, YDuration, YFunc); + if (Math.Abs(_layerModel.Width - _width) > 0.001) + _widthTweener = new Tweener(_width, (float) _layerModel.Width, WidthDuration, WidthFunc); + if (Math.Abs(_layerModel.Height - _height) > 0.001) + _heightTweener = new Tweener(_height, (float) _layerModel.Height, HeightDuration, HeightFunc); + if (Math.Abs(_layerModel.Opacity - _opacity) > 0.001) + _opacityTweener = new Tweener(_opacity, (float) _layerModel.Opacity, OpacityDuration, OpacityFunc); + + _xTweener.Update(40); + _yTweener.Update(40); + _widthTweener.Update(40); + _heightTweener.Update(40); + _opacityTweener.Update(40); + + StoreCurrentValues(); + + _layerModel.X = _xTweener.Value; + _layerModel.Y = _yTweener.Value; + _layerModel.Width = _widthTweener.Value; + _layerModel.Height = _heightTweener.Value; + _layerModel.Opacity = _opacityTweener.Value; + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs b/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs index b64983c10..7ad428a31 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs @@ -28,6 +28,7 @@ namespace Artemis.Profiles.Layers.Types.Audio private readonly WasapiLoopbackCapture _waveIn; private int _lines; private AudioPropertiesModel _previousSettings; + private DateTime _lastAudioUpdate; public AudioType() { @@ -36,7 +37,7 @@ namespace Artemis.Profiles.Layers.Types.Audio _sampleAggregator.FftCalculated += FftCalculated; _sampleAggregator.PerformFFT = true; - + // Start listening for sound data _waveIn = new WasapiLoopbackCapture(); _waveIn.DataAvailable += OnDataAvailable; @@ -107,14 +108,15 @@ namespace Artemis.Profiles.Layers.Types.Audio { UpdateLayers(layerModel); - if (!SpectrumData.Any()) - return; - - var settings = (AudioPropertiesModel) layerModel.Properties; - if ((settings.Direction == Direction.TopToBottom) || (settings.Direction == Direction.BottomToTop)) - ApplyVertical(settings); - else if ((settings.Direction == Direction.LeftToRight) || (settings.Direction == Direction.RightToLeft)) - ApplyHorizontal(settings); + if (SpectrumData.Any()) + { + var settings = (AudioPropertiesModel) layerModel.Properties; + if ((settings.Direction == Direction.TopToBottom) || (settings.Direction == Direction.BottomToTop)) + ApplyVertical(settings); + else if ((settings.Direction == Direction.LeftToRight) || + (settings.Direction == Direction.RightToLeft)) + ApplyHorizontal(settings); + } } } @@ -222,6 +224,8 @@ namespace Artemis.Profiles.Layers.Types.Audio audioLayer.Properties.Height = settings.Height; audioLayer.LayerAnimation?.Update(audioLayer, true); + audioLayer.TweenModel.Update(); + // Restore the height and width audioLayer.Properties.Height = oldHeight; audioLayer.Properties.Width = oldWidth; @@ -325,6 +329,11 @@ namespace Artemis.Profiles.Layers.Types.Audio // TODO: Check how often this is called private void OnDataAvailable(object sender, WaveInEventArgs e) { + if ((DateTime.Now - _lastAudioUpdate) < TimeSpan.FromMilliseconds(200)) + return; + + _lastAudioUpdate = DateTime.Now; + var buffer = e.Buffer; var bytesRecorded = e.BytesRecorded; var bufferIncrement = _waveIn.WaveFormat.BlockAlign; diff --git a/Artemis/Artemis/packages.config b/Artemis/Artemis/packages.config index 0e4350b48..6faac38d1 100644 --- a/Artemis/Artemis/packages.config +++ b/Artemis/Artemis/packages.config @@ -1,5 +1,6 @@  + From 041a2db6e2a4190da3241b1da31145a8e3622f7a Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Thu, 1 Dec 2016 00:12:41 +0100 Subject: [PATCH 07/17] Tweening config backend --- .../Profiles/Layers/Models/LayerModel.cs | 8 +- .../Layers/Models/LayerPropertiesModel.cs | 21 +++++ .../Profiles/Layers/Models/TweenModel.cs | 84 +++++++++---------- .../Profiles/Layers/Types/Audio/AudioType.cs | 10 +-- Artemis/Artemis/Utilities/ImageUtilities.cs | 3 - 5 files changed, 70 insertions(+), 56 deletions(-) diff --git a/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs b/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs index f7c833247..766a3b467 100644 --- a/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Models/LayerModel.cs @@ -19,7 +19,8 @@ namespace Artemis.Profiles.Layers.Models public LayerModel() { Children = new ChildItemCollection(this); - TweenModel = new TweenModel(this, 200); + TweenModel = new TweenModel(this); + var model = Properties as KeyboardPropertiesModel; if (model != null) GifImage = new GifImage(model.GifFile); @@ -53,8 +54,9 @@ namespace Artemis.Profiles.Layers.Models LayerType.Update(this, dataModel, preview); LayerAnimation?.Update(this, updateAnimations); - TweenModel.Update(); - + if (!preview && updateAnimations) + TweenModel.Update(); + LastRender = DateTime.Now; } diff --git a/Artemis/Artemis/Profiles/Layers/Models/LayerPropertiesModel.cs b/Artemis/Artemis/Profiles/Layers/Models/LayerPropertiesModel.cs index 9dc878e84..310aec92d 100644 --- a/Artemis/Artemis/Profiles/Layers/Models/LayerPropertiesModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Models/LayerPropertiesModel.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Windows; using System.Windows.Media; @@ -26,6 +27,16 @@ namespace Artemis.Profiles.Layers.Models Conditions = source.Conditions; DynamicProperties = source.DynamicProperties; Brush = source.Brush; + XEase = source.XEase; + YEase = source.YEase; + HeightEase = source.HeightEase; + WidthEase = source.WidthEase; + OpacityEase = source.OpacityEase; + XEaseTime = source.XEaseTime; + YEaseTime = source.YEaseTime; + HeightEaseTime = source.HeightEaseTime; + WidthEaseTime = source.WidthEaseTime; + OpacityEaseTime = source.OpacityEaseTime; } public double X { get; set; } @@ -35,6 +46,16 @@ namespace Artemis.Profiles.Layers.Models public bool Contain { get; set; } public double Opacity { get; set; } public double AnimationSpeed { get; set; } + public double OpacityEaseTime { get; set; } + public double HeightEaseTime { get; set; } + public double WidthEaseTime { get; set; } + public double YEaseTime { get; set; } + public double XEaseTime { get; set; } + public string XEase { get; set; } + public string YEase { get; set; } + public string WidthEase { set; get; } + public string HeightEase { get; set; } + public string OpacityEase { get; set; } public List Conditions { get; set; } = new List(); public List DynamicProperties { get; set; } = new List(); diff --git a/Artemis/Artemis/Profiles/Layers/Models/TweenModel.cs b/Artemis/Artemis/Profiles/Layers/Models/TweenModel.cs index 47e68220d..3d401159d 100644 --- a/Artemis/Artemis/Profiles/Layers/Models/TweenModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Models/TweenModel.cs @@ -17,64 +17,36 @@ namespace Artemis.Profiles.Layers.Models private float _y; private Tweener _yTweener; - public TweenModel(LayerModel layerModel, double defaultDuration) + public TweenModel(LayerModel layerModel) { _layerModel = layerModel; - XDuration = defaultDuration; - YDuration = defaultDuration; - WidthDuration = defaultDuration; - HeightDuration = defaultDuration; - OpacityDuration = defaultDuration; - - XFunc = Ease.Quad.InOut; - YFunc = Ease.Quad.InOut; - WidthFunc = Ease.Quad.InOut; - HeightFunc = Ease.Quad.InOut; - OpacityFunc = Ease.Quad.InOut; - - _xTweener = new Tweener(0, (float) layerModel.X, XDuration, XFunc); - _yTweener = new Tweener(0, (float) layerModel.Y, YDuration, YFunc); - _widthTweener = new Tweener(0, (float) layerModel.Width, WidthDuration, WidthFunc); - _heightTweener = new Tweener(0, (float) layerModel.Height, HeightDuration, HeightFunc); - _opacityTweener = new Tweener(0, (float) layerModel.Opacity, OpacityDuration, OpacityFunc); + _xTweener = new Tweener((float) layerModel.X, (float) layerModel.X, 0); + _yTweener = new Tweener((float) layerModel.Y, (float) layerModel.Y, 0); + _widthTweener = new Tweener((float) layerModel.Width, (float) layerModel.Width, 0); + _heightTweener = new Tweener((float) layerModel.Height, (float) layerModel.Height, 0); + _opacityTweener = new Tweener((float) layerModel.Opacity, (float) layerModel.Opacity, 0); StoreCurrentValues(); } - public double XDuration { get; set; } - public double YDuration { get; set; } - public double WidthDuration { get; set; } - public double HeightDuration { get; set; } - public double OpacityDuration { get; set; } - - public EaseFunc XFunc { get; set; } - public EaseFunc YFunc { get; set; } - public EaseFunc WidthFunc { get; set; } - public EaseFunc HeightFunc { get; set; } - public EaseFunc OpacityFunc { get; set; } - - private void StoreCurrentValues() - { - _x = (float) _layerModel.X; - _y = (float) _layerModel.Y; - _width = (float) _layerModel.Width; - _height = (float) _layerModel.Height; - _opacity = (float) _layerModel.Opacity; - } - public void Update() { if (Math.Abs(_layerModel.X - _x) > 0.001) - _xTweener = new Tweener(_x, (float) _layerModel.X, XDuration, XFunc); + _xTweener = new Tweener(_x, (float) _layerModel.X, _layerModel.Properties.XEaseTime, + GetEaseFunction(_layerModel.Properties.XEase)); if (Math.Abs(_layerModel.Y - _y) > 0.001) - _yTweener = new Tweener(_y, (float) _layerModel.Y, YDuration, YFunc); + _yTweener = new Tweener(_y, (float) _layerModel.Y, _layerModel.Properties.YEaseTime, + GetEaseFunction(_layerModel.Properties.YEase)); if (Math.Abs(_layerModel.Width - _width) > 0.001) - _widthTweener = new Tweener(_width, (float) _layerModel.Width, WidthDuration, WidthFunc); + _widthTweener = new Tweener(_width, (float) _layerModel.Width, + _layerModel.Properties.WidthEaseTime, GetEaseFunction(_layerModel.Properties.WidthEase)); if (Math.Abs(_layerModel.Height - _height) > 0.001) - _heightTweener = new Tweener(_height, (float) _layerModel.Height, HeightDuration, HeightFunc); + _heightTweener = new Tweener(_height, (float) _layerModel.Height, + _layerModel.Properties.HeightEaseTime, GetEaseFunction(_layerModel.Properties.HeightEase)); if (Math.Abs(_layerModel.Opacity - _opacity) > 0.001) - _opacityTweener = new Tweener(_opacity, (float) _layerModel.Opacity, OpacityDuration, OpacityFunc); + _opacityTweener = new Tweener(_opacity, (float) _layerModel.Opacity, + _layerModel.Properties.OpacityEaseTime, GetEaseFunction(_layerModel.Properties.OpacityEase)); _xTweener.Update(40); _yTweener.Update(40); @@ -90,5 +62,29 @@ namespace Artemis.Profiles.Layers.Models _layerModel.Height = _heightTweener.Value; _layerModel.Opacity = _opacityTweener.Value; } + + private void StoreCurrentValues() + { + _x = (float) _layerModel.X; + _y = (float) _layerModel.Y; + _width = (float) _layerModel.Width; + _height = (float) _layerModel.Height; + _opacity = (float) _layerModel.Opacity; + } + + private static EaseFunc GetEaseFunction(string functionName) + { + switch (functionName) + { + case "In": + return Ease.Quint.In; + case "Out": + return Ease.Quint.Out; + case "InOut": + return Ease.Quint.InOut; + default: + return Ease.Linear; + } + } } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs b/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs index 7ad428a31..6db7563b3 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioType.cs @@ -26,9 +26,9 @@ namespace Artemis.Profiles.Layers.Types.Audio private readonly MMDevice _device; private readonly SampleAggregator _sampleAggregator = new SampleAggregator(1024); private readonly WasapiLoopbackCapture _waveIn; + private DateTime _lastAudioUpdate; private int _lines; private AudioPropertiesModel _previousSettings; - private DateTime _lastAudioUpdate; public AudioType() { @@ -37,7 +37,7 @@ namespace Artemis.Profiles.Layers.Types.Audio _sampleAggregator.FftCalculated += FftCalculated; _sampleAggregator.PerformFFT = true; - + // Start listening for sound data _waveIn = new WasapiLoopbackCapture(); _waveIn.DataAvailable += OnDataAvailable; @@ -223,8 +223,6 @@ namespace Artemis.Profiles.Layers.Types.Audio audioLayer.Properties.Width = settings.Width; audioLayer.Properties.Height = settings.Height; audioLayer.LayerAnimation?.Update(audioLayer, true); - - audioLayer.TweenModel.Update(); // Restore the height and width audioLayer.Properties.Height = oldHeight; @@ -329,9 +327,9 @@ namespace Artemis.Profiles.Layers.Types.Audio // TODO: Check how often this is called private void OnDataAvailable(object sender, WaveInEventArgs e) { - if ((DateTime.Now - _lastAudioUpdate) < TimeSpan.FromMilliseconds(200)) + if (DateTime.Now - _lastAudioUpdate < TimeSpan.FromMilliseconds(40)) return; - + _lastAudioUpdate = DateTime.Now; var buffer = e.Buffer; diff --git a/Artemis/Artemis/Utilities/ImageUtilities.cs b/Artemis/Artemis/Utilities/ImageUtilities.cs index 2984b1a6c..3326e3253 100644 --- a/Artemis/Artemis/Utilities/ImageUtilities.cs +++ b/Artemis/Artemis/Utilities/ImageUtilities.cs @@ -1,12 +1,9 @@ using System.Drawing; using System.Drawing.Imaging; using System.IO; -using System.Runtime.InteropServices; using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; -using PixelFormat = System.Drawing.Imaging.PixelFormat; -using Point = System.Drawing.Point; namespace Artemis.Utilities { From ab82491137bba4aebad9e4a93ef35f8795357c77 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Thu, 1 Dec 2016 15:06:43 +0100 Subject: [PATCH 08/17] Added easing config --- Artemis/Artemis/Artemis.csproj | 8 + .../Profiles/Layers/Models/TweenModel.cs | 15 +- .../Keyboard/KeyboardPropertiesView.xaml | 6 +- .../Keyboard/KeyboardPropertiesViewModel.cs | 2 + .../Profiles/LayerTweenViewModel.cs | 18 ++ .../Views/Profiles/LayerEditorView.xaml | 175 +++++++++--------- .../Views/Profiles/LayerTweenView.xaml | 62 +++++++ .../Views/Profiles/LayerTweenView.xaml.cs | 28 +++ 8 files changed, 218 insertions(+), 96 deletions(-) create mode 100644 Artemis/Artemis/ViewModels/Profiles/LayerTweenViewModel.cs create mode 100644 Artemis/Artemis/Views/Profiles/LayerTweenView.xaml create mode 100644 Artemis/Artemis/Views/Profiles/LayerTweenView.xaml.cs diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 1d77f6b3f..e04b70f19 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -602,6 +602,7 @@ + @@ -674,6 +675,9 @@ VolumeDisplayView.xaml + + LayerTweenView.xaml + ProfileEditorView.xaml @@ -916,6 +920,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/Artemis/Artemis/Profiles/Layers/Models/TweenModel.cs b/Artemis/Artemis/Profiles/Layers/Models/TweenModel.cs index 3d401159d..275f406f9 100644 --- a/Artemis/Artemis/Profiles/Layers/Models/TweenModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Models/TweenModel.cs @@ -6,16 +6,16 @@ namespace Artemis.Profiles.Layers.Models public class TweenModel { private readonly LayerModel _layerModel; - private float _height; - private Tweener _heightTweener; - private float _opacity; - private Tweener _opacityTweener; - private float _width; - private Tweener _widthTweener; private float _x; private Tweener _xTweener; private float _y; private Tweener _yTweener; + private float _width; + private Tweener _widthTweener; + private float _height; + private Tweener _heightTweener; + private float _opacity; + private Tweener _opacityTweener; public TweenModel(LayerModel layerModel) { @@ -32,6 +32,7 @@ namespace Artemis.Profiles.Layers.Models public void Update() { + // TODO: Don't update if animation speed is 0 if (Math.Abs(_layerModel.X - _x) > 0.001) _xTweener = new Tweener(_x, (float) _layerModel.X, _layerModel.Properties.XEaseTime, GetEaseFunction(_layerModel.Properties.XEase)); @@ -80,7 +81,7 @@ namespace Artemis.Profiles.Layers.Models return Ease.Quint.In; case "Out": return Ease.Quint.Out; - case "InOut": + case "In/out": return Ease.Quint.InOut; default: return Ease.Linear; diff --git a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardPropertiesView.xaml b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardPropertiesView.xaml index 9e582617b..30e5c540d 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardPropertiesView.xaml +++ b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardPropertiesView.xaml @@ -23,6 +23,7 @@ + + VerticalAlignment="Top" Height="Auto" TextWrapping="Wrap" > @@ -98,5 +98,7 @@ + + \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardPropertiesViewModel.cs b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardPropertiesViewModel.cs index 478b482b9..c84b3c3aa 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardPropertiesViewModel.cs +++ b/Artemis/Artemis/Profiles/Layers/Types/Keyboard/KeyboardPropertiesViewModel.cs @@ -20,6 +20,7 @@ namespace Artemis.Profiles.Layers.Types.Keyboard HeightProperties = new LayerDynamicPropertiesViewModel("Height", editorVm); WidthProperties = new LayerDynamicPropertiesViewModel("Width", editorVm); OpacityProperties = new LayerDynamicPropertiesViewModel("Opacity", editorVm); + LayerTweenViewModel = new LayerTweenViewModel(editorVm); SelectedLayerAnimation = LayerAnimations.FirstOrDefault(l => l.Name == editorVm.ProposedLayer.LayerAnimation?.Name) ?? @@ -33,6 +34,7 @@ namespace Artemis.Profiles.Layers.Types.Keyboard public LayerDynamicPropertiesViewModel HeightProperties { get; set; } public LayerDynamicPropertiesViewModel WidthProperties { get; set; } public LayerDynamicPropertiesViewModel OpacityProperties { get; set; } + public LayerTweenViewModel LayerTweenViewModel { get; set; } public bool IsGif { diff --git a/Artemis/Artemis/ViewModels/Profiles/LayerTweenViewModel.cs b/Artemis/Artemis/ViewModels/Profiles/LayerTweenViewModel.cs new file mode 100644 index 000000000..9d9379a63 --- /dev/null +++ b/Artemis/Artemis/ViewModels/Profiles/LayerTweenViewModel.cs @@ -0,0 +1,18 @@ +using Artemis.Profiles.Layers.Models; +using Caliburn.Micro; + +namespace Artemis.ViewModels.Profiles +{ + public class LayerTweenViewModel : Screen + { + public LayerModel LayerModel { get; set; } + + public LayerTweenViewModel(LayerEditorViewModel editorViewModel) + { + LayerModel = editorViewModel.ProposedLayer; + EaseFunctions = new BindableCollection {"Linear", "In", "Out", "In/out"}; + } + + public BindableCollection EaseFunctions { get; set; } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Views/Profiles/LayerEditorView.xaml b/Artemis/Artemis/Views/Profiles/LayerEditorView.xaml index c29ada817..da882c4d0 100644 --- a/Artemis/Artemis/Views/Profiles/LayerEditorView.xaml +++ b/Artemis/Artemis/Views/Profiles/LayerEditorView.xaml @@ -11,99 +11,100 @@ xmlns:cal="http://www.caliburnproject.org" GlowBrush="{DynamicResource AccentColorBrush}" Icon="../../Resources/bow.png" ResizeMode="NoResize"> - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + + + -