Add support for setting the drawing content of tooltips.
This commit is contained in:
parent
71b2b26c5a
commit
8e118e4a40
2 changed files with 9 additions and 7 deletions
|
@ -35,13 +35,14 @@ static const int text_width = 400;
|
|||
|
||||
struct tooltip
|
||||
{
|
||||
tooltip(const SDL_Rect& r, const std::string& msg, const std::string& act = "", bool use_markup = false)
|
||||
: rect(r), message(msg), action(act), markup(use_markup)
|
||||
tooltip(const SDL_Rect& r, const std::string& msg, const std::string& act = "", bool use_markup = false, const surface fg = surface())
|
||||
: rect(r), message(msg), action(act), markup(use_markup), foreground(fg)
|
||||
{}
|
||||
SDL_Rect rect;
|
||||
std::string message;
|
||||
std::string action;
|
||||
bool markup;
|
||||
surface foreground;
|
||||
};
|
||||
|
||||
std::vector<tooltip> tips;
|
||||
|
@ -74,7 +75,7 @@ static void show_tooltip(const tooltip& tip)
|
|||
|
||||
unsigned int border = 10;
|
||||
|
||||
font::floating_label flabel(tip.message);
|
||||
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);
|
||||
|
@ -143,16 +144,16 @@ void clear_tooltips(const SDL_Rect& rect)
|
|||
}
|
||||
}
|
||||
|
||||
void add_tooltip(const SDL_Rect& rect, const std::string& message, const std::string& action, bool use_markup)
|
||||
void add_tooltip(const SDL_Rect& rect, const std::string& message, const std::string& action, bool use_markup, const surface& foreground)
|
||||
{
|
||||
for(std::vector<tooltip>::iterator i = tips.begin(); i != tips.end(); ++i) {
|
||||
if(sdl::rects_overlap(i->rect,rect)) {
|
||||
*i = tooltip(rect, message, action, use_markup);
|
||||
*i = tooltip(rect, message, action, use_markup, foreground);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
tips.push_back(tooltip(rect, message, action, use_markup));
|
||||
tips.push_back(tooltip(rect, message, action, use_markup, foreground));
|
||||
current_tooltip = tips.end();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define TOOLTIPS_HPP_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include "sdl/utils.hpp"
|
||||
|
||||
class CVideo;
|
||||
struct SDL_Rect;
|
||||
|
@ -30,7 +31,7 @@ struct manager
|
|||
|
||||
void clear_tooltips();
|
||||
void clear_tooltips(const SDL_Rect& rect);
|
||||
void add_tooltip(const SDL_Rect& rect, const std::string& message, const std::string& action ="", bool use_markup = true);
|
||||
void add_tooltip(const SDL_Rect& rect, const std::string& message, const std::string& action ="", bool use_markup = true, const surface& foreground = surface(NULL));
|
||||
void process(int mousex, int mousey);
|
||||
|
||||
// Check if we clicked on a tooltip having an action.
|
||||
|
|
Loading…
Add table
Reference in a new issue