31 #define DBG_FT LOG_STREAM(debug, log_font)
32 #define LOG_FT LOG_STREAM(info, log_font)
33 #define WRN_FT LOG_STREAM(warn, log_font)
34 #define ERR_FT LOG_STREAM(err, log_font)
37 #define ERR_DP LOG_STREAM(err, log_display)
41 typedef std::map<int, font::floating_label> label_map;
45 std::stack<std::set<int>> label_contexts;
60 , bgcolor_(0, 0, 0, SDL_ALPHA_TRANSPARENT)
114 if(
tex_ !=
nullptr) {
124 DBG_FT <<
"creating floating label texture";
140 if(!
text_.empty() && *(
text_.rbegin()) ==
'\n') {
148 ERR_FT <<
"could not create floating label's text";
169 ERR_FT <<
"failed to create texture for floating label";
202 ERR_DP <<
"trying to draw floating label with no texture!";
249 if (alpha_sub >= 255) {
252 return 255 - alpha_sub;
261 if(label_contexts.empty()) {
266 labels.emplace(label_id, flabel);
267 label_contexts.top().insert(label_id);
274 if(
i != labels.end()) {
275 i->second.move(xmove, ymove);
283 i->second.move(xmove, ymove);
291 if(
i != labels.end()) {
293 i->second.set_lifetime(0, fadeout);
295 }
else if(fadeout < 0) {
296 i->second.set_lifetime(0,
i->second.get_fade_time());
304 if(!label_contexts.empty()) {
305 label_contexts.top().erase(
handle);
312 if(
i != labels.end()) {
313 i->second.show(value);
320 if(
i != labels.end()) {
321 if (
i->second.create_texture()) {
322 SDL_Point
size =
i->second.get_draw_size();
332 label_contexts.emplace();
338 const std::set<int>& context = label_contexts.top();
340 while(!context.empty()) {
346 label_contexts.pop();
351 if(label_contexts.empty()) {
355 const std::set<int>& context = label_contexts.top();
359 for(
auto& [
id,
label] : labels) {
360 if(context.count(
id) > 0) {
368 if(label_contexts.empty()) {
371 int time = SDL_GetTicks();
373 std::set<int>& context = label_contexts.top();
375 for(
auto& [
id,
label] : labels) {
376 if(context.count(
id) > 0) {
383 if(context.count(j->first) > 0 && j->second.expired(time)) {
384 DBG_FT <<
"removing expired floating label " << j->first;
385 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.
int xpos(std::size_t width) const
void move(double xmove, double ymove)
Change the floating label's position.
floating_label(const std::string &text, const surface &surface=nullptr)
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.
SDL_Surface * get() const
Wrapper class to encapsulate creation and management of an SDL_Texture.
int w() const
The draw-space width of the texture, in pixels.
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.