34 #define ERR_HL LOG_STREAM(err, log_halo)
35 #define WRN_HL LOG_STREAM(warn, log_halo)
36 #define LOG_HL LOG_STREAM(info, log_halo)
37 #define DBG_HL LOG_STREAM(debug, log_halo)
68 bool on_location(
const std::set<map_location>& locations)
const;
155 orientation_(orientation),
159 assert(
disp !=
nullptr);
174 if (new_x != abs_mid_.x || new_y != abs_mid_.y) {
175 DBG_HL <<
"setting halo location " <<
point{new_x,new_y};
190 double zf = disp->get_zoom_factor();
192 if(map_loc_.x != -1 && map_loc_.y != -1) {
196 disp->get_location_x(map_loc_) + disp->hex_size() / 2,
197 disp->get_location_y(map_loc_) + disp->hex_size() / 2
203 if(cached_zoom_ != zf) {
204 abs_mid_.x *= zf / cached_zoom_;
205 abs_mid_.y *= zf / cached_zoom_;
213 ERR_HL <<
"no texture found for current halo animation frame";
219 int w(tex_.w() * disp->get_zoom_factor());
220 int h(tex_.h() * disp->get_zoom_factor());
225 const int xpos = zero_x + abs_mid_.x -
w/2;
226 const int ypos = zero_y + abs_mid_.y -
h/2;
228 screen_loc_ = {xpos, ypos,
w,
h};
231 if(screen_loc_ != last_draw_loc_) {
234 last_draw_loc_ = screen_loc_;
243 if(map_loc_.x != -1 && map_loc_.y != -1 && disp->shrouded(map_loc_)) {
248 if(!screen_loc_.overlaps(disp->map_outside_area())) {
261 images_.update_last_draw_time();
270 DBG_HL <<
"drawing halo at " << screen_loc_;
272 if (orientation_ ==
NORMAL) {
280 last_draw_loc_ = screen_loc_;
287 if(!last_draw_loc_.overlaps(disp->map_outside_area())) {
290 DBG_HL <<
"queueing halo undraw at " << last_draw_loc_;
299 DBG_HL <<
"queueing halo redraw at " << screen_loc_;
320 std::string str =
item;
323 if(sub_items.size() > 1) {
324 str = sub_items.front();
326 time = std::stoi(sub_items.back());
327 }
catch(
const std::invalid_argument&) {
328 ERR_HL <<
"Invalid time value found when constructing halo: " << sub_items.back();
334 haloes.emplace(
id,
effect(x, y, image_vector, loc, orientation, infinite));
336 if(
haloes.find(
id)->second.does_change() || !infinite) {
345 if(itor !=
haloes.end()) {
346 itor->second.set_location(x,y);
376 DBG_HL <<
"invalidating deleted halo " <<
id;
377 haloes.at(
id).queue_undraw();
395 if(
halo.need_update() &&
halo.visible()) {
396 DBG_HL <<
"invalidating changed halo " <<
id;
410 DBG_HL <<
"drawing intersected halo " <<
id;
429 int new_halo =
impl_->add(x,y,
image, loc, orientation, infinite);
436 impl_->set_location(
h->id_,x,y);
470 my_manager_(my_manager)
475 if (!
valid())
return;
477 std::shared_ptr<halo_impl> man =
my_manager_.lock();
void start_animation(int 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.
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
std::pair< std::string, unsigned > item
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.
const std::vector< std::string > items
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.