Skip to content

Commit

Permalink
Style fixes and code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
avaidyam committed Nov 20, 2012
1 parent ca806e4 commit e17f9f9
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 83 deletions.
8 changes: 8 additions & 0 deletions LICENSE.md
Expand Up @@ -12,6 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

----------

Code from the Google Toolbox for Mac is used in TwUI. Google Toolbox for Mac is copyright (c) 2007 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -26,6 +28,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

----------

Code from the Velvet framework is used in TwUI. Velvet is copyright (c) 2012, Bitswift, Inc.

All rights reserved.
Expand All @@ -37,6 +41,8 @@ Redistribution and use in source and binary forms, with or without modification,

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

----------

Code from Matt Gemmell is used in portions of TwUI. License Agreement for Source Code provided by Matt Gemmell:

This software is supplied to you by Matt Gemmell in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this software.
Expand All @@ -47,6 +53,8 @@ The software is provided by Matt Gemmell on an "AS IS" basis. MATT GEMMELL MAKES

IN NO EVENT SHALL MATT GEMMELL BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF MATT GEMMELL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

----------

Sample code from Apple Documentation is used in portions of TwUI. Portions Copyright (c) 1999-2012 Apple Inc. All Rights Reserved.

This file contains Original Code and/or Modifications of Original Code as defined in and that are subject to the Apple Public Source License Version 2.0 (the 'License'). You may not use this file except in compliance with the License. Please obtain a copy of the License at http://www.opensource.apple.com/apsl/ and read it before using this file.
Expand Down
2 changes: 1 addition & 1 deletion lib/Support/ABActiveRange.m
Expand Up @@ -35,7 +35,7 @@ - (id)copyWithZone:(NSZone *)zone

- (NSString *)description
{
return [NSString stringWithFormat:@"<ABFlavoredRange %ld %@ (%@)>", rangeFlavor, NSStringFromRange(rangeValue), displayString];
return [NSString stringWithFormat:@"<ABFlavoredRange %lu %@ (%@)>", (unsigned long)rangeFlavor, NSStringFromRange(rangeValue), displayString];
}

- (ABActiveTextRangeFlavor)rangeFlavor
Expand Down
3 changes: 0 additions & 3 deletions lib/UIKit/NSAffineTransform+TUIExtensions.h
Expand Up @@ -21,9 +21,6 @@
// Creates an NSAffineTransform object with the passed CGAffineTransform.
+ (NSAffineTransform *)tui_transformWithCGAffineTransform:(CGAffineTransform)transform;

// Initializes an NSAffineTransform object with the passed CGAffineTransform.
- (id)initWithCGAffineTransform:(CGAffineTransform)transform;

// Creates an CGAffineTransform struct with the transform of the reciever.
- (CGAffineTransform)tui_CGAffineTransform;

Expand Down
25 changes: 10 additions & 15 deletions lib/UIKit/NSAffineTransform+TUIExtensions.m
Expand Up @@ -19,22 +19,17 @@
@implementation NSAffineTransform (TUIExtensions)

+ (NSAffineTransform *)tui_transformWithCGAffineTransform:(CGAffineTransform)transform {
return [[self.class alloc] initWithCGAffineTransform:transform];
}

- (id)initWithCGAffineTransform:(CGAffineTransform)transform {
if((self = [super init])) {
self.transformStruct = (NSAffineTransformStruct) {
.m11 = transform.a,
.m12 = transform.b,
.m21 = transform.c,
.m22 = transform.d,
.tX = transform.tx,
.tY = transform.ty
};
}
NSAffineTransform *affineTransform = [NSAffineTransform transform];
affineTransform.transformStruct = (NSAffineTransformStruct) {
.m11 = transform.a,
.m12 = transform.b,
.m21 = transform.c,
.m22 = transform.d,
.tX = transform.tx,
.tY = transform.ty
};

return self;
return affineTransform;
}

