From 1f8451001d69df708ef788b8730cf13a11a75065 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 9 Jan 2017 16:43:44 -0300 Subject: -Translation text will change automatically for in-game buttons, labels, poups when translation is changed. -Added a NOTIFICATION_TRANSLATION_CHANGED for controls that need custom code -Sorry, editor will not update automatically because it uses a different translatio method. --- scene/gui/button.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'scene/gui/button.cpp') diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index a7e08f9f7e..f28595b622 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -34,7 +34,7 @@ Size2 Button::get_minimum_size() const { - Size2 minsize=get_font("font")->get_string_size( text ); + Size2 minsize=get_font("font")->get_string_size( xl_text ); if (clip_text) minsize.width=0; @@ -48,7 +48,7 @@ Size2 Button::get_minimum_size() const { minsize.height=MAX( minsize.height, _icon->get_height() ); minsize.width+=_icon->get_width(); - if (text!="") + if (xl_text!="") minsize.width+=get_constant("hseparation"); } @@ -59,6 +59,13 @@ Size2 Button::get_minimum_size() const { void Button::_notification(int p_what) { + if (p_what==NOTIFICATION_TRANSLATION_CHANGED) { + + xl_text=XL_MESSAGE(text); + minimum_size_changed(); + update(); + } + if (p_what==NOTIFICATION_DRAW) { RID ci = get_canvas_item(); @@ -114,7 +121,7 @@ void Button::_notification(int p_what) { Point2 icon_ofs = (!_icon.is_null())?Point2( _icon->get_width() + get_constant("hseparation"), 0):Point2(); int text_clip=size.width - style->get_minimum_size().width - icon_ofs.width; - Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - font->get_string_size( text ) )/2.0; + Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - font->get_string_size( xl_text ) )/2.0; switch(align) { case ALIGN_LEFT: { @@ -128,14 +135,14 @@ void Button::_notification(int p_what) { text_ofs+=style->get_offset(); } break; case ALIGN_RIGHT: { - text_ofs.x=size.x - style->get_margin(MARGIN_RIGHT) - font->get_string_size( text ).x; + text_ofs.x=size.x - style->get_margin(MARGIN_RIGHT) - font->get_string_size( xl_text ).x; text_ofs.y+=style->get_offset().y; } break; } text_ofs.y+=font->get_ascent(); - font->draw( ci, text_ofs.floor(), text, color,clip_text?text_clip:-1); + font->draw( ci, text_ofs.floor(), xl_text, color,clip_text?text_clip:-1); if (!_icon.is_null()) { int valign = size.height-style->get_minimum_size().y; @@ -152,7 +159,8 @@ void Button::set_text(const String& p_text) { if (text==p_text) return; - text=XL_MESSAGE(p_text); + text=p_text; + xl_text=XL_MESSAGE(p_text); update(); _change_notify("text"); minimum_size_changed(); -- cgit v1.2.3