unit_frame.hpp

Go to the documentation of this file.
00001 /* $Id: unit_frame.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2006 - 2012 by Jeremy Rosen <jeremy.rosen@enst-bretagne.fr>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /**
00017  *  @file
00018  *  Frame for unit's animation sequence.
00019  */
00020 
00021 #ifndef UNIT_FRAME_H_INCLUDED
00022 #define UNIT_FRAME_H_INCLUDED
00023 
00024 #include "image.hpp"
00025 
00026 class config;
00027 
00028 class progressive_string {
00029     public:
00030         progressive_string(const std::string& data = "",int duration = 0);
00031         int duration() const;
00032         const std::string & get_current_element(int time) const;
00033         bool does_not_change() const { return data_.size() <= 1; }
00034         std::string get_original() const { return input_; }
00035     private:
00036         std::vector<std::pair<std::string,int> > data_;
00037         std::string input_;
00038 };
00039 
00040 template <class T>
00041 class progressive_
00042 {
00043     std::vector<std::pair<std::pair<T, T>, int> > data_;
00044     std::string input_;
00045 public:
00046     progressive_(const std::string& data = "", int duration = 0);
00047     int duration() const;
00048     const T get_current_element(int time,T default_val=0) const;
00049     bool does_not_change() const;
00050     std::string get_original() const { return input_; }
00051 };
00052 
00053 typedef progressive_<int> progressive_int;
00054 typedef progressive_<double> progressive_double;
00055 
00056 typedef enum tristate {t_false,t_true,t_unset} tristate;
00057 /** All parameters from a frame at a given instant */
00058 class frame_parameters{
00059     public:
00060     frame_parameters();
00061 
00062     int duration;
00063     image::locator image;
00064     image::locator image_diagonal;
00065     std::string image_mod;
00066     std::string halo;
00067     int halo_x;
00068     int halo_y;
00069     std::string halo_mod;
00070     std::string sound;
00071     std::string text;
00072     Uint32 text_color;
00073     Uint32 blend_with;
00074     double blend_ratio;
00075     double highlight_ratio;
00076     double offset;
00077     double submerge;
00078     int x;
00079     int y;
00080     int directional_x;
00081     int directional_y;
00082     tristate auto_vflip;
00083     tristate auto_hflip;
00084     tristate primary_frame;
00085     int drawing_layer;
00086 } ;
00087 /**
00088  * easily build frame parameters with the serialized constructors
00089  */
00090 class frame_parsed_parameters;
00091 class frame_builder {
00092     public:
00093         frame_builder();
00094         frame_builder(const config& cfg,const std::string &frame_string = "");
00095         /** allow easy chained modifications will raised assert if used after initialization */
00096         frame_builder & duration(const int duration);
00097         frame_builder & image(const image::locator& image ,const std::string & image_mod="");
00098         frame_builder & image_diagonal(const image::locator& image_diagonal,const std::string & image_mod="");
00099         frame_builder & sound(const std::string& sound);
00100         frame_builder & text(const std::string& text,const  Uint32 text_color);
00101         frame_builder & halo(const std::string &halo, const std::string &halo_x, const std::string& halo_y,const std::string& halo_mod);
00102         frame_builder & blend(const std::string& blend_ratio,const Uint32 blend_color);
00103         frame_builder & highlight(const std::string& highlight);
00104         frame_builder & offset(const std::string& offset);
00105         frame_builder & submerge(const std::string& submerge);
00106         frame_builder & x(const std::string& x);
00107         frame_builder & y(const std::string& y);
00108         frame_builder & directional_x(const std::string& directional_x);
00109         frame_builder & directional_y(const std::string& directional_y);
00110         frame_builder & auto_vflip(const bool auto_vflip);
00111         frame_builder & auto_hflip(const bool auto_hflip);
00112         frame_builder & primary_frame(const bool primary_frame);
00113         frame_builder & drawing_layer(const std::string& drawing_layer);
00114         /** getters for the different parameters */
00115     private:
00116         friend class frame_parsed_parameters;
00117         int duration_;
00118         image::locator image_;
00119         image::locator image_diagonal_;
00120         std::string image_mod_;
00121         std::string halo_;
00122         std::string halo_x_;
00123         std::string halo_y_;
00124         std::string halo_mod_;
00125         std::string sound_;
00126         std::string text_;
00127         Uint32 text_color_;
00128         Uint32 blend_with_;
00129         std::string blend_ratio_;
00130         std::string highlight_ratio_;
00131         std::string offset_;
00132         std::string submerge_;
00133         std::string x_;
00134         std::string y_;
00135         std::string directional_x_;
00136         std::string directional_y_;
00137         tristate auto_vflip_;
00138         tristate auto_hflip_;
00139         tristate primary_frame_;
00140         std::string drawing_layer_;
00141 };
00142 /**
00143  * keep most parameters in a separate class to simplify handling of large
00144  * number of parameters hanling is common for frame level and animation level
00145  */
00146 class frame_parsed_parameters {
00147     public:
00148         frame_parsed_parameters(const frame_builder& builder=frame_builder(),int override_duration = 0);
00149         /** allow easy chained modifications will raised assert if used after initialization */
00150         void override( int duration
00151                 , const std::string& highlight = ""
00152                 , const std::string& blend_ratio =""
00153                 , Uint32 blend_color = 0
00154                 , const std::string& offset = ""
00155                 , const std::string& layer = ""
00156                 , const std::string& modifiers = "");
00157         /** getters for the different parameters */
00158         const frame_parameters parameters(int current_time) const ;
00159 
00160         int duration() const{ return duration_;};
00161         bool does_not_change() const;
00162         bool need_update() const;
00163     private:
00164         int duration_;
00165         image::locator image_;
00166         image::locator image_diagonal_;
00167         std::string image_mod_;
00168         progressive_string halo_;
00169         progressive_int halo_x_;
00170         progressive_int halo_y_;
00171         std::string halo_mod_;
00172         std::string sound_;
00173         std::string text_;
00174         Uint32 text_color_;
00175         Uint32 blend_with_;
00176         progressive_double blend_ratio_;
00177         progressive_double highlight_ratio_;
00178         progressive_double offset_;
00179         progressive_double submerge_;
00180         progressive_int x_;
00181         progressive_int y_;
00182         progressive_int directional_x_;
00183         progressive_int directional_y_;
00184         tristate auto_vflip_;
00185         tristate auto_hflip_;
00186         tristate primary_frame_;
00187         progressive_int drawing_layer_;
00188 };
00189 /** Describe a unit's animation sequence. */
00190 class unit_frame {
00191     public:
00192         // Constructors
00193         unit_frame(const frame_builder builder=frame_builder()):builder_(builder){};
00194         void redraw(const int frame_time,bool first_time,const map_location & src,const map_location & dst,int*halo_id,const frame_parameters & animation_val,const frame_parameters & engine_val)const;
00195         const frame_parameters merge_parameters(int current_time,const frame_parameters & animation_val,const frame_parameters & engine_val=frame_parameters()) const;
00196         const frame_parameters parameters(int current_time) const {return builder_.parameters(current_time);};
00197 
00198         int duration() const { return builder_.duration();};
00199         bool does_not_change() const{ return builder_.does_not_change();};
00200         bool need_update() const{ return builder_.need_update();};
00201         std::set<map_location> get_overlaped_hex(const int frame_time,const map_location & src,const map_location & dst,const frame_parameters & animation_val,const frame_parameters & engine_val) const;
00202     private:
00203         frame_parsed_parameters builder_;
00204 
00205 };
00206 
00207 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:14 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs