Skip to content

Commit 648170f

Browse files
kikiloveswiftliqiang
and
liqiang
authored
[ios] Provide the ability to convert an Attachment into a BoundingBoxAttachment. (#2671)
Co-authored-by: liqiang <[email protected]>
1 parent a815fc4 commit 648170f

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

spine-cpp/spine-cpp-lite/spine-cpp-lite.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -2424,6 +2424,16 @@ spine_attachment spine_attachment_copy(spine_attachment attachment) {
24242424
return (spine_attachment) _attachment->copy();
24252425
}
24262426

2427+
spine_bounding_box_attachment spine_attachment_cast_to_bounding_box_attachment(spine_attachment attachment) {
2428+
if (attachment == nullptr) return nullptr;
2429+
Attachment *_attachment = (Attachment *)attachment;
2430+
if (_attachment->getRTTI().isExactly(BoundingBoxAttachment::rtti)) {
2431+
BoundingBoxAttachment *boundingBox = static_cast<BoundingBoxAttachment *>(_attachment);
2432+
return (spine_bounding_box_attachment)boundingBox;
2433+
}
2434+
return nullptr;
2435+
}
2436+
24272437
void spine_attachment_dispose(spine_attachment attachment) {
24282438
if (attachment == nullptr) return;
24292439
Attachment *_attachment = (Attachment *) attachment;

spine-cpp/spine-cpp-lite/spine-cpp-lite.h

+2
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,8 @@ SPINE_CPP_LITE_EXPORT const utf8 *spine_attachment_get_name(spine_attachment att
630630
SPINE_CPP_LITE_EXPORT spine_attachment_type spine_attachment_get_type(spine_attachment attachment);
631631
// @ignore
632632
SPINE_CPP_LITE_EXPORT spine_attachment spine_attachment_copy(spine_attachment attachment);
633+
// @optional
634+
SPINE_CPP_LITE_EXPORT spine_bounding_box_attachment spine_attachment_cast_to_bounding_box_attachment(spine_attachment attachment);
633635
SPINE_CPP_LITE_EXPORT void spine_attachment_dispose(spine_attachment attachment);
634636

635637
SPINE_CPP_LITE_EXPORT spine_vector spine_point_attachment_compute_world_position(spine_point_attachment attachment, spine_bone bone);

spine-ios/Sources/Spine/Spine.Generated.swift

+5
Original file line numberDiff line numberDiff line change
@@ -2553,6 +2553,11 @@ public final class Attachment: NSObject {
25532553
return spine_attachment_get_type(wrappee)
25542554
}
25552555

2556+
@discardableResult
2557+
public func castToBoundingBoxAttachment() -> BoundingBoxAttachment? {
2558+
return spine_attachment_cast_to_bounding_box_attachment(wrappee).flatMap { .init($0) }
2559+
}
2560+
25562561
public func dispose() {
25572562
if disposed { return }
25582563
disposed = true

0 commit comments

Comments
 (0)