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

Removed ugly null reference try-catch. Layers are propertly drawn to keyboard now

This commit is contained in:
SpoinkyNL 2016-04-07 23:15:51 +02:00
parent e95b33e9bb
commit 399a6f97ca
10 changed files with 116 additions and 125 deletions

View File

@ -120,6 +120,10 @@
</PropertyGroup>
<PropertyGroup />
<ItemGroup>
<Reference Include="Antlr3.Runtime, Version=3.5.0.2, Culture=neutral, PublicKeyToken=eb42632606e9261f, processorArchitecture=MSIL">
<HintPath>..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Autofac, Version=4.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.4.0.0-rc1-177\lib\net45\Autofac.dll</HintPath>
<Private>True</Private>
@ -148,6 +152,10 @@
<HintPath>..\packages\CUE.NET.1.0.2.2\lib\net45\CUE.NET.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ExpressionEvaluator, Version=2.0.4.0, Culture=neutral, PublicKeyToken=90d9f15d622e2348, processorArchitecture=MSIL">
<HintPath>..\packages\ExpressionEvaluator.2.0.4.0\lib\net40\ExpressionEvaluator.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Hardcodet.Wpf.TaskbarNotification, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Hardcodet.NotifyIcon.Wpf.1.0.5\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll</HintPath>
<Private>True</Private>

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq.Dynamic;
using Artemis.Models.Interfaces;
using Artemis.Utilities;
namespace Artemis.Models.Profiles
{
@ -16,19 +16,17 @@ namespace Artemis.Models.Profiles
{
if (string.IsNullOrEmpty(Field) || string.IsNullOrEmpty(Value) || string.IsNullOrEmpty(Type))
return false;
try
{
// Put the subject in a list, allowing Dynamic Linq to be used.
var subjectList = new List<T> {(T) subject};
var res = Type == "String"
? subjectList.Where($"{Field}.ToLower() {Operator} @0", Value.ToLower()).Any()
: subjectList.Where($"{Field} {Operator} {Value}").Any();
return res;
}
catch (NullReferenceException)
{
var inspect = GeneralHelpers.GetPropertyValue(subject, Field);
if (inspect == null)
return false;
}
// Put the subject in a list, allowing Dynamic Linq to be used.
var subjectList = new List<T> {(T) subject};
var res = Type == "String"
? subjectList.Where($"{Field}.ToLower() {Operator} @0", Value.ToLower()).Any()
: subjectList.Where($"{Field} {Operator} {Value}").Any();
return res;
}
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Windows.Media;
namespace Artemis.Models.Profiles
{
@ -7,11 +8,13 @@ namespace Artemis.Models.Profiles
public ProfileModel()
{
Layers = new List<LayerModel>();
DrawingVisual = new DrawingVisual();
}
public string Name { get; set; }
public string KeyboardName { get; set; }
public string GameName { get; set; }
public DrawingVisual DrawingVisual { get; set; }
public List<LayerModel> Layers { get; set; }

View File

@ -1,11 +1,11 @@
using System.Drawing;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Artemis.Managers;
using Artemis.Models;
using Artemis.Utilities;
using Artemis.Utilities.GameState;
using Newtonsoft.Json;
using Color = System.Windows.Media.Color;
namespace Artemis.Modules.Games.CounterStrike
{
@ -52,24 +52,32 @@ namespace Artemis.Modules.Games.CounterStrike
public override Bitmap GenerateBitmap()
{
var keyboardRect = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRectangle(Scale);
if (Profile == null || GameDataModel == null)
return null;
var visual = new DrawingVisual();
using (var drawingContext = visual.RenderOpen())
var keyboardRect = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRectangle(Scale);
Bitmap bitmap = null;
Profile.DrawingVisual.Dispatcher.Invoke(delegate
{
// Setup the DrawingVisual's size
drawingContext.PushClip(new RectangleGeometry(keyboardRect));
drawingContext.DrawRectangle(new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0)), null, keyboardRect);
var visual = new DrawingVisual();
using (var drawingContext = visual.RenderOpen())
{
// Setup the DrawingVisual's size
drawingContext.PushClip(new RectangleGeometry(keyboardRect));
drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)),
null, keyboardRect);
// Draw the layers
foreach (var layerModel in Profile.Layers)
layerModel.Draw<CounterStrikeDataModel>(GameDataModel, drawingContext);
// Draw the layers
foreach (var layerModel in Profile.Layers)
layerModel.Draw<CounterStrikeDataModel>(GameDataModel, drawingContext);
// Remove the clip
drawingContext.Pop();
}
// Remove the clip
drawingContext.Pop();
}
return ImageUtilities.DrawinVisualToBitmap(visual, keyboardRect);
bitmap = ImageUtilities.DrawinVisualToBitmap(visual, keyboardRect);
});
return bitmap;
}
public void HandleGameData(object sender, GameDataReceivedEventArgs e)

