23 #include <SDL2/SDL_rect.h> 28 static const int text_width = 400;
32 tooltip(
const SDL_Rect& r,
const std::string&
msg,
const std::string& act =
"",
bool use_markup =
false,
const surface& fg =
surface())
33 : rect(r), message(msg), action(act), markup(use_markup), foreground(fg)
42 std::map<int, tooltip>
tips;
43 std::map<int, tooltip>::const_iterator current_tooltip = tips.end();
45 int tooltip_handle = 0;
48 surface current_background =
nullptr;
54 if(tooltip_handle != 0) {
70 const color_t bgcolor {0,0,0,192};
73 unsigned int border = 10;
90 if(tip.rect.y > rect.h) {
91 rect.y = tip.rect.y - rect.h;
93 rect.y = tip.rect.y + tip.rect.h;
99 }
else if(rect.x + rect.w > area.w) {
100 rect.x = area.w - rect.w;
124 current_tooltip = tips.end();
131 if (
i==current_tooltip) {
135 current_tooltip = tips.end();
145 const std::string& action,
bool use_markup)
148 if (it == tips.end() )
return false;
149 it->second.action = action;
150 it->second.markup = use_markup;
151 it->second.message = message;
152 it->second.rect = rect;
157 const std::string& action,
bool use_markup,
const surface& foreground)
160 if (it == tips.end() )
return false;
161 it->second.action = action;
162 it->second.foreground = foreground;
163 it->second.markup = use_markup;
164 it->second.message = message;
165 it->second.rect = rect;
175 int add_tooltip(
const SDL_Rect& rect,
const std::string& message,
const std::string& action,
bool use_markup,
const surface& foreground)
185 int id = tooltip_id++;
187 tips.emplace(
id, tooltip(rect, message, action, use_markup, foreground));
189 current_tooltip = tips.end();
195 for(std::map<int, tooltip>::const_iterator
i = tips.begin();
i != tips.end(); ++
i) {
196 if(mousex >
i->second.rect.x && mousey >
i->second.rect.y &&
197 mousex < i->second.rect.x +
i->second.rect.w && mousey < i->second.rect.y +
i->second.rect.h) {
198 if(current_tooltip !=
i) {
208 current_tooltip = tips.end();
213 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 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.
void remove_floating_label(int handle)
removes the floating label given by 'handle' from the screen
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)
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)
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)
SDL_Rect screen_area(bool as_pixels=true) const
Returns the current window renderer area, either in pixels or screen coordinates. ...
std::string::const_iterator iterator