void clear_tooltips(const SDL_Rect& rect) { for(std::map<int,tooltip>::iterator i = tips.begin(); i != tips.end(); ) { if(sdl::rects_overlap(i->second.rect,rect)) { if (i==current_tooltip) { clear_tooltip(); } tips.erase(i++); current_tooltip = tips.end(); } else { ++i; } } }
void clear_tooltips(const SDL_Rect& rect) { for(std::vector<tooltip>::iterator i = tips.begin(); i != tips.end(); ) { if(rects_overlap(i->rect,rect)) { if (i==current_tooltip) { clear_tooltip(); } i = tips.erase(i); current_tooltip = tips.end(); } else { ++i; } } }
void process(int mousex, int mousey) { for(std::vector<tooltip>::const_iterator i = tips.begin(); i != tips.end(); ++i) { if(mousex > i->rect.x && mousey > i->rect.y && mousex < i->rect.x + i->rect.w && mousey < i->rect.y + i->rect.h) { if(current_tooltip != i) { show_tooltip(*i); current_tooltip = i; } return; } } clear_tooltip(); current_tooltip = tips.end(); }
static void show_tooltip(const tooltip& tip) { if(video_ == NULL) { return; } clear_tooltip(); const SDL_Color bgcolor = {0,0,0,160}; #if defined(_KINGDOM_EXE) || !defined(_WIN32) SDL_Rect area = screen_area(); #else SDL_Rect area = create_rect(0, 0, 800, 600); #endif unsigned int border = 10; font::floating_label flabel(tip.message); flabel.set_font_size(font_size); flabel.set_color(font::NORMAL_COLOR); flabel.set_clip_rect(area); flabel.set_width(text_width); flabel.set_bg_color(bgcolor); flabel.set_border_size(border); tooltip_handle = font::add_floating_label(flabel); SDL_Rect rect = font::get_floating_label_rect(tooltip_handle); //see if there is enough room to fit it above the tip area if(tip.rect.y > rect.h) { rect.y = tip.rect.y - rect.h; } else { rect.y = tip.rect.y + tip.rect.h; } rect.x = tip.rect.x; if(rect.x < 0) { rect.x = 0; } else if(rect.x + rect.w > area.w) { rect.x = area.w - rect.w; } font::move_floating_label(tooltip_handle,rect.x,rect.y); }
static void show_tooltip(const tooltip& tip) { if(video_ == NULL) { return; } clear_tooltip(); const SDL_Color bgcolor = {0,0,0,160}; SDL_Rect area = screen_area(); unsigned int border = 10; font::floating_label flabel(tip.message, tip.foreground); flabel.use_markup(tip.markup); flabel.set_font_size(font_size); flabel.set_color(font::NORMAL_COLOR); flabel.set_clip_rect(area); flabel.set_width(text_width); flabel.set_alignment(font::LEFT_ALIGN); flabel.set_bg_color(bgcolor); flabel.set_border_size(border); tooltip_handle = font::add_floating_label(flabel); SDL_Rect rect = font::get_floating_label_rect(tooltip_handle); //see if there is enough room to fit it above the tip area if(tip.rect.y > rect.h) { rect.y = tip.rect.y - rect.h; } else { rect.y = tip.rect.y + tip.rect.h; } rect.x = tip.rect.x; if(rect.x < 0) { rect.x = 0; } else if(rect.x + rect.w > area.w) { rect.x = area.w - rect.w; } font::move_floating_label(tooltip_handle,rect.x,rect.y); }
static void show_tooltip(const tooltip& tip) { if(video_ == NULL) { return; } clear_tooltip(); const SDL_Color bgcolour = {0,0,0,128}; SDL_Rect area = screen_area(); #ifdef USE_TINY_GUI unsigned int border = 2; #else unsigned int border = 10; #endif const std::string wrapped_message = font::word_wrap_text(tip.message, font_size, text_width); tooltip_handle = font::add_floating_label(wrapped_message,font_size,tip.color, 0,0,0,0,-1,area,font::LEFT_ALIGN,&bgcolour,border); SDL_Rect rect = font::get_floating_label_rect(tooltip_handle); //see if there is enough room to fit it above the tip area if(tip.rect.y > rect.h) { rect.y = tip.rect.y - rect.h; } else { rect.y = tip.rect.y + tip.rect.h; } rect.x = tip.rect.x; if(rect.x < 0) { rect.x = 0; } else if(rect.x + rect.w > area.w) { rect.x = area.w - rect.w; } font::move_floating_label(tooltip_handle,rect.x,rect.y); }
void clear_tooltips() { clear_tooltip(); tips.clear(); current_tooltip = tips.end(); }
void remove_tooltip(int id) { tips.erase(id); clear_tooltip(); }