Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Prefix all methods in NSImage+TUIExtensions

  • Loading branch information...
commit d12c0ed432943497256d058766790668e10d4711 1 parent efd0121
@jspahrsummers jspahrsummers authored
Showing with 55 additions and 55 deletions.
  1. +16 −16 lib/UIKit/NSImage+TUIExtensions.h
  2. +39 −39 lib/UIKit/NSImage+TUIExtensions.m
View
32 lib/UIKit/NSImage+TUIExtensions.h
@@ -22,8 +22,8 @@
@interface NSImage (TUIExtensions)
-+ (NSImage *)imageWithCGImage:(CGImageRef)cgImage;
-+ (NSImage *)imageWithSize:(CGSize)size drawing:(void (^)(CGContextRef))draw; // thread safe
++ (NSImage *)tui_imageWithCGImage:(CGImageRef)cgImage;
++ (NSImage *)tui_imageWithSize:(CGSize)size drawing:(void (^)(CGContextRef))draw; // thread safe
/*
* Returns a CGImageRef corresponding to the receiver.
@@ -31,38 +31,38 @@
* This should only be used with bitmaps. For vector images, use
* -CGImageForProposedRect:context:hints instead.
*/
-@property (nonatomic, readonly) CGImageRef CGImage;
+@property (nonatomic, readonly) CGImageRef tui_CGImage;
/*
* Similar to -CGImageForProposedRect:context:hints:, but accepts a CGContextRef
* instead.
*/
-- (CGImageRef)CGImageForProposedRect:(CGRect *)rectPtr CGContext:(CGContextRef)context;
+- (CGImageRef)tui_CGImageForProposedRect:(CGRect *)rectPtr CGContext:(CGContextRef)context;
/*
* Draws the whole image originating at the given point.
*/
-- (void)drawAtPoint:(CGPoint)point;
+- (void)tui_drawAtPoint:(CGPoint)point;
/*
* Draws the whole image into the given rectangle.
*/
-- (void)drawInRect:(CGRect)rect;
+- (void)tui_drawInRect:(CGRect)rect;
/*
* Creates and returns a new image, based on the receiver, that has the
* specified end cap insets.
*/
-- (TUIStretchableImage *)resizableImageWithCapInsets:(TUIEdgeInsets)insets;
+- (TUIStretchableImage *)tui_resizableImageWithCapInsets:(TUIEdgeInsets)insets;
-- (NSImage *)crop:(CGRect)cropRect;
-- (NSImage *)upsideDownCrop:(CGRect)cropRect;
-- (NSImage *)scale:(CGSize)size;
-- (NSImage *)thumbnail:(CGSize)size;
-- (NSImage *)pad:(CGFloat)padding; // can be negative (to crop to center)
-- (NSImage *)roundImage:(CGFloat)radius;
-- (NSImage *)invertedMask;
-- (NSImage *)embossMaskWithOffset:(CGSize)offset; // subtract reciever from itself offset by 'offset', use as a mask to draw emboss
-- (NSImage *)innerShadowWithOffset:(CGSize)offset radius:(CGFloat)radius color:(TUIColor *)color backgroundColor:(TUIColor *)backgroundColor; // 'backgroundColor' is used as the color the shadow is drawn with, it is mostly masked out, but a halo will remain, leading to artifacts unless it is close enough to the background color
+- (NSImage *)tui_crop:(CGRect)cropRect;
+- (NSImage *)tui_upsideDownCrop:(CGRect)cropRect;
+- (NSImage *)tui_scale:(CGSize)size;
+- (NSImage *)tui_thumbnail:(CGSize)size;
+- (NSImage *)tui_pad:(CGFloat)padding; // can be negative (to crop to center)
+- (NSImage *)tui_roundImage:(CGFloat)radius;
+- (NSImage *)tui_invertedMask;
+- (NSImage *)tui_embossMaskWithOffset:(CGSize)offset; // subtract reciever from itself offset by 'offset', use as a mask to draw emboss
+- (NSImage *)tui_innerShadowWithOffset:(CGSize)offset radius:(CGFloat)radius color:(TUIColor *)color backgroundColor:(TUIColor *)backgroundColor; // 'backgroundColor' is used as the color the shadow is drawn with, it is mostly masked out, but a halo will remain, leading to artifacts unless it is close enough to the background color
@end
View
78 lib/UIKit/NSImage+TUIExtensions.m
@@ -21,12 +21,12 @@
@implementation NSImage (TUIExtensions)
-+ (NSImage *)imageWithCGImage:(CGImageRef)cgImage {
++ (NSImage *)tui_imageWithCGImage:(CGImageRef)cgImage {
CGSize size = CGSizeMake(CGImageGetWidth(cgImage), CGImageGetHeight(cgImage));
return [[self alloc] initWithCGImage:cgImage size:size];
}
-+ (NSImage *)imageWithSize:(CGSize)size drawing:(void(^)(CGContextRef))draw
++ (NSImage *)tui_imageWithSize:(CGSize)size drawing:(void(^)(CGContextRef))draw
{
if(size.width < 1 || size.height < 1)
return nil;
@@ -38,28 +38,28 @@ + (NSImage *)imageWithSize:(CGSize)size drawing:(void(^)(CGContextRef))draw
return i;
}
-- (CGImageRef)CGImage
+- (CGImageRef)tui_CGImage
{
return [self CGImageForProposedRect:NULL context:nil hints:nil];
}
-- (CGImageRef)CGImageForProposedRect:(CGRect *)rectPtr CGContext:(CGContextRef)context
+- (CGImageRef)tui_CGImageForProposedRect:(CGRect *)rectPtr CGContext:(CGContextRef)context
{
NSGraphicsContext *graphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
return [self CGImageForProposedRect:rectPtr context:graphicsContext hints:nil];
}
-- (void)drawAtPoint:(CGPoint)point
+- (void)tui_drawAtPoint:(CGPoint)point
{
[self drawAtPoint:point fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
-- (void)drawInRect:(CGRect)rect
+- (void)tui_drawInRect:(CGRect)rect
{
[self drawInRect:rect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
-- (TUIStretchableImage *)resizableImageWithCapInsets:(TUIEdgeInsets)insets {
+- (TUIStretchableImage *)tui_resizableImageWithCapInsets:(TUIEdgeInsets)insets {
TUIStretchableImage *image = [[TUIStretchableImage alloc] init];
[image addRepresentations:self.representations];
@@ -67,17 +67,17 @@ - (TUIStretchableImage *)resizableImageWithCapInsets:(TUIEdgeInsets)insets {
return image;
}
-- (NSImage *)scale:(CGSize)size
+- (NSImage *)tui_scale:(CGSize)size
{
- return [NSImage imageWithSize:size drawing:^(CGContextRef ctx) {
+ return [NSImage tui_imageWithSize:size drawing:^(CGContextRef ctx) {
CGRect r;
r.origin = CGPointZero;
r.size = size;
- CGContextDrawImage(ctx, r, self.CGImage);
+ CGContextDrawImage(ctx, r, self.tui_CGImage);
}];
}
-- (NSImage *)crop:(CGRect)cropRect
+- (NSImage *)tui_crop:(CGRect)cropRect
{
if((cropRect.size.width < 1) || (cropRect.size.height < 1))
return nil;
@@ -87,34 +87,34 @@ - (NSImage *)crop:(CGRect)cropRect
CGFloat my = cropRect.origin.y + cropRect.size.height;
if((cropRect.origin.x >= 0.0) && (cropRect.origin.y >= 0.0) && (mx <= s.width) && (my <= s.height)) {
// fast crop
- CGImageRef cgimage = CGImageCreateWithImageInRect(self.CGImage, cropRect);
+ CGImageRef cgimage = CGImageCreateWithImageInRect(self.tui_CGImage, cropRect);
if(!cgimage) {
NSLog(@"CGImageCreateWithImageInRect failed %@ %@", NSStringFromRect(cropRect), NSStringFromSize(s));
return nil;
}
- NSImage *i = [NSImage imageWithCGImage:cgimage];
+ NSImage *i = [NSImage tui_imageWithCGImage:cgimage];
CGImageRelease(cgimage);
return i;
} else {
// slow crop - probably doing pad
- return [NSImage imageWithSize:cropRect.size drawing:^(CGContextRef ctx) {
+ return [NSImage tui_imageWithSize:cropRect.size drawing:^(CGContextRef ctx) {
CGRect imageRect;
imageRect.origin.x = -cropRect.origin.x;
imageRect.origin.y = -cropRect.origin.y;
imageRect.size = s;
- CGContextDrawImage(ctx, imageRect, self.CGImage);
+ CGContextDrawImage(ctx, imageRect, self.tui_CGImage);
}];
}
}
-- (NSImage *)upsideDownCrop:(CGRect)cropRect
+- (NSImage *)tui_upsideDownCrop:(CGRect)cropRect
{
CGSize s = self.size;
cropRect.origin.y = s.height - (cropRect.origin.y + cropRect.size.height);
- return [self crop:cropRect];
+ return [self tui_crop:cropRect];
}
-- (NSImage *)thumbnail:(CGSize)newSize
+- (NSImage *)tui_thumbnail:(CGSize)newSize
{
CGSize s = self.size;
float oldProp = s.width / s.height;
@@ -128,52 +128,52 @@ - (NSImage *)thumbnail:(CGSize)newSize
cropRect.size.height = s.width / newProp;
}
cropRect.origin = CGPointMake((s.width - cropRect.size.width) / 2.0, (s.height - cropRect.size.height) / 2.0);
- return [[self crop:cropRect] scale:newSize];
+ return [[self tui_crop:cropRect] tui_scale:newSize];
}
-- (NSImage *)pad:(CGFloat)padding
+- (NSImage *)tui_pad:(CGFloat)padding
{
CGSize s = self.size;
- return [self crop:CGRectMake(-padding, -padding, s.width + padding*2, s.height + padding*2)];
+ return [self tui_crop:CGRectMake(-padding, -padding, s.width + padding*2, s.height + padding*2)];
}
-- (NSImage *)roundImage:(CGFloat)radius
+- (NSImage *)tui_roundImage:(CGFloat)radius
{
CGRect r;
r.origin = CGPointZero;
r.size = self.size;
- return [NSImage imageWithSize:r.size drawing:^(CGContextRef ctx) {
+ return [NSImage tui_imageWithSize:r.size drawing:^(CGContextRef ctx) {
CGContextClipToRoundRect(ctx, r, radius);
- CGContextDrawImage(ctx, r, self.CGImage);
+ CGContextDrawImage(ctx, r, self.tui_CGImage);
}];
}
-- (NSImage *)invertedMask
+- (NSImage *)tui_invertedMask
{
CGSize s = self.size;
- return [NSImage imageWithSize:s drawing:^(CGContextRef ctx) {
+ return [NSImage tui_imageWithSize:s drawing:^(CGContextRef ctx) {
CGRect rect = CGRectMake(0, 0, s.width, s.height);
CGContextSetRGBFillColor(ctx, 0, 0, 0, 1);
CGContextFillRect(ctx, rect);
CGContextSaveGState(ctx);
- CGContextClipToMask(ctx, rect, self.CGImage);
+ CGContextClipToMask(ctx, rect, self.tui_CGImage);
CGContextClearRect(ctx, rect);
CGContextRestoreGState(ctx);
}];
}
-- (NSImage *)innerShadowWithOffset:(CGSize)offset radius:(CGFloat)radius color:(TUIColor *)color backgroundColor:(TUIColor *)backgroundColor
+- (NSImage *)tui_innerShadowWithOffset:(CGSize)offset radius:(CGFloat)radius color:(TUIColor *)color backgroundColor:(TUIColor *)backgroundColor
{
CGFloat padding = ceil(radius);
- NSImage *paddedImage = [self pad:padding];
- NSImage *shadowImage = [NSImage imageWithSize:paddedImage.size drawing:^(CGContextRef ctx) {
+ NSImage *paddedImage = [self tui_pad:padding];
+ NSImage *shadowImage = [NSImage tui_imageWithSize:paddedImage.size drawing:^(CGContextRef ctx) {
CGContextSaveGState(ctx);
CGRect r = CGRectMake(0, 0, paddedImage.size.width, paddedImage.size.height);
- CGContextClipToMask(ctx, r, paddedImage.CGImage); // clip to image
+ CGContextClipToMask(ctx, r, paddedImage.tui_CGImage); // clip to image
CGContextSetShadowWithColor(ctx, offset, radius, color.CGColor);
CGContextBeginTransparencyLayer(ctx, NULL);
{
- CGContextClipToMask(ctx, r, [[paddedImage invertedMask] CGImage]); // clip to inverted
+ CGContextClipToMask(ctx, r, [[paddedImage tui_invertedMask] tui_CGImage]); // clip to inverted
CGContextSetFillColorWithColor(ctx, backgroundColor.CGColor);
CGContextFillRect(ctx, r); // draw with shadow
}
@@ -181,25 +181,25 @@ - (NSImage *)innerShadowWithOffset:(CGSize)offset radius:(CGFloat)radius color:(
CGContextRestoreGState(ctx);
}];
- return [shadowImage pad:-padding];
+ return [shadowImage tui_pad:-padding];
}
-- (NSImage *)embossMaskWithOffset:(CGSize)offset
+- (NSImage *)tui_embossMaskWithOffset:(CGSize)offset
{
CGFloat padding = MAX(offset.width, offset.height) + 1;
- NSImage *paddedImage = [self pad:padding];
+ NSImage *paddedImage = [self tui_pad:padding];
CGSize s = paddedImage.size;
- NSImage *embossedImage = [NSImage imageWithSize:s drawing:^(CGContextRef ctx) {
+ NSImage *embossedImage = [NSImage tui_imageWithSize:s drawing:^(CGContextRef ctx) {
CGContextSaveGState(ctx);
CGRect r = CGRectMake(0, 0, s.width, s.height);
- CGContextClipToMask(ctx, r, [paddedImage CGImage]);
- CGContextClipToMask(ctx, CGRectOffset(r, offset.width, offset.height), [[paddedImage invertedMask] CGImage]);
+ CGContextClipToMask(ctx, r, [paddedImage tui_CGImage]);
+ CGContextClipToMask(ctx, CGRectOffset(r, offset.width, offset.height), [[paddedImage tui_invertedMask] tui_CGImage]);
CGContextSetRGBFillColor(ctx, 0, 0, 0, 1);
CGContextFillRect(ctx, r);
CGContextRestoreGState(ctx);
}];
- return [embossedImage pad:-padding];
+ return [embossedImage tui_pad:-padding];
}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.