The Battle for Wesnoth  1.17.12+dev
halo.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2022
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 struct rect;
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();
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  /** Process animations, remove deleted halos, and invalidate screen
63  * regions now requiring redraw. */
64  void update();
65 
66  /** Render halos in region. */
67  void render(const rect& r);
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:37
bool valid() const
Definition: halo.hpp:86
void update()
Process animations, remove deleted halos, and invalidate screen regions now requiring redraw...
Definition: halo.cpp:446
#define h
std::weak_ptr< halo_impl > my_manager_
Definition: halo.hpp:93
void render(const rect &r)
Render halos in region.
Definition: halo.cpp:451
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:426
Encapsulates the map of the game.
Definition: location.hpp:38
std::shared_ptr< halo_impl > impl_
Definition: halo.hpp:70
An abstract description of a rectangle with integer coordinates.
Definition: rect.hpp:46
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:434
Definition: display.hpp:45
ORIENTATION
Definition: halo.hpp:35
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:31