label.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*************************************************************************/
  2. /* label.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "label.h"
  31. #include "print_string.h"
  32. #include "project_settings.h"
  33. #include "translation.h"
  34. void Label::set_autowrap(bool p_autowrap) {
  35. autowrap = p_autowrap;
  36. word_cache_dirty = true;
  37. update();
  38. }
  39. bool Label::has_autowrap() const {
  40. return autowrap;
  41. }
  42. void Label::set_uppercase(bool p_uppercase) {
  43. uppercase = p_uppercase;
  44. word_cache_dirty = true;
  45. update();
  46. }
  47. bool Label::is_uppercase() const {
  48. return uppercase;
  49. }
  50. int Label::get_line_height() const {
  51. return get_font("font")->get_height();
  52. }
  53. void Label::_notification(int p_what) {
  54. if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
  55. String new_text = tr(text);
  56. if (new_text == xl_text)
  57. return; //nothing new
  58. xl_text = new_text;
  59. regenerate_word_cache();
  60. update();
  61. }
  62. if (p_what == NOTIFICATION_DRAW) {
  63. if (clip || autowrap) {
  64. VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
  65. }
  66. if (word_cache_dirty)
  67. regenerate_word_cache();
  68. RID ci = get_canvas_item();
  69. Size2 string_size;
  70. Size2 size = get_size();
  71. Ref<StyleBox> style = get_stylebox("normal");
  72. Ref<Font> font = get_font("font");
  73. Color font_color = get_color("font_color");
  74. Color font_color_shadow = get_color("font_color_shadow");
  75. bool use_outline = get_constant("shadow_as_outline");
  76. Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y"));
  77. int line_spacing = get_constant("line_spacing");
  78. style->draw(ci, Rect2(Point2(0, 0), get_size()));
  79. VisualServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(), font.is_valid() && font->is_distance_field_hint());
  80. int font_h = font->get_height() + line_spacing;
  81. int lines_visible = (size.y + line_spacing) / font_h;
  82. int space_w = font->get_char_size(' ').width;
  83. int chars_total = 0;
  84. int vbegin = 0, vsep = 0;
  85. if (lines_visible > line_count) {
  86. lines_visible = line_count;
  87. }
  88. if (max_lines_visible >= 0 && lines_visible > max_lines_visible) {
  89. lines_visible = max_lines_visible;
  90. }
  91. if (lines_visible > 0) {
  92. switch (valign) {
  93. case VALIGN_TOP: {
  94. //nothing
  95. } break;
  96. case VALIGN_CENTER: {
  97. vbegin = (size.y - (lines_visible * font_h - line_spacing)) / 2;
  98. vsep = 0;
  99. } break;
  100. case VALIGN_BOTTOM: {
  101. vbegin = size.y - (lines_visible * font_h - line_spacing);
  102. vsep = 0;
  103. } break;
  104. case VALIGN_FILL: {
  105. vbegin = 0;
  106. if (lines_visible > 1) {
  107. vsep = (size.y - (lines_visible * font_h - line_spacing)) / (lines_visible - 1);
  108. } else {
  109. vsep = 0;
  110. }
  111. } break;
  112. }
  113. }
  114. WordCache *wc = word_cache;
  115. if (!wc)
  116. return;
  117. int line = 0;
  118. int line_to = lines_skipped + (lines_visible > 0 ? lines_visible : 1);
  119. while (wc) {
  120. /* handle lines not meant to be drawn quickly */
  121. if (line >= line_to)
  122. break;
  123. if (line < lines_skipped) {
  124. while (wc && wc->char_pos >= 0)
  125. wc = wc->next;
  126. if (wc)
  127. wc = wc->next;
  128. line++;
  129. continue;
  130. }
  131. /* handle lines normally */
  132. if (wc->char_pos < 0) {
  133. //empty line
  134. wc = wc->next;
  135. line++;
  136. continue;
  137. }
  138. WordCache *from = wc;
  139. WordCache *to = wc;
  140. int taken = 0;
  141. int spaces = 0;
  142. while (to && to->char_pos >= 0) {
  143. taken += to->pixel_width;
  144. if (to != from && to->space_count) {
  145. spaces += to->space_count;
  146. }
  147. to = to->next;
  148. }
  149. bool can_fill = to && to->char_pos == WordCache::CHAR_WRAPLINE;
  150. float x_ofs = 0;
  151. switch (align) {
  152. case ALIGN_FILL:
  153. case ALIGN_LEFT: {
  154. x_ofs = style->get_offset().x;
  155. } break;
  156. case ALIGN_CENTER: {
  157. x_ofs = int(size.width - (taken + spaces * space_w)) / 2;
  158. } break;
  159. case ALIGN_RIGHT: {
  160. x_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (taken + spaces * space_w));
  161. } break;
  162. }
  163. int y_ofs = style->get_offset().y;
  164. y_ofs += (line - lines_skipped) * font_h + font->get_ascent();
  165. y_ofs += vbegin + line * vsep;
  166. while (from != to) {
  167. // draw a word
  168. int pos = from->char_pos;
  169. if (from->char_pos < 0) {
  170. ERR_PRINT("BUG");
  171. return;
  172. }
  173. if (from->space_count) {
  174. /* spacing */
  175. x_ofs += space_w * from->space_count;
  176. if (can_fill && align == ALIGN_FILL && spaces) {
  177. x_ofs += int((size.width - (taken + space_w * spaces)) / spaces);
  178. }
  179. }
  180. if (font_color_shadow.a > 0) {
  181. int chars_total_shadow = chars_total; //save chars drawn
  182. float x_ofs_shadow = x_ofs;
  183. for (int i = 0; i < from->word_len; i++) {
  184. if (visible_chars < 0 || chars_total_shadow < visible_chars) {
  185. CharType c = xl_text[i + pos];
  186. CharType n = xl_text[i + pos + 1];
  187. if (uppercase) {
  188. c = String::char_uppercase(c);
  189. n = String::char_uppercase(c);
  190. }
  191. float move = font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + shadow_ofs, c, n, font_color_shadow);
  192. if (use_outline) {
  193. font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, shadow_ofs.y), c, n, font_color_shadow);
  194. font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow);
  195. font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow);
  196. }
  197. x_ofs_shadow += move;
  198. chars_total_shadow++;
  199. }
  200. }
  201. }
  202. for (int i = 0; i < from->word_len; i++) {
  203. if (visible_chars < 0 || chars_total < visible_chars) {
  204. CharType c = xl_text[i + pos];
  205. CharType n = xl_text[i + pos + 1];
  206. if (uppercase) {
  207. c = String::char_uppercase(c);
  208. n = String::char_uppercase(c);
  209. }
  210. x_ofs += font->draw_char(ci, Point2(x_ofs, y_ofs), c, n, font_color);
  211. chars_total++;
  212. }
  213. }
  214. from = from->next;
  215. }
  216. wc = to ? to->next : 0;
  217. line++;
  218. }
  219. }
  220. if (p_what == NOTIFICATION_THEME_CHANGED) {
  221. word_cache_dirty = true;
  222. update();
  223. }
  224. if (p_what == NOTIFICATION_RESIZED) {
  225. word_cache_dirty = true;
  226. }
  227. }
  228. Size2 Label::get_minimum_size() const {
  229. Size2 min_style = get_stylebox("normal")->get_minimum_size();
  230. if (autowrap)
  231. return Size2(1, clip ? 1 : minsize.height) + min_style;
  232. else {
  233. // don't want to mutable everything
  234. if (word_cache_dirty)
  235. const_cast<Label *>(this)->regenerate_word_cache();
  236. Size2 ms = minsize;
  237. if (clip)
  238. ms.width = 1;
  239. return ms + min_style;
  240. }
  241. }
  242. int Label::get_longest_line_width() const {
  243. Ref<Font> font = get_font("font");
  244. int max_line_width = 0;
  245. int line_width = 0;
  246. for (int i = 0; i < xl_text.size(); i++) {
  247. CharType current = xl_text[i];
  248. if (uppercase)
  249. current = String::char_uppercase(current);
  250. if (current < 32) {
  251. if (current == '\n') {
  252. if (line_width > max_line_width)
  253. max_line_width = line_width;
  254. line_width = 0;
  255. }
  256. } else {
  257. int char_width = font->get_char_size(current, xl_text[i + 1]).width;
  258. line_width += char_width;
  259. }
  260. }
  261. if (line_width > max_line_width)
  262. max_line_width = line_width;
  263. return max_line_width;
  264. }
  265. int Label::get_line_count() const {
  266. if (!is_inside_tree())
  267. return 1;
  268. if (word_cache_dirty)
  269. const_cast<Label *>(this)->regenerate_word_cache();
  270. return line_count;
  271. }
  272. int Label::get_visible_line_count() const {
  273. int line_spacing = get_constant("line_spacing");
  274. int font_h = get_font("font")->get_height() + line_spacing;
  275. int lines_visible = (get_size().height - get_stylebox("normal")->get_minimum_size().height + line_spacing) / font_h;
  276. if (lines_visible > line_count)
  277. lines_visible = line_count;
  278. if (max_lines_visible >= 0 && lines_visible > max_lines_visible)
  279. lines_visible = max_lines_visible;
  280. return lines_visible;
  281. }
  282. void Label::regenerate_word_cache() {
  283. while (word_cache) {
  284. WordCache *current = word_cache;
  285. word_cache = current->next;
  286. memdelete(current);
  287. }
  288. Ref<StyleBox> style = get_stylebox("normal");
  289. int width = autowrap ? (get_size().width - style->get_minimum_size().width) : get_longest_line_width();
  290. Ref<Font> font = get_font("font");
  291. int current_word_size = 0;
  292. int word_pos = 0;
  293. int line_width = 0;
  294. int space_count = 0;
  295. int space_width = font->get_char_size(' ').width;
  296. int line_spacing = get_constant("line_spacing");
  297. line_count = 1;
  298. total_char_cache = 0;
  299. WordCache *last = NULL;
  300. for (int i = 0; i < xl_text.size() + 1; i++) {
  301. CharType current = i < xl_text.length() ? xl_text[i] : ' '; //always a space at the end, so the algo works
  302. if (uppercase)
  303. current = String::char_uppercase(current);
  304. // ranges taken from http://www.unicodemap.org/
  305. // if your language is not well supported, consider helping improve
  306. // the unicode support in Godot.
  307. bool separatable = (current >= 0x2E08 && current <= 0xFAFF) || (current >= 0xFE30 && current <= 0xFE4F);
  308. //current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57);
  309. bool insert_newline = false;
  310. int char_width = 0;
  311. if (current < 33) {
  312. if (current_word_size > 0) {
  313. WordCache *wc = memnew(WordCache);
  314. if (word_cache) {
  315. last->next = wc;
  316. } else {
  317. word_cache = wc;
  318. }
  319. last = wc;
  320. wc->pixel_width = current_word_size;
  321. wc->char_pos = word_pos;
  322. wc->word_len = i - word_pos;
  323. wc->space_count = space_count;
  324. current_word_size = 0;
  325. space_count = 0;
  326. }
  327. if (current == '\n') {
  328. insert_newline = true;
  329. } else {
  330. total_char_cache++;
  331. }
  332. if (i < xl_text.length() && xl_text[i] == ' ') {
  333. total_char_cache--; // do not count spaces
  334. if (line_width > 0 || last == NULL || last->char_pos != WordCache::CHAR_WRAPLINE) {
  335. space_count++;
  336. line_width += space_width;
  337. } else {
  338. space_count = 0;
  339. }
  340. }
  341. } else {
  342. // latin characters
  343. if (current_word_size == 0) {
  344. word_pos = i;
  345. }
  346. char_width = font->get_char_size(current, xl_text[i + 1]).width;
  347. current_word_size += char_width;
  348. line_width += char_width;
  349. total_char_cache++;
  350. }
  351. if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || separatable)) || insert_newline) {
  352. if (separatable) {
  353. if (current_word_size > 0) {
  354. WordCache *wc = memnew(WordCache);
  355. if (word_cache) {
  356. last->next = wc;
  357. } else {
  358. word_cache = wc;
  359. }
  360. last = wc;
  361. wc->pixel_width = current_word_size - char_width;
  362. wc->char_pos = word_pos;
  363. wc->word_len = i - word_pos;
  364. wc->space_count = space_count;
  365. current_word_size = char_width;
  366. space_count = 0;
  367. word_pos = i;
  368. }
  369. }
  370. WordCache *wc = memnew(WordCache);
  371. if (word_cache) {
  372. last->next = wc;
  373. } else {
  374. word_cache = wc;
  375. }
  376. last = wc;
  377. wc->pixel_width = 0;
  378. wc->char_pos = insert_newline ? WordCache::CHAR_NEWLINE : WordCache::CHAR_WRAPLINE;
  379. line_width = current_word_size;
  380. line_count++;
  381. space_count = 0;
  382. }
  383. }
  384. if (!autowrap)
  385. minsize.width = width;
  386. if (max_lines_visible > 0 && line_count > max_lines_visible) {
  387. minsize.height = (font->get_height() * max_lines_visible) + (line_spacing * (max_lines_visible - 1));
  388. } else {
  389. minsize.height = (font->get_height() * line_count) + (line_spacing * (line_count - 1));
  390. }
  391. if (!autowrap || !clip) {
  392. //helps speed up some labels that may change a lot, as no resizing is requested. Do not change.
  393. minimum_size_changed();
  394. }
  395. word_cache_dirty = false;
  396. }
  397. void Label::set_align(Align p_align) {
  398. ERR_FAIL_INDEX(p_align, 4);
  399. align = p_align;
  400. update();
  401. }
  402. Label::Align Label::get_align() const {
  403. return align;
  404. }
  405. void Label::set_valign(VAlign p_align) {
  406. ERR_FAIL_INDEX(p_align, 4);
  407. valign = p_align;
  408. update();
  409. }
  410. Label::VAlign Label::get_valign() const {
  411. return valign;
  412. }
  413. void Label::set_text(const String &p_string) {
  414. if (text == p_string)
  415. return;
  416. text = p_string;
  417. xl_text = tr(p_string);
  418. word_cache_dirty = true;
  419. if (percent_visible < 1)
  420. visible_chars = get_total_character_count() * percent_visible;
  421. update();
  422. }
  423. void Label::set_clip_text(bool p_clip) {
  424. clip = p_clip;
  425. update();
  426. minimum_size_changed();
  427. }
  428. bool Label::is_clipping_text() const {
  429. return clip;
  430. }
  431. String Label::get_text() const {
  432. return text;
  433. }
  434. void Label::set_visible_characters(int p_amount) {
  435. visible_chars = p_amount;
  436. if (get_total_character_count() > 0) {
  437. percent_visible = (float)p_amount / (float)total_char_cache;
  438. }
  439. update();
  440. }
  441. int Label::get_visible_characters() const {
  442. return visible_chars;
  443. }
  444. void Label::set_percent_visible(float p_percent) {
  445. if (p_percent < 0 || p_percent >= 1) {
  446. visible_chars = -1;
  447. percent_visible = 1;
  448. } else {
  449. visible_chars = get_total_character_count() * p_percent;
  450. percent_visible = p_percent;
  451. }
  452. update();
  453. }
  454. float Label::get_percent_visible() const {
  455. return percent_visible;
  456. }
  457. void Label::set_lines_skipped(int p_lines) {
  458. lines_skipped = p_lines;
  459. update();
  460. }
  461. int Label::get_lines_skipped() const {
  462. return lines_skipped;
  463. }
  464. void Label::set_max_lines_visible(int p_lines) {
  465. max_lines_visible = p_lines;
  466. update();
  467. }
  468. int Label::get_max_lines_visible() const {
  469. return max_lines_visible;
  470. }
  471. int Label::get_total_character_count() const {
  472. if (word_cache_dirty)
  473. const_cast<Label *>(this)->regenerate_word_cache();
  474. return total_char_cache;
  475. }
  476. void Label::_bind_methods() {
  477. ClassDB::bind_method(D_METHOD("set_align", "align"), &Label::set_align);
  478. ClassDB::bind_method(D_METHOD("get_align"), &Label::get_align);
  479. ClassDB::bind_method(D_METHOD("set_valign", "valign"), &Label::set_valign);
  480. ClassDB::bind_method(D_METHOD("get_valign"), &Label::get_valign);
  481. ClassDB::bind_method(D_METHOD("set_text", "text"), &Label::set_text);
  482. ClassDB::bind_method(D_METHOD("get_text"), &Label::get_text);
  483. ClassDB::bind_method(D_METHOD("set_autowrap", "enable"), &Label::set_autowrap);
  484. ClassDB::bind_method(D_METHOD("has_autowrap"), &Label::has_autowrap);
  485. ClassDB::bind_method(D_METHOD("set_clip_text", "enable"), &Label::set_clip_text);
  486. ClassDB::bind_method(D_METHOD("is_clipping_text"), &Label::is_clipping_text);
  487. ClassDB::bind_method(D_METHOD("set_uppercase", "enable"), &Label::set_uppercase);
  488. ClassDB::bind_method(D_METHOD("is_uppercase"), &Label::is_uppercase);
  489. ClassDB::bind_method(D_METHOD("get_line_height"), &Label::get_line_height);
  490. ClassDB::bind_method(D_METHOD("get_line_count"), &Label::get_line_count);
  491. ClassDB::bind_method(D_METHOD("get_visible_line_count"), &Label::get_visible_line_count);
  492. ClassDB::bind_method(D_METHOD("get_total_character_count"), &Label::get_total_character_count);
  493. ClassDB::bind_method(D_METHOD("set_visible_characters", "amount"), &Label::set_visible_characters);
  494. ClassDB::bind_method(D_METHOD("get_visible_characters"), &Label::get_visible_characters);
  495. ClassDB::bind_method(D_METHOD("set_percent_visible", "percent_visible"), &Label::set_percent_visible);
  496. ClassDB::bind_method(D_METHOD("get_percent_visible"), &Label::get_percent_visible);
  497. ClassDB::bind_method(D_METHOD("set_lines_skipped", "lines_skipped"), &Label::set_lines_skipped);
  498. ClassDB::bind_method(D_METHOD("get_lines_skipped"), &Label::get_lines_skipped);
  499. ClassDB::bind_method(D_METHOD("set_max_lines_visible", "lines_visible"), &Label::set_max_lines_visible);
  500. ClassDB::bind_method(D_METHOD("get_max_lines_visible"), &Label::get_max_lines_visible);
  501. BIND_ENUM_CONSTANT(ALIGN_LEFT);
  502. BIND_ENUM_CONSTANT(ALIGN_CENTER);
  503. BIND_ENUM_CONSTANT(ALIGN_RIGHT);
  504. BIND_ENUM_CONSTANT(ALIGN_FILL);
  505. BIND_ENUM_CONSTANT(VALIGN_TOP);
  506. BIND_ENUM_CONSTANT(VALIGN_CENTER);
  507. BIND_ENUM_CONSTANT(VALIGN_BOTTOM);
  508. BIND_ENUM_CONSTANT(VALIGN_FILL);
  509. ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text");
  510. ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_align", "get_align");
  511. ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "valign", PROPERTY_HINT_ENUM, "Top,Center,Bottom,Fill"), "set_valign", "get_valign");
  512. ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "autowrap"), "set_autowrap", "has_autowrap");
  513. ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "is_clipping_text");
  514. ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "uppercase"), "set_uppercase", "is_uppercase");
  515. ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible");
  516. ADD_PROPERTY(PropertyInfo(Variant::INT, "lines_skipped", PROPERTY_HINT_RANGE, "0,999,1"), "set_lines_skipped", "get_lines_skipped");
  517. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_lines_visible", PROPERTY_HINT_RANGE, "-1,999,1"), "set_max_lines_visible", "get_max_lines_visible");
  518. }
  519. Label::Label(const String &p_text) {
  520. align = ALIGN_LEFT;
  521. valign = VALIGN_TOP;
  522. xl_text = "";
  523. word_cache = NULL;
  524. word_cache_dirty = true;
  525. autowrap = false;
  526. line_count = 0;
  527. set_v_size_flags(0);
  528. clip = false;
  529. set_mouse_filter(MOUSE_FILTER_IGNORE);
  530. total_char_cache = 0;
  531. visible_chars = -1;
  532. percent_visible = 1;
  533. lines_skipped = 0;
  534. max_lines_visible = -1;
  535. set_text(p_text);
  536. uppercase = false;
  537. set_v_size_flags(SIZE_SHRINK_CENTER);
  538. }
  539. Label::~Label() {
  540. while (word_cache) {
  541. WordCache *current = word_cache;
  542. word_cache = current->next;
  543. memdelete(current);
  544. }
  545. }