29 #define DBG_FT LOG_STREAM(debug, log_font)
30 #define LOG_FT LOG_STREAM(info, log_font)
31 #define WRN_FT LOG_STREAM(warn, log_font)
32 #define ERR_FT LOG_STREAM(err, log_font)
36 typedef std::map<int, font::floating_label> label_map;
40 std::stack<std::set<int> > label_contexts;
49 : surf_(surf), buf_(
nullptr),
55 xmove_(0), ymove_(0), lifetime_(-1),
56 width_(-1), height_(-1),
81 sdl::timage floating_label::create_image()
91 if(!
text_.empty() && *(
text_.rbegin()) ==
'\n'){
99 if(foreground ==
nullptr) {
100 ERR_FT <<
"could not create floating label's text" << std::endl;
101 return sdl::timage();
109 if (background ==
nullptr) {
110 ERR_FT <<
"could not create tooltip box" << std::endl;
111 img_ = sdl::timage(foreground);
128 img_ = sdl::timage(background);
133 (foreground->w + 4, foreground->h + 4);
135 SDL_Rect
r = { 2, 2, 0, 0 };
139 if (background ==
nullptr) {
140 ERR_FT <<
"could not create floating label's shadow" << std::endl;
141 img_ = sdl::timage(foreground);
146 img_ = sdl::timage(background);
164 if(!
text_.empty() && *(
text_.rbegin()) ==
'\n'){
172 if(foreground ==
nullptr) {
173 ERR_FT <<
"could not create floating label's text" << std::endl;
182 if (background ==
nullptr) {
183 ERR_FT <<
"could not create tooltip box" << std::endl;
209 (foreground->w + 4, foreground->h + 4);
211 SDL_Rect
r = { 2, 2, 0, 0 };
215 if (background ==
nullptr) {
216 ERR_FT <<
"could not create floating label's shadow" << std::endl;
242 video.draw_texture(img_,
xpos(img_.width()),
int(
ypos_));
261 if(screen ==
nullptr) {
266 if(
surf_ ==
nullptr) {
270 if(
buf_ ==
nullptr) {
272 if(
buf_ ==
nullptr) {
290 video.clear_overlay_area(r);
295 if(screen ==
nullptr ||
buf_ ==
nullptr) {
318 if(label_contexts.empty()) {
323 labels.insert(std::pair<int, floating_label>(label_id, flabel));
324 label_contexts.top().insert(label_id);
331 if(i != labels.end()) {
332 i->second.move(xmove,ymove);
340 i->second.move(xmove,ymove);
348 if(i != labels.end()) {
349 if(label_contexts.empty() ==
false) {
350 label_contexts.top().erase(i->first);
360 if(i != labels.end()) {
361 i->second.show(value);
369 if(i != labels.end()) {
370 const sdl::timage
img = i->second.create_image();
376 if(i != labels.end()) {
377 const surface surf = i->second.create_surface();
378 if(surf !=
nullptr) {
392 if(screen !=
nullptr) {
397 label_contexts.push(std::set<int>());
402 const std::set<int>& labels = label_contexts.top();
403 for(std::set<int>::const_iterator
i = labels.begin();
i != labels.end(); ) {
407 label_contexts.pop();
413 if(screen !=
nullptr) {
422 if(label_contexts.empty()) {
426 const std::set<int>& context = label_contexts.top();
431 if(context.count(
i->first) > 0) {
432 i->second.draw(video);
439 if(label_contexts.empty()) {
443 std::set<int>& context = label_contexts.top();
447 if(context.count(j->first) > 0 && j->second.expired()) {
448 j->second.undraw(video);
449 context.erase(j->first);
460 if(label_contexts.empty()) {
464 const std::set<int>& context = label_contexts.top();
469 if(context.count(
i->first) > 0) {
470 i->second.draw(screen);
477 if(label_contexts.empty()) {
481 std::set<int>& context = label_contexts.top();
485 for(label_map::reverse_iterator
i = labels.rbegin();
i != labels.rend(); ++
i) {
486 if(context.count(
i->first) > 0) {
487 i->second.undraw(screen);
493 if(context.count(j->first) > 0 && j->second.expired()) {
494 context.erase(j->first);
floating_label(const std::string &text, const surface &surface=nullptr)
surface create_neutral_surface(int w, int h)
static lg::log_domain log_font("font")
void fill_rect(surface &dst, SDL_Rect *dst_rect, const Uint32 color)
Fill a rectangle on a given surface.
surface adjust_surface_alpha_add(const surface &surf, int amount, bool optimize)
void scroll_floating_labels(double xmove, double ymove)
moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP
surface create_optimized_surface(const surface &surf)
void show_floating_label(int handle, bool value)
hides or shows a floating label
const SDL_Rect empty_rect
void remove_floating_label(int handle)
removes the floating label given by 'handle' from the screen
ttext & set_font_size(const unsigned font_size)
ttext & set_maximum_width(int width)
void move(double xmove, double ymove)
tformula< t_string > text_
The text to draw.
const SDL_Color NORMAL_COLOR
void move_floating_label(int handle, double xmove, double ymove)
moves the floating label given by 'handle' by (xmove,ymove)
void blit_surface(const surface &surf, const SDL_Rect *srcrect, surface &dst, const SDL_Rect *dstrect)
Replacement for sdl_blit.
surface shadow_image(const surface &surf, bool optimize)
create an heavy shadow of the image, by blurring, increasing alpha and darkening
ttext & set_maximum_height(int height, bool multiline)
GLsizei const GLfloat * value
surface adjust_surface_alpha(const surface &surf, fixed_t amount, bool optimize)
~floating_label_context()
map_display and display: classes which take care of displaying the map and game-data on the screen...
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
surface render() const
Returns the rendered text.
int xpos(size_t width) const
void undraw_floating_labels(surface screen)
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
SDL_Rect get_floating_label_rect(int handle)
GLdouble GLdouble GLdouble r
void undraw(surface screen)
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
void draw(surface screen)
Standard logging facilities (interface).
void assign(const surface &o)
surface create_compatible_surface(const surface &surf, int width, int height)
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
GLint GLint GLint GLint GLint GLint GLsizei width
void sdl_copy_portion(const surface &screen, SDL_Rect *screen_rect, surface &dst, SDL_Rect *dst_rect)
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha)
Compatibility layer for using SDL 1.2 and 2.0.
void update_rect(const SDL_Rect &)
GLsizei const GLcharARB ** string
void draw_floating_labels(surface screen)
#define ftofxp(x)
IN: float or int - OUT: fixed_t.
boost::shared_ptr< halo_record > handle
ttext & set_foreground_color(const Uint32 color)