30 #define DBG_FT LOG_STREAM(debug, log_font)
31 #define LOG_FT LOG_STREAM(info, log_font)
32 #define WRN_FT LOG_STREAM(warn, log_font)
33 #define ERR_FT LOG_STREAM(err, log_font)
36 #define ERR_DP LOG_STREAM(err, log_display)
40 typedef std::map<int, font::floating_label> label_map;
44 std::stack<std::set<int>> label_contexts;
48 using namespace std::chrono_literals;
52 floating_label::floating_label(
const std::string& text)
61 , bgcolor_(0, 0, 0, SDL_ALPHA_TRANSPARENT)
112 if(
tex_ !=
nullptr) {
122 DBG_FT <<
"creating floating label texture, text: " <<
text_.substr(0,15);
138 if(!
text_.empty() && *(
text_.rbegin()) ==
'\n') {
146 ERR_FT <<
"could not create floating label's text";
167 ERR_FT <<
"failed to create texture for floating label";
200 ERR_DP <<
"trying to draw floating label with no texture!";
232 return std::chrono::duration_cast<std::chrono::milliseconds>(current_time -
time_start_);
240 static_cast<int>(time_alive.count() *
ymove_ +
ypos_)
251 if (alpha_sub >= 255) {
254 return 255 - alpha_sub;
263 if(label_contexts.empty()) {
268 labels.emplace(label_id, flabel);
269 label_contexts.top().insert(label_id);
276 if(
i != labels.end()) {
277 i->second.move(xmove, ymove);
285 i->second.move(xmove, ymove);
293 if(
i != labels.end()) {
295 i->second.set_lifetime(0ms, fadeout);
297 }
else if(fadeout < 0ms) {
298 i->second.set_lifetime(0ms,
i->second.get_fade_time());
306 if(!label_contexts.empty()) {
307 label_contexts.top().erase(
handle);
314 if(
i != labels.end()) {
315 i->second.show(value);
322 if(
i != labels.end()) {
323 if (
i->second.create_texture()) {
324 SDL_Point
size =
i->second.get_draw_size();
334 for(
auto& [
id,
label] : labels) {
335 if(label_contexts.top().count(
id) > 0) {
341 label_contexts.emplace();
347 const std::set<int>& context = label_contexts.top();
349 while(!context.empty()) {
355 label_contexts.pop();
360 if(label_contexts.empty()) {
364 const std::set<int>& context = label_contexts.top();
368 for(
auto& [
id,
label] : labels) {
369 if(context.count(
id) > 0) {
377 if(label_contexts.empty()) {
380 auto time = std::chrono::steady_clock::now();
382 std::set<int>& context = label_contexts.top();
384 for(
auto& [
id,
label] : labels) {
385 if(context.count(
id) > 0) {
392 if(context.count(j->first) > 0 && j->second.expired(time)) {
393 DBG_FT <<
"removing expired floating label " << j->first;
394 context.erase(j->first);
std::chrono::milliseconds lifetime_
rect get_bg_rect(const rect &text_rect) const
clock::time_point time_start_
bool create_texture()
Ensure a texture for this floating label exists, creating one if needed.
point get_pos(const clock::time_point &time)
std::chrono::milliseconds get_time_alive(const clock::time_point ¤t_time) const
int xpos(std::size_t width) const
void update(const clock::time_point &time)
Finalize draw position and alpha, and queue redrawing if changed.
void set_lifetime(const std::chrono::milliseconds &lifetime, const std::chrono::milliseconds &fadeout=std::chrono::milliseconds{100})
std::chrono::milliseconds fadeout_
uint8_t get_alpha(const clock::time_point &time)
void move(double xmove, double ymove)
Change the floating label's position.
void draw()
Draw the label to the screen.
void undraw()
Mark the last drawn location as requiring redraw.
pango_text & set_font_style(const FONT_STYLE font_style)
pango_text & set_characters_per_line(const unsigned characters_per_line)
pango_text & set_foreground_color(const color_t &color)
pango_text & set_family_class(font::family_class fclass)
pango_text & set_add_outline(bool do_add)
pango_text & set_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
pango_text & set_alignment(const PangoAlignment alignment)
pango_text & set_font_size(unsigned font_size)
pango_text & set_link_aware(bool b)
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
pango_text & set_maximum_height(int height, bool multiline)
pango_text & set_maximum_width(int width)
texture render_and_get_texture()
Returns the cached texture, or creates a new one otherwise.
int w() const
The draw-space width of the texture, in pixels.
void reset()
Releases ownership of the managed texture and resets the ptr to null.
int h() const
The draw-space height of the texture, in pixels.
void set_alpha_mod(uint8_t alpha)
Alpha modifier.
Drawing functions, for drawing things on the screen.
static lg::log_domain log_font("font")
static lg::log_domain log_display("display")
std::string label
What to show in the filter's drop-down list.
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 fill(const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Fill an area with the given colour.
void blit(const texture &tex, const SDL_Rect &dst)
Draws a texture, or part of a texture, at the given location.
::rect get_clip()
Get the current clipping area, in draw coordinates.
pango_text & get_text_renderer()
Returns a reference to a static pango_text object.
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
void show_floating_label(int handle, bool value)
hides or shows a floating label
void scroll_floating_labels(double xmove, double ymove)
moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP
SDL_Rect get_floating_label_rect(int handle)
void remove_floating_label(int handle, const std::chrono::milliseconds &fadeout)
removes the floating label given by 'handle' from the screen
void update_floating_labels()
void move_floating_label(int handle, double xmove, double ymove)
moves the floating label given by 'handle' by (xmove,ymove)
void draw_floating_labels()
const color_t NORMAL_COLOR
std::shared_ptr< halo_record > handle
constexpr const SDL_Rect empty_rect
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
bool headless()
The game is running headless.
rect game_canvas()
The game canvas area, in drawing coordinates.
std::string::const_iterator iterator
~floating_label_context()
An abstract description of a rectangle with integer coordinates.
bool empty() const
False if both w and h are > 0, true otherwise.
constexpr rect padded_by(int dx, int dy) const
Returns a new rectangle with dx horizontal padding and dy vertical padding.
rect intersect(const SDL_Rect &r) const
Calculates the intersection of this rectangle and another; that is, the maximal rectangle that is con...
bool overlaps(const SDL_Rect &r) const
Whether the given rectangle and this rectangle overlap.