This commit is contained in:
Justin Spahr-Summers 2012-10-22 21:19:53 -07:00
Родитель 9bd339bfb8
Коммит 1275dee9ea
8 изменённых файлов: 78 добавлений и 78 удалений

Просмотреть файл

@ -12,80 +12,80 @@
#import "NSColor+RBLCGColorAdditions.h"
static void drawCGImagePattern (void *info, CGContextRef context) {
CGImageRef image = info;
CGImageRef image = info;
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
}
static void releasePatternInfo (void *info) {
CFRelease(info);
CFRelease(info);
}
@implementation NSColor (RBLCGColorAdditions)
+ (NSColor *)rbl_colorWithCGColor:(CGColorRef)color {
if (color == nil) {
return nil;
if (color == nil) {
return nil;
}
CGColorSpaceRef colorSpaceRef = CGColorGetColorSpace(color);
CGColorSpaceRef colorSpaceRef = CGColorGetColorSpace(color);
NSColorSpace *colorSpace = [[NSColorSpace alloc] initWithCGColorSpace:colorSpaceRef];
NSColor *result = [self colorWithColorSpace:colorSpace components:CGColorGetComponents(color) count:(size_t)CGColorGetNumberOfComponents(color)];
[colorSpace release];
NSColorSpace *colorSpace = [[NSColorSpace alloc] initWithCGColorSpace:colorSpaceRef];
NSColor *result = [self colorWithColorSpace:colorSpace components:CGColorGetComponents(color) count:(size_t)CGColorGetNumberOfComponents(color)];
[colorSpace release];
return result;
return result;
}
- (CGColorRef)rbl_CGColor {
if ([self.colorSpaceName isEqualToString:NSPatternColorSpace]) {
CGImageRef patternImage = [self.patternImage CGImageForProposedRect:NULL context:nil hints:nil];
if (patternImage == NULL) {
return NULL;
if ([self.colorSpaceName isEqualToString:NSPatternColorSpace]) {
CGImageRef patternImage = [self.patternImage CGImageForProposedRect:NULL context:nil hints:nil];
if (patternImage == NULL) {
return NULL;
}
size_t width = CGImageGetWidth(patternImage);
size_t height = CGImageGetHeight(patternImage);
size_t width = CGImageGetWidth(patternImage);
size_t height = CGImageGetHeight(patternImage);
CGRect patternBounds = CGRectMake(0, 0, width, height);
CGPatternRef pattern = CGPatternCreate(
CGRect patternBounds = CGRectMake(0, 0, width, height);
CGPatternRef pattern = CGPatternCreate(
// Released in releasePatternInfo().
(void *)CFRetain(patternImage),
patternBounds,
CGAffineTransformIdentity,
width,
height,
kCGPatternTilingConstantSpacingMinimalDistortion,
YES,
&(CGPatternCallbacks){
.version = 0,
.drawPattern = &drawCGImagePattern,
.releaseInfo = &releasePatternInfo
}
);
(void *)CFRetain(patternImage),
patternBounds,
CGAffineTransformIdentity,
width,
height,
kCGPatternTilingConstantSpacingMinimalDistortion,
YES,
&(CGPatternCallbacks){
.version = 0,
.drawPattern = &drawCGImagePattern,
.releaseInfo = &releasePatternInfo
}
);
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreatePattern(NULL);
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreatePattern(NULL);
CGColorRef result = CGColorCreateWithPattern(colorSpaceRef, pattern, (CGFloat[]){ 1.0 });
CGColorRef result = CGColorCreateWithPattern(colorSpaceRef, pattern, (CGFloat[]){ 1.0 });
CGColorSpaceRelease(colorSpaceRef);
CGPatternRelease(pattern);
CGColorSpaceRelease(colorSpaceRef);
CGPatternRelease(pattern);
return (CGColorRef)[(id)result autorelease];
}
return (CGColorRef)[(id)result autorelease];
}
NSColorSpace *colorSpace = [NSColorSpace genericRGBColorSpace];
NSColor *color = [self colorUsingColorSpace:colorSpace];
NSColorSpace *colorSpace = NSColorSpace.genericRGBColorSpace;
NSColor *color = [self colorUsingColorSpace:colorSpace];
CGFloat components[color.numberOfComponents];
[color getComponents:components];
CGFloat components[color.numberOfComponents];
[color getComponents:components];
CGColorSpaceRef colorSpaceRef = colorSpace.CGColorSpace;
CGColorRef result = CGColorCreate(colorSpaceRef, components);
CGColorSpaceRef colorSpaceRef = colorSpace.CGColorSpace;
CGColorRef result = CGColorCreate(colorSpaceRef, components);
return (CGColorRef)[(id)result autorelease];
return (CGColorRef)[(id)result autorelease];
}
@end

Просмотреть файл

@ -15,27 +15,27 @@
static void (*originalDrawRectIMP)(id, SEL, NSRect);
static void fixedDrawRect (NSTextView *self, SEL _cmd, NSRect rect) {
CGContextRef context = [NSGraphicsContext currentContext].graphicsPort;
CGContextRef context = NSGraphicsContext.currentContext.graphicsPort;
CGContextSetAllowsAntialiasing(context, YES);
CGContextSetAllowsFontSmoothing(context, YES);
CGContextSetAllowsFontSubpixelPositioning(context, YES);
CGContextSetAllowsFontSubpixelQuantization(context, YES);
CGContextSetAllowsAntialiasing(context, YES);
CGContextSetAllowsFontSmoothing(context, YES);
CGContextSetAllowsFontSubpixelPositioning(context, YES);
CGContextSetAllowsFontSubpixelQuantization(context, YES);
if (self.superview) {
// NSTextView likes to fall on non-integral points sometimes -- fix
if (self.superview) {
// NSTextView likes to fall on non-integral points sometimes -- fix
// that.
self.frame = [self.superview backingAlignedRect:self.frame options:NSAlignAllEdgesNearest];
}
self.frame = [self.superview backingAlignedRect:self.frame options:NSAlignAllEdgesNearest];
}
originalDrawRectIMP(self, _cmd, rect);
originalDrawRectIMP(self, _cmd, rect);
}
@implementation NSTextView (RBLAntialiasingAdditions)
+ (void)load {
Method drawRect = class_getInstanceMethod(self, @selector(drawRect:));
originalDrawRectIMP = (void (*)(id, SEL, NSRect))method_getImplementation(drawRect);
Method drawRect = class_getInstanceMethod(self, @selector(drawRect:));
originalDrawRectIMP = (void (*)(id, SEL, NSRect))method_getImplementation(drawRect);
method_setImplementation(drawRect, (IMP)&fixedDrawRect);
}

Просмотреть файл

@ -21,7 +21,7 @@ static NSUInteger RBLAnimationContextCount = 0;
// block.
if (completion == nil) completion = ^{};
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
RBLAnimationContextCount++;
animations();
RBLAnimationContextCount--;
@ -30,7 +30,7 @@ static NSUInteger RBLAnimationContextCount = 0;
+ (void)rbl_animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(void))completion {
[self rbl_animate:^{
[NSAnimationContext currentContext].duration = duration;
NSAnimationContext.currentContext.duration = duration;
animations();
} completion:completion];
}
@ -40,7 +40,7 @@ static NSUInteger RBLAnimationContextCount = 0;
}
- (instancetype)rbl_animator {
return [self.class rbl_isInAnimationContext] ? self.animator : self;
return self.class.rbl_isInAnimationContext ? self.animator : self;
}
@end

