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