1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef TrenchBroom_Animation
21 #define TrenchBroom_Animation
22 
23 #include "SharedPointer.h"
24 #include "View/ExecutableEvent.h"
25 
26 #include <map>
27 #include <vector>
28 
29 #include <wx/longlong.h>
30 #include <wx/thread.h>
31 
32 namespace TrenchBroom {
33     namespace View {
34         class AnimationCurve;
35 
36         class Animation {
37         public:
38             typedef int Type;
39             static const Type NoType = -1;
40 
41             typedef std::shared_ptr<Animation> Ptr;
42             typedef std::vector<Ptr> List;
43 
44             typedef enum {
45                 Curve_Flat,
46                 Curve_EaseInEaseOut
47             } Curve;
48 
49         private:
50             const Type m_type;
51             const AnimationCurve* m_curve;
52 
53             const wxLongLong m_duration;
54             wxLongLong m_elapsed;
55             double m_progress;
56         public:
57             static Type freeType();
58 
59             Animation(Type type, Curve curve, wxLongLong duration);
60             virtual ~Animation();
61 
62             Type type() const;
63             bool step(wxLongLong delta);
64             void update();
65         private:
66             virtual void doUpdate(double progress) = 0;
67         };
68 
69         class ExecutableAnimation : public ExecutableEvent::Executable {
70         private:
71             Animation::List m_animations;
72         public:
73             ExecutableAnimation(const Animation::List& animations);
74         private:
75             void execute();
76         };
77 
78         class AnimationManager : public wxThread {
79         private:
80             typedef std::map<Animation::Type, Animation::List> AnimationMap;
81 
82             AnimationMap m_animations;
83             wxLongLong m_lastTime;
84         public:
85             AnimationManager();
86             void runAnimation(Animation* animation, bool replace);
87         private:
88             ExitCode Entry();
89         };
90     }
91 }
92 
93 #endif /* defined(TrenchBroom_Animation) */
94