The Battle for Wesnoth  1.19.7+dev
arrow.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2024
3  by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Arrows destined to be drawn on the map. Created for the whiteboard project.
19  */
20 
21 #pragma once
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 {
31 
32 public:
33 
34  arrow(const arrow&) = delete;
35  arrow& operator=(const arrow&) = delete;
36 
37  explicit arrow(bool hidden = false);
38  ~arrow();
39 
40  /** Sets the arrow's visibility */
41  void hide();
42  void show();
43 
44  void set_path(const arrow_path_t& path);
45 
46  /** invalidates and clears the present path, forgets the previous path, clears the symbols map */
47  void reset();
48 
49  /**
50  * The string color parameter is in the same format expected by the
51  * image::locator modifiers parameter. Examples: red is "red" or "FF0000" or "255,0,0".
52  * Feel free to add another method that accepts an uint32_t as a parameter instead.
53  */
54  void set_color(const std::string& color);
55 
56  std::string get_color() const { return color_; }
57 
58  /**
59  * The style is simply the name of a subdirectory under images/arrows,
60  * that holds an alternate copy of the arrow graphics.
61  * If it doesn't exist or has missing images, you'll get "under construction"
62  * symbols instead of arrow graphics.
63  */
64  std::string get_style() const {return style_;}
65  void set_style(const std::string& style);
66  /** If you add more styles, you should look at move::update_arrow_style() */
67  static const std::string STYLE_STANDARD;
68  static const std::string STYLE_HIGHLIGHTED;
69  static const std::string STYLE_FOCUS;
70  static const std::string STYLE_FOCUS_INVALID;
71 
72  const arrow_path_t& get_path() const;
73  const arrow_path_t& get_previous_path() const;
74 
75  bool path_contains(const map_location& hex) const;
76 
78 
79  /** Checks that the path is not of length 0 or 1 */
80  static bool valid_path(const arrow_path_t& path);
81  /** Invalidates every hex along the given path */
82  static void invalidate_arrow_path(const arrow_path_t& path);
83 
84  void notify_arrow_changed();
85 
86 private:
87 
88  /**
89  * Calculate the symbols to place along the arrow path.
90  * Invalidates every hex along the path.
91  */
92  void update_symbols();
93 
94  std::string color_;
95  /** represents the subdirectory that holds images for this arrow style */
96  std::string style_;
97 
100 
101  typedef std::map<map_location, image::locator> arrow_symbols_map_t;
103 
104  bool hidden_;
105 };
std::vector< map_location > arrow_path_t
Definition: arrow.hpp:25
Arrows destined to be drawn on the map.
Definition: arrow.hpp:30
bool hidden_
Definition: arrow.hpp:104
static void invalidate_arrow_path(const arrow_path_t &path)
Invalidates every hex along the given path.
Definition: arrow.cpp:282
void show()
Definition: arrow.cpp:62
static const std::string STYLE_FOCUS_INVALID
Definition: arrow.hpp:70
void hide()
Sets the arrow's visibility.
Definition: arrow.cpp:49
void set_style(const std::string &style)
Definition: arrow.cpp:113
std::map< map_location, image::locator > arrow_symbols_map_t
Definition: arrow.hpp:101
arrow_path_t path_
Definition: arrow.hpp:98
arrow_path_t previous_path_
Definition: arrow.hpp:99
static const std::string STYLE_FOCUS
Definition: arrow.hpp:69
arrow & operator=(const arrow &)=delete
bool path_contains(const map_location &hex) const
Definition: arrow.cpp:132
std::string get_color() const
Definition: arrow.hpp:56
void reset()
invalidates and clears the present path, forgets the previous path, clears the symbols map
Definition: arrow.cpp:89
static const std::string STYLE_STANDARD
If you add more styles, you should look at move::update_arrow_style()
Definition: arrow.hpp:67
static const std::string STYLE_HIGHLIGHTED
Definition: arrow.hpp:68
std::string style_
represents the subdirectory that holds images for this arrow style
Definition: arrow.hpp:96
void update_symbols()
Calculate the symbols to place along the arrow path.
Definition: arrow.cpp:152
const arrow_path_t & get_previous_path() const
Definition: arrow.cpp:127
void notify_arrow_changed()
Definition: arrow.cpp:291
~arrow()
Definition: arrow.cpp:44
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:64
arrow(const arrow &)=delete
const arrow_path_t & get_path() const
Definition: arrow.cpp:122
void set_path(const arrow_path_t &path)
Definition: arrow.cpp:74
arrow_symbols_map_t symbols_map_
Definition: arrow.hpp:102
std::string color_
Definition: arrow.hpp:94
image::locator get_image_for_loc(const map_location &hex) const
Definition: arrow.cpp:138
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:99
static bool valid_path(const arrow_path_t &path)
Checks that the path is not of length 0 or 1.
Definition: arrow.cpp:147
Generic locator abstracting the location of an image.
Definition: picture.hpp:59
map_display and display: classes which take care of displaying the map and game-data on the screen.
std::string path
Definition: filesystem.cpp:91
Encapsulates the map of the game.
Definition: location.hpp:45