[c] extension methods for bounds, worldToLocal etc. SPINE_OPAQUE_TYPE is now fully opaque.

This commit is contained in:
Mario Zechner 2025-07-30 13:22:59 +02:00
parent f9fefee0c8
commit eaa4d5dd54
3 changed files with 59 additions and 60 deletions

View File

@ -58,28 +58,22 @@
#if defined(__clang__)
/* Clang needs to suppress both pedantic and C/C++ compatibility warnings */
#define SPINE_OPAQUE_TYPE(name) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wpedantic\"") \
_Pragma("clang diagnostic ignored \"-Wextern-c-compat\"") \
typedef struct name##_wrapper { \
} name##_wrapper; \
_Pragma("clang diagnostic pop") \
typedef name##_wrapper *name;
#define SPINE_OPAQUE_TYPE(name) \
_Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wpedantic\"") \
_Pragma("clang diagnostic ignored \"-Wextern-c-compat\"") typedef struct name##_wrapper { \
} name##_wrapper; \
_Pragma("clang diagnostic pop") typedef name##_wrapper *name;
#elif defined(__GNUC__)
/* GCC only needs to suppress pedantic warning */
#define SPINE_OPAQUE_TYPE(name) \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wpedantic\"") \
typedef struct name##_wrapper { \
} name##_wrapper; \
_Pragma("GCC diagnostic pop") \
typedef name##_wrapper *name;
#define SPINE_OPAQUE_TYPE(name) \
_Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wpedantic\"") typedef struct name##_wrapper { \
} name##_wrapper; \
_Pragma("GCC diagnostic pop") typedef name##_wrapper *name;
#else
/* Other compilers - generic version */
#define SPINE_OPAQUE_TYPE(name) \
typedef struct name##_wrapper { \
} name##_wrapper; \
#define SPINE_OPAQUE_TYPE(name) \
typedef struct name##_wrapper { \
} name##_wrapper; \
typedef name##_wrapper *name;
#endif

View File

