label_settings.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*************************************************************************/
  2. /* label_settings.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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_settings.h"
  31. #include "core/core_string_names.h"
  32. void LabelSettings::_font_changed() {
  33. emit_changed();
  34. }
  35. void LabelSettings::_bind_methods() {
  36. ClassDB::bind_method(D_METHOD("set_line_spacing", "spacing"), &LabelSettings::set_line_spacing);
  37. ClassDB::bind_method(D_METHOD("get_line_spacing"), &LabelSettings::get_line_spacing);
  38. ClassDB::bind_method(D_METHOD("set_font", "font"), &LabelSettings::set_font);
  39. ClassDB::bind_method(D_METHOD("get_font"), &LabelSettings::get_font);
  40. ClassDB::bind_method(D_METHOD("set_font_size", "size"), &LabelSettings::set_font_size);
  41. ClassDB::bind_method(D_METHOD("get_font_size"), &LabelSettings::get_font_size);
  42. ClassDB::bind_method(D_METHOD("set_font_color", "color"), &LabelSettings::set_font_color);
  43. ClassDB::bind_method(D_METHOD("get_font_color"), &LabelSettings::get_font_color);
  44. ClassDB::bind_method(D_METHOD("set_outline_size", "size"), &LabelSettings::set_outline_size);
  45. ClassDB::bind_method(D_METHOD("get_outline_size"), &LabelSettings::get_outline_size);
  46. ClassDB::bind_method(D_METHOD("set_outline_color", "color"), &LabelSettings::set_outline_color);
  47. ClassDB::bind_method(D_METHOD("get_outline_color"), &LabelSettings::get_outline_color);
  48. ClassDB::bind_method(D_METHOD("set_shadow_size", "size"), &LabelSettings::set_shadow_size);
  49. ClassDB::bind_method(D_METHOD("get_shadow_size"), &LabelSettings::get_shadow_size);
  50. ClassDB::bind_method(D_METHOD("set_shadow_color", "color"), &LabelSettings::set_shadow_color);
  51. ClassDB::bind_method(D_METHOD("get_shadow_color"), &LabelSettings::get_shadow_color);
  52. ClassDB::bind_method(D_METHOD("set_shadow_offset", "offset"), &LabelSettings::set_shadow_offset);
  53. ClassDB::bind_method(D_METHOD("get_shadow_offset"), &LabelSettings::get_shadow_offset);
  54. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "line_spacing", PROPERTY_HINT_NONE, "suffix:px"), "set_line_spacing", "get_line_spacing");
  55. ADD_GROUP("Font", "font");
  56. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "font", PROPERTY_HINT_RESOURCE_TYPE, "Font"), "set_font", "get_font");
  57. ADD_PROPERTY(PropertyInfo(Variant::INT, "font_size", PROPERTY_HINT_RANGE, "1,1024,1,or_greater,suffix:px"), "set_font_size", "get_font_size");
  58. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "font_color"), "set_font_color", "get_font_color");
  59. ADD_GROUP("Outline", "outline");
  60. ADD_PROPERTY(PropertyInfo(Variant::INT, "outline_size", PROPERTY_HINT_RANGE, "0,127,1,or_greater,suffix:px"), "set_outline_size", "get_outline_size");
  61. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "outline_color"), "set_outline_color", "get_outline_color");
  62. ADD_GROUP("Shadow", "shadow");
  63. ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_size", PROPERTY_HINT_RANGE, "0,127,1,or_greater,suffix:px"), "set_shadow_size", "get_shadow_size");
  64. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color"), "set_shadow_color", "get_shadow_color");
  65. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "shadow_offset", PROPERTY_HINT_NONE, "suffix:px"), "set_shadow_offset", "get_shadow_offset");
  66. }
  67. void LabelSettings::set_line_spacing(real_t p_spacing) {
  68. if (line_spacing != p_spacing) {
  69. line_spacing = p_spacing;
  70. emit_changed();
  71. }
  72. }
  73. real_t LabelSettings::get_line_spacing() const {
  74. return line_spacing;
  75. }
  76. void LabelSettings::set_font(const Ref<Font> &p_font) {
  77. if (font != p_font) {
  78. if (font.is_valid()) {
  79. font->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &LabelSettings::_font_changed));
  80. }
  81. font = p_font;
  82. if (font.is_valid()) {
  83. font->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &LabelSettings::_font_changed), CONNECT_REFERENCE_COUNTED);
  84. }
  85. emit_changed();
  86. }
  87. }
  88. Ref<Font> LabelSettings::get_font() const {
  89. return font;
  90. }
  91. void LabelSettings::set_font_size(int p_size) {
  92. if (font_size != p_size) {
  93. font_size = p_size;
  94. emit_changed();
  95. }
  96. }
  97. int LabelSettings::get_font_size() const {
  98. return font_size;
  99. }
  100. void LabelSettings::set_font_color(const Color &p_color) {
  101. if (font_color != p_color) {
  102. font_color = p_color;
  103. emit_changed();
  104. }
  105. }
  106. Color LabelSettings::get_font_color() const {
  107. return font_color;
  108. }
  109. void LabelSettings::set_outline_size(int p_size) {
  110. if (outline_size != p_size) {
  111. outline_size = p_size;
  112. emit_changed();
  113. }
  114. }
  115. int LabelSettings::get_outline_size() const {
  116. return outline_size;
  117. }
  118. void LabelSettings::set_outline_color(const Color &p_color) {
  119. if (outline_color != p_color) {
  120. outline_color = p_color;
  121. emit_changed();
  122. }
  123. }
  124. Color LabelSettings::get_outline_color() const {
  125. return outline_color;
  126. }
  127. void LabelSettings::set_shadow_size(int p_size) {
  128. if (shadow_size != p_size) {
  129. shadow_size = p_size;
  130. emit_changed();
  131. }
  132. }
  133. int LabelSettings::get_shadow_size() const {
  134. return shadow_size;
  135. }
  136. void LabelSettings::set_shadow_color(const Color &p_color) {
  137. if (shadow_color != p_color) {
  138. shadow_color = p_color;
  139. emit_changed();
  140. }
  141. }
  142. Color LabelSettings::get_shadow_color() const {
  143. return shadow_color;
  144. }
  145. void LabelSettings::set_shadow_offset(const Vector2 &p_offset) {
  146. if (shadow_offset != p_offset) {
  147. shadow_offset = p_offset;
  148. emit_changed();
  149. }
  150. }
  151. Vector2 LabelSettings::get_shadow_offset() const {
  152. return shadow_offset;
  153. }