theme.hpp

Go to the documentation of this file.
00001 /* $Id: theme.hpp 53881 2012-04-09 15:34:47Z fendrin $ */
00002 /*
00003    Copyright (C) 2003 - 2012 by David White <dave@whitevine.net>
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  *  Definitions related to theme-support.
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         // This supports relocating of theme elements ingame.
00045         // It is needed for [change] tags in theme WML.
00046         void modify_location(const _rect rect);
00047         void modify_location(std::string rect_str, SDL_Rect rect_ref);
00048 
00049         // All on-screen objects have 'anchoring' in the x and y dimensions.
00050         // 'fixed' means that they have fixed co-ordinates and don't move.
00051         // 'top anchored' means they are anchored to the top (or left) side
00052         // of the screen - the top (or left) edge stays a constant distance
00053         // from the top of the screen.
00054         // 'bottom anchored' is the inverse of top anchored.
00055         // 'proportional' means the location and dimensions change
00056         // proportionally to the screen size.
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         // If the item has a label associated with it, Show where the label is
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     //refresh_title2 changes the title of a menu entry, identified by id.
00206     //If no menu entry is found, an empty menu object is returned.
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     //notify observers that the theme has been rebuilt completely
00239     //atm this is used for replay_controller to add replay controls to the standard theme
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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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