The Battle for Wesnoth  1.17.0-dev
halo.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
3  by David White <dave@whitevine.net>
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 #pragma once
17 
18 class display;
19 
20 #include "map/location.hpp"
21 
22 #include <memory>
23 
24 namespace halo
25 {
26 
27 
28 class halo_impl;
29 
31 
32 typedef std::shared_ptr<halo_record> handle;
33 
35 
36 const int NO_HALO = 0;
37 
38 class manager
39 {
40 public:
41  manager(display& screen);
42 
43  /**
44  * Add a haloing effect using 'image centered on (x,y).
45  * @return The handle to the halo object.
46  * @retval 0 is the invalid handle.
47  *
48  * If the halo is attached to an item, it needs to be hidden if the
49  * shroud is active. (Note it will be shown with the fog active.)
50  * If it is not attached to an item, the location should be set to -1, -1
51  */
52  handle add(int x, int y, const std::string& image, const map_location& loc,
53  halo::ORIENTATION orientation=NORMAL, bool infinite=true);
54 
55  /** Set the position of an existing haloing effect, according to its handle. */
56  void set_location(const handle & h, int x, int y);
57 
58  /** Remove the halo with the given handle. */
59  void remove(const handle & h);
60 
61  /**
62  * Render and unrender haloes.
63  *
64  * Which haloes are rendered is determined by invalidated_locations and the
65  * internal state in the control sets (in halo.cpp).
66  */
67  void unrender(std::set<map_location> invalidated_locations);
68  void render();
69 
70 private:
71  std::shared_ptr<halo_impl> impl_;
72 };
73 
74 /**
75  * RAII object which manages a halo. When it goes out of scope it removes the corresponding halo entry.
76  */
78 {
79 public:
80  halo_record(const halo_record&) = delete;
81  halo_record& operator=(const halo_record&) = delete;
82 
83  halo_record();
84  halo_record(int id, const std::shared_ptr<halo_impl> & my_manager);
85  ~halo_record();
86 
87  bool valid() const {
88  return id_ != NO_HALO && !my_manager_.expired();
89  }
90 
91  friend class manager;
92 private:
93  int id_;
94  std::weak_ptr<halo_impl> my_manager_;
95 
96 };
97 
98 } // end namespace halo
const int NO_HALO
Definition: halo.hpp:36
bool valid() const
Definition: halo.hpp:87
#define h
std::weak_ptr< halo_impl > my_manager_
Definition: halo.hpp:94
manager(display &screen)
Definition: halo.cpp:450
handle add(int x, int y, const std::string &image, const map_location &loc, halo::ORIENTATION orientation=NORMAL, bool infinite=true)
Add a haloing effect using &#39;image centered on (x,y).
Definition: halo.cpp:453
Encapsulates the map of the game.
Definition: location.hpp:38
std::shared_ptr< halo_impl > impl_
Definition: halo.hpp:71
void unrender(std::set< map_location > invalidated_locations)
Render and unrender haloes.
Definition: halo.cpp:479
void set_location(const handle &h, int x, int y)
Set the position of an existing haloing effect, according to its handle.
Definition: halo.cpp:461
void render()
Definition: halo.cpp:484
Definition: display.hpp:45
ORIENTATION
Definition: halo.hpp:34
Functions to load and save images from/to disk.
RAII object which manages a halo.
Definition: halo.hpp:77
std::shared_ptr< halo_record > handle
Definition: halo.hpp:30