24 #include <SDL2/SDL_rect.h> 29 static const int text_width = 400;
33 tooltip(
const SDL_Rect& r,
const std::string&
msg,
const std::string& act =
"",
bool use_markup =
false,
const surface& fg =
surface())
34 : rect(r),
message(msg), action(act), markup(use_markup), foreground(fg)
43 std::map<int, tooltip>
tips;
44 std::map<int, tooltip>::const_iterator current_tooltip = tips.end();
46 int tooltip_handle = 0;
49 surface current_background =
nullptr;
55 if(tooltip_handle != 0) {
71 const color_t bgcolor {0,0,0,192};
74 unsigned int border = 10;
91 if(tip.rect.y > rect.h) {
92 rect.y = tip.rect.y - rect.h;
94 rect.y = tip.rect.y + tip.rect.h;
100 }
else if(rect.x + rect.w > area.w) {
101 rect.x = area.w - rect.w;
125 current_tooltip = tips.end();
132 if (
i==current_tooltip) {
136 current_tooltip = tips.end();
146 const std::string& action,
bool use_markup)
149 if (it == tips.end() )
return false;
150 it->second.action = action;
151 it->second.markup = use_markup;
152 it->second.message = message;
153 it->second.rect = rect;
158 const std::string& action,
bool use_markup,
const surface& foreground)
161 if (it == tips.end() )
return false;
162 it->second.action = action;
163 it->second.foreground = foreground;
164 it->second.markup = use_markup;
165 it->second.message = message;
166 it->second.rect = rect;
176 int add_tooltip(
const SDL_Rect& rect,
const std::string& message,
const std::string& action,
bool use_markup,
const surface& foreground)
180 int id = tooltip_id++;
182 tips.emplace(
id,
tooltip(rect, message, action, use_markup, foreground));
184 current_tooltip = tips.end();
190 for(std::map<int, tooltip>::const_iterator
i = tips.begin();
i != tips.end(); ++
i) {
191 if(mousex >
i->second.rect.x && mousey >
i->second.rect.y &&
192 mousex < i->second.rect.x +
i->second.rect.w && mousey < i->second.rect.y +
i->second.rect.h) {
193 if(current_tooltip !=
i) {
203 current_tooltip = tips.end();
208 for(std::map<int, tooltip>::const_iterator
i = tips.begin();
i != tips.end(); ++
i) {
void show_help(const std::string &show_topic, int xloc, int yloc)
Open the help browser, show topic with id show_topic.
void remove_floating_label(int handle, int fadeout)
removes the floating label given by 'handle' from the screen
void set_clip_rect(const SDL_Rect &r)
std::vector< game_tip > tips
bool rects_overlap(const SDL_Rect &rect1, const SDL_Rect &rect2)
Tests whether two rectangles overlap.
static CVideo & get_singleton()
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
void set_font_size(int font_size)
void move_floating_label(int handle, double xmove, double ymove)
moves the floating label given by 'handle' by (xmove,ymove)
SDL_Rect draw_area() const
Returns the size and location of the current drawing area in pixels.
void set_alignment(ALIGN align)
void set_bg_color(const color_t &bg_color)
const color_t NORMAL_COLOR
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
void set_color(const color_t &color)
std::string id
Text to match against addon_info.tags()
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)
void set_border_size(int border)
std::string::const_iterator iterator
std::string tooltip
Shown when hovering over an entry in the filter's drop-down list.