label.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*************************************************************************/
  2. /* label.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef LABEL_H
  30. #define LABEL_H
  31. #include "scene/gui/range.h"
  32. /**
  33. @author Juan Linietsky <[email protected]>
  34. */
  35. class Label : public Range {
  36. OBJ_TYPE( Label, Range );
  37. public:
  38. enum Align {
  39. ALIGN_LEFT,
  40. ALIGN_CENTER,
  41. ALIGN_RIGHT,
  42. ALIGN_FILL
  43. };
  44. enum VAlign {
  45. VALIGN_TOP,
  46. VALIGN_CENTER,
  47. VALIGN_BOTTOM,
  48. VALIGN_FILL
  49. };
  50. private:
  51. Align align;
  52. VAlign valign;
  53. String text;
  54. bool autowrap;
  55. bool clip;
  56. Size2 minsize;
  57. int line_count;
  58. bool uppercase;
  59. int get_longest_line_width() const;
  60. struct WordCache {
  61. enum {
  62. CHAR_NEWLINE=-1,
  63. CHAR_WRAPLINE=-2
  64. };
  65. int char_pos; // if -1, then newline
  66. int word_len;
  67. int pixel_width;
  68. WordCache *next;
  69. WordCache() { char_pos=0; word_len=0; pixel_width=0; next=0; }
  70. };
  71. bool word_cache_dirty;
  72. void regenerate_word_cache();
  73. float percent_visible;
  74. WordCache *word_cache;
  75. int total_char_cache;
  76. int visible_chars;
  77. protected:
  78. void _notification(int p_what);
  79. static void _bind_methods();
  80. // bind helpers
  81. public:
  82. virtual Size2 get_minimum_size() const;
  83. void set_align(Align p_align);
  84. Align get_align() const;
  85. void set_valign(VAlign p_align);
  86. VAlign get_valign() const;
  87. void set_text(const String& p_string);
  88. String get_text() const;
  89. void set_autowrap(bool p_autowrap);
  90. bool has_autowrap() const;
  91. void set_uppercase(bool p_uppercase);
  92. bool is_uppercase() const;
  93. void set_visible_characters(int p_amount);
  94. int get_total_character_count() const;
  95. void set_clip_text(bool p_clip);
  96. bool is_clipping_text() const;
  97. void set_percent_visible(float p_percent);
  98. float get_percent_visible() const;
  99. int get_line_height() const;
  100. int get_line_count() const;
  101. Label(const String& p_text=String());
  102. ~Label();
  103. };
  104. VARIANT_ENUM_CAST( Label::Align );
  105. VARIANT_ENUM_CAST( Label::VAlign );
  106. #endif