View File

@ -55,6 +55,19 @@ namespace Artemis.Utilities
}
}
public static object GetPropertyValue(object o, string path)
{
var propertyNames = path.Split('.');
var value = o.GetType().GetProperty(propertyNames[0]).GetValue(o, null);
if (propertyNames.Length == 1 || value == null)
return value;
else
{
return GetPropertyValue(value, path.Replace(propertyNames[0] + ".", ""));
}
}
public static List<PropertyCollection> GenerateTypeMap(object o) => GenerateTypeMap(o.GetType().GetProperties());
public static List<PropertyCollection> GenerateTypeMap<T>() => GenerateTypeMap(typeof (T).GetProperties());
@ -66,11 +79,11 @@ namespace Artemis.Utilities
{
var friendlyName = Empty;
if (propertyInfo.PropertyType.Name == "Int32")
friendlyName = "(Number) ";
friendlyName = "(Number)";
else if (propertyInfo.PropertyType.Name == "String")
friendlyName = "(Text) ";
friendlyName = "(Text)";
if (propertyInfo.PropertyType.BaseType?.Name == "Enum")
friendlyName = "(Choice) ";
friendlyName = "(Choice)";
var parent = new PropertyCollection
{

View File

@ -25,8 +25,6 @@ namespace Artemis.Utilities
{
if (_layerModel.LayerCalculatedProperties.Brush == null)
return;
if (!_layerModel.LayerCalculatedProperties.Brush.IsFrozen)
return;
// Set up variables for this frame
_rectangle = new Rect(_layerModel.LayerCalculatedProperties.X*Scale,
@ -95,13 +93,15 @@ namespace Artemis.Utilities
public void DrawRectangle(DrawingContext c)
{
c.DrawRectangle(_layerModel.LayerCalculatedProperties.Brush, null, _rectangle);
_layerModel.LayerCalculatedProperties.Brush.Dispatcher.Invoke(
() => c.DrawRectangle(_layerModel.LayerCalculatedProperties.Brush, null, _rectangle));
}
public void DrawEllipse(DrawingContext c)
{
c.DrawEllipse(_layerModel.LayerCalculatedProperties.Brush, null,
new Point(_rectangle.Width/2, _rectangle.Height/2), _rectangle.Width, _rectangle.Height);
_layerModel.LayerCalculatedProperties.Brush.Dispatcher.Invoke(
() => c.DrawEllipse(_layerModel.LayerCalculatedProperties.Brush, null,
new Point(_rectangle.Width/2, _rectangle.Height/2), _rectangle.Width, _rectangle.Height));
}
public void DrawGif(DrawingContext bmp)

View File

@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Windows;
@ -35,8 +36,7 @@ namespace Artemis.ViewModels
new BindableCollection<LayerConditionViewModel<T>>(
layer.LayerConditions.Select(c => new LayerConditionViewModel<T>(this, c, DataModelProps)));
_previewWorker = new BackgroundWorker();
_previewWorker.WorkerSupportsCancellation = true;
_previewWorker = new BackgroundWorker {WorkerSupportsCancellation = true};
_previewWorker.DoWork += PreviewWorkerOnDoWork;
_previewWorker.RunWorkerAsync();
@ -75,8 +75,6 @@ namespace Artemis.ViewModels
{
get
{
// For the preview, put the proposed properties into the calculated properties
_layer.LayerCalculatedProperties = ProposedProperties;
var keyboardRect = _activeKeyboard.KeyboardRectangle(4);
var visual = new DrawingVisual();
@ -103,7 +101,7 @@ namespace Artemis.ViewModels
while (!_previewWorker.CancellationPending)
{
NotifyOfPropertyChange(() => LayerImage);
Thread.Sleep(1000/25);
Thread.Sleep(1000 / 25);
}
}

View File

@ -44,10 +44,6 @@ namespace Artemis.ViewModels
{
if (Equals(value, _selectedProfileModel)) return;
_selectedProfileModel = value;
foreach (var layerModel in SelectedProfileModel.Layers)
{
layerModel.LayerUserProperties.Brush?.Freeze();
}
NotifyOfPropertyChange();
}
}

View File

@ -48,21 +48,12 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" MinHeight="42" />
<RowDefinition Height="Auto" MinHeight="128" />
<RowDefinition Height="*" />
<RowDefinition />
</Grid.RowDefinitions>
<!-- Header -->
<Label Grid.Row="0" Grid.ColumnSpan="4" FontSize="20">
<Label.Content>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Layer.Name}" />
<TextBlock Text=" - Basics" />
</StackPanel>
</Label.Content>
</Label>
<Label Grid.Row="0" Grid.ColumnSpan="4" FontSize="20" Content="Basics" />
<!-- Layer name -->
<TextBlock Grid.Row="1" Grid.Column="0" Margin="10,12" FontSize="13.333" Text="Name:"
@ -70,17 +61,6 @@
<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=Layer.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.." />
@ -96,69 +76,44 @@
</ListBox.Template>
</ListBox>
</Border>
<Button Grid.Row="4" Grid.Column="3" x:Name="AddCondition" Content="Add condition"
VerticalAlignment="Center"
<Button Grid.Row="4" Grid.Column="3" x:Name="AddCondition" Content="Add condition" VerticalAlignment="Center"
Style="{DynamicResource SquareButtonStyle}" Width="95" HorizontalAlignment="Right" Height="30"
Margin="0,10,10,27" ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.RowSpan="2" />
Margin="0,10,10,10" ScrollViewer.VerticalScrollBarVisibility="Auto" />
<!-- Advanced -->
<Label Grid.Row="5" Grid.Column="0" FontSize="20" HorizontalAlignment="Left"
Content="Advanced" Width="97" />
<!-- X -->
<TextBlock Grid.Row="6" Grid.Column="0" Margin="10" FontSize="13.333" Text="X Position:"
VerticalAlignment="Center" Height="18" />
<TextBox Grid.Row="6" Grid.Column="1" Margin="10" Text="{Binding Path=ProposedProperties.X}" />
<!-- Y -->
<TextBlock Grid.Row="6" Grid.Column="2" Margin="10" FontSize="13.333" Text="Y Position:"
VerticalAlignment="Center" Height="18" />
<TextBox Grid.Row="6" Grid.Column="3" Margin="10" Text="{Binding Path=ProposedProperties.Y}" />
<Label Grid.Row="4" Grid.Column="0" FontSize="20" HorizontalAlignment="Left"
Content="Advanced" Width="97" VerticalAlignment="Bottom" />
<!-- Height -->
<TextBlock Grid.Row="7" Grid.Column="0" Margin="10" FontSize="13.333" Text="Height:" VerticalAlignment="Center"
<TextBlock Grid.Row="5" Grid.Column="0" Margin="10" FontSize="13.333" Text="Height:" VerticalAlignment="Center"
Height="18" />
<TextBox Grid.Row="7" Grid.Column="1" Margin="10" Text="{Binding Path=ProposedProperties.Height}" />
<TextBox Grid.Row="5" Grid.Column="1" Margin="10" Text="{Binding Path=ProposedProperties.Height}" />
<!-- Width -->
<TextBlock Grid.Row="7" Grid.Column="2" Margin="10" FontSize="13.333" Text="Width:" VerticalAlignment="Center"
<TextBlock Grid.Row="5" Grid.Column="2" Margin="10" FontSize="13.333" Text="Width:" VerticalAlignment="Center"
Height="18" />
<TextBox Grid.Row="7" Grid.Column="3" Margin="10" Text="{Binding Path=ProposedProperties.Width}" />
<TextBox Grid.Row="5" Grid.Column="3" Margin="10" Text="{Binding Path=ProposedProperties.Width}" />
<!-- Opacity -->
<TextBlock Grid.Row="8" Grid.Column="0" Margin="10" FontSize="13.333" Text="Opacity:"
VerticalAlignment="Center" Height="18" />
<Slider x:Name="Sensitivity" Grid.Row="8" Grid.Column="1" VerticalAlignment="Center"
TickPlacement="BottomRight" TickFrequency="20"
Value="{Binding Path=ProposedProperties.Opacity, Mode=TwoWay}" Minimum="1" Maximum="255"
SmallChange="1" Margin="10,7" Height="24" />
<!-- Colors -->
<TextBlock Grid.Row="6" Grid.Column="0" Margin="10,13,10,0" FontSize="13.333" Text="Color(s):"
VerticalAlignment="Top" Height="18" />
<Border Grid.Row="6" Grid.Column="1" Margin="10" BorderThickness="1"
BorderBrush="{StaticResource ControlBorderBrush}" ToolTip="Click to edit">
<ncore:ColorBox Brush="{Binding Path=ProposedProperties.Brush, Mode=TwoWay}" />
</Border>
<!-- ContainedBrush -->
<TextBlock Grid.Row="8" Grid.Column="2" Margin="10" FontSize="13.333" Text="Contained colors:"
<TextBlock Grid.Row="6" 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="8"
<controls:ToggleSwitch IsChecked="{Binding Path=ProposedProperties.ContainedBrush, Mode=TwoWay}" Grid.Row="6"
Grid.Column="3" OnLabel="Yes" OffLabel="No" Margin="10,1,5,1" VerticalAlignment="Center"
Height="36" />
<!-- Rotate -->
<TextBlock Grid.Row="9" Grid.Column="0" Margin="10" FontSize="13.333" Text="Rotate:" VerticalAlignment="Center"
<!-- Animation -->
<TextBlock Grid.Row="7" Grid.Column="0" Margin="10" FontSize="13.333" Text="Animation:"
VerticalAlignment="Center"
Height="18" />
<controls:ToggleSwitch IsChecked="{Binding Path=ProposedProperties.Rotate, Mode=TwoWay}" Grid.Row="9"
Grid.Column="1" OnLabel="Yes" OffLabel="No" Margin="10,1,5,1" VerticalAlignment="Center"
Height="36" />
<!-- RotateSpeed -->
<TextBlock Grid.Row="9" Grid.Column="2" Margin="10" FontSize="13.333" Text="Rotation speed:"
VerticalAlignment="Center" Height="18" />
<Slider x:Name="RotationSpeed" Grid.Row="9" Grid.Column="3" VerticalAlignment="Center"
TickPlacement="BottomRight" TickFrequency="0.1"
Value="{Binding Path=ProposedProperties.RotateSpeed, Mode=TwoWay}" Minimum="0.1" Maximum="3"
SmallChange="1" IsSnapToTickEnabled="True" Margin="10,7" Height="24" />
<!-- Color direction -->
<TextBlock Grid.Row="10" Grid.Column="0" Margin="10,13,10,0" FontSize="13.333" Text="Color direction:"
VerticalAlignment="Top" Height="18" />
<ComboBox Grid.Row="10" Grid.Column="1" ItemsSource="{Binding Source={StaticResource ColorEnumValues}}"
<ComboBox Grid.Row="7" Grid.Column="1" ItemsSource="{Binding Source={StaticResource ColorEnumValues}}"
Margin="10,10,10,0" SelectedItem="{Binding Path=ProposedProperties.ColorMode}"
VerticalAlignment="Top" Height="22">
<ComboBox.ItemTemplate>
@ -168,24 +123,34 @@
</ComboBox.ItemTemplate>
</ComboBox>
<!-- Colors -->
<TextBlock Grid.Row="10" Grid.Column="2" Margin="10,13,10,0" FontSize="13.333" Text="Color(s):"
VerticalAlignment="Top" Height="18" />
<Border Grid.Row="10" Grid.Column="3" Margin="10" BorderThickness="1" BorderBrush="{StaticResource ControlBorderBrush}" ToolTip="Click to edit">
<ncore:ColorBox Brush="{Binding Path=ProposedProperties.Brush, Mode=TwoWay}" />
</Border>
<!-- Animation Speed -->
<TextBlock Grid.Row="7" Grid.Column="2" Margin="10" FontSize="13.333" Text="Animation speed:"
VerticalAlignment="Center" Height="18" />
<Slider x:Name="RotationSpeed" Grid.Row="7" Grid.Column="3" VerticalAlignment="Center"
TickPlacement="BottomRight" TickFrequency="0.1"
Value="{Binding Path=ProposedProperties.RotateSpeed, Mode=TwoWay}" Minimum="0.1" Maximum="3"
SmallChange="1" IsSnapToTickEnabled="True" Margin="10,7" Height="24" />
<!-- Opacity -->
<TextBlock Grid.Row="8" Grid.Column="0" Margin="10" FontSize="13.333" Text="Opacity:"
VerticalAlignment="Center" Height="18" />
<Slider x:Name="Sensitivity" Grid.Row="8" Grid.Column="1" VerticalAlignment="Center"
TickPlacement="BottomRight" TickFrequency="20"
Value="{Binding Path=ProposedProperties.Opacity, Mode=TwoWay}" Minimum="1" Maximum="255"
SmallChange="1" Margin="10,7" Height="24" />
<!-- Preview -->
<TextBlock Grid.Row="11" Grid.Column="0" Margin="10,13,10,0" FontSize="13.333" Text="Preview:"
<TextBlock Grid.Row="9" Grid.Column="0" Margin="10,13,10,0" FontSize="13.333" Text="Preview:"
VerticalAlignment="Top" Height="18" />
<Border Grid.Row="11" Grid.Column="1" Grid.ColumnSpan="2" Margin="10" BorderThickness="1"
BorderBrush="{StaticResource ControlBorderBrush}" Width="280" Height="105">
<Border Grid.Row="9" Grid.Column="1" Grid.ColumnSpan="2" Margin="10" BorderThickness="1"
BorderBrush="{StaticResource ControlBorderBrush}">
<Image Source="{Binding LayerImage}" />
</Border>
<Button Grid.Row="12" Grid.Column="0" x:Name="Apply" Content="Apply" VerticalAlignment="Bottom"
<Button Grid.Row="10" 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="10" 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>

View File

@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.5.0.2" targetFramework="net452" />
<package id="Autofac" version="4.0.0-rc1-177" targetFramework="net452" />
<package id="Caliburn.Micro" version="2.0.2" targetFramework="net452" />
<package id="Caliburn.Micro.AutofacBootstrap" version="2.0.9-beta" targetFramework="net452" />
<package id="Caliburn.Micro.Core" version="2.0.2" targetFramework="net452" />
<package id="Colore" version="4.0.0" targetFramework="net452" />
<package id="CUE.NET" version="1.0.2.2" targetFramework="net452" />
<package id="ExpressionEvaluator" version="2.0.4.0" targetFramework="net452" />
<package id="Extended.Wpf.Toolkit" version="2.6" targetFramework="net452" />
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.5" targetFramework="net452" />
<package id="ImageLibrary" version="2.0.5" targetFramework="net452" />