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

Merge pull request #106 from DarthAffe/master

Workarounded performance issues in Bubbles-Effect
This commit is contained in:
Robert Beekman 2016-06-13 11:45:41 +02:00 committed by GitHub
commit af75f2e44d
7 changed files with 29 additions and 27 deletions

View File

@ -266,10 +266,10 @@
<value>True</value> <value>True</value>
</setting> </setting>
<setting name="BubbleSize" serializeAs="String"> <setting name="BubbleSize" serializeAs="String">
<value>100</value> <value>25</value>
</setting> </setting>
<setting name="MoveSpeed" serializeAs="String"> <setting name="MoveSpeed" serializeAs="String">
<value>16</value> <value>4</value>
</setting> </setting>
<setting name="ShiftColorSpeed" serializeAs="String"> <setting name="ShiftColorSpeed" serializeAs="String">
<value>12</value> <value>12</value>

View File

@ -144,17 +144,20 @@ namespace Artemis.Managers
return; return;
// Fill the bitmap's background with black to avoid trailing colors on some keyboards // Fill the bitmap's background with black to avoid trailing colors on some keyboards
var fixedBmp = new Bitmap(bitmap.Width, bitmap.Height); // Bitmaps needs to be disposd!
using (var g = Graphics.FromImage(fixedBmp)) using (var fixedBmp = new Bitmap(bitmap.Width, bitmap.Height))
{ {
g.Clear(Color.Black); using (var g = Graphics.FromImage(fixedBmp))
g.DrawImage(bitmap, 0, 0); {
g.Clear(Color.Black);
g.DrawImage(bitmap, 0, 0);
}
bitmap = fixedBmp;
// Update the keyboard
_deviceManager.ActiveKeyboard?.DrawBitmap(bitmap);
} }
bitmap = fixedBmp;
// Update the keyboard
_deviceManager.ActiveKeyboard?.DrawBitmap(bitmap);
} }
} }
} }

View File

