SpineBoneData.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated April 5, 2025. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2025, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #include "SpineBoneData.h"
  30. #include "SpineCommon.h"
  31. void SpineBoneData::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("get_index"), &SpineBoneData::get_index);
  33. ClassDB::bind_method(D_METHOD("get_bone_name"), &SpineBoneData::get_bone_name);
  34. ClassDB::bind_method(D_METHOD("get_parent"), &SpineBoneData::get_parent);
  35. ClassDB::bind_method(D_METHOD("get_length"), &SpineBoneData::get_length);
  36. ClassDB::bind_method(D_METHOD("set_length", "v"), &SpineBoneData::set_length);
  37. ClassDB::bind_method(D_METHOD("get_x"), &SpineBoneData::get_x);
  38. ClassDB::bind_method(D_METHOD("set_x", "v"), &SpineBoneData::set_x);
  39. ClassDB::bind_method(D_METHOD("get_y"), &SpineBoneData::get_y);
  40. ClassDB::bind_method(D_METHOD("set_y", "v"), &SpineBoneData::set_y);
  41. ClassDB::bind_method(D_METHOD("get_rotation"), &SpineBoneData::get_rotation);
  42. ClassDB::bind_method(D_METHOD("set_rotation", "v"), &SpineBoneData::set_rotation);
  43. ClassDB::bind_method(D_METHOD("get_scale_x"), &SpineBoneData::get_scale_x);
  44. ClassDB::bind_method(D_METHOD("set_scale_x", "v"), &SpineBoneData::set_scale_x);
  45. ClassDB::bind_method(D_METHOD("get_scale_y"), &SpineBoneData::get_scale_y);
  46. ClassDB::bind_method(D_METHOD("set_scale_y", "v"), &SpineBoneData::set_scale_y);
  47. ClassDB::bind_method(D_METHOD("get_shear_x"), &SpineBoneData::get_shear_x);
  48. ClassDB::bind_method(D_METHOD("set_shear_x", "v"), &SpineBoneData::set_shear_x);
  49. ClassDB::bind_method(D_METHOD("get_shear_y"), &SpineBoneData::get_shear_y);
  50. ClassDB::bind_method(D_METHOD("set_shear_y", "v"), &SpineBoneData::set_shear_y);
  51. ClassDB::bind_method(D_METHOD("get_inherit"), &SpineBoneData::get_inherit);
  52. ClassDB::bind_method(D_METHOD("set_inherit", "v"), &SpineBoneData::set_inherit);
  53. ClassDB::bind_method(D_METHOD("is_skin_required"), &SpineBoneData::is_skin_required);
  54. ClassDB::bind_method(D_METHOD("set_skin_required", "v"), &SpineBoneData::set_skin_required);
  55. ClassDB::bind_method(D_METHOD("get_color"), &SpineBoneData::get_color);
  56. ClassDB::bind_method(D_METHOD("set_color", "v"), &SpineBoneData::set_color);
  57. ClassDB::bind_method(D_METHOD("get_icon"), &SpineBoneData::get_icon);
  58. ClassDB::bind_method(D_METHOD("set_visible", "v"), &SpineBoneData::set_visible);
  59. ClassDB::bind_method(D_METHOD("is_visible"), &SpineBoneData::is_visible);
  60. }
  61. int SpineBoneData::get_index() {
  62. SPINE_CHECK(get_spine_object(), 0)
  63. return get_spine_object()->getIndex();
  64. }
  65. String SpineBoneData::get_bone_name() {
  66. SPINE_CHECK(get_spine_object(), "")
  67. String name;
  68. name.parse_utf8(get_spine_object()->getName().buffer());
  69. return name;
  70. }
  71. Ref<SpineBoneData> SpineBoneData::get_parent() {
  72. SPINE_CHECK(get_spine_object(), nullptr)
  73. auto parent = get_spine_object()->getParent();
  74. if (!parent) return nullptr;
  75. Ref<SpineBoneData> parent_ref(memnew(SpineBoneData));
  76. parent_ref->set_spine_object(get_spine_owner(), parent);
  77. return parent_ref;
  78. }
  79. float SpineBoneData::get_length() {
  80. SPINE_CHECK(get_spine_object(), 0)
  81. return get_spine_object()->getLength();
  82. }
  83. void SpineBoneData::set_length(float v) {
  84. SPINE_CHECK(get_spine_object(), )
  85. get_spine_object()->setLength(v);
  86. }
  87. float SpineBoneData::get_x() {
  88. SPINE_CHECK(get_spine_object(), 0)
  89. return get_spine_object()->getX();
  90. }
  91. void SpineBoneData::set_x(float v) {
  92. SPINE_CHECK(get_spine_object(), )
  93. get_spine_object()->setX(v);
  94. }
  95. float SpineBoneData::get_y() {
  96. SPINE_CHECK(get_spine_object(), 0)
  97. return get_spine_object()->getY();
  98. }
  99. void SpineBoneData::set_y(float v) {
  100. SPINE_CHECK(get_spine_object(), )
  101. get_spine_object()->setY(v);
  102. }
  103. float SpineBoneData::get_rotation() {
  104. SPINE_CHECK(get_spine_object(), 0)
  105. return get_spine_object()->getRotation();
  106. }
  107. void SpineBoneData::set_rotation(float v) {
  108. SPINE_CHECK(get_spine_object(), )
  109. get_spine_object()->setRotation(v);
  110. }
  111. float SpineBoneData::get_scale_x() {
  112. SPINE_CHECK(get_spine_object(), 0)
  113. return get_spine_object()->getScaleX();
  114. }
  115. void SpineBoneData::set_scale_x(float v) {
  116. SPINE_CHECK(get_spine_object(), )
  117. get_spine_object()->setScaleX(v);
  118. }
  119. float SpineBoneData::get_scale_y() {
  120. SPINE_CHECK(get_spine_object(), 0)
  121. return get_spine_object()->getScaleY();
  122. }
  123. void SpineBoneData::set_scale_y(float v) {
  124. SPINE_CHECK(get_spine_object(), )
  125. get_spine_object()->setScaleY(v);
  126. }
  127. float SpineBoneData::get_shear_x() {
  128. SPINE_CHECK(get_spine_object(), 0)
  129. return get_spine_object()->getShearX();
  130. }
  131. void SpineBoneData::set_shear_x(float v) {
  132. SPINE_CHECK(get_spine_object(), )
  133. get_spine_object()->setShearX(v);
  134. }
  135. float SpineBoneData::get_shear_y() {
  136. SPINE_CHECK(get_spine_object(), 0)
  137. return get_spine_object()->getShearY();
  138. }
  139. void SpineBoneData::set_shear_y(float v) {
  140. SPINE_CHECK(get_spine_object(), )
  141. get_spine_object()->setShearY(v);
  142. }
  143. SpineConstant::Inherit SpineBoneData::get_inherit() {
  144. SPINE_CHECK(get_spine_object(), SpineConstant::Inherit::Inherit_Normal)
  145. return (SpineConstant::Inherit) get_spine_object()->getInherit();
  146. }
  147. void SpineBoneData::set_inherit(SpineConstant::Inherit v) {
  148. SPINE_CHECK(get_spine_object(), )
  149. get_spine_object()->setInherit((spine::Inherit) v);
  150. }
  151. bool SpineBoneData::is_skin_required() {
  152. SPINE_CHECK(get_spine_object(), false)
  153. return get_spine_object()->isSkinRequired();
  154. }
  155. void SpineBoneData::set_skin_required(bool v) {
  156. SPINE_CHECK(get_spine_object(), )
  157. get_spine_object()->setSkinRequired(v);
  158. }
  159. Color SpineBoneData::get_color() {
  160. SPINE_CHECK(get_spine_object(), Color())
  161. auto color = get_spine_object()->getColor();
  162. return Color(color.r, color.g, color.b, color.a);
  163. }
  164. void SpineBoneData::set_color(Color color) {
  165. SPINE_CHECK(get_spine_object(), )
  166. get_spine_object()->getColor().set(color.r, color.g, color.b, color.a);
  167. }
  168. String SpineBoneData::get_icon() {
  169. SPINE_CHECK(get_spine_object(), "")
  170. return get_spine_object()->getIcon().buffer();
  171. }
  172. bool SpineBoneData::is_visible() {
  173. SPINE_CHECK(get_spine_object(), true)
  174. return get_spine_object()->isVisible();
  175. }
  176. void SpineBoneData::set_visible(bool v) {
  177. SPINE_CHECK(get_spine_object(), )
  178. get_spine_object()->setVisible(v);
  179. }