33using System . Drawing ;
44using System . Drawing . Drawing2D ;
55using System . Drawing . Imaging ;
6+ using System . Windows ;
67using Aurora . Devices ;
78using Aurora . Settings ;
89using Aurora . Utils ;
10+ using Point = System . Drawing . Point ;
911
1012namespace Aurora . EffectsEngine
1113{
@@ -14,8 +16,8 @@ namespace Aurora.EffectsEngine
1416 /// </summary>
1517 public class EffectLayer : IDisposable
1618 {
17- private static readonly Lazy < EffectLayer > _emptyLayerFactory = new ( ) ;
18- public static EffectLayer EmptyLayer => _emptyLayerFactory . Value ;
19+ private static readonly Lazy < EffectLayer > EmptyLayerFactory = new ( ) ;
20+ public static EffectLayer EmptyLayer => EmptyLayerFactory . Value ;
1921
2022 private readonly string _name ;
2123 private Bitmap _colormap ;
@@ -46,7 +48,6 @@ internal TextureBrush TextureBrush
4648
4749 return _textureBrush ;
4850 }
49-
5051 }
5152
5253 private Color _peripheral ;
@@ -66,7 +67,7 @@ public EffectLayer()
6667 {
6768 _name = "Unknown Layer" ;
6869 _colormap = new Bitmap ( Effects . CanvasWidth , Effects . CanvasHeight ) ;
69- Effects . CanvasChanged += Invalidate ;
70+ WeakEventManager < Effects , CanvasChangedArgs > . AddHandler ( null , " CanvasChanged" , InvalidateColorMap ) ;
7071 _textureBrush = new TextureBrush ( _colormap ) ;
7172 Dimension = new Rectangle ( 0 , 0 , _colormap . Width , _colormap . Height ) ;
7273 _peripheral = Color . Empty ;
@@ -84,10 +85,9 @@ public EffectLayer(EffectLayer anotherLayer)
8485 var graphicsUnit = anotherLayer . GetGraphics ( ) . PageUnit ;
8586 var rectangleF = anotherLayer . _colormap . GetBounds ( ref graphicsUnit ) ;
8687 _colormap = anotherLayer . _colormap . Clone ( rectangleF , anotherLayer . _colormap . PixelFormat ) ;
87- Effects . CanvasChanged += Invalidate ;
88+ WeakEventManager < Effects , CanvasChangedArgs > . AddHandler ( null , " CanvasChanged" , InvalidateColorMap ) ;
8889 _textureBrush = new TextureBrush ( _colormap ) ;
8990 Dimension = new Rectangle ( 0 , 0 , _colormap . Width , _colormap . Height ) ;
90- Graphics . FromImage ( _colormap ) ;
9191 _peripheral = anotherLayer . _peripheral ;
9292
9393 _needsRender = anotherLayer . _needsRender ;
@@ -101,10 +101,9 @@ public EffectLayer(string name)
101101 {
102102 _name = name ;
103103 _colormap = new Bitmap ( Effects . CanvasWidth , Effects . CanvasHeight ) ;
104- Effects . CanvasChanged += Invalidate ;
104+ WeakEventManager < Effects , CanvasChangedArgs > . AddHandler ( null , " CanvasChanged" , InvalidateColorMap ) ;
105105 _textureBrush = new TextureBrush ( _colormap ) ;
106106 Dimension = new Rectangle ( 0 , 0 , _colormap . Width , _colormap . Height ) ;
107- Graphics . FromImage ( _colormap ) ;
108107 _peripheral = Color . Empty ;
109108
110109 FillOver ( Color . FromArgb ( 0 , 1 , 1 , 1 ) ) ;
@@ -119,10 +118,9 @@ public EffectLayer(string name, Color color)
119118 {
120119 _name = name ;
121120 _colormap = new Bitmap ( Effects . CanvasWidth , Effects . CanvasHeight ) ;
122- Effects . CanvasChanged += Invalidate ;
121+ WeakEventManager < Effects , CanvasChangedArgs > . AddHandler ( null , " CanvasChanged" , InvalidateColorMap ) ;
123122 _textureBrush = new TextureBrush ( _colormap ) ;
124123 Dimension = new Rectangle ( 0 , 0 , _colormap . Width , _colormap . Height ) ;
125- Graphics . FromImage ( _colormap ) ;
126124 _peripheral = color ;
127125
128126 FillOver ( color ) ;
@@ -140,10 +138,9 @@ public EffectLayer(string name, Color color)
140138 {
141139 _name = name ;
142140 _colormap = new Bitmap ( Effects . CanvasWidth , Effects . CanvasHeight ) ;
143- Effects . CanvasChanged += Invalidate ;
141+ WeakEventManager < Effects , CanvasChangedArgs > . AddHandler ( null , " CanvasChanged" , InvalidateColorMap ) ;
144142 _textureBrush = new TextureBrush ( _colormap ) ;
145143 Dimension = new Rectangle ( 0 , 0 , _colormap . Width , _colormap . Height ) ;
146- Graphics . FromImage ( _colormap ) ;
147144 _peripheral = new Color ( ) ;
148145 Brush brush ;
149146 var shift = 0.0f ;
@@ -342,7 +339,7 @@ public void Dispose()
342339 _textureBrush . Dispose ( ) ;
343340 _textureBrush = null ;
344341 _colormap . Dispose ( ) ;
345- Effects . CanvasChanged -= Invalidate ;
342+ WeakEventManager < Effects , CanvasChangedArgs > . RemoveHandler ( null , " CanvasChanged" , InvalidateColorMap ) ;
346343 }
347344
348345 /// <summary>
@@ -789,7 +786,7 @@ public void Add(EffectLayer other)
789786 }
790787
791788 private KeySequenceType _previousSequenceType ;
792-
789+
793790 /// <summary>
794791 /// Draws a percent effect on the layer bitmap using a KeySequence with solid colors.
795792 /// </summary>
@@ -1053,9 +1050,9 @@ private void Invalidate()
10531050 _needsRender = true ;
10541051 _keyColors . Clear ( ) ;
10551052 }
1056- private void Invalidate ( object sender , object args )
1053+ private void InvalidateColorMap ( object sender , EventArgs args )
10571054 {
1058- _colormap . Dispose ( ) ;
1055+ _colormap ? . Dispose ( ) ;
10591056 _colormap = new Bitmap ( Effects . CanvasWidth , Effects . CanvasHeight ) ;
10601057 Dimension . Height = Effects . CanvasHeight ;
10611058 Dimension . Width = Effects . CanvasWidth ;
0 commit comments