Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef IMAGE_HPP_INCLUDED
00017 #define IMAGE_HPP_INCLUDED
00018
00019 #include "map_location.hpp"
00020 #include "sdl_utils.hpp"
00021 #include "terrain_translation.hpp"
00022
00023
00024
00025
00026 namespace image {
00027 const int tile_size = 72;
00028
00029 template<typename T>
00030 class cache_type;
00031
00032
00033 class locator
00034 {
00035 public:
00036 enum type { NONE, FILE, SUB_FILE };
00037 private:
00038
00039
00040 void init_index();
00041 void parse_arguments();
00042 struct value {
00043 value();
00044 value(const value &a);
00045 value(const char *filename);
00046 value(const std::string& filename);
00047 value(const std::string& filename, const std::string& modifications);
00048 value(const std::string& filename, const map_location& loc, int center_x, int center_y, const std::string& modifications);
00049
00050 bool operator==(const value& a) const;
00051 bool operator<(const value& a) const;
00052
00053 type type_;
00054 std::string filename_;
00055 map_location loc_;
00056 std::string modifications_;
00057 int center_x_;
00058 int center_y_;
00059 };
00060
00061 friend size_t hash_value(const value&);
00062
00063 public:
00064
00065
00066
00067
00068
00069
00070
00071 typedef std::map<size_t, std::map<value, int> > locator_finder_t;
00072
00073
00074
00075
00076
00077 locator();
00078 locator(const locator &a, const std::string &mods ="");
00079 locator(const char *filename);
00080 locator(const std::string& filename);
00081 locator(const std::string& filename, const std::string& modifications);
00082 locator(const std::string &filename, const map_location &loc,
00083 int center_x, int center_y, const std::string& modifications = "");
00084
00085 locator& operator=(const locator &a);
00086 bool operator==(const locator &a) const { return index_ == a.index_; }
00087 bool operator!=(const locator &a) const { return index_ != a.index_; }
00088 bool operator<(const locator &a) const { return index_ < a.index_; }
00089
00090 const std::string &get_filename() const { return val_.filename_; }
00091 const map_location& get_loc() const { return val_.loc_ ; }
00092 int get_center_x() const { return val_.center_x_; }
00093 int get_center_y() const { return val_.center_y_; }
00094 const std::string& get_modifications() const {return val_.modifications_;}
00095 type get_type() const { return val_.type_; };
00096
00097
00098
00099
00100 bool is_void() const { return val_.type_ == NONE; }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 bool file_exists() const;
00113
00114
00115 surface load_from_disk() const;
00116
00117 template <typename T>
00118 bool in_cache(cache_type<T> &cache) const;
00119 template <typename T>
00120 T &access_in_cache(cache_type<T> &cache) const;
00121 template <typename T>
00122 const T &locate_in_cache(cache_type<T> &cache) const;
00123 template <typename T>
00124 void add_to_cache(cache_type<T> &cache, const T &data) const;
00125
00126 private:
00127
00128 surface load_image_file() const;
00129 surface load_image_sub_file() const;
00130
00131 int index_;
00132 value val_;
00133 };
00134
00135 size_t hash_value(const locator::value&);
00136
00137
00138 typedef cache_type<surface> image_cache;
00139 typedef cache_type<bool> bool_cache;
00140
00141 typedef std::map<t_translation::t_terrain, surface> mini_terrain_cache_map;
00142 extern mini_terrain_cache_map mini_terrain_cache;
00143 extern mini_terrain_cache_map mini_fogged_terrain_cache;
00144
00145
00146
00147
00148
00149 typedef std::basic_string<signed char> light_string;
00150
00151 light_string get_light_string(int op, int r, int g, int b);
00152
00153
00154 typedef std::map<light_string, surface> lit_variants;
00155
00156 typedef cache_type<lit_variants> lit_cache;
00157
00158 void flush_cache();
00159
00160
00161
00162
00163 struct manager
00164 {
00165 manager();
00166 ~manager();
00167 };
00168
00169
00170
00171
00172 void set_color_adjustment(int r, int g, int b);
00173
00174 class color_adjustment_resetter
00175 {
00176 public:
00177 color_adjustment_resetter();
00178 void reset();
00179 private:
00180 int r_, g_, b_;
00181 };
00182
00183
00184
00185
00186 void set_team_colors(const std::vector<std::string>* colors = NULL);
00187
00188 const std::vector<std::string>& get_team_colors();
00189
00190
00191
00192 void set_pixel_format(SDL_PixelFormat* format);
00193
00194
00195
00196 void set_zoom(int zoom);
00197
00198
00199
00200
00201
00202
00203
00204 enum TYPE { UNSCALED, SCALED_TO_ZOOM, HEXED, SCALED_TO_HEX, TOD_COLORED, BRIGHTENED};
00205
00206
00207
00208
00209 surface get_image(const locator& i_locator, TYPE type=UNSCALED);
00210
00211
00212
00213
00214 surface get_lighted_image(const image::locator& i_locator, const light_string& ls, TYPE type);
00215
00216
00217 surface get_hexmask();
00218
00219
00220
00221 bool is_in_hex(const locator& i_locator);
00222
00223
00224
00225 bool is_empty_hex(const locator& i_locator);
00226
00227
00228
00229
00230 surface reverse_image(const surface &surf);
00231
00232
00233 bool exists(const locator& i_locator);
00234
00235
00236 void precache_file_existence(const std::string& subdir = "");
00237 bool precached_file_exists(const std::string& file);
00238 }
00239
00240 #endif
00241