mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-02 10:43:31 +00:00
Merge branch 'development' of https://github.com/SpoinkyNL/Artemis.git
This commit is contained in:
commit
0e1bddfaa6
@ -494,13 +494,13 @@
|
|||||||
<Compile Include="Profiles\Layers\Types\AmbientLight\ScreenCapturing\DX9ScreenCapture.cs" />
|
<Compile Include="Profiles\Layers\Types\AmbientLight\ScreenCapturing\DX9ScreenCapture.cs" />
|
||||||
<Compile Include="Profiles\Layers\Types\AmbientLight\ScreenCapturing\IScreenCapture.cs" />
|
<Compile Include="Profiles\Layers\Types\AmbientLight\ScreenCapturing\IScreenCapture.cs" />
|
||||||
<Compile Include="Profiles\Layers\Types\AmbientLight\ScreenCapturing\ScreenCaptureManager.cs" />
|
<Compile Include="Profiles\Layers\Types\AmbientLight\ScreenCapturing\ScreenCaptureManager.cs" />
|
||||||
<Compile Include="Profiles\Layers\Types\AngularBrush\AngularBrushPropertiesModel.cs" />
|
<Compile Include="Profiles\Layers\Types\ConicalBrush\ConicalBrushPropertiesModel.cs" />
|
||||||
<Compile Include="Profiles\Layers\Types\AngularBrush\AngularBrushPropertiesView.xaml.cs">
|
<Compile Include="Profiles\Layers\Types\ConicalBrush\ConicalBrushPropertiesView.xaml.cs">
|
||||||
<DependentUpon>AngularBrushPropertiesView.xaml</DependentUpon>
|
<DependentUpon>ConicalBrushPropertiesView.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Profiles\Layers\Types\AngularBrush\AngularBrushPropertiesViewModel.cs" />
|
<Compile Include="Profiles\Layers\Types\ConicalBrush\ConicalBrushPropertiesViewModel.cs" />
|
||||||
<Compile Include="Profiles\Layers\Types\AngularBrush\AngularBrushType.cs" />
|
<Compile Include="Profiles\Layers\Types\ConicalBrush\ConicalBrushType.cs" />
|
||||||
<Compile Include="Profiles\Layers\Types\AngularBrush\Drawing\GradientDrawer.cs" />
|
<Compile Include="Profiles\Layers\Types\ConicalBrush\Drawing\ConicalGradientDrawer.cs" />
|
||||||
<Compile Include="Profiles\Layers\Types\Audio\AudioCapturing\AudioCapture.cs" />
|
<Compile Include="Profiles\Layers\Types\Audio\AudioCapturing\AudioCapture.cs" />
|
||||||
<Compile Include="Profiles\Layers\Types\Audio\AudioCapturing\AudioCaptureManager.cs" />
|
<Compile Include="Profiles\Layers\Types\Audio\AudioCapturing\AudioCaptureManager.cs" />
|
||||||
<Compile Include="Events\AudioDeviceChangedEventArgs.cs" />
|
<Compile Include="Events\AudioDeviceChangedEventArgs.cs" />
|
||||||
@ -872,7 +872,7 @@
|
|||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Page>
|
</Page>
|
||||||
<Page Include="Profiles\Layers\Types\AngularBrush\AngularBrushPropertiesView.xaml">
|
<Page Include="Profiles\Layers\Types\ConicalBrush\ConicalBrushPropertiesView.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
@ -1,12 +0,0 @@
|
|||||||
using System.Windows.Controls;
|
|
||||||
|
|
||||||
namespace Artemis.Profiles.Layers.Types.AngularBrush
|
|
||||||
{
|
|
||||||
public partial class AngularBrushPropertiesView : UserControl
|
|
||||||
{
|
|
||||||
public AngularBrushPropertiesView()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -3,9 +3,9 @@ using System.Collections.Generic;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using Artemis.Profiles.Layers.Models;
|
using Artemis.Profiles.Layers.Models;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Layers.Types.AngularBrush
|
namespace Artemis.Profiles.Layers.Types.ConicalBrush
|
||||||
{
|
{
|
||||||
public class AngularBrushPropertiesModel : LayerPropertiesModel
|
public class ConicalBrushPropertiesModel : LayerPropertiesModel
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
@ -15,14 +15,10 @@ namespace Artemis.Profiles.Layers.Types.AngularBrush
|
|||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
public AngularBrushPropertiesModel(LayerPropertiesModel properties = null)
|
public ConicalBrushPropertiesModel(LayerPropertiesModel properties = null)
|
||||||
: base(properties)
|
: base(properties)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
<UserControl x:Class="Artemis.Profiles.Layers.Types.AngularBrush.AngularBrushPropertiesView"
|
<UserControl x:Class="Artemis.Profiles.Layers.Types.ConicalBrush.ConicalBrushPropertiesView"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
using System.Windows.Controls;
|
||||||
|
|
||||||
|
namespace Artemis.Profiles.Layers.Types.ConicalBrush
|
||||||
|
{
|
||||||
|
public partial class ConicalBrushPropertiesView : UserControl
|
||||||
|
{
|
||||||
|
public ConicalBrushPropertiesView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System.Linq;
|
||||||
using System.Linq;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using Artemis.Profiles.Layers.Abstract;
|
using Artemis.Profiles.Layers.Abstract;
|
||||||
using Artemis.Profiles.Layers.Interfaces;
|
using Artemis.Profiles.Layers.Interfaces;
|
||||||
using Artemis.Utilities;
|
using Artemis.Utilities;
|
||||||
@ -8,9 +6,9 @@ using Artemis.ViewModels;
|
|||||||
using Artemis.ViewModels.Profiles;
|
using Artemis.ViewModels.Profiles;
|
||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Layers.Types.AngularBrush
|
namespace Artemis.Profiles.Layers.Types.ConicalBrush
|
||||||
{
|
{
|
||||||
public class AngularBrushPropertiesViewModel : LayerPropertiesViewModel
|
public class ConicalBrushPropertiesViewModel : LayerPropertiesViewModel
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
@ -38,7 +36,7 @@ namespace Artemis.Profiles.Layers.Types.AngularBrush
|
|||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
public AngularBrushPropertiesViewModel(LayerEditorViewModel editorVm)
|
public ConicalBrushPropertiesViewModel(LayerEditorViewModel editorVm)
|
||||||
: base(editorVm)
|
: base(editorVm)
|
||||||
{
|
{
|
||||||
LayerAnimations = new BindableCollection<ILayerAnimation>(editorVm.LayerAnimations);
|
LayerAnimations = new BindableCollection<ILayerAnimation>(editorVm.LayerAnimations);
|
||||||
@ -7,40 +7,42 @@ using Artemis.Profiles.Layers.Abstract;
|
|||||||
using Artemis.Profiles.Layers.Animations;
|
using Artemis.Profiles.Layers.Animations;
|
||||||
using Artemis.Profiles.Layers.Interfaces;
|
using Artemis.Profiles.Layers.Interfaces;
|
||||||
using Artemis.Profiles.Layers.Models;
|
using Artemis.Profiles.Layers.Models;
|
||||||
using Artemis.Profiles.Layers.Types.AngularBrush.Drawing;
|
using Artemis.Profiles.Layers.Types.ConicalBrush.Drawing;
|
||||||
using Artemis.ViewModels;
|
using Artemis.ViewModels;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Layers.Types.AngularBrush
|
namespace Artemis.Profiles.Layers.Types.ConicalBrush
|
||||||
{
|
{
|
||||||
public class AngularBrushType : ILayerType
|
public class ConicalBrushType : ILayerType
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private GradientDrawer _gradientDrawer;
|
private ConicalGradientDrawer _conicalGradientDrawer;
|
||||||
|
private ConicalGradientDrawer _conicalGradientDrawerThumbnail;
|
||||||
|
|
||||||
public string Name => "Angular Brush";
|
public string Name => "Conical Brush";
|
||||||
public bool ShowInEdtor => true;
|
public bool ShowInEdtor => true;
|
||||||
public DrawType DrawType => DrawType.Keyboard;
|
public DrawType DrawType => DrawType.Keyboard;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public AngularBrushType()
|
public ConicalBrushType()
|
||||||
{
|
{
|
||||||
_gradientDrawer = new GradientDrawer();
|
_conicalGradientDrawer = new ConicalGradientDrawer();
|
||||||
|
_conicalGradientDrawerThumbnail = new ConicalGradientDrawer(18, 18);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
public ImageSource DrawThumbnail(LayerModel layer)
|
public ImageSource DrawThumbnail(LayerModel layer)
|
||||||
{
|
{
|
||||||
//TODO DarthAffe 14.01.2017: This could be replaced with the real brush but it complaints about the thread too
|
_conicalGradientDrawerThumbnail.GradientStops = GetGradientStops(layer.Brush).Select(x => new Tuple<double, Color>(x.Offset, x.Color)).ToList();
|
||||||
|
_conicalGradientDrawerThumbnail.Update();
|
||||||
|
|
||||||
Rect thumbnailRect = new Rect(0, 0, 18, 18);
|
Rect thumbnailRect = new Rect(0, 0, 18, 18);
|
||||||
DrawingVisual visual = new DrawingVisual();
|
DrawingVisual visual = new DrawingVisual();
|
||||||
using (DrawingContext c = visual.RenderOpen())
|
using (DrawingContext c = visual.RenderOpen())
|
||||||
if (layer.Properties.Brush != null)
|
if (_conicalGradientDrawerThumbnail.Brush != null)
|
||||||
c.DrawRectangle(layer.Properties.Brush,
|
c.DrawRectangle(_conicalGradientDrawerThumbnail.Brush.Clone(), new Pen(new SolidColorBrush(Colors.White), 1), thumbnailRect);
|
||||||
new Pen(new SolidColorBrush(Colors.White), 1),
|
|
||||||
thumbnailRect);
|
|
||||||
|
|
||||||
DrawingImage image = new DrawingImage(visual.Drawing);
|
DrawingImage image = new DrawingImage(visual.Drawing);
|
||||||
return image;
|
return image;
|
||||||
@ -48,15 +50,14 @@ namespace Artemis.Profiles.Layers.Types.AngularBrush
|
|||||||
|
|
||||||
public void Draw(LayerModel layerModel, DrawingContext c)
|
public void Draw(LayerModel layerModel, DrawingContext c)
|
||||||
{
|
{
|
||||||
AngularBrushPropertiesModel properties = layerModel.Properties as AngularBrushPropertiesModel;
|
ConicalBrushPropertiesModel properties = layerModel.Properties as ConicalBrushPropertiesModel;
|
||||||
if (properties == null) return;
|
if (properties == null) return;
|
||||||
|
|
||||||
Brush origBrush = layerModel.Brush;
|
Brush origBrush = layerModel.Brush;
|
||||||
|
|
||||||
//TODO DarthAffe 14.01.2017: Check if an update is needed
|
_conicalGradientDrawer.GradientStops = GetGradientStops(layerModel.Brush).Select(x => new Tuple<double, Color>(x.Offset, x.Color)).ToList();
|
||||||
_gradientDrawer.GradientStops = GetGradientStops(layerModel.Brush).Select(x => new Tuple<double, Color>(x.Offset, x.Color)).ToList();
|
_conicalGradientDrawer.Update();
|
||||||
_gradientDrawer.Update();
|
layerModel.Brush = _conicalGradientDrawer.Brush;
|
||||||
layerModel.Brush = _gradientDrawer.Brush.Clone();
|
|
||||||
|
|
||||||
// If an animation is present, let it handle the drawing
|
// If an animation is present, let it handle the drawing
|
||||||
if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation))
|
if (layerModel.LayerAnimation != null && !(layerModel.LayerAnimation is NoneAnimation))
|
||||||
@ -97,15 +98,15 @@ namespace Artemis.Profiles.Layers.Types.AngularBrush
|
|||||||
|
|
||||||
public void SetupProperties(LayerModel layerModel)
|
public void SetupProperties(LayerModel layerModel)
|
||||||
{
|
{
|
||||||
if (layerModel.Properties is AngularBrushPropertiesModel)
|
if (layerModel.Properties is ConicalBrushPropertiesModel)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
layerModel.Properties = new AngularBrushPropertiesModel(layerModel.Properties);
|
layerModel.Properties = new ConicalBrushPropertiesModel(layerModel.Properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel, LayerPropertiesViewModel layerPropertiesViewModel)
|
public LayerPropertiesViewModel SetupViewModel(LayerEditorViewModel layerEditorViewModel, LayerPropertiesViewModel layerPropertiesViewModel)
|
||||||
{
|
{
|
||||||
return (layerPropertiesViewModel as AngularBrushPropertiesViewModel) ?? new AngularBrushPropertiesViewModel(layerEditorViewModel);
|
return (layerPropertiesViewModel as ConicalBrushPropertiesViewModel) ?? new ConicalBrushPropertiesViewModel(layerEditorViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GradientStopCollection GetGradientStops(Brush brush)
|
private GradientStopCollection GetGradientStops(Brush brush)
|
||||||
@ -1,13 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
using Brush = System.Windows.Media.Brush;
|
||||||
|
using Color = System.Windows.Media.Color;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Layers.Types.AngularBrush.Drawing
|
namespace Artemis.Profiles.Layers.Types.ConicalBrush.Drawing
|
||||||
{
|
{
|
||||||
public class GradientDrawer
|
public class ConicalGradientDrawer
|
||||||
{
|
{
|
||||||
#region Constants
|
#region Constants
|
||||||
|
|
||||||
@ -17,22 +20,67 @@ namespace Artemis.Profiles.Layers.Types.AngularBrush.Drawing
|
|||||||
|
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private int _width;
|
||||||
|
private int _height;
|
||||||
|
|
||||||
|
private bool _isDirty = true;
|
||||||
|
private int _lastGradientHash;
|
||||||
|
|
||||||
private WriteableBitmap _bitmap;
|
private WriteableBitmap _bitmap;
|
||||||
|
|
||||||
private IList<Tuple<double, Color>> _gradientStops;
|
private IList<Tuple<double, Color>> _gradientStops;
|
||||||
public IList<Tuple<double, Color>> GradientStops
|
public IList<Tuple<double, Color>> GradientStops
|
||||||
{
|
{
|
||||||
set { _gradientStops = FixGradientStops(value); }
|
set
|
||||||
|
{
|
||||||
|
int hash = GetHash(value);
|
||||||
|
if (_lastGradientHash != hash)
|
||||||
|
{
|
||||||
|
_gradientStops = FixGradientStops(value);
|
||||||
|
_lastGradientHash = hash;
|
||||||
|
_isDirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PointF _center = new PointF(0.5f, 0.5f);
|
||||||
|
public PointF Center
|
||||||
|
{
|
||||||
|
get { return _center; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_center != value)
|
||||||
|
{
|
||||||
|
_center = value;
|
||||||
|
_isDirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Brush Brush { get; private set; }
|
public Brush Brush { get; private set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public ConicalGradientDrawer()
|
||||||
|
: this(100, 100)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public ConicalGradientDrawer(int width, int height)
|
||||||
|
{
|
||||||
|
this._width = width;
|
||||||
|
this._height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
public void Update()
|
public void Update(bool force = false)
|
||||||
{
|
{
|
||||||
|
if (!_isDirty && !force) return;
|
||||||
|
|
||||||
if (_bitmap == null)
|
if (_bitmap == null)
|
||||||
CreateBrush();
|
CreateBrush();
|
||||||
|
|
||||||
@ -41,31 +89,27 @@ namespace Artemis.Profiles.Layers.Types.AngularBrush.Drawing
|
|||||||
_bitmap.Lock();
|
_bitmap.Lock();
|
||||||
byte* buffer = (byte*)_bitmap.BackBuffer.ToPointer();
|
byte* buffer = (byte*)_bitmap.BackBuffer.ToPointer();
|
||||||
|
|
||||||
int width = _bitmap.PixelWidth;
|
for (int y = 0; y < _height; y++)
|
||||||
double widthHalf = width / 2.0;
|
for (int x = 0; x < _width; x++)
|
||||||
|
|
||||||
int height = _bitmap.PixelHeight;
|
|
||||||
double heightHalf = height / 2.0;
|
|
||||||
|
|
||||||
for (int y = 0; y < height; y++)
|
|
||||||
for (int x = 0; x < width; x++)
|
|
||||||
{
|
{
|
||||||
int offset = (((y * width) + x) * 4);
|
int offset = (((y * _width) + x) * 4);
|
||||||
|
|
||||||
double gradientOffset = CalculateGradientOffset(x, y, widthHalf, heightHalf);
|
double gradientOffset = CalculateGradientOffset(x, y, _width * Center.X, _height * Center.Y);
|
||||||
GetColor(_gradientStops, gradientOffset,
|
GetColor(_gradientStops, gradientOffset,
|
||||||
ref buffer[offset + 3], ref buffer[offset + 2],
|
ref buffer[offset + 3], ref buffer[offset + 2],
|
||||||
ref buffer[offset + 1], ref buffer[offset]);
|
ref buffer[offset + 1], ref buffer[offset]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
|
_bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height));
|
||||||
_bitmap.Unlock();
|
_bitmap.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_isDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateBrush()
|
private void CreateBrush()
|
||||||
{
|
{
|
||||||
_bitmap = new WriteableBitmap(100, 100, 96, 96, PixelFormats.Bgra32, null);
|
_bitmap = new WriteableBitmap(_width, _height, 96, 96, PixelFormats.Bgra32, null);
|
||||||
Brush = new ImageBrush(_bitmap) { Stretch = Stretch.UniformToFill };
|
Brush = new ImageBrush(_bitmap) { Stretch = Stretch.UniformToFill };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +171,7 @@ namespace Artemis.Profiles.Layers.Types.AngularBrush.Drawing
|
|||||||
colB = (byte)((afterColor.B - beforeColor.B) * blendFactor + beforeColor.B);
|
colB = (byte)((afterColor.B - beforeColor.B) * blendFactor + beforeColor.B);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IList<Tuple<double, Color>> FixGradientStops(IList<Tuple<double, Color>> gradientStops)
|
private static IList<Tuple<double, Color>> FixGradientStops(IList<Tuple<double, Color>> gradientStops)
|
||||||
{
|
{
|
||||||
if (gradientStops == null) return new List<Tuple<double, Color>>();
|
if (gradientStops == null) return new List<Tuple<double, Color>>();
|
||||||
|
|
||||||
@ -144,6 +188,14 @@ namespace Artemis.Profiles.Layers.Types.AngularBrush.Drawing
|
|||||||
return stops;
|
return stops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int GetHash(IList<Tuple<double, Color>> sequence)
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
return sequence.Aggregate(487, (current, item) => (((current * 31) + item.Item1.GetHashCode()) * 31) + item.Item2.GetHashCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user