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)
38 using namespace std::chrono_literals;
54 void set_location(
int x,
int y);
55 rect get_draw_location();
65 bool expired()
const {
return !images_.cycles() && images_.animation_finished(); }
67 bool does_change()
const {
return !images_.does_not_change(); }
89 double cached_zoom_ = 1.0;
124 void set_location(
int handle,
int x,
int y);
136 halo_impl::effect::effect(
int xpos,
int ypos,
140 orientation_(orientation),
144 assert(
disp !=
nullptr);
158 if(new_center != abs_mid_) {
159 DBG_HL <<
"setting halo location " << new_center;
160 abs_mid_ = new_center;
172 double zf = disp->get_zoom_factor();
174 if(map_loc_.x != -1 && map_loc_.y != -1) {
177 auto [x, y] = disp->get_location_rect(map_loc_).center();
183 if(cached_zoom_ != zf) {
184 abs_mid_.x *= zf / cached_zoom_;
185 abs_mid_.y *= zf / cached_zoom_;
193 ERR_HL <<
"no texture found for current halo animation frame";
199 int w(tex_.w() * disp->get_zoom_factor());
200 int h(tex_.h() * disp->get_zoom_factor());
204 const int xpos = zero_x + abs_mid_.x -
w/2;
205 const int ypos = zero_y + abs_mid_.y -
h/2;
207 screen_loc_ = {xpos, ypos,
w,
h};
210 if(screen_loc_ != last_draw_loc_) {
213 last_draw_loc_ = screen_loc_;
222 if(map_loc_.x != -1 && map_loc_.y != -1 && disp->shrouded(map_loc_)) {
227 if(!screen_loc_.overlaps(disp->map_outside_area())) {
240 images_.update_last_draw_time();
249 DBG_HL <<
"drawing halo at " << screen_loc_;
251 if (orientation_ ==
NORMAL) {
259 last_draw_loc_ = screen_loc_;
266 if(!last_draw_loc_.overlaps(disp->map_outside_area())) {
269 DBG_HL <<
"queueing halo undraw at " << last_draw_loc_;
278 DBG_HL <<
"queueing halo redraw at " << screen_loc_;
296 for(
const std::string& item : items) {
297 const std::vector<std::string>& sub_items =
utils::split(item,
':');
298 std::string str = item;
301 if(sub_items.size() > 1) {
302 str = sub_items.front();
304 time = std::chrono::milliseconds{
std::stoi(sub_items.back())};
305 }
catch(
const std::invalid_argument&) {
306 ERR_HL <<
"Invalid time value found when constructing halo: " << sub_items.back();
311 haloes.try_emplace(
id, x, y, image_vector,
loc, orientation, infinite);
313 if(
haloes.find(
id)->second.does_change() || !infinite) {
322 if(itor !=
haloes.end()) {
323 itor->second.set_location(x,y);
353 DBG_HL <<
"invalidating deleted halo " <<
id;
354 haloes.at(
id).queue_undraw();
372 if(
halo.need_update() &&
halo.visible()) {
373 DBG_HL <<
"invalidating changed halo " <<
id;
387 DBG_HL <<
"drawing intersected halo " <<
id;
405 int new_halo =
impl_->add(x,y,
image,
loc, orientation, infinite);
412 impl_->set_location(
h->id_,x,y);
446 my_manager_(my_manager)
451 if (!
valid())
return;
453 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.
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)
animated< image::locator > images_
const image::locator & current_image() const
void update()
Update the current location, animation frame, etc.
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.
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 ::rect &clip)
Set the clipping area to the intersection of the current clipping area and the given rectangle.
void flipped(const texture &tex, const ::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 ::rect &dst)
Draws a texture, or part of a texture, at the given location.
void remove()
Removes a tip.
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, bool floating)
Generates a Help markup tag corresponding to an image.
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 rect &r) const
Whether the given rectangle and this rectangle overlap.