added samples
[windows-sources.git] / sdk / samples / WPFSamples / CompositionTargetRenderingAnimations / cpp / particleeffectexamples / fireworkeffect.h
blob4bb9a2d36b3b501e0aca7fcfade57a9e09cc5464
1 //FireworkEffect.h file
2 #pragma once
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;
15 namespace Microsoft {
16 namespace Samples {
17 namespace PerFrameAnimations {
18 private ref class Particle {
19 public:
20 Point Location;
21 Vector Velocity;
22 System::DateTime LifeTime;
23 System::DateTime DeathTime;
24 Color StartColor;
25 Color EndColor;
26 double Diameter;
29 public ref class FireworkEffect : OverlayRenderDecorator {
31 private:
32 List<Particle^>^ _particles;
33 bool _bounceOffContainer;
34 Vector _gravity;
35 bool _gravitateToMouse;
36 double _gravitateScale;
37 bool _mouseDropsParticles;
38 double _secondsUntilDrop;
39 Point _lastMousePosition;
40 TimeTracker^ _timeTracker;
42 protected: System::Random^ _random;
44 public:
45 FireworkEffect () ;
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
57 public:
58 property double Radius {
59 double get () ;
60 void set (double value) ;
63 property double RadiusVariation {
64 double get () ;
65 void set (double value) ;
68 property Color StartColor {
69 Color get () ;
70 void set (Color value) ;
73 property Color EndColor {
74 Color get () ;
75 void set (Color value) ;
78 property Color StartColorVariation {
79 Color get () ;
80 void set (Color value) ;
83 property Color EndColorVariation {
84 Color get () ;
85 void set (Color value) ;
88 property bool BounceOffContainer {
89 bool get () ;
90 void set (bool value) ;
93 property bool GravitateToMouse {
94 bool get () ;
95 void set (bool value) ;
98 property double GravitateScale {
99 double get () ;
100 void set (double value) ;
103 property bool MouseDropsParticles {
104 bool get () ;
105 void set (bool value) ;
108 property double MouseDropDelay {
109 double get () ;
110 void set (double value) ;
113 property double MouseDropDelayVariation {
114 double get () ;
115 void set (double value) ;
118 property int ClickBurstSize {
119 int get () ;
120 void set (int value) ;
124 protected:
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 ;
131 private:
132 void _initFields () ;
133 void OnMouseMove (System::Object^ sender, Input::MouseEventArgs^ e) ;
134 void OnMouseLeftButtonUp (System::Object^ sender, Input::MouseButtonEventArgs^ e) ;
136 public:
137 void AddRandomBurst () ;
138 void AddRandomBurst (Point location) ;
139 void AddRandomBurst (Point location, int count) ;