The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
arrow.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2016 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13  */
14 
15 /**
16  * @file
17  * Arrows destined to be drawn on the map. Created for the whiteboard project.
18  */
19 
20 #ifndef ARROW_HPP_INCLUDED
21 #define ARROW_HPP_INCLUDED
22 
23 #include "display.hpp"
24 
25 typedef std::vector<map_location> arrow_path_t;
26 
27 /**
28  * Arrows destined to be drawn on the map. Created for the whiteboard system.
29  */
30 class arrow : private boost::noncopyable {
31 
32 public:
33 
34  arrow(bool hidden = false);
35  virtual ~arrow();
36 
37  ///Sets the arrow's visibility
38  void hide();
39  void show();
40 
41  virtual void set_path(arrow_path_t const& path);
42 
43  ///invalidates and clears the present path, forgets the previous path, clears the symbols map
44  virtual void reset();
45 
46  /**
47  * The string color parameter is in the same format expected by the
48  * image::locator modifiers parameter. Examples: red is "red" or "FF0000" or "255,0,0".
49  * Feel free to add another method that accepts an Uint32 as a parameter instead.
50  */
51  virtual void set_color(std::string const& color);
52 
53  virtual std::string get_color() const { return color_; }
54 
55  /**
56  * The style is simply the name of a subdirectory under images/arrows,
57  * that holds an alternate copy of the arrow graphics.
58  * If it doesn't exist or has missing images, you'll get "under construction"
59  * symbols instead of arrow graphics.
60  */
61  typedef std::string STYLE;
62  STYLE get_style() {return style_;}
63  void set_style(std::string const& style);
64  ///If you add more styles, you should look at move::update_arrow_style()
67  static std::string const STYLE_FOCUS;
69 
70  arrow_path_t const& get_path() const;
71  arrow_path_t const& get_previous_path() const;
72 
73  bool path_contains(map_location const& hex) const;
74 
75  virtual void draw_hex(map_location const& hex);
76 
77  /// Checks that the path is not of length 0 or 1
78  static bool valid_path(arrow_path_t const& path);
79  /// Invalidates every hex along the given path
80  static void invalidate_arrow_path(arrow_path_t const& path);
81 
82  virtual void notify_arrow_changed();
83 
84 protected:
85 
86  /**
87  * Calculate the symbols to place along the arrow path.
88  * Invalidates every hex along the path.
89  */
90  virtual void update_symbols();
91 
93 
95  /// represents the subdirectory that holds images for this arrow style
97 
100 
101  typedef std::map<map_location, image::locator> arrow_symbols_map_t;
102  arrow_symbols_map_t symbols_map_;
103 
104  bool hidden_;
105 };
106 #endif
std::string style_
represents the subdirectory that holds images for this arrow style
Definition: arrow.hpp:96
virtual void notify_arrow_changed()
Definition: arrow.cpp:296
virtual std::string get_color() const
Definition: arrow.hpp:53
static std::string const STYLE_FOCUS
Definition: arrow.hpp:67
void hide()
Sets the arrow's visibility.
Definition: arrow.cpp:52
arrow_path_t const & get_path() const
Definition: arrow.cpp:123
arrow(bool hidden=false)
Definition: arrow.cpp:34
arrow_symbols_map_t symbols_map_
Definition: arrow.hpp:102
static void invalidate_arrow_path(arrow_path_t const &path)
Invalidates every hex along the given path.
Definition: arrow.cpp:286
static std::string const STYLE_FOCUS_INVALID
Definition: arrow.hpp:68
std::vector< map_location > arrow_path_t
Definition: arrow.hpp:25
std::map< map_location, image::locator > arrow_symbols_map_t
Definition: arrow.hpp:101
tdrawing_layer
The layers to render something on.
Definition: display.hpp:864
GLsizei const char ** path
Definition: glew.h:4654
display::tdrawing_layer layer_
Definition: arrow.hpp:92
bool path_contains(map_location const &hex) const
Definition: arrow.cpp:133
Arrows destined to be drawn on the map.
Definition: arrow.hpp:30
virtual void update_symbols()
Calculate the symbols to place along the arrow path.
Definition: arrow.cpp:156
static bool valid_path(arrow_path_t const &path)
Checks that the path is not of length 0 or 1.
Definition: arrow.cpp:148
static std::string const STYLE_STANDARD
If you add more styles, you should look at move::update_arrow_style()
Definition: arrow.hpp:65
static std::string const STYLE_HIGHLIGHTED
Definition: arrow.hpp:66
map_display and display: classes which take care of displaying the map and game-data on the screen...
GLuint color
Definition: glew.h:5801
arrow_path_t const & get_previous_path() const
Definition: arrow.cpp:128
Encapsulates the map of the game.
Definition: location.hpp:38
std::string color_
Definition: arrow.hpp:94
void show()
Definition: arrow.cpp:65
virtual void reset()
invalidates and clears the present path, forgets the previous path, clears the symbols map ...
Definition: arrow.cpp:90
arrow_path_t path_
Definition: arrow.hpp:98
virtual void set_path(arrow_path_t const &path)
Definition: arrow.cpp:75
virtual void set_color(std::string const &color)
The string color parameter is in the same format expected by the image::locator modifiers parameter...
Definition: arrow.cpp:100
virtual void draw_hex(map_location const &hex)
Definition: arrow.cpp:139
STYLE get_style()
Definition: arrow.hpp:62
void set_style(std::string const &style)
Definition: arrow.cpp:114
std::string STYLE
The style is simply the name of a subdirectory under images/arrows, that holds an alternate copy of t...
Definition: arrow.hpp:61
GLsizei const GLcharARB ** string
Definition: glew.h:4503
arrow_path_t previous_path_
Definition: arrow.hpp:99
virtual ~arrow()
Definition: arrow.cpp:47
bool hidden_
Definition: arrow.hpp:104