map_label.hpp

Go to the documentation of this file.
00001 /* $Id: map_label.hpp 23842 2008-02-16 08:47:16Z mordante $ */
00002 /*
00003    Copyright (C) 2003 - 2008 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 version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 #ifndef MAP_LABEL_HPP_INCLUDED
00016 #define MAP_LABEL_HPP_INCLUDED
00017 
00018 class config;
00019 #include "map.hpp"
00020 #include "font.hpp"
00021 
00022 #include "serialization/string_utils.hpp"
00023 
00024 #include <map>
00025 #include <string>
00026 
00027 class display;
00028 class terrain_label;
00029 class game_state;
00030 
00031 
00032 
00033 class map_labels
00034 {
00035 public:
00036     typedef std::map<gamemap::location,const terrain_label*> label_map;
00037     typedef std::map<std::string,label_map> team_label_map;
00038 
00039     map_labels(const display& disp, const gamemap& map, const team*);
00040     map_labels(const display& disp, const config& cfg, const gamemap& map, const team*, const variable_set *variables);
00041     ~map_labels();
00042 
00043     void write(config& res) const;
00044     void read(const config& cfg, const variable_set *variables);
00045 
00046     static size_t get_max_chars();
00047 
00048     const terrain_label* get_label(const gamemap::location& loc, const std::string& team_name);
00049     // search a team-only label, if fails then try public labels
00050     const terrain_label* get_label(const gamemap::location& loc);
00051     const terrain_label* set_label(const gamemap::location& loc,
00052                                const std::string& text,
00053                                const std::string team = "",
00054                                const SDL_Color colour = font::NORMAL_COLOUR);
00055 
00056     void add_label(const gamemap::location&,
00057                    const terrain_label*);
00058 
00059     void clear(const std::string&);
00060 
00061     void scroll(double xmove, double ymove);
00062 
00063     void recalculate_labels();
00064     bool visible_global_label(const gamemap::location&) const;
00065 
00066     void recalculate_shroud();
00067 
00068     const display& disp() const;
00069 
00070     const std::string& team_name() const;
00071 
00072     void set_team(const team*);
00073 
00074 private:
00075     void clear_map(const label_map&);
00076     void clear_all();
00077     map_labels(const map_labels&);
00078     void operator=(const map_labels&);
00079 
00080     const display& disp_;
00081     const team* team_;
00082     const gamemap& map_;
00083 
00084     team_label_map labels_;
00085     label_map label_cache_;
00086 };
00087 
00088 /// To store label data
00089 /// Class implements logic for rendering
00090 class terrain_label
00091 {
00092 public:
00093     terrain_label(const std::string&,
00094                   const std::string&,
00095                   const gamemap::location&,
00096                   const map_labels&,
00097                   const SDL_Color colour = font::NORMAL_COLOUR);
00098 
00099     terrain_label(const map_labels&,
00100               const config&,
00101               const variable_set *variables);
00102 
00103     terrain_label(const map_labels&);
00104 
00105     ~terrain_label();
00106 
00107     void write(config& res) const;
00108     void read(const config& cfg, const variable_set *variables);
00109 
00110     const std::string& text() const;
00111     const std::string& team_name() const;
00112     const gamemap::location& location() const;
00113     const SDL_Colour& colour() const;
00114 
00115     void set_text(const std::string&);
00116 
00117     void update_info(const std::string&,
00118                      const std::string&,
00119                      const SDL_Color);
00120 
00121     void scroll(double xmove, double ymove) const;
00122 
00123     void recalculate();
00124     void calculate_shroud() const;
00125 
00126 private:
00127     terrain_label(const terrain_label&);
00128     const terrain_label& operator=(const terrain_label&);
00129     void clear();
00130     void draw();
00131     bool visible() const;
00132     void check_text_length();
00133     const std::string cfg_colour() const;
00134 
00135     int handle_;
00136 
00137     std::string text_;
00138     std::string team_name_;
00139     SDL_Color   colour_;
00140 
00141     const map_labels* parent_;
00142     gamemap::location loc_;
00143 
00144 };
00145 
00146 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs