mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[flutter] Attachment wrapper scaffolds, PointAttachment wrapper.
This commit is contained in:
parent
e0611d7499
commit
2d70bc7349
@ -944,7 +944,7 @@ class Slot {
|
||||
Attachment? getAttachment() {
|
||||
final attachment = _bindings.spine_slot_get_attachment(_slot);
|
||||
if (attachment.address == nullptr.address) return null;
|
||||
return Attachment._(attachment);
|
||||
return Attachment._toSubclass(attachment);
|
||||
}
|
||||
|
||||
void setAttachment(Attachment? attachment) {
|
||||
@ -968,7 +968,8 @@ enum AttachmentType {
|
||||
final int value;
|
||||
const AttachmentType(this.value);
|
||||
}
|
||||
class Attachment {
|
||||
|
||||
abstract class Attachment {
|
||||
final spine_attachment _attachment;
|
||||
|
||||
Attachment._(this._attachment);
|
||||
@ -982,6 +983,107 @@ class Attachment {
|
||||
final type = _bindings.spine_attachment_get_type(_attachment);
|
||||
return AttachmentType.values[type];
|
||||
}
|
||||
|
||||
static Attachment _toSubclass(spine_attachment attachment) {
|
||||
final type = AttachmentType.values[_bindings.spine_attachment_get_type(attachment)];
|
||||
switch(type) {
|
||||
case AttachmentType.Region:
|
||||
return RegionAttachment._(attachment);
|
||||
case AttachmentType.Mesh:
|
||||
return MeshAttachment._(attachment);
|
||||
case AttachmentType.Clipping:
|
||||
return ClippingAttachment._(attachment);
|
||||
case AttachmentType.BoundingBox:
|
||||
return BoundingBoxAttachment._(attachment);
|
||||
case AttachmentType.Path:
|
||||
return PathAttachment._(attachment);
|
||||
case AttachmentType.Point:
|
||||
return PointAttachment._(attachment);
|
||||
}
|
||||
}
|
||||
|
||||
Attachment copy() {
|
||||
return _toSubclass(_bindings.spine_attachment_copy(_attachment));
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_bindings.spine_attachment_dispose(_attachment);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME
|
||||
class RegionAttachment extends Attachment {
|
||||
RegionAttachment._(spine_attachment attachment): super._(attachment);
|
||||
}
|
||||
|
||||
class VertexAttachment extends Attachment {
|
||||
VertexAttachment._(spine_attachment attachment): super._(attachment);
|
||||
}
|
||||
|
||||
// FIXME
|
||||
class MeshAttachment extends VertexAttachment {
|
||||
MeshAttachment._(spine_attachment attachment): super._(attachment);
|
||||
}
|
||||
|
||||
// FIXME
|
||||
class ClippingAttachment extends VertexAttachment {
|
||||
ClippingAttachment._(spine_attachment attachment): super._(attachment);
|
||||
}
|
||||
|
||||
// FIXME
|
||||
class BoundingBoxAttachment extends VertexAttachment {
|
||||
BoundingBoxAttachment._(spine_attachment attachment): super._(attachment);
|
||||
}
|
||||
|
||||
// FIXME
|
||||
class PathAttachment extends VertexAttachment {
|
||||
PathAttachment._(spine_attachment attachment): super._(attachment);
|
||||
}
|
||||
|
||||
class PointAttachment extends Attachment {
|
||||
PointAttachment._(spine_attachment attachment): super._(attachment);
|
||||
|
||||
Vector2 computeWorldPosition(Bone bone) {
|
||||
final position = _bindings.spine_point_attachment_compute_world_position(_attachment, bone._bone);
|
||||
return Vector2(position.x, position.y);
|
||||
}
|
||||
|
||||
double computeWorldRotation(Bone bone) {
|
||||
return _bindings.spine_point_attachment_compute_world_rotation(_attachment, bone._bone);
|
||||
}
|
||||
|
||||
double getX() {
|
||||
return _bindings.spine_point_attachment_get_x(_attachment);
|
||||
}
|
||||
|
||||
void setX(double x) {
|
||||
_bindings.spine_point_attachment_set_x(_attachment, x);
|
||||
}
|
||||
|
||||
double getY() {
|
||||
return _bindings.spine_point_attachment_get_y(_attachment);
|
||||
}
|
||||
|
||||
void setY(double y) {
|
||||
_bindings.spine_point_attachment_set_y(_attachment, y);
|
||||
}
|
||||
|
||||
double getRotation() {
|
||||
return _bindings.spine_point_attachment_get_rotation(_attachment);
|
||||
}
|
||||
|
||||
void setRotation(double rotation) {
|
||||
_bindings.spine_point_attachment_set_x(_attachment, rotation);
|
||||
}
|
||||
|
||||
Color getColor() {
|
||||
final color = _bindings.spine_point_attachment_get_color(_attachment);
|
||||
return Color(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void setColor(double r, double g, double b, double a) {
|
||||
_bindings.spine_point_attachment_set_color(_attachment, r, g, b, a);
|
||||
}
|
||||
}
|
||||
|
||||
class SkinEntry {
|
||||
@ -992,6 +1094,7 @@ class SkinEntry {
|
||||
SkinEntry(this.slotIndex, this.name, this.attachment);
|
||||
}
|
||||
|
||||
// FIXME add a way to create a new skin
|
||||
class Skin {
|
||||
final spine_skin _skin;
|
||||
|
||||
@ -1008,7 +1111,7 @@ class Skin {
|
||||
final attachment = _bindings.spine_skin_get_attachment(_skin, slotIndex, nativeName.cast());
|
||||
malloc.free(nativeName);
|
||||
if (attachment.address == nullptr.address) return null;
|
||||
return Attachment._(attachment);
|
||||
return Attachment._toSubclass(attachment);
|
||||
}
|
||||
|
||||
void removeAttachment(int slotIndex, String name) {
|
||||
@ -1033,7 +1136,7 @@ class Skin {
|
||||
for (int i = 0; i < numEntries; i++) {
|
||||
final entry = entries.ref.entries[i];
|
||||
Pointer<Utf8> name = entry.name.cast();
|
||||
result.add(SkinEntry(entry.slotIndex, name.toDartString(), entry.attachment.address == nullptr.address ? null : Attachment._(entry.attachment)));
|
||||
result.add(SkinEntry(entry.slotIndex, name.toDartString(), entry.attachment.address == nullptr.address ? null : Attachment._toSubclass(entry.attachment)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -1701,7 +1804,7 @@ class Skeleton {
|
||||
malloc.free(slotNameNative);
|
||||
malloc.free(attachmentNameNative);
|
||||
if (attachment.address == nullptr.address) return null;
|
||||
return Attachment._(attachment);
|
||||
return Attachment._toSubclass(attachment);
|
||||
}
|
||||
|
||||
Attachment? getAttachment(int slotIndex, String attachmentName) {
|
||||
@ -1709,7 +1812,7 @@ class Skeleton {
|
||||
final attachment = _bindings.spine_skeleton_get_attachment(_skeleton, slotIndex, attachmentNameNative.cast());
|
||||
malloc.free(attachmentNameNative);
|
||||
if (attachment.address == nullptr.address) return null;
|
||||
return Attachment._(attachment);
|
||||
return Attachment._toSubclass(attachment);
|
||||
}
|
||||
|
||||
void setAttachment(String slotName, String attachmentName) {
|
||||
@ -1879,6 +1982,7 @@ class Skeleton {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME expose timelines and apply?
|
||||
class Animation {
|
||||
final spine_animation _animation;
|
||||
|
||||
|
||||
@ -4581,6 +4581,205 @@ class SpineFlutterBindings {
|
||||
late final _spine_attachment_get_type = _spine_attachment_get_typePtr
|
||||
.asFunction<int Function(spine_attachment)>();
|
||||
|
||||
spine_attachment spine_attachment_copy(
|
||||
spine_attachment attachment,
|
||||
) {
|
||||
return _spine_attachment_copy(
|
||||
attachment,
|
||||
);
|
||||
}
|
||||
|
||||
late final _spine_attachment_copyPtr =
|
||||
_lookup<ffi.NativeFunction<spine_attachment Function(spine_attachment)>>(
|
||||
'spine_attachment_copy');
|
||||
late final _spine_attachment_copy = _spine_attachment_copyPtr
|
||||
.asFunction<spine_attachment Function(spine_attachment)>();
|
||||
|
||||
void spine_attachment_dispose(
|
||||
spine_attachment attachment,
|
||||
) {
|
||||
return _spine_attachment_dispose(
|
||||
attachment,
|
||||
);
|
||||
}
|
||||
|
||||
late final _spine_attachment_disposePtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(spine_attachment)>>(
|
||||
'spine_attachment_dispose');
|
||||
late final _spine_attachment_dispose = _spine_attachment_disposePtr
|
||||
.asFunction<void Function(spine_attachment)>();
|
||||
|
||||
spine_vector spine_point_attachment_compute_world_position(
|
||||
spine_point_attachment attachment,
|
||||
spine_bone bone,
|
||||
) {
|
||||
return _spine_point_attachment_compute_world_position(
|
||||
attachment,
|
||||
bone,
|
||||
);
|
||||
}
|
||||
|
||||
late final _spine_point_attachment_compute_world_positionPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
spine_vector Function(spine_point_attachment,
|
||||
spine_bone)>>('spine_point_attachment_compute_world_position');
|
||||
late final _spine_point_attachment_compute_world_position =
|
||||
_spine_point_attachment_compute_world_positionPtr.asFunction<
|
||||
spine_vector Function(spine_point_attachment, spine_bone)>();
|
||||
|
||||
double spine_point_attachment_compute_world_rotation(
|
||||
spine_point_attachment attachment,
|
||||
spine_bone bone,
|
||||
) {
|
||||
return _spine_point_attachment_compute_world_rotation(
|
||||
attachment,
|
||||
bone,
|
||||
);
|
||||
}
|
||||
|
||||
late final _spine_point_attachment_compute_world_rotationPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Float Function(spine_point_attachment,
|
||||
spine_bone)>>('spine_point_attachment_compute_world_rotation');
|
||||
late final _spine_point_attachment_compute_world_rotation =
|
||||
_spine_point_attachment_compute_world_rotationPtr
|
||||
.asFunction<double Function(spine_point_attachment, spine_bone)>();
|
||||
|
||||
double spine_point_attachment_get_x(
|
||||
spine_point_attachment attachment,
|
||||
) {
|
||||
return _spine_point_attachment_get_x(
|
||||
attachment,
|
||||
);
|
||||
}
|
||||
|
||||
late final _spine_point_attachment_get_xPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Float Function(spine_point_attachment)>>(
|
||||
'spine_point_attachment_get_x');
|
||||
late final _spine_point_attachment_get_x = _spine_point_attachment_get_xPtr
|
||||
.asFunction<double Function(spine_point_attachment)>();
|
||||
|
||||
void spine_point_attachment_set_x(
|
||||
spine_point_attachment attachment,
|
||||
double x,
|
||||
) {
|
||||
return _spine_point_attachment_set_x(
|
||||
attachment,
|
||||
x,
|
||||
);
|
||||
}
|
||||
|
||||
late final _spine_point_attachment_set_xPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(spine_point_attachment,
|
||||
ffi.Float)>>('spine_point_attachment_set_x');
|
||||
late final _spine_point_attachment_set_x = _spine_point_attachment_set_xPtr
|
||||
.asFunction<void Function(spine_point_attachment, double)>();
|
||||
|
||||
double spine_point_attachment_get_y(
|
||||
spine_point_attachment attachment,
|
||||
) {
|
||||
return _spine_point_attachment_get_y(
|
||||
attachment,
|
||||
);
|
||||
}
|
||||
|
||||
late final _spine_point_attachment_get_yPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Float Function(spine_point_attachment)>>(
|
||||
'spine_point_attachment_get_y');
|
||||
late final _spine_point_attachment_get_y = _spine_point_attachment_get_yPtr
|
||||
.asFunction<double Function(spine_point_attachment)>();
|
||||
|
||||
void spine_point_attachment_set_y(
|
||||
spine_point_attachment attachment,
|
||||
double y,
|
||||
) {
|
||||
return _spine_point_attachment_set_y(
|
||||
attachment,
|
||||
y,
|
||||
);
|
||||
}
|
||||
|
||||
late final _spine_point_attachment_set_yPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(spine_point_attachment,
|
||||
ffi.Float)>>('spine_point_attachment_set_y');
|
||||
late final _spine_point_attachment_set_y = _spine_point_attachment_set_yPtr
|
||||
.asFunction<void Function(spine_point_attachment, double)>();
|
||||
|
||||
double spine_point_attachment_get_rotation(
|
||||
spine_point_attachment attachment,
|
||||
) {
|
||||
return _spine_point_attachment_get_rotation(
|
||||
attachment,
|
||||
);
|
||||
}
|
||||
|
||||
late final _spine_point_attachment_get_rotationPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Float Function(spine_point_attachment)>>(
|
||||
'spine_point_attachment_get_rotation');
|
||||
late final _spine_point_attachment_get_rotation =
|
||||
_spine_point_attachment_get_rotationPtr
|
||||
.asFunction<double Function(spine_point_attachment)>();
|
||||
|
||||
void spine_point_attachment_set_rotation(
|
||||
spine_point_attachment attachment,
|
||||
double rotation,
|
||||
) {
|
||||
return _spine_point_attachment_set_rotation(
|
||||
attachment,
|
||||
rotation,
|
||||
);
|
||||
}
|
||||
|
||||
late final _spine_point_attachment_set_rotationPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(spine_point_attachment,
|
||||
ffi.Float)>>('spine_point_attachment_set_rotation');
|
||||
late final _spine_point_attachment_set_rotation =
|
||||
_spine_point_attachment_set_rotationPtr
|
||||
.asFunction<void Function(spine_point_attachment, double)>();
|
||||
|
||||
spine_color spine_point_attachment_get_color(
|
||||
spine_point_attachment attachment,
|
||||
) {
|
||||
return _spine_point_attachment_get_color(
|
||||
attachment,
|
||||
);
|
||||
}
|
||||
|
||||
late final _spine_point_attachment_get_colorPtr =
|
||||
_lookup<ffi.NativeFunction<spine_color Function(spine_point_attachment)>>(
|
||||
'spine_point_attachment_get_color');
|
||||
late final _spine_point_attachment_get_color =
|
||||
_spine_point_attachment_get_colorPtr
|
||||
.asFunction<spine_color Function(spine_point_attachment)>();
|
||||
|
||||
void spine_point_attachment_set_color(
|
||||
spine_point_attachment attachment,
|
||||
double r,
|
||||
double g,
|
||||
double b,
|
||||
double a,
|
||||
) {
|
||||
return _spine_point_attachment_set_color(
|
||||
attachment,
|
||||
r,
|
||||
g,
|
||||
b,
|
||||
a,
|
||||
);
|
||||
}
|
||||
|
||||
late final _spine_point_attachment_set_colorPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(spine_point_attachment, ffi.Float, ffi.Float,
|
||||
ffi.Float, ffi.Float)>>('spine_point_attachment_set_color');
|
||||
late final _spine_point_attachment_set_color =
|
||||
_spine_point_attachment_set_colorPtr.asFunction<
|
||||
void Function(
|
||||
spine_point_attachment, double, double, double, double)>();
|
||||
|
||||
void spine_skin_set_attachment(
|
||||
spine_skin skin,
|
||||
int slotIndex,
|
||||
@ -7119,4 +7318,5 @@ typedef spine_slot = ffi.Pointer<ffi.Void>;
|
||||
typedef spine_ik_constraint = ffi.Pointer<ffi.Void>;
|
||||
typedef spine_transform_constraint = ffi.Pointer<ffi.Void>;
|
||||
typedef spine_path_constraint = ffi.Pointer<ffi.Void>;
|
||||
typedef spine_point_attachment = ffi.Pointer<ffi.Void>;
|
||||
typedef spine_constraint_data = ffi.Pointer<ffi.Void>;
|
||||
|
||||
@ -1987,6 +1987,83 @@ FFI_PLUGIN_EXPORT spine_attachment_type spine_attachment_get_type(spine_attachme
|
||||
}
|
||||
}
|
||||
|
||||
FFI_PLUGIN_EXPORT spine_attachment spine_attachment_copy(spine_attachment attachment) {
|
||||
if (attachment == nullptr) return nullptr;
|
||||
Attachment *_attachment = (Attachment*)attachment;
|
||||
return (spine_attachment)_attachment->copy();
|
||||
}
|
||||
|
||||
FFI_PLUGIN_EXPORT void spine_attachment_dispose(spine_attachment attachment) {
|
||||
if (attachment == nullptr) return;
|
||||
Attachment *_attachment = (Attachment*)attachment;
|
||||
delete _attachment;
|
||||
}
|
||||
|
||||
FFI_PLUGIN_EXPORT spine_vector spine_point_attachment_compute_world_position(spine_point_attachment attachment, spine_bone bone) {
|
||||
spine_vector result = { 0, 0 };
|
||||
if (attachment == nullptr) return result;
|
||||
PointAttachment *_attachment = (PointAttachment*)attachment;
|
||||
_attachment->computeWorldPosition(*(Bone*)bone, result.x, result.y);
|
||||
return result;
|
||||
}
|
||||
|
||||
FFI_PLUGIN_EXPORT float spine_point_attachment_compute_world_rotation(spine_point_attachment attachment, spine_bone bone) {
|
||||
if (attachment == nullptr) return 0;
|
||||
PointAttachment *_attachment = (PointAttachment*)attachment;
|
||||
return _attachment->computeWorldRotation(*(Bone*)bone);
|
||||
}
|
||||
|
||||
FFI_PLUGIN_EXPORT float spine_point_attachment_get_x(spine_point_attachment attachment) {
|
||||
if (attachment == nullptr) return 0;
|
||||
PointAttachment *_attachment = (PointAttachment*)attachment;
|
||||
return _attachment->getX();
|
||||
}
|
||||
|
||||
FFI_PLUGIN_EXPORT void spine_point_attachment_set_x(spine_point_attachment attachment, float x) {
|
||||
if (attachment == nullptr) return;
|
||||
PointAttachment *_attachment = (PointAttachment*)attachment;
|
||||
_attachment->setX(x);
|
||||
}
|
||||
|
||||
FFI_PLUGIN_EXPORT float spine_point_attachment_get_y(spine_point_attachment attachment) {
|
||||
if (attachment == nullptr) return 0;
|
||||
PointAttachment *_attachment = (PointAttachment*)attachment;
|
||||
return _attachment->getY();
|
||||
}
|
||||
|
||||
FFI_PLUGIN_EXPORT void spine_point_attachment_set_y(spine_point_attachment attachment, float y) {
|
||||
if (attachment == nullptr) return;
|
||||
PointAttachment *_attachment = (PointAttachment*)attachment;
|
||||
_attachment->setY(y);
|
||||
}
|
||||
|
||||
FFI_PLUGIN_EXPORT float spine_point_attachment_get_rotation(spine_point_attachment attachment) {
|
||||
if (attachment == nullptr) return 0;
|
||||
PointAttachment *_attachment = (PointAttachment*)attachment;
|
||||
return _attachment->getRotation();
|
||||
}
|
||||
|
||||
FFI_PLUGIN_EXPORT void spine_point_attachment_set_rotation(spine_point_attachment attachment, float rotation) {
|
||||
if (attachment == nullptr) return;
|
||||
PointAttachment *_attachment = (PointAttachment*)attachment;
|
||||
_attachment->setRotation(rotation);
|
||||
}
|
||||
|
||||
FFI_PLUGIN_EXPORT spine_color spine_point_attachment_get_color(spine_point_attachment attachment) {
|
||||
spine_color result = { 0, 0, 0, 0 };
|
||||
if (attachment == nullptr) return result;
|
||||
PointAttachment *_attachment = (PointAttachment*)attachment;
|
||||
Color &color = _attachment->getColor();
|
||||
result = { color.r, color.g, color.b, color.a };
|
||||
return result;
|
||||
}
|
||||
|
||||
FFI_PLUGIN_EXPORT void spine_point_attachment_set_color(spine_point_attachment attachment, float r, float g, float b, float a) {
|
||||
if (attachment == nullptr) return;
|
||||
PointAttachment *_attachment = (PointAttachment*)attachment;
|
||||
_attachment->getColor().set(r, g, b, a);
|
||||
}
|
||||
|
||||
// Skin
|
||||
FFI_PLUGIN_EXPORT void spine_skin_set_attachment(spine_skin skin, int slotIndex, const char* name, spine_attachment attachment) {
|
||||
if (skin == nullptr) return;
|
||||
|
||||
@ -31,6 +31,12 @@ typedef void* spine_slot;
|
||||
typedef void* spine_slot_data;
|
||||
typedef void* spine_skin;
|
||||
typedef void* spine_attachment;
|
||||
typedef void* spine_point_attachment;
|
||||
typedef void* spine_region_attachment;
|
||||
typedef void* spine_mesh_attachment;
|
||||
typedef void* spine_clipping_attachment;
|
||||
typedef void* spine_bounding_box_attachment;
|
||||
typedef void* spine_path_attachment;
|
||||
typedef void* spine_constraint;
|
||||
typedef void* spine_constraint_data;
|
||||
typedef void* spine_ik_constraint;
|
||||
@ -467,6 +473,19 @@ FFI_PLUGIN_EXPORT void spine_bone_set_is_active(spine_bone bone, int isActive);
|
||||
|
||||
FFI_PLUGIN_EXPORT const char* spine_attachment_get_name(spine_attachment attachment);
|
||||
FFI_PLUGIN_EXPORT spine_attachment_type spine_attachment_get_type(spine_attachment attachment);
|
||||
FFI_PLUGIN_EXPORT spine_attachment spine_attachment_copy(spine_attachment attachment);
|
||||
FFI_PLUGIN_EXPORT void spine_attachment_dispose(spine_attachment attachment);
|
||||
|
||||
FFI_PLUGIN_EXPORT spine_vector spine_point_attachment_compute_world_position(spine_point_attachment attachment, spine_bone bone);
|
||||
FFI_PLUGIN_EXPORT float spine_point_attachment_compute_world_rotation(spine_point_attachment attachment, spine_bone bone);
|
||||
FFI_PLUGIN_EXPORT float spine_point_attachment_get_x(spine_point_attachment attachment);
|
||||
FFI_PLUGIN_EXPORT void spine_point_attachment_set_x(spine_point_attachment attachment, float x);
|
||||
FFI_PLUGIN_EXPORT float spine_point_attachment_get_y(spine_point_attachment attachment);
|
||||
FFI_PLUGIN_EXPORT void spine_point_attachment_set_y(spine_point_attachment attachment, float y);
|
||||
FFI_PLUGIN_EXPORT float spine_point_attachment_get_rotation(spine_point_attachment attachment);
|
||||
FFI_PLUGIN_EXPORT void spine_point_attachment_set_rotation(spine_point_attachment attachment, float rotation);
|
||||
FFI_PLUGIN_EXPORT spine_color spine_point_attachment_get_color(spine_point_attachment attachment);
|
||||
FFI_PLUGIN_EXPORT void spine_point_attachment_set_color(spine_point_attachment attachment, float r, float g, float b, float a);
|
||||
|
||||
FFI_PLUGIN_EXPORT void spine_skin_set_attachment(spine_skin skin, int slotIndex, const char* name, spine_attachment attachment);
|
||||
FFI_PLUGIN_EXPORT spine_attachment spine_skin_get_attachment(spine_skin skin, int slotIndex, const char* name);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user