1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Implemented GIF layer, added layer type icons

This commit is contained in:
SpoinkyNL 2016-05-04 23:44:54 +02:00
parent e18b8adfb7
commit 4f0091f45c
20 changed files with 357 additions and 157 deletions

View File

@ -2,50 +2,21 @@
<configuration>
<configSections>
<sectionGroup name="userSettings"
type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Artemis.Modules.Games.TheDivision.TheDivision"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.Dota2.Dota2"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Overlays.VolumeDisplay.VolumeDisplay"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.RocketLeague.RocketLeague"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.Offsets"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.Witcher3.Witcher3"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Effects.AudioVisualizer.AudioVisualization"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.CounterStrike.CounterStrike"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.CounterStrike"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.AudioVisualization"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.RocketLeague"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.TypeWave"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.General"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Artemis.Modules.Games.TheDivision.TheDivision" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.Dota2.Dota2" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Overlays.VolumeDisplay.VolumeDisplay" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.RocketLeague.RocketLeague" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.Offsets" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.Witcher3.Witcher3" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Effects.AudioVisualizer.AudioVisualization" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.CounterStrike.CounterStrike" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.CounterStrike" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.AudioVisualization" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.RocketLeague" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.TypeWave" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.General" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings />

View File

@ -223,6 +223,10 @@
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="XamlAnimatedGif, Version=1.1.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\XamlAnimatedGif.1.1.2\lib\net45\XamlAnimatedGif.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xceed.Wpf.AvalonDock, Version=2.7.0.0, Culture=neutral, PublicKeyToken=3e4669d2f30244f4, processorArchitecture=MSIL">
<HintPath>..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.AvalonDock.dll</HintPath>
<Private>True</Private>
@ -391,6 +395,7 @@
<Compile Include="Utilities\GameState\GameDataReceivedEventArgs.cs" />
<Compile Include="Utilities\GameState\GameStateWebServer.cs" />
<Compile Include="Utilities\GeneralHelpers.cs" />
<Compile Include="Utilities\GifImage.cs" />
<Compile Include="Utilities\ImageUtilities.cs" />
<Compile Include="Utilities\Keyboard\KeyboardHook.cs" />
<Compile Include="Utilities\LayerDrawer.cs" />
@ -551,7 +556,6 @@
<Resource Include="Resources\Dota2\dotaGamestateConfiguration.txt" />
<Resource Include="Resources\Entypo.ttf" />
<None Include="Resources\LogitechLED.dll" />
<None Include="Resources\folder.png" />
<Resource Include="Resources\Keyboards\k65.png" />
<Resource Include="Resources\Keyboards\k70.png" />
<Resource Include="Resources\Keyboards\k95.png" />
@ -559,6 +563,10 @@
<Resource Include="Resources\Keyboards\g910.png" />
<Resource Include="Resources\WindowsIcons-license.txt" />
<Resource Include="Resources\Entypo-license.txt" />
<None Include="Resources\folder.png" />
<None Include="Resources\headset.png" />
<None Include="Resources\mouse.png" />
<None Include="Resources\gif.png" />
<Content Include="Resources\Witcher3\playerWitcher.txt" />
<Content Include="Resources\Witcher3\artemis.txt" />
<None Include="Settings\Offsets.settings">

View File

@ -149,7 +149,7 @@ namespace Artemis.Managers
ActiveEffect?.Dispose();
ActiveEffect = PauseEffect;
ActiveEffect.Enable();
ActiveEffect?.Enable();
_mainManager.Unpause();
PauseEffect = null;
@ -159,7 +159,7 @@ namespace Artemis.Managers
return;
// Non-game effects are stored as the new LastEffect.
General.Default.LastEffect = ActiveEffect.Name;
General.Default.LastEffect = ActiveEffect?.Name;
General.Default.Save();
}

View File

