Use pango word wrapping in tooltip instead of our homemade function.

This fix inaccuracies when using pango markups.
This commit is contained in:
Ali El Gariani 2010-06-02 01:32:05 +00:00
parent 98442423cd
commit 9a004e457c
3 changed files with 9 additions and 5 deletions

View file

@ -928,7 +928,9 @@ floating_label::floating_label(const std::string& text)
font_size_(SIZE_NORMAL),
colour_(NORMAL_COLOUR), bgcolour_(), bgalpha_(0),
xpos_(0), ypos_(0),
xmove_(0), ymove_(0), lifetime_(-1), clip_rect_(screen_area()),
xmove_(0), ymove_(0), lifetime_(-1),
width_(-1),
clip_rect_(screen_area()),
alpha_change_(0), visible_(true), align_(CENTER_ALIGN),
border_(0), scroll_(ANCHOR_LABEL_SCREEN), use_markup_(true)
{}
@ -957,7 +959,7 @@ surface floating_label::create_surface()
font::ttext text;
text.set_foreground_colour((colour_.r << 24) | (colour_.g << 16) | (colour_.b << 8) | 255);
text.set_font_size(font_size_);
text.set_maximum_width(clip_rect_.w);
text.set_maximum_width(width_ < 0 ? clip_rect_.w : width_);
text.set_maximum_height(clip_rect_.h);
text.set_text(text_, use_markup_);
// Reset the maximum width, as we want the smallest bounding box.

View file

@ -154,6 +154,8 @@ public:
bgalpha_ = bg_colour.unused;
}
void set_border_size(int border) {border_ = border;}
// set width for word wrapping (use -1 to disable it)
void set_width(int w) {width_ = w;}
void set_clip_rect(const SDL_Rect& r) {clip_rect_ = r;}
void set_alignement(ALIGN align) {align_ = align;}
void set_scroll_mode(LABEL_SCROLL_MODE scroll) {scroll_ = scroll;}
@ -183,6 +185,7 @@ private:
int bgalpha_;
double xpos_, ypos_, xmove_, ymove_;
int lifetime_;
int width_;
SDL_Rect clip_rect_;
int alpha_change_;
bool visible_;

View file

@ -76,12 +76,11 @@ static void show_tooltip(const tooltip& tip)
unsigned int border = 10;
#endif
const std::string wrapped_message = font::word_wrap_text(tip.message, font_size, text_width);
font::floating_label flabel(wrapped_message);
font::floating_label flabel(tip.message);
flabel.set_font_size(font_size);
flabel.set_colour(tip.color);
flabel.set_clip_rect(area);
flabel.set_width(text_width);
flabel.set_alignement(font::LEFT_ALIGN);
flabel.set_bg_colour(bgcolour);
flabel.set_border_size(border);