@ -495,51 +495,70 @@ spine_skin_entries spine_skin_get_entries(spine_skin skin) {
}
// Skeleton bounds function
spine_bounds spine_skeleton_get_bounds(spine_skeleton skeleton) {
spine_bounds bounds = {0, 0, 0, 0};
if (!skeleton) return bounds;
void spine_skeleton_get_bounds(spine_skeleton self, spine_array_float output) {
spine_array_float_clear(output);
if (!self) return;
Skeleton *_skeleton = (Skeleton *) skeleton;
_skeleton->getBounds(bounds.x, bounds.y, bounds.width, bounds.height);
return bounds;
Skeleton *_skeleton = (Skeleton *) self;
float x, y, width, height;
_skeleton->getBounds(x, y, width, height);
spine_array_float_add(output, x);
spine_array_float_add(output, y);
spine_array_float_add(output, width);
spine_array_float_add(output, height);
}
spine_vector spine_skeleton_get_position_v(spine_skeleton skeleton) {
if (!skeleton) return {0, 0};
Skeleton *_skeleton = (Skeleton *) skeleton;
void spine_skeleton_get_position_v(spine_skeleton self, spine_array_float output) {
spine_array_float_clear(output);
if (!self) return;
Skeleton *_skeleton = (Skeleton *) self;
float x, y;
_skeleton->getPosition(x, y);
return {x, y};
spine_array_float_add(output, x);
spine_array_float_add(output, y);
}
spine_vector spine_bone_pose_world_to_local_v(spine_bone_pose self, float world_x, float world_y) {
if (!self) return {0, 0};
void spine_bone_pose_world_to_local_v(spine_bone_pose self, float world_x, float world_y, spine_array_float output) {
spine_array_float_clear(output);
if (!self) return;
BonePose *_self = (BonePose *) self;
float localX, localY;
_self->worldToLocal(world_x, world_y, localX, localY);
return {localX, localY};
spine_array_float_add(output, localX);
spine_array_float_add(output, localY);
}
spine_vector spine_bone_pose_local_to_world_v(spine_bone_pose self, float local_x, float local_y) {
if (!self) return {0, 0};
void spine_bone_pose_local_to_world_v(spine_bone_pose self, float local_x, float local_y, spine_array_float output) {
spine_array_float_clear(output);
if (!self) return;
BonePose *_self = (BonePose *) self;
float worldX, worldY;
_self->localToWorld(local_x, local_y, worldX, worldY);
return {worldX, worldY};
spine_array_float_add(output, worldX);
spine_array_float_add(output, worldY);
}
spine_vector spine_bone_pose_world_to_parent_v(spine_bone_pose self, float world_x, float world_y) {
if (!self) return {0, 0};
void spine_bone_pose_world_to_parent_v(spine_bone_pose self, float world_x, float world_y, spine_array_float output) {
spine_array_float_clear(output);
if (!self) return;
BonePose *_self = (BonePose *) self;
float parentX, parentY;
_self->worldToParent(world_x, world_y, parentX, parentY);
return {parentX, parentY};
spine_array_float_add(output, parentX);
spine_array_float_add(output, parentY);
}
spine_vector spine_bone_pose_parent_to_world_v(spine_bone_pose self, float parent_x, float parent_y) {
if (!self) return {0, 0};
void spine_bone_pose_parent_to_world_v(spine_bone_pose self, float parent_x, float parent_y, spine_array_float output) {
spine_array_float_clear(output);
if (!self) return;
BonePose *_self = (BonePose *) self;
float worldX, worldY;
_self->parentToWorld(parent_x, parent_y, worldX, worldY);
return {worldX, worldY};
spine_array_float_add(output, worldX);
spine_array_float_add(output, worldY);
}

View File

@ -48,20 +48,6 @@ SPINE_OPAQUE_TYPE(spine_skin_entry)
SPINE_OPAQUE_TYPE(spine_skin_entries)
SPINE_OPAQUE_TYPE(spine_texture_loader)
// Bounds struct
typedef struct spine_bounds {
float x;
float y;
float width;
float height;
} spine_bounds;
// Vector struct
typedef struct spine_vector {
float x;
float y;
} spine_vector;
// Additional types
typedef void *spine_void;
typedef void (*spine_dispose_renderer_object)(void *);
@ -122,14 +108,14 @@ SPINE_C_API const char *spine_skin_entry_get_name(spine_skin_entry entry);
SPINE_C_API spine_attachment spine_skin_entry_get_attachment(spine_skin_entry entry);
// Skeleton functions
SPINE_C_API spine_bounds spine_skeleton_get_bounds(spine_skeleton skeleton);
SPINE_C_API spine_vector spine_skeleton_get_position_v(spine_skeleton skeleton);
SPINE_C_API void spine_skeleton_get_bounds(spine_skeleton skeleton, spine_array_float output);
SPINE_C_API void spine_skeleton_get_position_v(spine_skeleton skeleton, spine_array_float output);
// BonePose functions
SPINE_C_API spine_vector spine_bone_pose_world_to_local_v(spine_bone_pose self, float world_x, float world_y);
SPINE_C_API spine_vector spine_bone_pose_local_to_world_v(spine_bone_pose self, float local_x, float local_y);
SPINE_C_API spine_vector spine_bone_pose_world_to_parent_v(spine_bone_pose self, float world_x, float world_y);
SPINE_C_API spine_vector spine_bone_pose_parent_to_world_v(spine_bone_pose self, float parent_x, float parent_y);
SPINE_C_API void spine_bone_pose_world_to_local_v(spine_bone_pose self, float world_x, float world_y, spine_array_float output);
SPINE_C_API void spine_bone_pose_local_to_world_v(spine_bone_pose self, float local_x, float local_y, spine_array_float output);
SPINE_C_API void spine_bone_pose_world_to_parent_v(spine_bone_pose self, float world_x, float world_y, spine_array_float output);
SPINE_C_API void spine_bone_pose_parent_to_world_v(spine_bone_pose self, float parent_x, float parent_y, spine_array_float output);
#ifdef __cplusplus
}