The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
halo.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #ifndef HALO_HPP_INCLUDED
18 #define HALO_HPP_INCLUDED
19 
20 class display;
21 
22 #include "map/location.hpp"
23 
24 #include <boost/noncopyable.hpp>
25 #include <boost/shared_ptr.hpp>
26 #include <boost/weak_ptr.hpp>
27 
28 namespace halo
29 {
30 
31 
32 class halo_impl;
33 
35 
37 
39 
40 const int NO_HALO = 0;
41 
42 class manager
43 {
44 public:
45  manager(display& disp);
46 
47  /**
48  * Add a haloing effect using 'image centered on (x,y).
49  * @return The handle to the halo object.
50  * @retval 0 is the invalid handle.
51  *
52  * If the halo is attached to an item, it needs to be hidden if the
53  * shroud is active. (Note it will be shown with the fog active.)
54  * If it is not attached to an item, the location should be set to -1, -1
55  */
56  handle add(int x, int y, const std::string& image, const map_location& loc,
57  halo::ORIENTATION orientation=NORMAL, bool infinite=true);
58 
59  /** Set the position of an existing haloing effect, according to its handle. */
60  void set_location(const handle & h, int x, int y);
61 
62  /** Remove the halo with the given handle. */
63  void remove(const handle & h);
64 
65  /**
66  * Render and unrender haloes.
67  *
68  * Which haloes are rendered is determined by invalidated_locations and the
69  * internal state in the control sets (in halo.cpp).
70  */
71  void unrender(std::set<map_location> invalidated_locations);
72  void render();
73 
74 private:
76 };
77 
78 /**
79  * RAII object which manages a halo. When it goes out of scope it removes the corresponding halo entry.
80  */
81 class halo_record : public boost::noncopyable
82 {
83 public:
84  halo_record();
85  halo_record(int id, const boost::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  boost::weak_ptr<halo_impl> my_manager_;
96 
97 };
98 
99 } // end namespace halo
100 
101 #endif
manager(display &disp)
Definition: halo.cpp:475
const int NO_HALO
Definition: halo.hpp:40
#define h
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
halo_record()
halo::halo_record implementation
Definition: halo.cpp:521
boost::weak_ptr< halo_impl > my_manager_
Definition: halo.hpp:95
bool valid() const
Definition: halo.hpp:88
boost::shared_ptr< halo_impl > impl_
Definition: halo.hpp:75
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 'image centered on (x,y).
Definition: halo.cpp:478
Encapsulates the map of the game.
Definition: location.hpp:38
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:5910
void unrender(std::set< map_location > invalidated_locations)
Render and unrender haloes.
Definition: halo.cpp:504
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
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:486
void render()
Definition: halo.cpp:509
Definition: display.hpp:43
ORIENTATION
Definition: halo.hpp:38
this module manages the cache of images.
Definition: image.cpp:75
RAII object which manages a halo.
Definition: halo.hpp:81
GLsizei const GLcharARB ** string
Definition: glew.h:4503
boost::shared_ptr< halo_record > handle
Definition: halo.hpp:34