Fix ltr language alignement problems in the language dialog.

Needed to set the proper maximum width and use the extends size and
offset to get the proper required width. Added a debug ostream function
which already has been written a few times and added some debug code.
This commit is contained in:
Mark de Wever 2008-09-07 19:53:31 +00:00
parent 6e767674bd
commit 7f13663100
3 changed files with 20 additions and 5 deletions

View file

@ -20,6 +20,7 @@
y = {GUI__TEXT_VERTICALLY_CENTRED}
w = "(width - 6)"
h = "(text_height)"
maximum_width = "(width - 6)"
font_size = {FONT_SIZE}
colour = {FONT_COLOUR}
text = "(text)"

View file

@ -818,7 +818,13 @@ void ttext::draw(surface& canvas,
game_logic::map_formula_callable local_variables(variables);
local_variables.add("text_width", variant(surf->w));
local_variables.add("text_height", variant(surf->h));
/*
std::cerr << "Text: drawing text '" << text
<< " maximum width " << maximum_width_(variables)
<< " maximum height " << maximum_height_(variables)
<< " text width " << surf->w
<< " text height " << surf->h;
*/
//@todo formulas are now recalculated every draw cycle which is a
// bit silly unless there has been a resize. So to optimize we should
// use an extra flag or do the calculation in a separate routine.

View file

@ -383,6 +383,12 @@ private:
PangoFontDescription *font_;
};
std::ostream& operator<<(std::ostream& s, const PangoRectangle &rect)
{
s << rect.x << ',' << rect.y << ' ' << rect.width << ',' << rect.height;
return s;
}
} // namespace
void ttext::recalculate(const bool force) const
@ -404,12 +410,14 @@ void ttext::rerender(const bool force) const
recalculate(force);
surface_dirty_ = false;
const unsigned stride = rect_.width * 4;
create_surface_buffer(stride * rect_.height);
const unsigned width = rect_.x + rect_.width;
const unsigned height = rect_.y + rect_.height;
const unsigned stride = width * 4;
create_surface_buffer(stride * height);
cairo_surface_t *cairo_surface =
cairo_image_surface_create_for_data(surface_buffer_,
CAIRO_FORMAT_ARGB32, rect_.width, rect_.height, stride);
CAIRO_FORMAT_ARGB32, width, height, stride);
cairo_t *cr = cairo_create(cairo_surface);
pango_cairo_update_context (cr, context_); // Needed?
@ -432,7 +440,7 @@ void ttext::rerender(const bool force) const
pango_cairo_show_layout(cr, layout_);
surface_.assign(SDL_CreateRGBSurfaceFrom(
surface_buffer_, rect_.width, rect_.height, 32, stride,
surface_buffer_, width, height, 32, stride,
0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000));
}
}