mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2024-11-30 07:20:35 +00:00
57 lines
1.9 KiB
Objective-C
57 lines
1.9 KiB
Objective-C
#import <CoreGraphics/CGColor.h>
|
|
#import <CoreGraphics/CGGradient.h>
|
|
#import <Foundation/NSString.h>
|
|
|
|
CGGradientRef CGGradientCreateWithColorComponents(CGColorSpaceRef colorSpace,
|
|
const CGFloat components[],
|
|
const CGFloat locations[],
|
|
size_t count)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
CGGradientRef CGGradientCreateWithColors(CGColorSpaceRef colorSpace,
|
|
CFArrayRef colors,
|
|
const CGFloat locations[])
|
|
{
|
|
CFIndex i, count = CFArrayGetCount(colors);
|
|
size_t numberOfComponents =
|
|
CGColorSpaceGetNumberOfComponents(colorSpace) + 1;
|
|
CGFloat components[count * numberOfComponents];
|
|
|
|
for (i = 0; i < count; i++) {
|
|
CGColorRef color = (CGColorRef) CFArrayGetValueAtIndex(colors, i);
|
|
size_t checkNumberOfComponents = CGColorGetNumberOfComponents(color);
|
|
size_t j;
|
|
|
|
if (checkNumberOfComponents == numberOfComponents) {
|
|
const CGFloat *copy = CGColorGetComponents(color);
|
|
|
|
for (j = 0; j < numberOfComponents; j++)
|
|
components[i * numberOfComponents + j] = components[j];
|
|
} else {
|
|
NSLog(@"CGGradientCreateWithColors, color spaces don't match, "
|
|
@"conversion not implemented");
|
|
for (j = 0; j < numberOfComponents; j++)
|
|
components[i * numberOfComponents + j] = 0;
|
|
}
|
|
}
|
|
|
|
return CGGradientCreateWithColorComponents(colorSpace, components,
|
|
locations, count);
|
|
}
|
|
|
|
void CGGradientRelease(CGGradientRef self) {
|
|
if (self == NULL)
|
|
return;
|
|
|
|
CFRelease(self);
|
|
}
|
|
|
|
CGGradientRef CGGradientRetain(CGGradientRef self) {
|
|
if (self == NULL)
|
|
return NULL;
|
|
|
|
return (CGGradientRef) CFRetain(self);
|
|
}
|