Allow values <= 0 to set no maximum width/height.

Some parts of the engine use 0 as no maximum width, so this change
fixes the text to always be detected as truncated (width 0 always
truncates).  This should make the layout system slighty faster and
also avoid future problems.
This commit is contained in:
Mark de Wever 2008-09-30 18:34:27 +00:00
parent bc739fe568
commit 00956e7e14
2 changed files with 23 additions and 6 deletions

View file

@ -289,8 +289,12 @@ ttext& ttext::set_foreground_colour(const Uint32 colour)
return *this;
}
ttext& ttext::set_maximum_width(const int width)
ttext& ttext::set_maximum_width(int width)
{
if(width <= 0) {
width = -1;
}
if(width != maximum_width_) {
pango_layout_set_width(layout_, width == -1 ? -1 : width * PANGO_SCALE);
maximum_width_ = width;
@ -301,8 +305,12 @@ ttext& ttext::set_maximum_width(const int width)
return *this;
}
ttext& ttext::set_maximum_height(const int height)
ttext& ttext::set_maximum_height(int height)
{
if(height <= 0) {
height = -1;
}
if(height != maximum_height_) {
/**
* @todo See whether we can make pango 1.20 mandatory before Wesnoth 1.6 is

View file

@ -171,9 +171,9 @@ public:
ttext& set_foreground_colour(const Uint32 colour);
ttext& set_maximum_width(const int width);
ttext& set_maximum_width(int width);
ttext& set_maximum_height(const int height);
ttext& set_maximum_height(int height);
ttext& set_ellipse_mode(const PangoEllipsizeMode ellipse_mode);
@ -205,10 +205,19 @@ private:
Uint32 foreground_colour_;
/**
* The maximum width of the text, -1 means no maximum. */
* The maximum width of the text.
*
* Values less or equal to 0 mean no maximum and are internally stored as
* -1, since that's the value pango uses for it.
*/
int maximum_width_;
/** The maximum height of the text, -1 means no maximum . */
/**
* The maximum height of the text.
*
* Values less or equal to 0 mean no maximum and are internally stored as
* -1, since that's the value pango uses for it.
*/
int maximum_height_;
/** The way too long text is shown depends on this mode. */