The Battle for Wesnoth  1.15.1+dev
arrow.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2018 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
3  Part of the Battle for Wesnoth Project https://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 #pragma once
21 
22 #include "display.hpp"
23 
24 typedef std::vector<map_location> arrow_path_t;
25 
26 /**
27  * Arrows destined to be drawn on the map. Created for the whiteboard system.
28  */
29 class arrow {
30 
31 public:
32 
33  arrow(const arrow&) = delete;
34  arrow& operator=(const arrow&) = delete;
35 
36  arrow(bool hidden = false);
37  virtual ~arrow();
38 
39  ///Sets the arrow's visibility
40  void hide();
41  void show();
42 
43  virtual void set_path(const arrow_path_t& path);
44 
45  ///invalidates and clears the present path, forgets the previous path, clears the symbols map
46  virtual void reset();
47 
48  /**
49  * The string color parameter is in the same format expected by the
50  * image::locator modifiers parameter. Examples: red is "red" or "FF0000" or "255,0,0".
51  * Feel free to add another method that accepts an uint32_t as a parameter instead.
52  */
53  virtual void set_color(const std::string& color);
54 
55  virtual std::string get_color() const { return color_; }
56 
57  /**
58  * The style is simply the name of a subdirectory under images/arrows,
59  * that holds an alternate copy of the arrow graphics.
60  * If it doesn't exist or has missing images, you'll get "under construction"
61  * symbols instead of arrow graphics.
62  */
63  std::string get_style() const {return style_;}
64  void set_style(const std::string& style);
65  ///If you add more styles, you should look at move::update_arrow_style()
66  static const std::string STYLE_STANDARD;
67  static const std::string STYLE_HIGHLIGHTED;
68  static const std::string STYLE_FOCUS;
69  static const std::string STYLE_FOCUS_INVALID;
70 
71  const arrow_path_t& get_path() const;
72  const arrow_path_t& get_previous_path() const;
73 
74  bool path_contains(const map_location& hex) const;
75 
76  virtual void draw_hex(const map_location& hex);
77 
78  /// Checks that the path is not of length 0 or 1
79  static bool valid_path(const arrow_path_t& path);
80  /// Invalidates every hex along the given path
81  static void invalidate_arrow_path(const arrow_path_t& path);
82 
83  virtual void notify_arrow_changed();
84 
85 protected:
86 
87  /**
88  * Calculate the symbols to place along the arrow path.
89  * Invalidates every hex along the path.
90  */
91  virtual void update_symbols();
92 
94 
95  std::string color_;
96  /// represents the subdirectory that holds images for this arrow style
97  std::string style_;
98 
101 
102  typedef std::map<map_location, image::locator> arrow_symbols_map_t;
103  arrow_symbols_map_t symbols_map_;
104 
105  bool hidden_;
106 };
static void invalidate_arrow_path(const arrow_path_t &path)
Invalidates every hex along the given path.
Definition: arrow.cpp:284
std::string style_
represents the subdirectory that holds images for this arrow style
Definition: arrow.hpp:97
virtual void notify_arrow_changed()
Definition: arrow.cpp:293
void hide()
Sets the arrow&#39;s visibility.
Definition: arrow.cpp:49
const arrow_path_t & get_path() const
Definition: arrow.cpp:120
arrow & operator=(const arrow &)=delete
bool path_contains(const map_location &hex) const
Definition: arrow.cpp:130
virtual void draw_hex(const map_location &hex)
Definition: arrow.cpp:136
arrow_symbols_map_t symbols_map_
Definition: arrow.hpp:103
virtual void set_path(const arrow_path_t &path)
Definition: arrow.cpp:72
drawing_layer
The layers to render something on.
Definition: display.hpp:815
std::vector< map_location > arrow_path_t
Definition: arrow.hpp:24
arrow(const arrow &)=delete
std::map< map_location, image::locator > arrow_symbols_map_t
Definition: arrow.hpp:102
static const std::string STYLE_HIGHLIGHTED
Definition: arrow.hpp:67
static const std::string STYLE_FOCUS
Definition: arrow.hpp:68
const arrow_path_t & get_previous_path() const
Definition: arrow.cpp:125
std::string get_style() const
The style is simply the name of a subdirectory under images/arrows, that holds an alternate copy of t...
Definition: arrow.hpp:63
Arrows destined to be drawn on the map.
Definition: arrow.hpp:29
display::drawing_layer layer_
Definition: arrow.hpp:93
virtual void update_symbols()
Calculate the symbols to place along the arrow path.
Definition: arrow.cpp:154
static const std::string STYLE_FOCUS_INVALID
Definition: arrow.hpp:69
std::string path
Definition: game_config.cpp:39
map_display and display: classes which take care of displaying the map and game-data on the screen...
Encapsulates the map of the game.
Definition: location.hpp:42
std::string color_
Definition: arrow.hpp:95
void show()
Definition: arrow.cpp:61
virtual void reset()
invalidates and clears the present path, forgets the previous path, clears the symbols map ...
Definition: arrow.cpp:87
virtual void set_color(const std::string &color)
The string color parameter is in the same format expected by the image::locator modifiers parameter...
Definition: arrow.cpp:97
arrow_path_t path_
Definition: arrow.hpp:99
virtual std::string get_color() const
Definition: arrow.hpp:55
static const std::string STYLE_STANDARD
If you add more styles, you should look at move::update_arrow_style()
Definition: arrow.hpp:66
void set_style(const std::string &style)
Definition: arrow.cpp:111
static bool valid_path(const arrow_path_t &path)
Checks that the path is not of length 0 or 1.
Definition: arrow.cpp:146
arrow_path_t previous_path_
Definition: arrow.hpp:100
virtual ~arrow()
Definition: arrow.cpp:44
bool hidden_
Definition: arrow.hpp:105