Permalink
Browse files

Style fix all the code

  • Loading branch information...
1 parent 9bd339b commit 1275dee9ea4cda112eda2848620cec3667dfa316 @jspahrsummers jspahrsummers committed Oct 23, 2012
@@ -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
- }
- );
-
- CGColorSpaceRef colorSpaceRef = CGColorSpaceCreatePattern(NULL);
-
- CGColorRef result = CGColorCreateWithPattern(colorSpaceRef, pattern, (CGFloat[]){ 1.0 });
-
- CGColorSpaceRelease(colorSpaceRef);
- CGPatternRelease(pattern);
-
- return (CGColorRef)[(id)result autorelease];
- }
+ (void *)CFRetain(patternImage),
+ patternBounds,
+ CGAffineTransformIdentity,
+ width,
+ height,
+ kCGPatternTilingConstantSpacingMinimalDistortion,
+ YES,
+ &(CGPatternCallbacks){
+ .version = 0,
+ .drawPattern = &drawCGImagePattern,
+ .releaseInfo = &releasePatternInfo
+ }
+ );
+
+ CGColorSpaceRef colorSpaceRef = CGColorSpaceCreatePattern(NULL);
+
+ CGColorRef result = CGColorCreateWithPattern(colorSpaceRef, pattern, (CGFloat[]){ 1.0 });
+
+ CGColorSpaceRelease(colorSpaceRef);
+ CGPatternRelease(pattern);
+
+ 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 @@ + (void)rbl_animate:(void (^)(void))animations completion:(void (^)(void))comple
// block.
if (completion == nil) completion = ^{};
- [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
+ [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
RBLAnimationContextCount++;
animations();
RBLAnimationContextCount--;
@@ -30,7 +30,7 @@ + (void)rbl_animate:(void (^)(void))animations completion:(void (^)(void))comple
+ (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 @@ + (BOOL)rbl_isInAnimationContext {
}
- (instancetype)rbl_animator {
- return [self.class rbl_isInAnimationContext] ? self.animator : self;
+ return self.class.rbl_isInAnimationContext ? self.animator : self;
}
@end
@@ -61,7 +61,7 @@ - (void)drawInRect:(NSRect)dstRect fromRect:(NSRect)srcRect operation:(NSComposi
// 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 @@ - (void)drawInRect:(NSRect)dstRect fromRect:(NSRect)srcRect operation:(NSComposi
BOOL flipped = NO;
if (respectFlipped) {
- flipped = [[NSGraphicsContext currentContext] isFlipped];
+ flipped = [NSGraphicsContext.currentContext isFlipped];
}
if (topLeft != nil || bottomRight != nil) {
@@ -176,7 +176,7 @@ - (void)encodeWithCoder:(NSCoder *)coder {
- (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;
View
@@ -58,8 +58,8 @@ - (void)setFlipped:(BOOL)value {
_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 @@ - (id)initWithFrame:(NSRect)frame {
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 @@ + (BOOL)doesCustomDrawing {
}
- (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 @@
__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 @@
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();
});
});
View
@@ -37,11 +37,11 @@
});
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

0 comments on commit 1275dee

Please sign in to comment.