Просмотреть файл

@ -61,7 +61,7 @@
// Length of sides that run horizontally.
CGFloat horizontalEdgeLength = fmax(0, self.size.width - insets.left - insets.right);
NSImage *(^imageWithRect)(CGRect) = ^ id (CGRect rect){
NSImage *(^imageWithRect)(CGRect) = ^ id (CGRect rect) {
CGRect scaledRect = CGRectMake(rect.origin.x * widthScale, rect.origin.y * heightScale, rect.size.width * widthScale, rect.size.height * heightScale);
CGImageRef part = CGImageCreateWithImageInRect(image, scaledRect);
if (part == NULL) return nil;
@ -125,7 +125,7 @@
BOOL flipped = NO;
if (respectFlipped) {
flipped = [[NSGraphicsContext currentContext] isFlipped];
flipped = [NSGraphicsContext.currentContext isFlipped];
}
if (topLeft != nil || bottomRight != nil) {
@ -176,7 +176,7 @@
- (BOOL)isEqual:(RBLResizableImage *)image {
if (self == image) return YES;
if (![image isKindOfClass:[RBLResizableImage class]]) return NO;
if (![image isKindOfClass:RBLResizableImage.class]) return NO;
if (![super isEqual:image]) return NO;
NSEdgeInsets a = self.capInsets;

Просмотреть файл

@ -58,8 +58,8 @@ static IMP RBLViewDrawRectIMP;
_flags.flipped = (value ? 1 : 0);
// Not sure how necessary these are, but it's probably a good idea.
[self setNeedsLayout:YES];
[self setNeedsDisplay:YES];
self.needsLayout = YES;
self.needsDisplay = YES;
}
- (BOOL)clearsContextBeforeDrawing {
@ -100,7 +100,7 @@ static IMP RBLViewDrawRectIMP;
self.layerContentsPlacement = NSViewLayerContentsPlacementScaleAxesIndependently;
self.clearsContextBeforeDrawing = YES;
if ([self.class doesCustomDrawing]) {
if (self.class.doesCustomDrawing) {
// Use more conservative defaults if -drawRect: is overridden, to ensure
// correct drawing. Callers or subclasses can override these defaults
// to optimize for performance instead.
@ -119,7 +119,7 @@ static IMP RBLViewDrawRectIMP;
}
- (void)drawRect:(NSRect)rect {
CGContextRef context = [NSGraphicsContext currentContext].graphicsPort;
CGContextRef context = NSGraphicsContext.currentContext.graphicsPort;
if (self.clearsContextBeforeDrawing && !self.opaque) {
CGContextClearRect(context, rect);

Просмотреть файл

@ -10,7 +10,7 @@ SpecBegin(CAAnimationRBLBlockAdditions)
__block CAAnimation *animation = nil;
__block BOOL completionExecuted = NO;
__block void(^completionBlock)(BOOL) = ^ (BOOL finished) {
__block void (^completionBlock)(BOOL) = ^(BOOL finished) {
completionExecuted = YES;
};

Просмотреть файл

@ -10,31 +10,31 @@ SpecBegin(NSViewRBLAnimationAdditions)
describe(@"animation contexts", ^{
it(@"should not be in an animation context by default", ^{
expect([NSView rbl_isInAnimationContext]).to.beFalsy();
expect(NSView.rbl_isInAnimationContext).to.beFalsy();
});
it(@"should not be in an animation context within a new NSAnimationContext", ^{
[NSAnimationContext beginGrouping];
expect([NSView rbl_isInAnimationContext]).to.beFalsy();
expect(NSView.rbl_isInAnimationContext).to.beFalsy();
[NSAnimationContext endGrouping];
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
expect([NSView rbl_isInAnimationContext]).to.beFalsy();
expect(NSView.rbl_isInAnimationContext).to.beFalsy();
} completionHandler:^{}];
});
it(@"should be in an animation context within a Rebel block-based animation", ^{
[NSView rbl_animate:^{
expect([NSView rbl_isInAnimationContext]).to.beTruthy();
expect(NSView.rbl_isInAnimationContext).to.beTruthy();
[NSView rbl_animate:^{
expect([NSView rbl_isInAnimationContext]).to.beTruthy();
expect(NSView.rbl_isInAnimationContext).to.beTruthy();
} completion:nil];
expect([NSView rbl_isInAnimationContext]).to.beTruthy();
expect(NSView.rbl_isInAnimationContext).to.beTruthy();
} completion:nil];
expect([NSView rbl_isInAnimationContext]).to.beFalsy();
expect(NSView.rbl_isInAnimationContext).to.beFalsy();
});
});

Просмотреть файл

@ -37,11 +37,11 @@ it(@"should get the backgroundColor of its backing layer", ^{
});
it(@"should set the backgroundColor of its backing layer", ^{
view.backgroundColor = [NSColor redColor];
view.backgroundColor = NSColor.redColor;
CGColorRef layerColor = view.layer.backgroundColor;
expect(layerColor).notTo.beNil();
expect(CGColorEqualToColor(layerColor, [NSColor redColor].rbl_CGColor)).to.beTruthy();
expect(CGColorEqualToColor(layerColor, NSColor.redColor.rbl_CGColor)).to.beTruthy();
});
SpecEnd