label_settings.cpp 7.1 KB

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