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 THEME_HPP_INCLUDED
00022 #define THEME_HPP_INCLUDED
00023
00024 #include "SDL.h"
00025 #include "config.hpp"
00026 #include "generic_event.hpp"
00027
00028 typedef struct { size_t x1,y1,x2,y2; } _rect;
00029
00030 class theme
00031 {
00032
00033 class object
00034 {
00035 public:
00036 object();
00037 object(const config& cfg);
00038 virtual ~object() { }
00039
00040 SDL_Rect& location(const SDL_Rect& screen) const;
00041 const SDL_Rect& get_location() const { return loc_; }
00042 const std::string& get_id() const { return id_; }
00043
00044
00045
00046 void modify_location(const _rect rect);
00047 void modify_location(std::string rect_str, SDL_Rect rect_ref);
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 enum ANCHORING { FIXED, TOP_ANCHORED, PROPORTIONAL, BOTTOM_ANCHORED };
00058
00059 private:
00060 bool location_modified_;
00061 std::string id_;
00062 SDL_Rect loc_;
00063 mutable SDL_Rect relative_loc_;
00064 mutable SDL_Rect last_screen_;
00065
00066 ANCHORING xanchor_, yanchor_;
00067
00068 static ANCHORING read_anchor(const std::string& str);
00069 };
00070
00071 struct tborder
00072 {
00073
00074 tborder();
00075 tborder(const config& cfg);
00076
00077 double size;
00078
00079 std::string background_image;
00080 std::string tile_image;
00081
00082 std::string corner_image_top_left;
00083 std::string corner_image_bottom_left;
00084
00085 std::string corner_image_top_right_odd;
00086 std::string corner_image_top_right_even;
00087
00088 std::string corner_image_bottom_right_odd;
00089 std::string corner_image_bottom_right_even;
00090
00091 std::string border_image_left;
00092 std::string border_image_right;
00093
00094 std::string border_image_top_odd;
00095 std::string border_image_top_even;
00096
00097 std::string border_image_bottom_odd;
00098 std::string border_image_bottom_even;
00099
00100 };
00101
00102 public:
00103
00104 class label : public object
00105 {
00106 public:
00107 label();
00108 explicit label(const config& cfg);
00109
00110 using object::location;
00111
00112 const std::string& text() const { return text_; }
00113 void set_text(const std::string& text) { text_ = 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 void modify_label(const std::string& id, const std::string& text);
00210
00211 const status_item* get_status_item(const std::string& item) const;
00212 const menu *get_menu_item(const std::string &key) const;
00213
00214 const SDL_Rect& main_map_location(const SDL_Rect& screen) const
00215 { return main_map_.location(screen); }
00216 const SDL_Rect& mini_map_location(const SDL_Rect& screen) const
00217 { return mini_map_.location(screen); }
00218 const SDL_Rect& unit_image_location(const SDL_Rect& screen) const
00219 { return unit_image_.location(screen); }
00220 const SDL_Rect& palette_location(const SDL_Rect& screen) const
00221 { return palette_.location(screen); }
00222 const SDL_Rect& brush_bar_location(const SDL_Rect& screen) const
00223 { return brush_bar_.location(screen); }
00224
00225 static void set_known_themes(const config* cfg);
00226 static std::vector<std::string> get_known_themes();
00227
00228 const tborder& border() const { return border_; }
00229
00230 events::generic_event& theme_reset_event() { return theme_reset_event_; }
00231
00232 private:
00233 theme::object& find_element(std::string id);
00234 void add_object(const config& cfg);
00235 void remove_object(std::string id);
00236 void set_object_location(theme::object& element, std::string rect_str, std::string ref_id);
00237
00238
00239
00240 events::generic_event theme_reset_event_;
00241
00242 static std::map<std::string, config> known_themes;
00243 std::string cur_theme;
00244 config cfg_;
00245 std::vector<panel> panels_;
00246 std::vector<label> labels_;
00247 std::vector<menu> menus_;
00248
00249 menu context_;
00250
00251 std::map<std::string,status_item> status_;
00252
00253 object main_map_, mini_map_, unit_image_, palette_, brush_bar_;
00254
00255 tborder border_;
00256 };
00257
00258 #endif