text_line.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**************************************************************************/
  2. /* text_line.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 TEXT_LINE_H
  31. #define TEXT_LINE_H
  32. #include "scene/resources/font.h"
  33. #include "servers/text_server.h"
  34. /*************************************************************************/
  35. class TextLine : public RefCounted {
  36. GDCLASS(TextLine, RefCounted);
  37. private:
  38. RID rid;
  39. bool dirty = true;
  40. float width = -1.0;
  41. BitField<TextServer::JustificationFlag> flags = TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA;
  42. HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_LEFT;
  43. String el_char = U"…";
  44. TextServer::OverrunBehavior overrun_behavior = TextServer::OVERRUN_TRIM_ELLIPSIS;
  45. Vector<float> tab_stops;
  46. protected:
  47. static void _bind_methods();
  48. void _shape();
  49. public:
  50. RID get_rid() const;
  51. void clear();
  52. void set_direction(TextServer::Direction p_direction);
  53. TextServer::Direction get_direction() const;
  54. void set_bidi_override(const Array &p_override);
  55. void set_orientation(TextServer::Orientation p_orientation);
  56. TextServer::Orientation get_orientation() const;
  57. void set_preserve_invalid(bool p_enabled);
  58. bool get_preserve_invalid() const;
  59. void set_preserve_control(bool p_enabled);
  60. bool get_preserve_control() const;
  61. bool add_string(const String &p_text, const Ref<Font> &p_font, int p_font_size, const String &p_language = "", const Variant &p_meta = Variant());
  62. bool add_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER, int p_length = 1, float p_baseline = 0.0);
  63. bool resize_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER, float p_baseline = 0.0);
  64. void set_horizontal_alignment(HorizontalAlignment p_alignment);
  65. HorizontalAlignment get_horizontal_alignment() const;
  66. void tab_align(const Vector<float> &p_tab_stops);
  67. void set_flags(BitField<TextServer::JustificationFlag> p_flags);
  68. BitField<TextServer::JustificationFlag> get_flags() const;
  69. void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior);
  70. TextServer::OverrunBehavior get_text_overrun_behavior() const;
  71. void set_ellipsis_char(const String &p_char);
  72. String get_ellipsis_char() const;
  73. void set_width(float p_width);
  74. float get_width() const;
  75. Array get_objects() const;
  76. Rect2 get_object_rect(Variant p_key) const;
  77. Size2 get_size() const;
  78. float get_line_ascent() const;
  79. float get_line_descent() const;
  80. float get_line_width() const;
  81. float get_line_underline_position() const;
  82. float get_line_underline_thickness() const;
  83. void draw(RID p_canvas, const Vector2 &p_pos, const Color &p_color = Color(1, 1, 1)) const;
  84. void draw_outline(RID p_canvas, const Vector2 &p_pos, int p_outline_size = 1, const Color &p_color = Color(1, 1, 1)) const;
  85. int hit_test(float p_coords) const;
  86. TextLine(const String &p_text, const Ref<Font> &p_font, int p_font_size, const String &p_language = "", TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL);
  87. TextLine();
  88. ~TextLine();
  89. };
  90. #endif // TEXT_LINE_H