label_settings.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**************************************************************************/
  2. /* label_settings.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. #pragma once
  31. #include "core/io/resource.h"
  32. #include "font.h"
  33. #include "scene/property_list_helper.h"
  34. /*************************************************************************/
  35. class LabelSettings : public Resource {
  36. GDCLASS(LabelSettings, Resource);
  37. public:
  38. struct StackedOutlineData {
  39. int32_t size = 0;
  40. Color color;
  41. };
  42. struct StackedShadowData {
  43. Vector2i offset = Vector2i(1, 1);
  44. Color color;
  45. int32_t outline_size = 0;
  46. };
  47. private:
  48. real_t line_spacing = 3;
  49. real_t paragraph_spacing = 0;
  50. Ref<Font> font;
  51. int font_size = Font::DEFAULT_FONT_SIZE;
  52. Color font_color = Color(1, 1, 1);
  53. int outline_size = 0;
  54. Color outline_color = Color(1, 1, 1);
  55. int shadow_size = 1;
  56. Color shadow_color = Color(0, 0, 0, 0);
  57. Vector2 shadow_offset = Vector2(1, 1);
  58. Vector<StackedOutlineData> stacked_outline_data;
  59. Vector<StackedShadowData> stacked_shadow_data;
  60. static inline PropertyListHelper stacked_outline_base_property_helper;
  61. static inline PropertyListHelper stacked_shadow_base_property_helper;
  62. PropertyListHelper stacked_outline_property_helper;
  63. PropertyListHelper stacked_shadow_property_helper;
  64. void _font_changed();
  65. protected:
  66. static void _bind_methods();
  67. bool _set(const StringName &p_name, const Variant &p_value) {
  68. return stacked_outline_property_helper.property_set_value(p_name, p_value) || stacked_shadow_property_helper.property_set_value(p_name, p_value);
  69. }
  70. bool _get(const StringName &p_name, Variant &r_ret) const {
  71. return stacked_outline_property_helper.property_get_value(p_name, r_ret) || stacked_shadow_property_helper.property_get_value(p_name, r_ret);
  72. }
  73. void _get_property_list(List<PropertyInfo> *p_list) const {
  74. stacked_outline_property_helper.get_property_list(p_list);
  75. stacked_shadow_property_helper.get_property_list(p_list);
  76. }
  77. bool _property_can_revert(const StringName &p_name) const {
  78. return stacked_outline_property_helper.property_can_revert(p_name) || stacked_shadow_property_helper.property_can_revert(p_name);
  79. }
  80. bool _property_get_revert(const StringName &p_name, Variant &r_property) const {
  81. return stacked_outline_property_helper.property_get_revert(p_name, r_property) || stacked_shadow_property_helper.property_get_revert(p_name, r_property);
  82. }
  83. public:
  84. void set_line_spacing(real_t p_spacing);
  85. real_t get_line_spacing() const;
  86. void set_paragraph_spacing(real_t p_spacing);
  87. real_t get_paragraph_spacing() const;
  88. void set_font(const Ref<Font> &p_font);
  89. Ref<Font> get_font() const;
  90. void set_font_size(int p_size);
  91. int get_font_size() const;
  92. void set_font_color(const Color &p_color);
  93. Color get_font_color() const;
  94. void set_outline_size(int p_size);
  95. int get_outline_size() const;
  96. void set_outline_color(const Color &p_color);
  97. Color get_outline_color() const;
  98. void set_shadow_size(int p_size);
  99. int get_shadow_size() const;
  100. void set_shadow_color(const Color &p_color);
  101. Color get_shadow_color() const;
  102. void set_shadow_offset(const Vector2 &p_offset);
  103. Vector2 get_shadow_offset() const;
  104. Vector<StackedOutlineData> get_stacked_outline_data() const;
  105. int get_stacked_outline_count() const;
  106. void set_stacked_outline_count(int p_count);
  107. void add_stacked_outline(int p_index = -1);
  108. void move_stacked_outline(int p_from_index, int p_to_position);
  109. void remove_stacked_outline(int p_index);
  110. void set_stacked_outline_size(int p_index, int p_size);
  111. int get_stacked_outline_size(int p_index) const;
  112. void set_stacked_outline_color(int p_index, const Color &p_color);
  113. Color get_stacked_outline_color(int p_index) const;
  114. Vector<StackedShadowData> get_stacked_shadow_data() const;
  115. int get_stacked_shadow_count() const;
  116. void set_stacked_shadow_count(int p_count);
  117. void add_stacked_shadow(int p_index = -1);
  118. void move_stacked_shadow(int p_from_index, int p_to_position);
  119. void remove_stacked_shadow(int p_index);
  120. void set_stacked_shadow_offset(int p_index, const Vector2 &p_offset);
  121. Vector2 get_stacked_shadow_offset(int p_index) const;
  122. void set_stacked_shadow_color(int p_index, const Color &p_color);
  123. Color get_stacked_shadow_color(int p_index) const;
  124. void set_stacked_shadow_outline_size(int p_index, int p_size);
  125. int get_stacked_shadow_outline_size(int p_index) const;
  126. LabelSettings() {
  127. stacked_outline_property_helper.setup_for_instance(stacked_outline_base_property_helper, this);
  128. stacked_shadow_property_helper.setup_for_instance(stacked_shadow_base_property_helper, this);
  129. }
  130. };