00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef THEME_HPP_INCLUDED
00019 #define THEME_HPP_INCLUDED
00020
00021 #include <map>
00022 #include <string>
00023 #include <vector>
00024
00025 #include "SDL.h"
00026 #include "config.hpp"
00027 #include "generic_event.hpp"
00028
00029 typedef struct { size_t x1,y1,x2,y2; } _rect;
00030
00031 class theme
00032 {
00033
00034 class object
00035 {
00036 public:
00037 object();
00038 object(const config& cfg);
00039 virtual ~object() { }
00040
00041 SDL_Rect& location(const SDL_Rect& screen) const;
00042 const SDL_Rect& get_location(void) const { return loc_; }
00043 const std::string& get_id() const { return id_; }
00044
00045
00046
00047 void modify_location(const _rect rect);
00048 void modify_location(std::string rect_str, SDL_Rect rect_ref);
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 enum ANCHORING { FIXED, TOP_ANCHORED, PROPORTIONAL, BOTTOM_ANCHORED };
00059
00060 private:
00061 bool location_modified_;
00062 std::string id_;
00063 SDL_Rect loc_;
00064 mutable SDL_Rect relative_loc_;
00065 mutable SDL_Rect last_screen_;
00066
00067 ANCHORING xanchor_, yanchor_;
00068
00069 static ANCHORING read_anchor(const std::string& str);
00070 };
00071
00072 struct tborder
00073 {
00074
00075 tborder();
00076 tborder(const config& cfg);
00077
00078 double size;
00079
00080 std::string background_image;
00081 std::string tile_image;
00082
00083 std::string corner_image_top_left;
00084 std::string corner_image_bottom_left;
00085
00086 std::string corner_image_top_right_odd;
00087 std::string corner_image_top_right_even;
00088
00089 std::string corner_image_bottom_right_odd;
00090 std::string corner_image_bottom_right_even;
00091
00092 std::string border_image_left;
00093 std::string border_image_right;
00094
00095 std::string border_image_top_odd;
00096 std::string border_image_top_even;
00097
00098 std::string border_image_bottom_odd;
00099 std::string border_image_bottom_even;
00100
00101 };
00102
00103 public:
00104
00105 class label : public object
00106 {
00107 public:
00108 label();
00109 explicit label(const config& cfg);
00110
00111 using object::location;
00112
00113 const std::string& text() const { return text_; }
00114 const std::string& icon() const { return icon_; }
00115
00116 bool empty() const { return text_.empty() && icon_.empty(); }
00117
00118 size_t font_size() const { return font_; }
00119 Uint32 font_rgb() const { return font_rgb_; }
00120 bool font_rgb_set() const { return font_rgb_set_; }
00121 private:
00122 std::string text_, icon_;
00123 size_t font_;
00124 bool font_rgb_set_;
00125 Uint32 font_rgb_;
00126 };
00127
00128 class status_item : public object
00129 {
00130 public:
00131
00132 explicit status_item(const config& cfg);
00133
00134 using object::location;
00135
00136 const std::string& prefix() const { return prefix_; }
00137 const std::string& postfix() const { return postfix_; }
00138
00139
00140 const label* get_label() const { return label_.empty() ? NULL : &label_; }
00141
00142 size_t font_size() const { return font_; }
00143 Uint32 font_rgb() const { return font_rgb_; }
00144 bool font_rgb_set() const { return font_rgb_set_; }
00145
00146 private:
00147 std::string prefix_, postfix_;
00148 label label_;
00149 size_t font_;
00150 bool font_rgb_set_;
00151 Uint32 font_rgb_;
00152 };
00153
00154 class panel : public object
00155 {
00156 public:
00157 explicit panel(const config& cfg);
00158
00159 using object::location;
00160
00161 const std::string& image() const { return image_; }
00162
00163 private:
00164 std::string image_;
00165 };
00166
00167 class menu : public object
00168 {
00169 public:
00170 menu();
00171 explicit menu(const config& cfg);
00172
00173 using object::location;
00174
00175 bool is_context() const { return context_; }
00176
00177 const std::string& title() const { return title_; }
00178
00179 const std::string& tooltip() const { return tooltip_; }
00180
00181 const std::string& type() const { return type_; }
00182
00183 const std::string& image() const { return image_; }
00184
00185 const std::vector<std::string>& items() const { return items_; }
00186
00187 void set_title(const std::string new_title) { title_ = new_title; }
00188 private:
00189 bool context_;
00190 std::string title_, tooltip_, image_, type_;
00191 std::vector<std::string> items_;
00192 };
00193
00194 explicit theme(const config& cfg, const SDL_Rect& screen);
00195 bool set_resolution(const SDL_Rect& screen);
00196 void modify(const config* cfg);
00197
00198 const std::vector<panel>& panels() const { return panels_; }
00199 const std::vector<label>& labels() const { return labels_; }
00200 const std::vector<menu>& menus() const { return menus_; }
00201
00202 const menu* context_menu() const
00203 { return context_.is_context() ? &context_ : NULL; }
00204
00205
00206
00207 menu* refresh_title(const std::string& id, const std::string& new_title);
00208 menu* refresh_title2(const std::string& id, const std::string& title_tag);
00209
00210 const status_item* get_status_item(const std::string& item) const;
00211
00212 const SDL_Rect& main_map_location(const SDL_Rect& screen) const
00213 { return main_map_.location(screen); }
00214 const SDL_Rect& mini_map_location(const SDL_Rect& screen) const
00215 { return mini_map_.location(screen); }
00216 const SDL_Rect& unit_image_location(const SDL_Rect& screen) const
00217 { return unit_image_.location(screen); }
00218
00219 static void set_known_themes(const config* cfg);
00220 static std::vector<std::string> get_known_themes();
00221
00222 const tborder& border() const { return border_; }
00223
00224 events::generic_event& theme_reset() { return theme_reset_; }
00225
00226 private:
00227 theme::object& find_element(std::string id);
00228 void add_object(const config& cfg);
00229 void remove_object(std::string id);
00230 void set_object_location(theme::object& element, std::string rect_str, std::string ref_id);
00231
00232
00233
00234 events::generic_event theme_reset_;
00235
00236 static std::map<std::string, config> known_themes;
00237 std::string cur_theme;
00238 config cfg_;
00239 std::vector<panel> panels_;
00240 std::vector<label> labels_;
00241 std::vector<menu> menus_;
00242
00243 menu context_;
00244
00245 std::map<std::string,status_item> status_;
00246
00247 object main_map_, mini_map_, unit_image_;
00248
00249 tborder border_;
00250 };
00251
00252 #endif