@ -29,6 +29,7 @@ namespace Artemis.Models.Profiles
public string Name { get; set; }
public LayerType LayerType { get; set; }
public string GifFile { get; set; }
public bool Enabled { get; set; }
public int Order { get; set; }
public LayerPropertiesModel UserProps { get; set; }
@ -60,7 +61,7 @@ namespace Artemis.Models.Profiles
if (LayerType == LayerType.Keyboard || LayerType == LayerType.Keyboard)
_drawer.Draw(c, _mustDraw);
else if (LayerType == LayerType.KeyboardGif)
_drawer.DrawGif(c);
_drawer.DrawGif(c, _mustDraw);
_mustDraw = false;
}

View File

@ -6,6 +6,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using Artemis.Events;
using Artemis.Managers;
using Artemis.Utilities;
using Artemis.ViewModels.Abstract;
using Caliburn.Micro;
@ -67,19 +68,7 @@ namespace Artemis.Modules.Effects.Debug
public void Handle(ChangeBitmap message)
{
using (var memory = new MemoryStream())
{
message.Bitmap.Save(memory, ImageFormat.Png);
memory.Position = 0;
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
ImageSource = bitmapImage;
}
ImageSource = ImageUtilities.BitmapToBitmapImage(message.Bitmap);
}
}
}

View File

@ -49,7 +49,7 @@
cal:Message.Attach="[Event LostFocus] = [Action PlaceConfigFile]" />
<Button x:Name="BrowseDirectory" Content="..." RenderTransformOrigin="-0.039,-0.944"
HorizontalAlignment="Right" Width="25"
Style="{DynamicResource SquareButtonStyle}" Height="25" />
Style="{DynamicResource SquareButtonStyle}" Height="26" Margin="0,-2,0,0" />
</Grid>
</StackPanel>

View File