- (CGAffineTransform)tui_CGAffineTransform {
Expand Down
14 changes: 7 additions & 7 deletions lib/UIKit/NSBezierPath+TUIExtensions.h
Expand Up @@ -24,21 +24,21 @@
- (CGPathRef)tui_CGPath CF_RETURNS_RETAINED;

// Fills the given shadow inside the bezier path.
- (void)fillWithInnerShadow:(NSShadow *)shadow;
- (void)tui_fillWithInnerShadow:(NSShadow *)shadow;

// Draws a blurred "shadow" inside the bezier path with a color and radius.
- (void)drawBlurWithColor:(NSColor *)color radius:(CGFloat)radius;
- (void)tui_drawBlurWithColor:(NSColor *)color radius:(CGFloat)radius;

// Returns a bezier path with a rounded rectangle in the given
// rect with the selected corners rounded at the given corner radii.
+ (NSBezierPath *)bezierPathWithRoundedRect:(CGRect)rect
byRoundingCorners:(TUIRectCorner)corners
cornerRadii:(CGSize)cornerRadii;
+ (NSBezierPath *)tui_bezierPathWithRoundedRect:(CGRect)rect
byRoundingCorners:(TUIRectCorner)corners
cornerRadii:(CGSize)cornerRadii;

// Strokes the bezier path on the inside, instead of the standard outside stroke.
- (void)strokeInside;
- (void)tui_strokeInside;

// Strokes the bezier path inside a clipped rectangle within the path's bounds.
- (void)strokeInsideWithinRect:(NSRect)clipRect;
- (void)tui_strokeInsideWithinRect:(NSRect)clipRect;

@end
20 changes: 10 additions & 10 deletions lib/UIKit/NSBezierPath+TUIExtensions.m
Expand Up @@ -18,7 +18,7 @@
#import "TUICGAdditions.h"

// Sourced from Apple Documentation.
static void CGPathCallback(void *info, const CGPathElement *element) {
static void tui_CGPathCallback(void *info, const CGPathElement *element) {
NSBezierPath *path = (__bridge NSBezierPath *)(info);
CGPoint *points = element->points;

Expand Down Expand Up @@ -54,7 +54,7 @@ @implementation NSBezierPath (TUIExtensions)
// Sourced from Apple Documentation.
+ (NSBezierPath *)tui_bezierPathWithCGPath:(CGPathRef)pathRef {
NSBezierPath *path = [NSBezierPath bezierPath];
CGPathApply(pathRef, (__bridge void *)(path), CGPathCallback);
CGPathApply(pathRef, (__bridge void *)(path), tui_CGPathCallback);

return path;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ - (CGPathRef)tui_CGPath {
return immutablePath;
}

- (void)fillWithInnerShadow:(NSShadow *)shadow {
- (void)tui_fillWithInnerShadow:(NSShadow *)shadow {
NSSize offset = shadow.shadowOffset;
NSSize originalOffset = offset;
CGFloat radius = shadow.shadowBlurRadius;
Expand Down Expand Up @@ -130,7 +130,7 @@ - (void)fillWithInnerShadow:(NSShadow *)shadow {
shadow.shadowOffset = originalOffset;
}

- (void)drawBlurWithColor:(NSColor *)color radius:(CGFloat)radius {
- (void)tui_drawBlurWithColor:(NSColor *)color radius:(CGFloat)radius {
NSRect bounds = NSInsetRect(self.bounds, -radius, -radius);
NSShadow *shadow = [NSShadow tui_shadowWithRadius:radius offset:NSMakeSize(0, bounds.size.height) color:color];

Expand All @@ -152,9 +152,9 @@ - (void)drawBlurWithColor:(NSColor *)color radius:(CGFloat)radius {
}

// Sourced from Google Source Toolbox for Mac.
+ (NSBezierPath *)bezierPathWithRoundedRect:(CGRect)rect
byRoundingCorners:(TUIRectCorner)corners
cornerRadii:(CGSize)cornerRadii {
+ (NSBezierPath *)tui_bezierPathWithRoundedRect:(CGRect)rect
byRoundingCorners:(TUIRectCorner)corners
cornerRadii:(CGSize)cornerRadii {
CGMutablePathRef path = CGPathCreateMutable();

CGPoint topLeft = rect.origin;
Expand Down Expand Up @@ -207,11 +207,11 @@ + (NSBezierPath *)bezierPathWithRoundedRect:(CGRect)rect
}

// Sourced from Matt Gemmell's NSBezierPath+StrokeExtensions
- (void)strokeInside {
[self strokeInsideWithinRect:NSZeroRect];
- (void)tui_strokeInside {
[self tui_strokeInsideWithinRect:NSZeroRect];
}

- (void)strokeInsideWithinRect:(NSRect)clipRect {
- (void)tui_strokeInsideWithinRect:(NSRect)clipRect {
CGFloat lineWidth = self.lineWidth;

[NSGraphicsContext saveGraphicsState];
Expand Down
3 changes: 0 additions & 3 deletions lib/UIKit/NSShadow+TUIExtensions.h
Expand Up @@ -21,7 +21,4 @@
// Returns a shadow with the given shadow radius, offset, and color properties.
+ (NSShadow *)tui_shadowWithRadius:(CGFloat)radius offset:(CGSize)offset color:(NSColor *)color;

// Returns a shadow with the given shadow radius, offset, and color properties.
- (id)initWithRadius:(CGFloat)radius offset:(CGSize)offset color:(NSColor *)color;

@end
15 changes: 5 additions & 10 deletions lib/UIKit/NSShadow+TUIExtensions.m
Expand Up @@ -19,17 +19,12 @@
@implementation NSShadow (TUIExtensions)

+ (NSShadow *)tui_shadowWithRadius:(CGFloat)radius offset:(CGSize)offset color:(NSColor *)color {
return [[self.class alloc] initWithRadius:radius offset:offset color:color];
}

- (id)initWithRadius:(CGFloat)radius offset:(CGSize)offset color:(NSColor *)color {
if((self = [super init])) {
self.shadowBlurRadius = radius;
self.shadowOffset = offset;
self.shadowColor = color;
}
NSShadow *shadow = [[self.class alloc] init];
shadow.shadowBlurRadius = radius;
shadow.shadowOffset = offset;
shadow.shadowColor = color;

return self;
return shadow;
}

@end
12 changes: 2 additions & 10 deletions lib/UIKit/TUIGeometry.h
Expand Up @@ -58,18 +58,10 @@ static inline CGPoint CGPointConstrainToRect(CGPoint point, CGRect rect) {
MAX(rect.origin.y, MIN((rect.origin.y + rect.size.height), point.y)));
}

@interface NSCoder (TUIExtensions)

// Allows NSCoder objects to encode or decode TUIEdgeInsets.
- (void)encodeTUIEdgeInsets:(TUIEdgeInsets)insets forKey:(NSString *)key;
- (TUIEdgeInsets)decodeTUIEdgeInsetsForKey:(NSString *)key;

@end

@interface NSValue (TUIExtensions)

// Allows NSValue boxing and unboxing of TUIEdgeInsets.
+ (NSValue *)valueWithTUIEdgeInsets:(TUIEdgeInsets)insets;
- (TUIEdgeInsets)TUIEdgeInsetsValue;
+ (NSValue *)tui_valueWithTUIEdgeInsets:(TUIEdgeInsets)insets;
- (TUIEdgeInsets)tui_TUIEdgeInsetsValue;

@end
27 changes: 4 additions & 23 deletions lib/UIKit/TUIGeometry.m
Expand Up @@ -19,47 +19,28 @@
const TUIEdgeInsets TUIEdgeInsetsZero = { .top = 0.0f, .left = 0.0f, .bottom = 0.0f, .right = 0.0f };

NSString* NSStringFromTUIEdgeInsets(TUIEdgeInsets insets) {
return [NSString stringWithFormat:@"{%lg, %lg, %lg, %lg}",
insets.top, insets.left, insets.bottom, insets.right];
return [NSString stringWithFormat:@"{%lg, %lg, %lg, %lg}", insets.top, insets.left, insets.bottom, insets.right];
}

TUIEdgeInsets TUIEdgeInsetsFromNSString(NSString *string) {
TUIEdgeInsets result = TUIEdgeInsetsZero;

if(string != nil) {
double top, left, bottom, right;
sscanf(string.UTF8String, "[%lg, %lg, %lg, %lg]", &top, &left, &bottom, &right);
sscanf(string.UTF8String, "{%lg, %lg, %lg, %lg}", &top, &left, &bottom, &right);
result = TUIEdgeInsetsMake(top, left, bottom, right);
}

return result;
}

@implementation NSCoder (TUIExtensions)

- (void)encodeTUIEdgeInsets:(TUIEdgeInsets)insets forKey:(NSString *)key {
NSData *data = [NSData dataWithBytes:&insets length:sizeof(TUIEdgeInsets)];
[self encodeObject:data forKey:key];
}

- (TUIEdgeInsets)decodeTUIEdgeInsetsForKey:(NSString *)key {
TUIEdgeInsets result = TUIEdgeInsetsZero;

NSData *data = [self decodeObjectForKey:key];
[data getBytes:&result length:sizeof(TUIEdgeInsets)];

return result;
}

@end

@implementation NSValue (TUIExtensions)

+ (NSValue *)valueWithTUIEdgeInsets:(TUIEdgeInsets)insets {
+ (NSValue *)tui_valueWithTUIEdgeInsets:(TUIEdgeInsets)insets {
return [NSValue valueWithBytes:&insets objCType:@encode(TUIEdgeInsets)];
}

- (TUIEdgeInsets)TUIEdgeInsetsValue {
- (TUIEdgeInsets)tui_TUIEdgeInsetsValue {
TUIEdgeInsets insets = TUIEdgeInsetsZero;
[self getValue:&insets];
return insets;
Expand Down
2 changes: 1 addition & 1 deletion lib/UIKit/TUIView.m
Expand Up @@ -512,7 +512,7 @@ - (void)setContentMode:(TUIViewContentMode)contentMode
} else if(contentMode == TUIViewContentModeScaleAspectFill) {
_layer.contentsGravity = kCAGravityResizeAspectFill;
} else {
NSAssert1(NO, @"%lu is not a valid contentMode.", contentMode);
NSAssert1(NO, @"%lu is not a valid contentMode.", (unsigned long)contentMode);
}
}

Expand Down

0 comments on commit e17f9f9

Please sign in to comment.