From cf9a3a4109fe31a59e101da78a64c0b0738efbda Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Sun, 27 Apr 2014 22:02:44 +0200 Subject: [PATCH] Per attachment color. --- spine-c/include/spine/Attachment.h | 2 +- spine-c/include/spine/RegionAttachment.h | 1 + spine-c/src/spine/RegionAttachment.c | 4 ++++ spine-c/src/spine/SkeletonJson.c | 15 +++++++++++---- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/spine-c/include/spine/Attachment.h b/spine-c/include/spine/Attachment.h index 6388f3bf4..1fceeecfd 100644 --- a/spine-c/include/spine/Attachment.h +++ b/spine-c/include/spine/Attachment.h @@ -38,7 +38,7 @@ extern "C" { struct spSlot; typedef enum { - ATTACHMENT_REGION, ATTACHMENT_REGION_SEQUENCE, ATTACHMENT_BOUNDING_BOX + ATTACHMENT_REGION, ATTACHMENT_BOUNDING_BOX } spAttachmentType; typedef struct spAttachment spAttachment; diff --git a/spine-c/include/spine/RegionAttachment.h b/spine-c/include/spine/RegionAttachment.h index 4c7811839..d05019fb9 100644 --- a/spine-c/include/spine/RegionAttachment.h +++ b/spine-c/include/spine/RegionAttachment.h @@ -47,6 +47,7 @@ typedef struct spRegionAttachment spRegionAttachment; struct spRegionAttachment { spAttachment super; float x, y, scaleX, scaleY, rotation, width, height; + float r, g, b, a; void* rendererObject; int regionOffsetX, regionOffsetY; /* Pixels stripped from the bottom left, unrotated. */ diff --git a/spine-c/src/spine/RegionAttachment.c b/spine-c/src/spine/RegionAttachment.c index 159d17725..06eeec5f5 100644 --- a/spine-c/src/spine/RegionAttachment.c +++ b/spine-c/src/spine/RegionAttachment.c @@ -43,6 +43,10 @@ spRegionAttachment* spRegionAttachment_create (const char* name) { spRegionAttachment* self = NEW(spRegionAttachment); self->scaleX = 1; self->scaleY = 1; + self->r = 1; + self->g = 1; + self->b = 1; + self->a = 1; _spAttachment_init(SUPER(self), name, ATTACHMENT_REGION, _spRegionAttachment_dispose); return self; } diff --git a/spine-c/src/spine/SkeletonJson.c b/spine-c/src/spine/SkeletonJson.c index 023f33a72..c94172725 100644 --- a/spine-c/src/spine/SkeletonJson.c +++ b/spine-c/src/spine/SkeletonJson.c @@ -414,6 +414,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha spAttachment* attachment; const char* skinAttachmentName = attachmentMap->name; const char* attachmentName = Json_getString(attachmentMap, "name", skinAttachmentName); + const char* color; const char* typeString = Json_getString(attachmentMap, "type", "region"); spAttachmentType type; @@ -421,8 +422,6 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha type = ATTACHMENT_REGION; else if (strcmp(typeString, "boundingbox") == 0) type = ATTACHMENT_BOUNDING_BOX; - else if (strcmp(typeString, "regionsequence") == 0) - type = ATTACHMENT_REGION_SEQUENCE; else { spSkeletonData_dispose(skeletonData); _spSkeletonJson_setError(self, root, "Unknown attachment type: ", typeString); @@ -440,8 +439,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha } switch (attachment->type) { - case ATTACHMENT_REGION: - case ATTACHMENT_REGION_SEQUENCE: { + case ATTACHMENT_REGION: { spRegionAttachment* regionAttachment = (spRegionAttachment*)attachment; regionAttachment->x = Json_getFloat(attachmentMap, "x", 0) * self->scale; regionAttachment->y = Json_getFloat(attachmentMap, "y", 0) * self->scale; @@ -450,6 +448,15 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha regionAttachment->rotation = Json_getFloat(attachmentMap, "rotation", 0); regionAttachment->width = Json_getFloat(attachmentMap, "width", 32) * self->scale; regionAttachment->height = Json_getFloat(attachmentMap, "height", 32) * self->scale; + + color = Json_getString(slotMap, "color", 0); + if (color) { + regionAttachment->r = toColor(color, 0); + regionAttachment->g = toColor(color, 1); + regionAttachment->b = toColor(color, 2); + regionAttachment->a = toColor(color, 3); + } + spRegionAttachment_updateOffset(regionAttachment); break; }