Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef ANIMATED_IMAGE_H_INCLUDED
00022 #define ANIMATED_IMAGE_H_INCLUDED
00023
00024 #include <string>
00025 #include <map>
00026 #include <vector>
00027
00028 void new_animation_frame();
00029 int get_current_animation_tick();
00030
00031
00032 template<typename T>
00033 class void_value
00034 {
00035 public:
00036 const T operator()() { return T(); }
00037 };
00038
00039 template<typename T, typename T_void_value=void_value<T> >
00040 class animated
00041 {
00042 public:
00043
00044 animated(int start_time=0);
00045 virtual ~animated(){};
00046
00047
00048 typedef std::pair<int,T> frame_description;
00049 typedef std::vector<frame_description> anim_description;
00050 animated(const std::vector<frame_description> &cfg, int start_time = 0,bool force_change =false);
00051
00052
00053
00054 void add_frame(int duration, const T& value,bool force_change =false);
00055
00056
00057
00058
00059
00060
00061
00062 void start_animation(int start_time, bool cycles=false);
00063 void pause_animation(){ started_ =false;};
00064 void restart_animation(){if(start_tick_) started_ = true;};
00065
00066 int get_begin_time() const;
00067 int get_end_time() const;
00068 void set_begin_time(int new_begin_time);
00069
00070 int time_to_tick(int animation_time) const;
00071 int tick_to_time(int animation_tick) const;
00072
00073 void update_last_draw_time(double acceleration = 0);
00074 bool need_update() const;
00075
00076 bool cycles() const {return cycles_;};
00077
00078
00079 bool animation_finished() const;
00080 bool animation_finished_potential() const;
00081 int get_animation_time() const;
00082 int get_animation_time_potential() const;
00083 void set_animation_time(int time);
00084
00085 int get_animation_duration() const;
00086 const T& get_current_frame() const;
00087 int get_current_frame_begin_time() const;
00088 int get_current_frame_end_time() const;
00089 int get_current_frame_duration() const;
00090 int get_current_frame_time() const;
00091 const T& get_first_frame() const;
00092 const T& get_frame(size_t n) const;
00093 const T& get_last_frame() const;
00094 size_t get_frames_count() const;
00095 void force_change() {does_not_change_ = false ; }
00096 bool does_not_change() const {return does_not_change_;}
00097
00098 static const T void_value_;
00099
00100 protected:
00101 friend class unit_animation;
00102 int starting_frame_time_;
00103 void remove_frames_until(int starting_time);
00104 void set_end_time(int ending_time);
00105
00106 private:
00107 struct frame
00108 {
00109
00110 frame(int duration , const T& value,int start_time) :
00111 duration_(duration),value_(value),start_time_(start_time)
00112 {};
00113 frame():
00114 duration_(0),value_(void_value_),start_time_(0)
00115 {};
00116
00117
00118 int duration_;
00119 T value_;
00120 int start_time_;
00121 };
00122
00123 bool does_not_change_;
00124 bool started_;
00125 bool force_next_update_;
00126 std::vector<frame> frames_;
00127
00128
00129 int start_tick_;
00130 bool cycles_;
00131 double acceleration_;
00132 int last_update_tick_;
00133 int current_frame_key_;
00134
00135 };
00136
00137 #endif
00138