label_settings.cpp 7.7 KB

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