00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef IMAGE_HPP_INCLUDED
00016 #define IMAGE_HPP_INCLUDED
00017
00018 #include "map.hpp"
00019 #include "sdl_utils.hpp"
00020
00021 #include "SDL.h"
00022 #include <string>
00023 #include <vector>
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 namespace image {
00035 #ifdef USE_TINY_GUI
00036
00037 const int tile_size = 36;
00038 #else
00039 const int tile_size = 72;
00040 #endif
00041
00042 template<typename T>
00043 struct cache_item {
00044 cache_item() : loaded(false), item() {}
00045 cache_item(T item) : loaded(true), item(item) {}
00046
00047 bool loaded;
00048 T item;
00049 };
00050
00051
00052 class locator
00053 {
00054 private:
00055
00056
00057 void init_index();
00058 void parse_arguments();
00059 public:
00060 enum type { NONE, FILE, SUB_FILE };
00061
00062 struct value {
00063 value();
00064 value(const value &a);
00065 value(const char *filename);
00066 value(const char *filename, const std::string& modifications);
00067 value(const std::string& filename);
00068 value(const std::string& filename, const std::string& modifications);
00069 value(const std::string& filename, const gamemap::location& loc, const std::string& modifications);
00070 value(const std::string& filename, const gamemap::location& loc, int center_x, int center_y, const std::string& modifications);
00071
00072 bool operator==(const value& a) const;
00073 bool operator<(const value& a) const;
00074
00075 type type_;
00076 std::string filename_;
00077 gamemap::location loc_;
00078 std::string modifications_;
00079 int center_x_;
00080 int center_y_;
00081 };
00082
00083
00084
00085
00086
00087 locator();
00088 locator(const locator &a, const std::string &mods ="");
00089 locator(const char *filename);
00090 locator(const char *filename, const std::string& modifications);
00091 locator(const std::string& filename);
00092 locator(const std::string& filename, const std::string& modifications);
00093 locator(const std::string& filename, const gamemap::location& loc, const std::string& modifications="");
00094 locator(const std::string& filename, const gamemap::location& loc, int center_x, int center_y, const std::string& modifications="");
00095
00096 locator& operator=(const locator &a);
00097 bool operator==(const locator &a) const { return index_ == a.index_; }
00098 bool operator!=(const locator &a) const { return index_ != a.index_; }
00099 bool operator<(const locator &a) const { return index_ < a.index_; }
00100
00101 const std::string &get_filename() const { return val_.filename_; }
00102 const gamemap::location& get_loc() const { return val_.loc_ ; }
00103 const std::string& get_modifications() const {return val_.modifications_;}
00104 type get_type() const { return val_.type_; };
00105
00106
00107
00108
00109 bool is_void() const { return val_.type_ == NONE; }
00110
00111 surface load_from_disk() const;
00112
00113 #if 0
00114
00115
00116 template<typename T>
00117 bool in_cache(const std::vector<cache_item<T> >& cache) const;
00118
00119 template<typename T>
00120 T locate_in_cache(const std::vector<cache_item<T> >& cache) const;
00121
00122
00123 template<typename T>
00124 void add_to_cache(std::vector<cache_item<T> >& cache, const T &image) const;
00125 #endif
00126 bool in_cache(const std::vector<cache_item<surface> >& cache) const
00127 { return index_ == -1 ? false : cache[index_].loaded; }
00128 surface locate_in_cache(const std::vector<cache_item<surface> >& cache) const
00129 { return index_ == -1 ? surface() : cache[index_].item; }
00130 void add_to_cache(std::vector<cache_item<surface> >& cache, const surface &image) const
00131 { if(index_ != -1 ) cache[index_] = cache_item<surface>(image); }
00132 bool in_cache(const std::vector<cache_item<locator> >& cache) const
00133 { return index_ == -1 ? false : cache[index_].loaded; }
00134 locator locate_in_cache(const std::vector<cache_item<locator> >& cache) const
00135 { return index_ == -1 ? locator() : cache[index_].item; }
00136 void add_to_cache(std::vector<cache_item<locator> >& cache, const locator &image) const
00137 { if(index_ != -1) cache[index_] = cache_item<locator>(image); }
00138 protected:
00139 static int last_index_;
00140 private:
00141
00142 surface load_image_file() const;
00143 surface load_image_sub_file() const;
00144
00145 int index_;
00146 value val_;
00147 };
00148
00149
00150 typedef std::vector<cache_item<surface> > image_cache;
00151 typedef std::vector<cache_item<locator> > locator_cache;
00152 typedef std::map<t_translation::t_terrain, surface> mini_terrain_cache_map;
00153 extern mini_terrain_cache_map mini_terrain_cache;
00154 extern mini_terrain_cache_map mini_fogged_terrain_cache;
00155
00156 void flush_cache();
00157
00158
00159
00160
00161 struct manager
00162 {
00163 manager();
00164 ~manager();
00165 };
00166
00167
00168
00169
00170 void set_wm_icon();
00171
00172
00173
00174
00175 void set_colour_adjustment(int r, int g, int b);
00176
00177
00178
00179
00180 void set_team_colors(const std::vector<std::string>* colors = NULL);
00181
00182
00183
00184 void set_image_mask(const std::string& image_name);
00185
00186 extern SDL_PixelFormat* pixel_format;
00187
00188
00189
00190 void set_pixel_format(SDL_PixelFormat* format);
00191
00192
00193
00194 void set_zoom(int zoom);
00195
00196
00197
00198
00199
00200 enum TYPE { UNSCALED, HEXED, UNMASKED, SCALED_TO_HEX, SCALED_TO_ZOOM, BRIGHTENED, SEMI_BRIGHTENED };
00201
00202
00203
00204
00205
00206 surface get_image(const locator& i_locator, TYPE type=UNSCALED, bool add_to_cache = true);
00207
00208
00209
00210
00211 surface reverse_image(const surface &surf);
00212
00213
00214 bool exists(const locator& i_locator);
00215 }
00216
00217 #endif
00218