| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  label.cpp                                                            */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2020-01-01 11:16:22 +01:00
										 |  |  | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "label.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/print_string.h"
 | 
					
						
							|  |  |  | #include "core/project_settings.h"
 | 
					
						
							|  |  |  | #include "core/translation.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void Label::set_autowrap(bool p_autowrap) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	autowrap = p_autowrap; | 
					
						
							|  |  |  | 	word_cache_dirty = true; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 	update(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | bool Label::has_autowrap() const { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return autowrap; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Label::set_uppercase(bool p_uppercase) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	uppercase = p_uppercase; | 
					
						
							|  |  |  | 	word_cache_dirty = true; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 	update(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | bool Label::is_uppercase() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return uppercase; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int Label::get_line_height() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return get_font("font")->get_height(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Label::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_TRANSLATION_CHANGED) { | 
					
						
							| 
									
										
										
										
											2017-01-09 16:43:44 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-18 22:29:15 +02:00
										 |  |  | 		String new_text = tr(text); | 
					
						
							| 
									
										
										
										
											2017-06-28 17:00:18 -03:00
										 |  |  | 		if (new_text == xl_text) | 
					
						
							|  |  |  | 			return; //nothing new
 | 
					
						
							|  |  |  | 		xl_text = new_text; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		regenerate_word_cache(); | 
					
						
							| 
									
										
										
										
											2017-01-09 16:43:44 -03:00
										 |  |  | 		update(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_DRAW) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 02:19:05 +09:00
										 |  |  | 		if (clip) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true); | 
					
						
							| 
									
										
										
										
											2017-01-09 15:50:08 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (word_cache_dirty) | 
					
						
							|  |  |  | 			regenerate_word_cache(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		RID ci = get_canvas_item(); | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		Size2 string_size; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Size2 size = get_size(); | 
					
						
							| 
									
										
										
										
											2017-08-04 20:16:04 +02:00
										 |  |  | 		Ref<StyleBox> style = get_stylebox("normal"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		Ref<Font> font = get_font("font"); | 
					
						
							|  |  |  | 		Color font_color = get_color("font_color"); | 
					
						
							|  |  |  | 		Color font_color_shadow = get_color("font_color_shadow"); | 
					
						
							| 
									
										
										
										
											2016-11-03 18:29:25 +07:00
										 |  |  | 		bool use_outline = get_constant("shadow_as_outline"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); | 
					
						
							| 
									
										
										
										
											2016-05-17 18:27:15 -03:00
										 |  |  | 		int line_spacing = get_constant("line_spacing"); | 
					
						
							| 
									
										
										
										
											2018-03-19 20:48:43 +07:00
										 |  |  | 		Color font_outline_modulate = get_color("font_outline_modulate"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 20:16:04 +02:00
										 |  |  | 		style->draw(ci, Rect2(Point2(0, 0), get_size())); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		VisualServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(), font.is_valid() && font->is_distance_field_hint()); | 
					
						
							| 
									
										
										
										
											2015-03-21 00:43:33 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		int font_h = font->get_height() + line_spacing; | 
					
						
							| 
									
										
										
										
											2016-06-09 22:16:13 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		int lines_visible = (size.y + line_spacing) / font_h; | 
					
						
							| 
									
										
										
										
											2016-06-09 22:16:13 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-14 20:18:44 +07:00
										 |  |  | 		// ceiling to ensure autowrapping does not cut text
 | 
					
						
							|  |  |  | 		int space_w = Math::ceil(font->get_char_size(' ').width); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		int chars_total = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		int vbegin = 0, vsep = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 		if (lines_visible > line_count) { | 
					
						
							|  |  |  | 			lines_visible = line_count; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (max_lines_visible >= 0 && lines_visible > max_lines_visible) { | 
					
						
							|  |  |  | 			lines_visible = max_lines_visible; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (lines_visible > 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			switch (valign) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				case VALIGN_TOP: { | 
					
						
							|  |  |  | 					//nothing
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case VALIGN_CENTER: { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					vbegin = (size.y - (lines_visible * font_h - line_spacing)) / 2; | 
					
						
							|  |  |  | 					vsep = 0; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case VALIGN_BOTTOM: { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					vbegin = size.y - (lines_visible * font_h - line_spacing); | 
					
						
							|  |  |  | 					vsep = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 				case VALIGN_FILL: { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					vbegin = 0; | 
					
						
							|  |  |  | 					if (lines_visible > 1) { | 
					
						
							|  |  |  | 						vsep = (size.y - (lines_visible * font_h - line_spacing)) / (lines_visible - 1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						vsep = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				} break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		WordCache *wc = word_cache; | 
					
						
							|  |  |  | 		if (!wc) | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		int line = 0; | 
					
						
							|  |  |  | 		int line_to = lines_skipped + (lines_visible > 0 ? lines_visible : 1); | 
					
						
							| 
									
										
										
										
											2018-03-19 20:48:43 +07:00
										 |  |  | 		FontDrawer drawer(font, font_outline_modulate); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		while (wc) { | 
					
						
							|  |  |  | 			/* handle lines not meant to be drawn quickly */ | 
					
						
							|  |  |  | 			if (line >= line_to) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (line < lines_skipped) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				while (wc && wc->char_pos >= 0) | 
					
						
							|  |  |  | 					wc = wc->next; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				if (wc) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					wc = wc->next; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				line++; | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			/* handle lines normally */ | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (wc->char_pos < 0) { | 
					
						
							|  |  |  | 				//empty line
 | 
					
						
							|  |  |  | 				wc = wc->next; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				line++; | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			WordCache *from = wc; | 
					
						
							|  |  |  | 			WordCache *to = wc; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			int taken = 0; | 
					
						
							|  |  |  | 			int spaces = 0; | 
					
						
							|  |  |  | 			while (to && to->char_pos >= 0) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				taken += to->pixel_width; | 
					
						
							|  |  |  | 				if (to != from && to->space_count) { | 
					
						
							|  |  |  | 					spaces += to->space_count; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				to = to->next; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			bool can_fill = to && to->char_pos == WordCache::CHAR_WRAPLINE; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			float x_ofs = 0; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			switch (align) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				case ALIGN_FILL: | 
					
						
							|  |  |  | 				case ALIGN_LEFT: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 20:16:04 +02:00
										 |  |  | 					x_ofs = style->get_offset().x; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case ALIGN_CENTER: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					x_ofs = int(size.width - (taken + spaces * space_w)) / 2; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							|  |  |  | 				case ALIGN_RIGHT: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 20:16:04 +02:00
										 |  |  | 					x_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (taken + spaces * space_w)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} break; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-19 18:48:30 -03:00
										 |  |  | 			float y_ofs = style->get_offset().y; | 
					
						
							| 
									
										
										
										
											2017-08-04 20:16:04 +02:00
										 |  |  | 			y_ofs += (line - lines_skipped) * font_h + font->get_ascent(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			y_ofs += vbegin + line * vsep; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			while (from != to) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				// draw a word
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				int pos = from->char_pos; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (from->char_pos < 0) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					ERR_PRINT("BUG"); | 
					
						
							|  |  |  | 					return; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-04-29 23:43:39 +08:00
										 |  |  | 				if (from->space_count) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					/* spacing */ | 
					
						
							|  |  |  | 					x_ofs += space_w * from->space_count; | 
					
						
							|  |  |  | 					if (can_fill && align == ALIGN_FILL && spaces) { | 
					
						
							| 
									
										
										
										
											2015-04-28 23:06:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						x_ofs += int((size.width - (taken + space_w * spaces)) / spaces); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (font_color_shadow.a > 0) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					int chars_total_shadow = chars_total; //save chars drawn
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					float x_ofs_shadow = x_ofs; | 
					
						
							|  |  |  | 					for (int i = 0; i < from->word_len; i++) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						if (visible_chars < 0 || chars_total_shadow < visible_chars) { | 
					
						
							|  |  |  | 							CharType c = xl_text[i + pos]; | 
					
						
							|  |  |  | 							CharType n = xl_text[i + pos + 1]; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 							if (uppercase) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 								c = String::char_uppercase(c); | 
					
						
							| 
									
										
										
										
											2018-12-17 20:55:45 +01:00
										 |  |  | 								n = String::char_uppercase(n); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-28 23:21:55 +02:00
										 |  |  | 							float move = drawer.draw_char(ci, Point2(x_ofs_shadow, y_ofs) + shadow_ofs, c, n, font_color_shadow); | 
					
						
							| 
									
										
										
										
											2016-11-03 18:29:25 +07:00
										 |  |  | 							if (use_outline) { | 
					
						
							| 
									
										
										
										
											2019-06-28 23:21:55 +02:00
										 |  |  | 								drawer.draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, shadow_ofs.y), c, n, font_color_shadow); | 
					
						
							|  |  |  | 								drawer.draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow); | 
					
						
							|  |  |  | 								drawer.draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 							x_ofs_shadow += move; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 							chars_total_shadow++; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				for (int i = 0; i < from->word_len; i++) { | 
					
						
							| 
									
										
										
										
											2015-04-30 12:47:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					if (visible_chars < 0 || chars_total < visible_chars) { | 
					
						
							|  |  |  | 						CharType c = xl_text[i + pos]; | 
					
						
							|  |  |  | 						CharType n = xl_text[i + pos + 1]; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						if (uppercase) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 							c = String::char_uppercase(c); | 
					
						
							| 
									
										
										
										
											2018-12-17 20:55:45 +01:00
										 |  |  | 							n = String::char_uppercase(n); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-17 15:44:34 +07:00
										 |  |  | 						x_ofs += drawer.draw_char(ci, Point2(x_ofs, y_ofs), c, n, font_color); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 						chars_total++; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				from = from->next; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			wc = to ? to->next : 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			line++; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_THEME_CHANGED) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		word_cache_dirty = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		update(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_what == NOTIFICATION_RESIZED) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		word_cache_dirty = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Size2 Label::get_minimum_size() const { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 20:16:04 +02:00
										 |  |  | 	Size2 min_style = get_stylebox("normal")->get_minimum_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 14:05:24 -03:00
										 |  |  | 	// don't want to mutable everything
 | 
					
						
							| 
									
										
										
										
											2019-11-04 10:12:15 +01:00
										 |  |  | 	if (word_cache_dirty) { | 
					
						
							| 
									
										
										
										
											2018-09-19 14:05:24 -03:00
										 |  |  | 		const_cast<Label *>(this)->regenerate_word_cache(); | 
					
						
							| 
									
										
										
										
											2019-11-04 10:12:15 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-09-19 14:05:24 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (autowrap) | 
					
						
							| 
									
										
										
										
											2017-08-04 20:16:04 +02:00
										 |  |  | 		return Size2(1, clip ? 1 : minsize.height) + min_style; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Size2 ms = minsize; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (clip) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			ms.width = 1; | 
					
						
							| 
									
										
										
										
											2017-08-04 20:16:04 +02:00
										 |  |  | 		return ms + min_style; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int Label::get_longest_line_width() const { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	Ref<Font> font = get_font("font"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int max_line_width = 0; | 
					
						
							|  |  |  | 	int line_width = 0; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < xl_text.size(); i++) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		CharType current = xl_text[i]; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (uppercase) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			current = String::char_uppercase(current); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (current < 32) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (current == '\n') { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (line_width > max_line_width) | 
					
						
							|  |  |  | 					max_line_width = line_width; | 
					
						
							|  |  |  | 				line_width = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-14 20:18:44 +07:00
										 |  |  | 			// ceiling to ensure autowrapping does not cut text
 | 
					
						
							|  |  |  | 			int char_width = Math::ceil(font->get_char_size(current, xl_text[i + 1]).width); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			line_width += char_width; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (line_width > max_line_width) | 
					
						
							|  |  |  | 		max_line_width = line_width; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return max_line_width; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int Label::get_line_count() const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-05 21:20:42 -03:00
										 |  |  | 	if (!is_inside_tree()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	if (word_cache_dirty) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		const_cast<Label *>(this)->regenerate_word_cache(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return line_count; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 23:31:06 +02:00
										 |  |  | int Label::get_visible_line_count() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int line_spacing = get_constant("line_spacing"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int font_h = get_font("font")->get_height() + line_spacing; | 
					
						
							| 
									
										
										
										
											2017-08-04 20:16:04 +02:00
										 |  |  | 	int lines_visible = (get_size().height - get_stylebox("normal")->get_minimum_size().height + line_spacing) / font_h; | 
					
						
							| 
									
										
										
										
											2016-07-18 23:31:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (lines_visible > line_count) | 
					
						
							|  |  |  | 		lines_visible = line_count; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (max_lines_visible >= 0 && lines_visible > max_lines_visible) | 
					
						
							|  |  |  | 		lines_visible = max_lines_visible; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return lines_visible; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void Label::regenerate_word_cache() { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	while (word_cache) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		WordCache *current = word_cache; | 
					
						
							|  |  |  | 		word_cache = current->next; | 
					
						
							|  |  |  | 		memdelete(current); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-04 10:12:15 +01:00
										 |  |  | 	int width; | 
					
						
							|  |  |  | 	if (autowrap) { | 
					
						
							|  |  |  | 		Ref<StyleBox> style = get_stylebox("normal"); | 
					
						
							|  |  |  | 		width = MAX(get_size().width, get_custom_minimum_size().width) - style->get_minimum_size().width; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		width = get_longest_line_width(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	Ref<Font> font = get_font("font"); | 
					
						
							| 
									
										
										
										
											2015-05-01 18:47:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int current_word_size = 0; | 
					
						
							|  |  |  | 	int word_pos = 0; | 
					
						
							|  |  |  | 	int line_width = 0; | 
					
						
							|  |  |  | 	int space_count = 0; | 
					
						
							| 
									
										
										
										
											2018-05-14 20:18:44 +07:00
										 |  |  | 	// ceiling to ensure autowrapping does not cut text
 | 
					
						
							|  |  |  | 	int space_width = Math::ceil(font->get_char_size(' ').width); | 
					
						
							| 
									
										
										
										
											2016-05-17 18:27:15 -03:00
										 |  |  | 	int line_spacing = get_constant("line_spacing"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	line_count = 1; | 
					
						
							|  |  |  | 	total_char_cache = 0; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	WordCache *last = NULL; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-15 12:34:08 +01:00
										 |  |  | 	for (int i = 0; i <= xl_text.length(); i++) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 22:31:02 +01:00
										 |  |  | 		CharType current = i < xl_text.length() ? xl_text[i] : L' '; //always a space at the end, so the algo works
 | 
					
						
							| 
									
										
										
										
											2015-05-01 18:47:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (uppercase) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			current = String::char_uppercase(current); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-19 22:26:25 -03:00
										 |  |  | 		// ranges taken from http://www.unicodemap.org/
 | 
					
						
							|  |  |  | 		// if your language is not well supported, consider helping improve
 | 
					
						
							|  |  |  | 		// the unicode support in Godot.
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		bool separatable = (current >= 0x2E08 && current <= 0xFAFF) || (current >= 0xFE30 && current <= 0xFE4F); | 
					
						
							|  |  |  | 		//current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57);
 | 
					
						
							|  |  |  | 		bool insert_newline = false; | 
					
						
							| 
									
										
										
										
											2017-09-01 22:33:39 +02:00
										 |  |  | 		int char_width = 0; | 
					
						
							| 
									
										
										
										
											2015-05-01 18:47:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (current < 33) { | 
					
						
							| 
									
										
										
										
											2015-05-01 18:47:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (current_word_size > 0) { | 
					
						
							|  |  |  | 				WordCache *wc = memnew(WordCache); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				if (word_cache) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					last->next = wc; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					word_cache = wc; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				last = wc; | 
					
						
							| 
									
										
										
										
											2015-05-01 18:47:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				wc->pixel_width = current_word_size; | 
					
						
							|  |  |  | 				wc->char_pos = word_pos; | 
					
						
							|  |  |  | 				wc->word_len = i - word_pos; | 
					
						
							| 
									
										
										
										
											2015-04-29 16:34:25 +08:00
										 |  |  | 				wc->space_count = space_count; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				current_word_size = 0; | 
					
						
							|  |  |  | 				space_count = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-05-01 18:47:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (current == '\n') { | 
					
						
							|  |  |  | 				insert_newline = true; | 
					
						
							| 
									
										
										
										
											2018-11-15 12:34:08 +01:00
										 |  |  | 			} else if (current != ' ') { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				total_char_cache++; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (i < xl_text.length() && xl_text[i] == ' ') { | 
					
						
							|  |  |  | 				if (line_width > 0 || last == NULL || last->char_pos != WordCache::CHAR_WRAPLINE) { | 
					
						
							| 
									
										
										
										
											2015-04-29 16:34:25 +08:00
										 |  |  | 					space_count++; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					line_width += space_width; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					space_count = 0; | 
					
						
							| 
									
										
										
										
											2015-04-29 16:34:25 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-05-31 23:50:10 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2015-04-29 16:34:25 +08:00
										 |  |  | 			// latin characters
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (current_word_size == 0) { | 
					
						
							|  |  |  | 				word_pos = i; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-05-14 20:18:44 +07:00
										 |  |  | 			// ceiling to ensure autowrapping does not cut text
 | 
					
						
							|  |  |  | 			char_width = Math::ceil(font->get_char_size(current, xl_text[i + 1]).width); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			current_word_size += char_width; | 
					
						
							|  |  |  | 			line_width += char_width; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			total_char_cache++; | 
					
						
							| 
									
										
										
										
											2019-10-14 18:51:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// allow autowrap to cut words when they exceed line width
 | 
					
						
							|  |  |  | 			if (autowrap && (current_word_size > width)) { | 
					
						
							|  |  |  | 				separatable = true; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-04-29 16:34:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-19 22:26:25 -03:00
										 |  |  | 		if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || separatable)) || insert_newline) { | 
					
						
							|  |  |  | 			if (separatable) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (current_word_size > 0) { | 
					
						
							|  |  |  | 					WordCache *wc = memnew(WordCache); | 
					
						
							| 
									
										
										
										
											2015-05-01 18:47:34 +08:00
										 |  |  | 					if (word_cache) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						last->next = wc; | 
					
						
							| 
									
										
										
										
											2015-05-01 18:47:34 +08:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						word_cache = wc; | 
					
						
							| 
									
										
										
										
											2015-05-01 18:47:34 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					last = wc; | 
					
						
							| 
									
										
										
										
											2015-05-01 18:47:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					wc->pixel_width = current_word_size - char_width; | 
					
						
							|  |  |  | 					wc->char_pos = word_pos; | 
					
						
							|  |  |  | 					wc->word_len = i - word_pos; | 
					
						
							| 
									
										
										
										
											2015-05-01 18:47:34 +08:00
										 |  |  | 					wc->space_count = space_count; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					current_word_size = char_width; | 
					
						
							|  |  |  | 					word_pos = i; | 
					
						
							| 
									
										
										
										
											2015-05-01 18:47:34 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-04-29 16:34:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			WordCache *wc = memnew(WordCache); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			if (word_cache) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				last->next = wc; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				word_cache = wc; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			last = wc; | 
					
						
							| 
									
										
										
										
											2015-04-29 16:34:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			wc->pixel_width = 0; | 
					
						
							|  |  |  | 			wc->char_pos = insert_newline ? WordCache::CHAR_NEWLINE : WordCache::CHAR_WRAPLINE; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			line_width = current_word_size; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			line_count++; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			space_count = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-21 15:14:11 +07:00
										 |  |  | 	if (!autowrap) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		minsize.width = width; | 
					
						
							| 
									
										
										
										
											2017-07-21 15:14:11 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (max_lines_visible > 0 && line_count > max_lines_visible) { | 
					
						
							|  |  |  | 		minsize.height = (font->get_height() * max_lines_visible) + (line_spacing * (max_lines_visible - 1)); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		minsize.height = (font->get_height() * line_count) + (line_spacing * (line_count - 1)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-19 10:50:54 -03:00
										 |  |  | 	if (!autowrap || !clip) { | 
					
						
							|  |  |  | 		//helps speed up some labels that may change a lot, as no resizing is requested. Do not change.
 | 
					
						
							|  |  |  | 		minimum_size_changed(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	word_cache_dirty = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Label::set_align(Align p_align) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 09:17:59 +02:00
										 |  |  | 	ERR_FAIL_INDEX((int)p_align, 4); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	align = p_align; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | Label::Align Label::get_align() const { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return align; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Label::set_valign(VAlign p_align) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 09:17:59 +02:00
										 |  |  | 	ERR_FAIL_INDEX((int)p_align, 4); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	valign = p_align; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | Label::VAlign Label::get_valign() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return valign; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void Label::set_text(const String &p_string) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (text == p_string) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	text = p_string; | 
					
						
							| 
									
										
										
										
											2017-08-18 22:29:15 +02:00
										 |  |  | 	xl_text = tr(p_string); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	word_cache_dirty = true; | 
					
						
							|  |  |  | 	if (percent_visible < 1) | 
					
						
							|  |  |  | 		visible_chars = get_total_character_count() * percent_visible; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Label::set_clip_text(bool p_clip) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	clip = p_clip; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | 	minimum_size_changed(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool Label::is_clipping_text() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return clip; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String Label::get_text() const { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return text; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-05-31 23:50:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void Label::set_visible_characters(int p_amount) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	visible_chars = p_amount; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 	if (get_total_character_count() > 0) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		percent_visible = (float)p_amount / (float)total_char_cache; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-12 00:35:12 +02:00
										 |  |  | 	_change_notify("percent_visible"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-07 22:56:16 +01:00
										 |  |  | int Label::get_visible_characters() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return visible_chars; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void Label::set_percent_visible(float p_percent) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_percent < 0 || p_percent >= 1) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		visible_chars = -1; | 
					
						
							|  |  |  | 		percent_visible = 1; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		visible_chars = get_total_character_count() * p_percent; | 
					
						
							|  |  |  | 		percent_visible = p_percent; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-12 00:35:12 +02:00
										 |  |  | 	_change_notify("visible_chars"); | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 	update(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | float Label::get_percent_visible() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return percent_visible; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | void Label::set_lines_skipped(int p_lines) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	lines_skipped = p_lines; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | int Label::get_lines_skipped() const { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return lines_skipped; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Label::set_max_lines_visible(int p_lines) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	max_lines_visible = p_lines; | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | int Label::get_max_lines_visible() const { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return max_lines_visible; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | int Label::get_total_character_count() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (word_cache_dirty) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		const_cast<Label *>(this)->regenerate_word_cache(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return total_char_cache; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Label::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_align", "align"), &Label::set_align); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_align"), &Label::get_align); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_valign", "valign"), &Label::set_valign); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_valign"), &Label::get_valign); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_text", "text"), &Label::set_text); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_text"), &Label::get_text); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_autowrap", "enable"), &Label::set_autowrap); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("has_autowrap"), &Label::has_autowrap); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_clip_text", "enable"), &Label::set_clip_text); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("is_clipping_text"), &Label::is_clipping_text); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_uppercase", "enable"), &Label::set_uppercase); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("is_uppercase"), &Label::is_uppercase); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_line_height"), &Label::get_line_height); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_line_count"), &Label::get_line_count); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_visible_line_count"), &Label::get_visible_line_count); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_total_character_count"), &Label::get_total_character_count); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_visible_characters", "amount"), &Label::set_visible_characters); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_visible_characters"), &Label::get_visible_characters); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_percent_visible", "percent_visible"), &Label::set_percent_visible); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_percent_visible"), &Label::get_percent_visible); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_lines_skipped", "lines_skipped"), &Label::set_lines_skipped); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_lines_skipped"), &Label::get_lines_skipped); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_max_lines_visible", "lines_visible"), &Label::set_max_lines_visible); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_max_lines_visible"), &Label::get_max_lines_visible); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:45:01 +02:00
										 |  |  | 	BIND_ENUM_CONSTANT(ALIGN_LEFT); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(ALIGN_CENTER); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(ALIGN_RIGHT); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(ALIGN_FILL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(VALIGN_TOP); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(VALIGN_CENTER); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(VALIGN_BOTTOM); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(VALIGN_FILL); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-08 11:30:02 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_align", "get_align"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "valign", PROPERTY_HINT_ENUM, "Top,Center,Bottom,Fill"), "set_valign", "get_valign"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autowrap"), "set_autowrap", "has_autowrap"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "is_clipping_text"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "uppercase"), "set_uppercase", "is_uppercase"); | 
					
						
							| 
									
										
										
										
											2018-01-12 00:35:12 +02:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1", PROPERTY_USAGE_EDITOR), "set_visible_characters", "get_visible_characters"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "lines_skipped", PROPERTY_HINT_RANGE, "0,999,1"), "set_lines_skipped", "get_lines_skipped"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "max_lines_visible", PROPERTY_HINT_RANGE, "-1,999,1"), "set_max_lines_visible", "get_max_lines_visible"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Label::Label(const String &p_text) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	align = ALIGN_LEFT; | 
					
						
							|  |  |  | 	valign = VALIGN_TOP; | 
					
						
							|  |  |  | 	xl_text = ""; | 
					
						
							|  |  |  | 	word_cache = NULL; | 
					
						
							|  |  |  | 	word_cache_dirty = true; | 
					
						
							|  |  |  | 	autowrap = false; | 
					
						
							|  |  |  | 	line_count = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	set_v_size_flags(0); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	clip = false; | 
					
						
							| 
									
										
										
										
											2017-01-08 19:54:19 -03:00
										 |  |  | 	set_mouse_filter(MOUSE_FILTER_IGNORE); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	total_char_cache = 0; | 
					
						
							|  |  |  | 	visible_chars = -1; | 
					
						
							|  |  |  | 	percent_visible = 1; | 
					
						
							|  |  |  | 	lines_skipped = 0; | 
					
						
							|  |  |  | 	max_lines_visible = -1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	set_text(p_text); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	uppercase = false; | 
					
						
							| 
									
										
										
										
											2017-07-17 22:47:00 -03:00
										 |  |  | 	set_v_size_flags(SIZE_SHRINK_CENTER); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Label::~Label() { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	while (word_cache) { | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		WordCache *current = word_cache; | 
					
						
							|  |  |  | 		word_cache = current->next; | 
					
						
							|  |  |  | 		memdelete(current); | 
					
						
							| 
									
										
										
										
											2015-09-07 19:56:17 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } |