The Battle for Wesnoth  1.19.0-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  virtual ~arrow();
39 
40  /** Sets the arrow's visibility */
41  void hide();
42  void show();
43 
44  virtual 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  virtual 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  virtual void set_color(const std::string& color);
55 
56  virtual 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 
77  virtual void draw_hex(const map_location& hex);
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  virtual void notify_arrow_changed();
85 
86 protected:
87 
88  /**
89  * Calculate the symbols to place along the arrow path.
90  * Invalidates every hex along the path.
91  */
92  virtual void update_symbols();
93 
95 
96  std::string color_;
97  /** represents the subdirectory that holds images for this arrow style */
98  std::string style_;
99 
102 
103  typedef std::map<map_location, image::locator> arrow_symbols_map_t;
105 
106  bool hidden_;
107 };
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:106
virtual std::string get_color() const
Definition: arrow.hpp:56
virtual void draw_hex(const map_location &hex)
Definition: arrow.cpp:139
static void invalidate_arrow_path(const arrow_path_t &path)
Invalidates every hex along the given path.
Definition: arrow.cpp:283
void show()
Definition: arrow.cpp:63
static const std::string STYLE_FOCUS_INVALID
Definition: arrow.hpp:70
void hide()
Sets the arrow's visibility.
Definition: arrow.cpp:50
void set_style(const std::string &style)
Definition: arrow.cpp:114
std::map< map_location, image::locator > arrow_symbols_map_t
Definition: arrow.hpp:103
arrow_path_t path_
Definition: arrow.hpp:100
arrow_path_t previous_path_
Definition: arrow.hpp:101
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:133
virtual void reset()
invalidates and clears the present path, forgets the previous path, clears the symbols map
Definition: arrow.cpp:90
display::drawing_layer layer_
Definition: arrow.hpp:94
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:98
virtual void update_symbols()
Calculate the symbols to place along the arrow path.
Definition: arrow.cpp:153
const arrow_path_t & get_previous_path() const
Definition: arrow.cpp:128
virtual void notify_arrow_changed()
Definition: arrow.cpp:292
virtual ~arrow()
Definition: arrow.cpp:45
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:123
virtual void set_path(const arrow_path_t &path)
Definition: arrow.cpp:75
arrow_symbols_map_t symbols_map_
Definition: arrow.hpp:104
std::string color_
Definition: arrow.hpp:96
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:100
static bool valid_path(const arrow_path_t &path)
Checks that the path is not of length 0 or 1.
Definition: arrow.cpp:148
drawing_layer
The layers to render something on.
Definition: display.hpp:820
std::string path
Definition: filesystem.cpp:83
Encapsulates the map of the game.
Definition: location.hpp:38