@ -155,6 +155,26 @@ namespace Artemis.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap gif {
get {
object obj = ResourceManager.GetObject("gif", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap headset {
get {
object obj = ResourceManager.GetObject("headset", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
@ -215,6 +235,16 @@ namespace Artemis.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap mouse {
get {
object obj = ResourceManager.GetObject("mouse", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized string similar to /***********************************************************************/
////** © 2015 CD PROJEKT S.A. All rights reserved.

View File

@ -142,9 +142,6 @@
<data name="playerWitcherWs" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\witcher3\playerwitcher.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16</value>
</data>
<data name="folder" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\folder.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="k65" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\keyboards\k65.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
@ -160,4 +157,16 @@
<data name="g910" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Keyboards\g910.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="folder" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\folder.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="headset" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\headset.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="mouse" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\mouse.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="gif" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\gif.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -33,11 +33,11 @@ namespace Artemis.Services
{
public class MetroDialogService : DialogService
{
private readonly ShellViewModel _shellViewModel;
private readonly IScreen _viewModel;
public MetroDialogService(ShellViewModel shellViewModel)
public MetroDialogService(IScreen viewModel)
{
_shellViewModel = shellViewModel;
_viewModel = viewModel;
}
private MetroWindow GetActiveWindow()
@ -58,7 +58,7 @@ namespace Artemis.Services
public override void ShowMessageBox(string title, string message)
{
if (_shellViewModel.IsActive == false)
if (_viewModel.IsActive == false)
return;
Execute.OnUIThread(() => GetActiveWindow().ShowMessageAsync(title, message));
@ -66,7 +66,7 @@ namespace Artemis.Services
public override async Task<bool?> ShowQuestionMessageBox(string title, string message)
{
if (_shellViewModel.IsActive == false)
if (_viewModel.IsActive == false)
return null;
var metroDialogSettings = new MetroDialogSettings {AffirmativeButtonText = "Yes", NegativeButtonText = "No"};
@ -87,7 +87,7 @@ namespace Artemis.Services
public override Task<string> ShowInputDialog(string title, string message)
{
if (_shellViewModel.IsActive == false)
if (_viewModel.IsActive == false)
return null;
return GetActiveWindow().ShowInputAsync(title, message);
@ -95,7 +95,7 @@ namespace Artemis.Services
public override bool ShowOpenDialog(out string path, string defaultExt, string filter, string initialDir = null)
{
if (_shellViewModel.IsActive == false)
if (_viewModel.IsActive == false)
{
path = null;
return false;

View File

@ -0,0 +1,63 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
namespace Artemis.Utilities
{
public class GifImage
{
private readonly int _delay;
private readonly FrameDimension _dimension;
private readonly int _frameCount;
private readonly Image _gifImage;
private int _currentFrame = -1;
private DateTime _lastRequest;
private int _step = 1;
public GifImage(string path)
{
_lastRequest = DateTime.Now;
_gifImage = Image.FromFile(path); //initialize
_dimension = new FrameDimension(_gifImage.FrameDimensionsList[0]); //gets the GUID
_frameCount = _gifImage.GetFrameCount(_dimension); //total frames in the animation
var item = _gifImage.GetPropertyItem(0x5100); // FrameDelay in libgdiplus
_delay = (item.Value[0] + item.Value[1]*256)*10; // Time is in 1/100th of a second
}
/// <summary>
/// Whether the gif should play backwards when it reaches the end
/// </summary>
public bool ReverseAtEnd { get; set; }
public Image GetNextFrame()
{
// Only pass the next frame if the proper amount of time has passed
if ((DateTime.Now - _lastRequest).Milliseconds > _delay)
{
_currentFrame += _step;
_lastRequest = DateTime.Now;
}
//if the animation reaches a boundary...
if (_currentFrame < _frameCount && _currentFrame >= 1)
return GetFrame(_currentFrame);
if (ReverseAtEnd)
{
_step *= -1; //...reverse the count
_currentFrame += _step; //apply it
}
else
_currentFrame = 0; //...or start over
return GetFrame(_currentFrame);
}
public Image GetFrame(int index)
{
_gifImage.SelectActiveFrame(_dimension, index); //find the frame
return (Image) _gifImage.Clone(); //return a copy of it
}
}
}

View File

@ -1,5 +1,6 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
@ -60,6 +61,26 @@ namespace Artemis.Utilities
}
}
public static BitmapImage BitmapToBitmapImage(Bitmap b)
{
if (b == null)
return null;
using (var memory = new MemoryStream())
{
b.Save(memory, ImageFormat.Png);
memory.Position = 0;
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
return bitmapImage;
}
}
public static Bitmap DrawinVisualToBitmap(DrawingVisual visual, Rect rect)
{
var bmp = new RenderTargetBitmap((int) rect.Width, (int) rect.Height, 96, 96, PixelFormats.Pbgra32);

View File

@ -1,7 +1,13 @@
using System;
using System.Drawing;
using System.IO;
using System.Windows;
using System.Windows.Media;
using Artemis.Models.Profiles;
using Artemis.Properties;
using Pen = System.Windows.Media.Pen;
using Point = System.Windows.Point;
using Size = System.Windows.Size;
namespace Artemis.Utilities
{
@ -10,6 +16,8 @@ namespace Artemis.Utilities
private readonly LayerModel _layerModel;
private double _animationProgress;
private Rect _firstRect;
private GifImage _gifImage;
private string _gifSource;
private Rect _rectangle;
private Rect _secondRect;
@ -113,13 +121,22 @@ namespace Artemis.Utilities
public DrawingImage GetThumbnail()
{
if (_layerModel.UserProps.Brush == null)
return null;
var thumbnailRect = new Rect(0, 0, 18, 18);
var visual = new DrawingVisual();
using (var c = visual.RenderOpen())
c.DrawRectangle(_layerModel.UserProps.Brush, new Pen(new SolidColorBrush(Colors.White), 1),
new Rect(0, 0, 18, 18));
{
// Draw the appropiate icon or draw the brush
if (_layerModel.LayerType == LayerType.Folder)
c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.folder), thumbnailRect);
else if (_layerModel.LayerType == LayerType.Headset)
c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.headset), thumbnailRect);
else if(_layerModel.LayerType == LayerType.Mouse)
c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.mouse), thumbnailRect);
else if(_layerModel.LayerType == LayerType.KeyboardGif)
c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.gif), thumbnailRect);
else if(_layerModel.LayerType == LayerType.Keyboard && _layerModel.UserProps.Brush != null)
c.DrawRectangle(_layerModel.UserProps.Brush, new Pen(new SolidColorBrush(Colors.White), 1), thumbnailRect);
}
var image = new DrawingImage(visual.Drawing);
return image;
@ -153,8 +170,25 @@ namespace Artemis.Utilities
new Point(_rectangle.Width/2, _rectangle.Height/2), _rectangle.Width, _rectangle.Height);
}
public void DrawGif(DrawingContext bmp)
public void DrawGif(DrawingContext c, bool update = true)
{
if (string.IsNullOrEmpty(_layerModel.GifFile))
return;
if (!File.Exists(_layerModel.GifFile))
return;
if (_layerModel.GifFile != _gifSource || _gifSource == null)
{
_gifImage = new GifImage(_layerModel.GifFile);
_gifSource = _layerModel.GifFile;
}
var gifRect = new Rect(_layerModel.CalcProps.X*Scale,
_layerModel.CalcProps.Y*Scale, _layerModel.CalcProps.Width*Scale,
_layerModel.CalcProps.Height*Scale);
var draw = update ? _gifImage.GetNextFrame() : _gifImage.GetFrame(0);
c.DrawImage(ImageUtilities.BitmapToBitmapImage(new Bitmap(draw)), gifRect);
}
public void UpdateMouse()

View File

@ -1,12 +1,16 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using System.Windows.Media;
using Artemis.KeyboardProviders;
using Artemis.Models.Profiles;
using Artemis.Services;
using Artemis.Utilities;
using Caliburn.Micro;
using Screen = Caliburn.Micro.Screen;
namespace Artemis.ViewModels.LayerEditor
{
@ -18,12 +22,15 @@ namespace Artemis.ViewModels.LayerEditor
private LayerModel _layer;
private LayerModel _proposedLayer;
private LayerPropertiesModel _proposedProperties;
private LayerType _layerType;
private MetroDialogService _dialogService;
public LayerEditorViewModel(KeyboardProvider activeKeyboard, LayerModel layer)
{
_activeKeyboard = activeKeyboard;
_wasEnabled = layer.Enabled;
_dialogService = new MetroDialogService(this);
Layer = layer;
ProposedLayer = new LayerModel();
GeneralHelpers.CopyProperties(ProposedLayer, Layer);
@ -42,10 +49,10 @@ namespace Artemis.ViewModels.LayerEditor
_previewWorker.DoWork += PreviewWorkerOnDoWork;
_previewWorker.RunWorkerAsync();
PropertyChanged += AnimationUiHandler;
PropertyChanged += GridDisplayHandler;
PreSelect();
}
public LayerDynamicPropertiesViewModel OpacityProperties { get; set; }
public LayerDynamicPropertiesViewModel WidthProperties { get; set; }
@ -91,6 +98,9 @@ namespace Artemis.ViewModels.LayerEditor
}
}
public bool KeyboardGridIsVisible => Layer.LayerType == LayerType.Keyboard;
public bool GifGridIsVisible => Layer.LayerType == LayerType.KeyboardGif;
public ImageSource LayerImage
{
get
@ -128,12 +138,28 @@ namespace Artemis.ViewModels.LayerEditor
public void PreSelect()
{
GeneralHelpers.CopyProperties(ProposedProperties, Layer.UserProps);
LayerType = Layer.LayerType;
}
private void AnimationUiHandler(object sender, PropertyChangedEventArgs e)
public LayerType LayerType
{
if (e.PropertyName != "_proposedProperties")
get { return _layerType; }
set
{
if (value == _layerType) return;
_layerType = value;
NotifyOfPropertyChange(() => LayerType);
}
}
private void GridDisplayHandler(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName != "LayerType")
return;
Layer.LayerType = LayerType;
NotifyOfPropertyChange(() => KeyboardGridIsVisible);
NotifyOfPropertyChange(() => GifGridIsVisible);
}
public void AddCondition()
@ -149,6 +175,9 @@ namespace Artemis.ViewModels.LayerEditor
HeightProperties.Apply();
WidthProperties.Apply();
OpacityProperties.Apply();
if (!File.Exists(Layer.GifFile) && Layer.LayerType == LayerType.KeyboardGif)
_dialogService.ShowErrorMessageBox("Couldn't find or access the provided GIF file.");
}
public void DeleteCondition(LayerConditionViewModel<T> layerConditionViewModel,
@ -158,6 +187,14 @@ namespace Artemis.ViewModels.LayerEditor
Layer.LayerConditions.Remove(layerConditionModel);
}
public void BrowseGif()
{
var dialog = new OpenFileDialog {Filter = "Animated image file (*.gif)|*.gif"};
var result = dialog.ShowDialog();
if (result == DialogResult.OK)
Layer.GifFile = dialog.FileName;
}
public override void CanClose(Action<bool> callback)
{
_previewWorker.CancelAsync();

View File

@ -1,14 +1,11 @@
using System;
using System.ComponentModel;
using System.Drawing.Imaging;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Artemis.DAL;
using Artemis.Events;
using Artemis.KeyboardProviders;
@ -133,7 +130,10 @@ namespace Artemis.ViewModels
drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, keyboardRect);
// Draw the layers
foreach (var layerModel in _selectedProfile.Layers.OrderByDescending(l => l.Order))
foreach (
var layerModel in
_selectedProfile.Layers.OrderByDescending(l => l.Order)
.Where(l => l.LayerType == LayerType.Keyboard || l.LayerType == LayerType.KeyboardGif))
layerModel.DrawPreview(drawingContext);
// Get the selection color
@ -170,28 +170,7 @@ namespace Artemis.ViewModels
}
}
public ImageSource KeyboardImage
{
get
{
using (var memory = new MemoryStream())
{
if (ActiveKeyboard?.PreviewSettings.Image == null)
return null;
ActiveKeyboard.PreviewSettings.Image.Save(memory, ImageFormat.Png);
memory.Position = 0;
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
return bitmapImage;
}
}
}
public ImageSource KeyboardImage => ImageUtilities.BitmapToBitmapImage(ActiveKeyboard?.PreviewSettings.Image);
public PreviewSettings? PreviewSettings => ActiveKeyboard?.PreviewSettings;

View File

@ -14,6 +14,13 @@
ResizeMode="NoResize">
<controls:MetroWindow.Resources>
<utilities:EnumDescriptionConverter x:Key="HEnumDescriptionConverter" />
<ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type sys:Enum}"
x:Key="LayerEnumValues">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="profileEnumerations:LayerType" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider MethodName="GetValues"
ObjectType="{x:Type sys:Enum}"
x:Key="AnimationEnumValues">
@ -44,12 +51,6 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition />
</Grid.RowDefinitions>
@ -62,6 +63,17 @@
<TextBox Grid.Row="1" Grid.Column="1" x:Name="Name" Margin="10" Text="{Binding Path=Layer.Name}" />
<!-- Layer type -->
<TextBlock Grid.Row="1" Grid.Column="2" Margin="10,12" FontSize="13.333" Text="Type:"
VerticalAlignment="Center" Height="18" />
<ComboBox Grid.Row="1" Grid.Column="3" ItemsSource="{Binding Source={StaticResource LayerEnumValues}}"
Margin="10" SelectedItem="{Binding Path=LayerType}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource HEnumDescriptionConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!-- Condition editor -->
<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" FontSize="20" Content="Display if.." />
@ -85,58 +97,104 @@
<Label Grid.Row="4" Grid.Column="0" FontSize="20" HorizontalAlignment="Left"
Content="Advanced" Width="97" VerticalAlignment="Bottom" />
<!-- Colors -->
<TextBlock Grid.Row="5" Grid.Column="0" Margin="10,13,10,0" FontSize="13.333" Text="Color(s):"
VerticalAlignment="Top" Height="18" />
<Border Grid.Row="5" Grid.Column="1" Margin="10" BorderBrush="{StaticResource ControlBorderBrush}"
BorderThickness="1" SnapsToDevicePixels="True" ToolTip="Click to edit">
<ncore:ColorBox Brush="{Binding Path=ProposedProperties.Brush, Mode=TwoWay}" Height="24" />
</Border>
<!-- Advanced settings - Keyboard -->
<Grid x:Name="KeyboardGridIsVisible" Grid.Row="5" Grid.ColumnSpan="4" Grid.Column="0">
<!-- Colors -->
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="10,13,10,0" FontSize="13.333" Text="Color(s):"
VerticalAlignment="Top" Height="18" />
<Border Grid.Row="0" Grid.Column="1" Margin="10" BorderBrush="{StaticResource ControlBorderBrush}"
BorderThickness="1" SnapsToDevicePixels="True" ToolTip="Click to edit">
<ncore:ColorBox Brush="{Binding Path=ProposedProperties.Brush, Mode=TwoWay}" Height="24" />
</Border>
<!-- ContainedBrush -->
<TextBlock Grid.Row="5" Grid.Column="2" Margin="10" FontSize="13.333" Text="Contained colors:"
VerticalAlignment="Center" Height="18" />
<controls:ToggleSwitch IsChecked="{Binding Path=ProposedProperties.ContainedBrush, Mode=TwoWay}" Grid.Row="5"
Grid.Column="3" OnLabel="Yes" OffLabel="No" Margin="10,1,5,1" VerticalAlignment="Center"
Height="36" />
<!-- ContainedBrush -->
<TextBlock Grid.Row="0" Grid.Column="2" Margin="10" FontSize="13.333" Text="Contained colors:"
VerticalAlignment="Center" Height="18" />
<controls:ToggleSwitch IsChecked="{Binding Path=ProposedProperties.ContainedBrush, Mode=TwoWay}"
Grid.Row="0"
Grid.Column="3" OnLabel="Yes" OffLabel="No" Margin="10,1,5,1"
VerticalAlignment="Center"
Height="36" />
<!-- Animation -->
<TextBlock Grid.Row="6" Grid.Column="0" Margin="10" FontSize="13.333" Text="Animation:"
VerticalAlignment="Center"
Height="18" />
<ComboBox Grid.Row="6" Grid.Column="1" ItemsSource="{Binding Source={StaticResource AnimationEnumValues}}"
Margin="10,10,10,0" SelectedItem="{Binding Path=ProposedProperties.Animation}"
VerticalAlignment="Top" Height="22">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource HEnumDescriptionConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!-- Animation -->
<TextBlock Grid.Row="1" Grid.Column="0" Margin="10" FontSize="13.333" Text="Animation:"
VerticalAlignment="Center"
Height="18" />
<ComboBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Source={StaticResource AnimationEnumValues}}"
Margin="10,10,10,0" SelectedItem="{Binding Path=ProposedProperties.Animation}"
VerticalAlignment="Top" Height="22">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource HEnumDescriptionConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!-- Animation Speed -->
<TextBlock Grid.Row="6" Grid.Column="2" Margin="10" FontSize="13.333" Text="Animation speed:"
VerticalAlignment="Center" Height="18" />
<Slider x:Name="RotationSpeed" Grid.Row="6" Grid.Column="3" VerticalAlignment="Center"
TickPlacement="None" TickFrequency="0.05"
Value="{Binding Path=ProposedProperties.AnimationSpeed, Mode=TwoWay}" Minimum="0.05" Maximum="3"
SmallChange="1" IsSnapToTickEnabled="True" Margin="10,12,10,2" Height="24" />
<!-- Animation Speed -->
<TextBlock Grid.Row="1" Grid.Column="2" Margin="10" FontSize="13.333" Text="Animation speed:"
VerticalAlignment="Center" Height="18" />
<Slider x:Name="RotationSpeed" Grid.Row="1" Grid.Column="3" VerticalAlignment="Center"
TickPlacement="None" TickFrequency="0.05"
Value="{Binding Path=ProposedProperties.AnimationSpeed, Mode=TwoWay}" Minimum="0.05" Maximum="3"
SmallChange="1" IsSnapToTickEnabled="True" Margin="10,12,10,2" Height="24" />
<!-- Dynamic -->
<Label Grid.Row="7" Grid.Column="0" FontSize="20" HorizontalAlignment="Left"
Content="Dynamic" Width="97" VerticalAlignment="Bottom" />
<!-- Dynamic -->
<Label Grid.Row="3" Grid.Column="0" FontSize="20" HorizontalAlignment="Left"
Content="Dynamic" Width="97" VerticalAlignment="Bottom" />
<!-- Dynamic property views -->
<ContentControl Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="4" x:Name="HeightProperties" />
<ContentControl Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="4" x:Name="WidthProperties" />
<ContentControl Grid.Row="10" Grid.Column="0" Grid.ColumnSpan="4" x:Name="OpacityProperties" />
<!-- Dynamic property views -->
<ContentControl Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="4" x:Name="HeightProperties" />
<ContentControl Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="4" x:Name="WidthProperties" />
<ContentControl Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="4" x:Name="OpacityProperties" />
</Grid>
<Button Grid.Row="12" Grid.Column="0" x:Name="Apply" Content="Apply" VerticalAlignment="Bottom"
<!-- Advanced settings - Keyboard -->
<Grid x:Name="GifGridIsVisible" Grid.Row="5" Grid.ColumnSpan="4" Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="10,13,10,0" FontSize="13.333" Text="GIF file:"
VerticalAlignment="Top" Height="18" />
<Grid Grid.Row="0" Grid.Column="1" ColumnSpan="3" Margin="5,10,10,0" VerticalAlignment="Top">
<TextBox Height="23" TextWrapping="Wrap" Margin="5,0,30,0"
Text="{Binding Path=Layer.GifFile, Mode=TwoWay}" />
<Button x:Name="BrowseGif" Content="..." RenderTransformOrigin="-0.039,-0.944"
HorizontalAlignment="Right" Width="25" Style="{DynamicResource SquareButtonStyle}" Height="25" />
</Grid>
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" Margin="10,13,10,0" FontSize="13.333"
Foreground="{DynamicResource HighlightBrush}"
Text="Note: It is recommended to use very tiny gifs (25x7 per example). Any higher will degrade performance without any noticeable quality difference."
VerticalAlignment="Top" Height="Auto" TextWrapping="Wrap" />
</Grid>
<Button Grid.Row="6" Grid.Column="0" x:Name="Apply" Content="Apply" VerticalAlignment="Bottom"
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Left" Margin="10,0,0,20"
Height="30" />
<Button Grid.Row="12" Grid.Column="1" x:Name="PreSelect" Content="Reset" VerticalAlignment="Bottom"
<Button Grid.Row="6" Grid.Column="1" x:Name="PreSelect" Content="Reset" VerticalAlignment="Bottom"
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Left" Margin="10,0,0,20"
Height="30" />
</Grid>
</controls:MetroWindow>

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="4.0.0-rc1-177" targetFramework="net452" />
<package id="Caliburn.Micro" version="2.0.2" targetFramework="net452" />
@ -24,4 +23,5 @@
<package id="System.Linq.Dynamic" version="1.0.6" targetFramework="net452" />
<package id="VirtualInput" version="1.0.1" targetFramework="net452" />
<package id="WpfExceptionViewer" version="1.0.0.0" targetFramework="net452" />
<package id="XamlAnimatedGif" version="1.1.2" targetFramework="net452" />
</packages>