label.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*************************************************************************/
  2. /* label.h */
  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. #ifndef LABEL_H
  31. #define LABEL_H
  32. #include "scene/gui/control.h"
  33. /**
  34. @author Juan Linietsky <reduzio@gmail.com>
  35. */
  36. class Label : public Control {
  37. GDCLASS(Label, Control);
  38. public:
  39. enum Align {
  40. ALIGN_LEFT,
  41. ALIGN_CENTER,
  42. ALIGN_RIGHT,
  43. ALIGN_FILL
  44. };
  45. enum VAlign {
  46. VALIGN_TOP,
  47. VALIGN_CENTER,
  48. VALIGN_BOTTOM,
  49. VALIGN_FILL
  50. };
  51. private:
  52. Align align;
  53. VAlign valign;
  54. String text;
  55. String xl_text;
  56. bool autowrap;
  57. bool clip;
  58. Size2 minsize;
  59. int line_count;
  60. bool uppercase;
  61. int get_longest_line_width() const;
  62. struct WordCache {
  63. enum {
  64. CHAR_NEWLINE = -1,
  65. CHAR_WRAPLINE = -2
  66. };
  67. int char_pos; // if -1, then newline
  68. int word_len;
  69. int pixel_width;
  70. int space_count;
  71. WordCache *next;
  72. WordCache() {
  73. char_pos = 0;
  74. word_len = 0;
  75. pixel_width = 0;
  76. next = 0;
  77. space_count = 0;
  78. }
  79. };
  80. bool word_cache_dirty;
  81. void regenerate_word_cache();
  82. float percent_visible;
  83. WordCache *word_cache;
  84. int total_char_cache;
  85. int visible_chars;
  86. int lines_skipped;
  87. int max_lines_visible;
  88. protected:
  89. void _notification(int p_what);
  90. static void _bind_methods();
  91. // bind helpers
  92. public:
  93. virtual Size2 get_minimum_size() const;
  94. void set_align(Align p_align);
  95. Align get_align() const;
  96. void set_valign(VAlign p_align);
  97. VAlign get_valign() const;
  98. void set_text(const String &p_string);
  99. String get_text() const;
  100. void set_autowrap(bool p_autowrap);
  101. bool has_autowrap() const;
  102. void set_uppercase(bool p_uppercase);
  103. bool is_uppercase() const;
  104. void set_visible_characters(int p_amount);
  105. int get_visible_characters() const;
  106. int get_total_character_count() const;
  107. void set_clip_text(bool p_clip);
  108. bool is_clipping_text() const;
  109. void set_percent_visible(float p_percent);
  110. float get_percent_visible() const;
  111. void set_lines_skipped(int p_lines);
  112. int get_lines_skipped() const;
  113. void set_max_lines_visible(int p_lines);
  114. int get_max_lines_visible() const;
  115. int get_line_height() const;
  116. int get_line_count() const;
  117. int get_visible_line_count() const;
  118. Label(const String &p_text = String());
  119. ~Label();
  120. };
  121. VARIANT_ENUM_CAST(Label::Align);
  122. VARIANT_ENUM_CAST(Label::VAlign);
  123. #endif