1 //FireworkEffect.h file
4 #include "OverlayRenderDecorator.h"
5 #include "TimeTracker.h"
7 using namespace System
;
8 using namespace System::Windows
;
9 using namespace System::Windows::Media
;
10 using namespace System::Windows::Media::Animation
;
11 using namespace System::Windows::Controls
;
12 using namespace System::Collections::Generic
;
13 using namespace System::Windows::Input
;
17 namespace PerFrameAnimations
{
18 private ref
class Particle
{
22 System::DateTime LifeTime
;
23 System::DateTime DeathTime
;
29 public ref
class FireworkEffect
: OverlayRenderDecorator
{
32 List
<Particle
^>^ _particles
;
33 bool _bounceOffContainer
;
35 bool _gravitateToMouse
;
36 double _gravitateScale
;
37 bool _mouseDropsParticles
;
38 double _secondsUntilDrop
;
39 Point _lastMousePosition
;
40 TimeTracker
^ _timeTracker
;
42 protected: System::Random
^ _random
;
46 static initonly DependencyProperty
^ RadiusProperty
= DependencyProperty::Register("RadiusBase", double::typeid, FireworkEffect::typeid, gcnew
FrameworkPropertyMetadata(15.0));
47 static initonly DependencyProperty
^ RadiusVariationProperty
= DependencyProperty::Register("RadiusVariation", double::typeid, FireworkEffect::typeid, gcnew
FrameworkPropertyMetadata(5.0));
48 static initonly DependencyProperty
^ StartColorProperty
= DependencyProperty::Register("StartColor", Color::typeid, FireworkEffect::typeid, gcnew
FrameworkPropertyMetadata(Color::FromArgb(245, 200, 50, 20)));
49 static initonly DependencyProperty
^ EndColorProperty
= DependencyProperty::Register("EndColor", Color::typeid, FireworkEffect::typeid, gcnew
FrameworkPropertyMetadata(Color::FromArgb(100, 200, 255, 20)));
50 static initonly DependencyProperty
^ StartColorVariationProperty
= DependencyProperty::Register("StartColorVariation", Color::typeid, FireworkEffect::typeid, gcnew
FrameworkPropertyMetadata(Color::FromArgb(10, 55, 50, 20)));
51 static initonly DependencyProperty
^ EndColorVariationProperty
= DependencyProperty::Register("EndColorVariation", Color::typeid, FireworkEffect::typeid, gcnew
FrameworkPropertyMetadata(Color::FromArgb(50, 20, 100, 20)));
52 static initonly DependencyProperty
^ MouseDropDelayProperty
= DependencyProperty::Register("MouseDropDelay", double::typeid, FireworkEffect::typeid, gcnew
FrameworkPropertyMetadata(0.1));
53 static initonly DependencyProperty
^ MouseDropDelayVariationProperty
= DependencyProperty::Register("MouseDropDelayVariation", double::typeid, FireworkEffect::typeid, gcnew
FrameworkPropertyMetadata(0.05));
54 static initonly DependencyProperty
^ ClickBurstSizeProperty
= DependencyProperty::Register("ClickBurstSize", int::typeid, Microsoft::Samples::PerFrameAnimations::FireworkEffect::typeid, gcnew
FrameworkPropertyMetadata(30));
56 //#region Public Properties
58 property
double Radius
{
60 void set (double value
) ;
63 property
double RadiusVariation
{
65 void set (double value
) ;
68 property Color StartColor
{
70 void set (Color value
) ;
73 property Color EndColor
{
75 void set (Color value
) ;
78 property Color StartColorVariation
{
80 void set (Color value
) ;
83 property Color EndColorVariation
{
85 void set (Color value
) ;
88 property
bool BounceOffContainer
{
90 void set (bool value
) ;
93 property
bool GravitateToMouse
{
95 void set (bool value
) ;
98 property
double GravitateScale
{
100 void set (double value
) ;
103 property
bool MouseDropsParticles
{
105 void set (bool value
) ;
108 property
double MouseDropDelay
{
110 void set (double value
) ;
113 property
double MouseDropDelayVariation
{
115 void set (double value
) ;
118 property
int ClickBurstSize
{
120 void set (int value
) ;
125 virtual void OnAttachChild (UIElement
^ child
) override
;
126 virtual void OnDetachChild (UIElement
^ child
) override
;
127 void OnFrameCallback (System::Object
^ sender
, System::EventArgs
^ e
) ;
128 virtual void UpdateParticles (double deltatime
) ;
129 virtual void OnOverlayRender (DrawingContext
^ drawingContext
) override
;
132 void _initFields () ;
133 void OnMouseMove (System::Object
^ sender
, Input::MouseEventArgs
^ e
) ;
134 void OnMouseLeftButtonUp (System::Object
^ sender
, Input::MouseButtonEventArgs
^ e
) ;
137 void AddRandomBurst () ;
138 void AddRandomBurst (Point location
) ;
139 void AddRandomBurst (Point location
, int count
) ;