@ -61,7 +61,7 @@ namespace Artemis.Modules.Effects.Bubbles {
[global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("100")] [global::System.Configuration.DefaultSettingValueAttribute("25")]
public int BubbleSize { public int BubbleSize {
get { get {
return ((int)(this["BubbleSize"])); return ((int)(this["BubbleSize"]));
@ -73,7 +73,7 @@ namespace Artemis.Modules.Effects.Bubbles {
[global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("16")] [global::System.Configuration.DefaultSettingValueAttribute("4")]
public int MoveSpeed { public int MoveSpeed {
get { get {
return ((int)(this["MoveSpeed"])); return ((int)(this["MoveSpeed"]));

View File

@ -12,10 +12,10 @@
<Value Profile="(Default)">True</Value> <Value Profile="(Default)">True</Value>
</Setting> </Setting>
<Setting Name="BubbleSize" Type="System.Int32" Scope="User"> <Setting Name="BubbleSize" Type="System.Int32" Scope="User">
<Value Profile="(Default)">100</Value> <Value Profile="(Default)">25</Value>
</Setting> </Setting>
<Setting Name="MoveSpeed" Type="System.Int32" Scope="User"> <Setting Name="MoveSpeed" Type="System.Int32" Scope="User">
<Value Profile="(Default)">16</Value> <Value Profile="(Default)">4</Value>
</Setting> </Setting>
<Setting Name="ShiftColorSpeed" Type="System.Int32" Scope="User"> <Setting Name="ShiftColorSpeed" Type="System.Int32" Scope="User">
<Value Profile="(Default)">12</Value> <Value Profile="(Default)">12</Value>

View File

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq.Dynamic;
using System.Windows; using System.Windows;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Models; using Artemis.Models;
@ -18,9 +17,10 @@ namespace Artemis.Modules.Effects.Bubbles
private static readonly Random _random = new Random(); private static readonly Random _random = new Random();
private const int SCALE = 100; private const int SCALE = 25;
private readonly List<Bubble> _bubbles = new List<Bubble>(); private readonly List<Bubble> _bubbles = new List<Bubble>();
private Bitmap _bitmap;
public BubblesSettings Settings { get; } public BubblesSettings Settings { get; }
@ -43,6 +43,7 @@ namespace Artemis.Modules.Effects.Bubbles
public override void Enable() public override void Enable()
{ {
Rect rect = MainManager.DeviceManager.ActiveKeyboard.KeyboardRectangle(SCALE); Rect rect = MainManager.DeviceManager.ActiveKeyboard.KeyboardRectangle(SCALE);
_bitmap = MainManager.DeviceManager.ActiveKeyboard.KeyboardBitmap(SCALE);
for (int i = 0; i < Settings.BubbleCount; i++) for (int i = 0; i < Settings.BubbleCount; i++)
{ {
@ -61,6 +62,7 @@ namespace Artemis.Modules.Effects.Bubbles
public override void Dispose() public override void Dispose()
{ {
_bitmap?.Dispose();
_bubbles.Clear(); _bubbles.Clear();
Initialized = false; Initialized = false;
} }
@ -80,17 +82,14 @@ namespace Artemis.Modules.Effects.Bubbles
public override void Render(out Bitmap keyboard, out Brush mouse, out Brush headset, bool renderMice, bool renderHeadsets) public override void Render(out Bitmap keyboard, out Brush mouse, out Brush headset, bool renderMice, bool renderHeadsets)
{ {
keyboard = null; keyboard = _bitmap;
mouse = null; mouse = null;
headset = null; headset = null;
if (!_bubbles.Any()) return;
keyboard = MainManager.DeviceManager.ActiveKeyboard.KeyboardBitmap(SCALE);
using (Graphics g = Graphics.FromImage(keyboard)) using (Graphics g = Graphics.FromImage(keyboard))
{ {
g.Clear(Color.Transparent); g.Clear(Color.Transparent);
g.SmoothingMode = SmoothingMode.HighQuality; g.SmoothingMode = SmoothingMode.None;
foreach (Bubble bubble in _bubbles) foreach (Bubble bubble in _bubbles)
bubble.Draw(g); bubble.Draw(g);

View File

@ -47,8 +47,8 @@ namespace Artemis.Modules.Effects.Bubbles
IsRandomColors = true; IsRandomColors = true;
BubbleColor = Color.FromArgb(255, 255, 0, 0); BubbleColor = Color.FromArgb(255, 255, 0, 0);
IsShiftColors = true; IsShiftColors = true;
ShiftColorSpeed = 12; ShiftColorSpeed = 4;
BubbleSize = 100; BubbleSize = 25;
MoveSpeed = 16; MoveSpeed = 16;
BubbleCount = 14; BubbleCount = 14;
} }

View File

@ -107,7 +107,7 @@
</TextBlock> </TextBlock>
<Slider x:Name="Size" Grid.Row="7" Grid.Column="1" VerticalAlignment="Center" <Slider x:Name="Size" Grid.Row="7" Grid.Column="1" VerticalAlignment="Center"
HorizontalAlignment="Right" Width="110" TickPlacement="None" TickFrequency="1" HorizontalAlignment="Right" Width="110" TickPlacement="None" TickFrequency="1"
Value="{Binding Path=EffectSettings.BubbleSize, Mode=TwoWay}" Minimum="40" Maximum="180" Value="{Binding Path=EffectSettings.BubbleSize, Mode=TwoWay}" Minimum="10" Maximum="50"
SmallChange="10" IsSnapToTickEnabled="True" /> SmallChange="10" IsSnapToTickEnabled="True" />
<!-- speed --> <!-- speed -->
@ -117,7 +117,7 @@
</TextBlock> </TextBlock>
<Slider x:Name="MoveSpeed" Grid.Row="8" Grid.Column="1" VerticalAlignment="Center" <Slider x:Name="MoveSpeed" Grid.Row="8" Grid.Column="1" VerticalAlignment="Center"
HorizontalAlignment="Right" Width="110" TickPlacement="None" TickFrequency="1" HorizontalAlignment="Right" Width="110" TickPlacement="None" TickFrequency="1"
Value="{Binding Path=EffectSettings.MoveSpeed, Mode=TwoWay}" Minimum="1" Maximum="50" Value="{Binding Path=EffectSettings.MoveSpeed, Mode=TwoWay}" Minimum="1" Maximum="15"
SmallChange="10" IsSnapToTickEnabled="True" /> SmallChange="10" IsSnapToTickEnabled="True" />
<!-- Buttons --> <!-- Buttons -->