33 #define ERR_HL LOG_STREAM(err, log_halo)
34 #define WRN_HL LOG_STREAM(warn, log_halo)
35 #define LOG_HL LOG_STREAM(info, log_halo)
36 #define DBG_HL LOG_STREAM(debug, log_halo)
67 bool on_location(
const std::set<map_location>& locations)
const;
154 orientation_(orientation),
158 assert(
disp !=
nullptr);
172 if(new_center != abs_mid_) {
173 DBG_HL <<
"setting halo location " << new_center;
174 abs_mid_ = new_center;
187 double zf = disp->get_zoom_factor();
189 if(map_loc_.x != -1 && map_loc_.y != -1) {
192 auto [x, y] = disp->get_location_rect(map_loc_).center();
198 if(cached_zoom_ != zf) {
199 abs_mid_.x *= zf / cached_zoom_;
200 abs_mid_.y *= zf / cached_zoom_;
208 ERR_HL <<
"no texture found for current halo animation frame";
214 int w(tex_.w() * disp->get_zoom_factor());
215 int h(tex_.h() * disp->get_zoom_factor());
219 const int xpos = zero_x + abs_mid_.x -
w/2;
220 const int ypos = zero_y + abs_mid_.y -
h/2;
222 screen_loc_ = {xpos, ypos,
w,
h};
225 if(screen_loc_ != last_draw_loc_) {
228 last_draw_loc_ = screen_loc_;
237 if(map_loc_.x != -1 && map_loc_.y != -1 && disp->shrouded(map_loc_)) {
242 if(!screen_loc_.overlaps(disp->map_outside_area())) {
255 images_.update_last_draw_time();
264 DBG_HL <<
"drawing halo at " << screen_loc_;
266 if (orientation_ ==
NORMAL) {
274 last_draw_loc_ = screen_loc_;
281 if(!last_draw_loc_.overlaps(disp->map_outside_area())) {
284 DBG_HL <<
"queueing halo undraw at " << last_draw_loc_;
293 DBG_HL <<
"queueing halo redraw at " << screen_loc_;
312 for(
const std::string& item : items) {
313 const std::vector<std::string>& sub_items =
utils::split(item,
':');
314 std::string str = item;
317 if(sub_items.size() > 1) {
318 str = sub_items.front();
321 }
catch(
const std::invalid_argument&) {
322 ERR_HL <<
"Invalid time value found when constructing halo: " << sub_items.back();
328 haloes.emplace(
id,
effect(x, y, image_vector,
loc, orientation, infinite));
330 if(
haloes.find(
id)->second.does_change() || !infinite) {
339 if(itor !=
haloes.end()) {
340 itor->second.set_location(x,y);
370 DBG_HL <<
"invalidating deleted halo " <<
id;
371 haloes.at(
id).queue_undraw();
389 if(
halo.need_update() &&
halo.visible()) {
390 DBG_HL <<
"invalidating changed halo " <<
id;
404 DBG_HL <<
"drawing intersected halo " <<
id;
423 int new_halo =
impl_->add(x,y,
image,
loc, orientation, infinite);
430 impl_->set_location(
h->id_,x,y);
464 my_manager_(my_manager)
469 if (!
valid())
return;
471 std::shared_ptr<halo_impl> man =
my_manager_.lock();
void start_animation(const std::chrono::milliseconds &start_time, bool cycles=false)
Starts an animation cycle.
bool does_not_change() const
bool animation_finished() const
Returns true if the current animation was finished.
const T & get_current_frame() const
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
static double get_zoom_factor()
Returns the current zoom factor.
bool visible()
Whether the halo is currently visible.
void set_location(int x, int y)
effect(int xpos, int ypos, const animated< image::locator >::anim_description &img, const map_location &loc, ORIENTATION, bool infinite)
animated< image::locator > images_
const image::locator & current_image() const
void update()
Update the current location, animation frame, etc.
bool location_not_known() const
bool on_location(const std::set< map_location > &locations) const
std::set< int > changing_haloes
Haloes that have an animation or expiration time need to be checked every frame and are stored in thi...
void set_location(int handle, int x, int y)
Set the position of an existing haloing effect, according to its handle.
void render(const rect &)
Render all halos overlapping the given region.
halo_impl()
impl's of exposed functions
std::set< int > invalidated_haloes
Upon unrendering, an invalidation list is send.
int add(int x, int y, const std::string &image, const map_location &loc, ORIENTATION orientation=NORMAL, bool infinite=true)
std::set< int > deleted_haloes
Upon deleting, a halo isn't deleted but added to this set, upon unrendering the image is unrendered a...
std::map< int, effect > haloes
void remove(int handle)
Remove the halo with the given handle.
RAII object which manages a halo.
std::weak_ptr< halo_impl > my_manager_
halo_record()
halo::halo_record implementation
std::shared_ptr< halo_impl > impl_
void update()
Process animations, remove deleted halos, and invalidate screen regions now requiring redraw.
void set_location(const handle &h, int x, int y)
Set the position of an existing haloing effect, according to its handle.
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).
void remove(const handle &h)
Remove the halo with the given handle.
void render(const rect &r)
Render halos in region.
Generic locator abstracting the location of an image.
Wrapper class to encapsulate creation and management of an SDL_Texture.
map_display and display: classes which take care of displaying the map and game-data on the screen.
Drawing functions, for drawing things on the screen.
std::string id
Text to match against addon_info.tags()
static lg::log_domain log_halo("halo")
Standard logging facilities (interface).
void invalidate_region(const rect ®ion)
Mark a region of the screen as requiring redraw.
clip_setter reduce_clip(const SDL_Rect &clip)
Set the clipping area to the intersection of the current clipping area and the given rectangle.
void flipped(const texture &tex, const SDL_Rect &dst, bool flip_h=true, bool flip_v=false)
Draws a texture, or part of a texture, at the given location, also mirroring/flipping the texture hor...
void blit(const texture &tex, const SDL_Rect &dst)
Draws a texture, or part of a texture, at the given location.
std::shared_ptr< halo_record > handle
Functions to load and save images from/to disk.
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
std::string img(const std::string &src, const std::string &align, const bool floating)
int stoi(std::string_view str)
Same interface as std::stoi and meant as a drop in replacement, except:
std::vector< std::string > square_parenthetical_split(const std::string &val, const char separator, const std::string &left, const std::string &right, const int flags)
Similar to parenthetical_split, but also expands embedded square brackets.
std::vector< std::string > split(const config_attribute_value &val)
std::string::const_iterator iterator
Contains the SDL_Rect helper code.
Encapsulates the map of the game.
static const map_location & ZERO()
An abstract description of a rectangle with integer coordinates.
bool overlaps(const SDL_Rect &r) const
Whether the given rectangle and this rectangle overlap.