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