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;
59 , bgcolor_(0, 0, 0, SDL_ALPHA_TRANSPARENT)
115 if(
tex_ !=
nullptr) {
125 DBG_FT <<
"creating floating label texture, text: " <<
text_.substr(0,15);
141 if(!
text_.empty() && *(
text_.rbegin()) ==
'\n') {
149 ERR_FT <<
"could not create floating label's text";
170 ERR_FT <<
"failed to create texture for floating label";
203 ERR_DP <<
"trying to draw floating label with no texture!";
250 if (alpha_sub >= 255) {
253 return 255 - alpha_sub;
262 if(label_contexts.empty()) {
267 labels.emplace(label_id, flabel);
268 label_contexts.top().insert(label_id);
275 if(
i != labels.end()) {
276 i->second.move(xmove, ymove);
284 i->second.move(xmove, ymove);
292 if(
i != labels.end()) {
294 i->second.set_lifetime(0, fadeout);
296 }
else if(fadeout < 0) {
297 i->second.set_lifetime(0,
i->second.get_fade_time());
305 if(!label_contexts.empty()) {
306 label_contexts.top().erase(
handle);
313 if(
i != labels.end()) {
314 i->second.show(value);
321 if(
i != labels.end()) {
322 if (
i->second.create_texture()) {
323 SDL_Point
size =
i->second.get_draw_size();
333 for(
auto& [
id,
label] : labels) {
334 if(label_contexts.top().count(
id) > 0) {
340 label_contexts.emplace();
346 const std::set<int>& context = label_contexts.top();
348 while(!context.empty()) {
354 label_contexts.pop();
359 if(label_contexts.empty()) {
363 const std::set<int>& context = label_contexts.top();
367 for(
auto& [
id,
label] : labels) {
368 if(context.count(
id) > 0) {
376 if(label_contexts.empty()) {
379 int time = SDL_GetTicks();
381 std::set<int>& context = label_contexts.top();
383 for(
auto& [
id,
label] : labels) {
384 if(context.count(
id) > 0) {
391 if(context.count(j->first) > 0 && j->second.expired(time)) {
392 DBG_FT <<
"removing expired floating label " << j->first;
393 context.erase(j->first);
uint8_t get_alpha(int time)
rect get_bg_rect(const rect &text_rect) const
void update(int time)
Finalize draw position and alpha, and queue redrawing if changed.
void set_lifetime(int lifetime, int fadeout=100)
int get_time_alive(int current_time) const
bool create_texture()
Ensure a texture for this floating label exists, creating one if needed.
floating_label(const std::string &text)
int xpos(std::size_t width) const
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.
Collection of helper functions relating to Pango formatting.
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 remove_floating_label(int handle, int fadeout)
removes the floating label given by 'handle' from the screen
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 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(const std::string &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.
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.