mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2025-02-26 14:56:51 +00:00
Implement CGPointMakeWithDictionaryRepresentation and CGPointCreateDictionaryRepresentation
This commit is contained in:
parent
76b2fdef29
commit
cc581ba7b7
@ -69,3 +69,48 @@ CGRect CGRectUnion(CGRect a, CGRect b) {
|
||||
CGFloat maxY = MAX(CGRectGetMaxY(a), CGRectGetMaxY(b));
|
||||
return CGRectMake(minX, minY, maxX - minX, maxY - minY);
|
||||
}
|
||||
|
||||
CFDictionaryRef CGPointCreateDictionaryRepresentation(CGPoint point)
|
||||
{
|
||||
CFDictionaryRef dict;
|
||||
CFStringRef keys[] = {
|
||||
CFSTR("X"), CFSTR("Y")
|
||||
};
|
||||
CFNumberRef values[2];
|
||||
|
||||
values[0] = CFNumberCreate(NULL, kCFNumberCGFloatType, &point.x);
|
||||
values[1] = CFNumberCreate(NULL, kCFNumberCGFloatType, &point.y);
|
||||
|
||||
dict = CFDictionaryCreate(NULL, (const void**) keys, (const void**) values, 2,
|
||||
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
|
||||
|
||||
CRelease(values[0]);
|
||||
CRelease(values[1]);
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGPoint *point)
|
||||
{
|
||||
if (!dict || !point)
|
||||
return NO;
|
||||
|
||||
CFNumberRef num;
|
||||
|
||||
num = (CFNumberRef) CFDictionaryGetValue(dect, CFSTR("X"));
|
||||
if (CFGetTypeID(num) != CFNumberGetTypeID())
|
||||
return NO;
|
||||
|
||||
if (!CFNumberGetValue(num, kCFNumberCGFloatType, &point->x))
|
||||
return NO;
|
||||
|
||||
num = (CFNumberRef) CFDictionaryGetValue(dect, CFSTR("Y"));
|
||||
if (CFGetTypeID(num) != CFNumberGetTypeID())
|
||||
return NO;
|
||||
|
||||
if (!CFNumberGetValue(num, kCFNumberCGFloatType, &point->y))
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
#import <CoreGraphics/CoreGraphicsExport.h>
|
||||
#import <CoreFoundation/CFBase.h>
|
||||
#import <CoreFoundation/CFDictionary.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <CoreGraphics/CGBase.h>
|
||||
@ -161,3 +162,9 @@ static inline bool CGRectContainsRect(CGRect a, CGRect b) {
|
||||
CGRectGetMinY(b) >= CGRectGetMinY(a) &&
|
||||
CGRectGetMaxY(b) <= CGRectGetMaxY(a));
|
||||
}
|
||||
|
||||
CFDictionaryRef CGPointCreateDictionaryRepresentation(CGPoint point);
|
||||
|
||||
bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGPoint *point);
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user