Permalink
Browse files

Initial commit

  • Loading branch information...
jasonmorrissey committed Jul 5, 2011
0 parents commit 157554a230dca8752ce055d4469d9e7858f69f41
@@ -0,0 +1,22 @@
+# xcode noise
+*.mode1v3
+*.pbxuser
+*.perspective
+*.perspectivev3
+*.pyc
+*~.nib/
+build/*
+
+*.xcuserdatad
+
+
+# Textmate - if you build your xcode projects with it
+*.tm_build_errors
+
+# old skool
+.svn
+
+# osx noise
+.DS_Store
+profile
+
@@ -0,0 +1,12 @@
+// Created by Jason Morrissey - jasonmorrissey.org
+
+@interface DemoAppDelegate : NSObject <UIApplicationDelegate>
+{
+ UIWindow *window_;
+ UINavigationController *UINavigationController_;
+}
+
+@property (nonatomic, retain) UIWindow *window;
+@property (nonatomic, retain) UINavigationController *navigationController;
+
+@end
@@ -0,0 +1,35 @@
+// Created by Jason Morrissey - jasonmorrissey.org
+
+#import "DemoAppDelegate.h"
+#import "DemoViewController.h"
+
+@implementation DemoAppDelegate
+
+@synthesize window = window_;
+@synthesize navigationController = navigationController_;
+
+#pragma mark -
+#pragma mark Application lifecycle
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ DemoViewController * demoViewController = [[[DemoViewController alloc] initWithNibName:nil bundle:nil] autorelease];
+ self.navigationController = [[[UINavigationController alloc] initWithRootViewController:demoViewController] autorelease];
+ [self.navigationController setNavigationBarHidden:YES];
+
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ [self.window addSubview:self.navigationController.view];
+ [self.window makeKeyAndVisible];
+
+ return YES;
+}
+
+- (void)dealloc
+{
+ self.navigationController = nil;
+ self.window = nil;
+ [super dealloc];
+}
+
+
+@end
@@ -0,0 +1,8 @@
+// Created by Jason Morrissey - jasonmorrissey.org
+
+#import <Foundation/Foundation.h>
+#import "JMSlider.h"
+
+@interface DemoViewController : UIViewController <JMSliderDelegate>
+
+@end
@@ -0,0 +1,57 @@
+// Created by Jason Morrissey - jasonmorrissey.org
+
+#import "DemoViewController.h"
+#import "UIView+JMNoise.h"
+#import "UIView+Positioning.h"
+
+@interface DemoViewController()
+@end
+
+@implementation DemoViewController
+
+-(void)loadView;
+{
+ [super loadView];
+ self.view.backgroundColor = [UIColor whiteColor];
+
+ [self.view applyNoise];
+
+ CGRect sliderFrame = CGRectMake(0., 0., 320., 90.);
+
+ JMSlider * slider = [JMSlider sliderWithFrame:sliderFrame centerTitle:@"more" leftTitle:@"hide read" rightTitle:@"hide all" delegate:self];
+
+ slider.centerExecuteBlock = ^{ NSLog(@"executing block: center"); };
+ slider.leftExecuteBlock = ^{ NSLog(@"executing block: left"); };
+ slider.rightExecuteBlock = ^{ NSLog(@"executing block: right"); };
+
+ [self.view addSubview:slider];
+
+ [slider centerInSuperView];
+}
+
+
+#pragma Mark -
+#pragma Mark - JMSliderDelegate Methods
+
+-(void)slider:(JMSlider *)slider didSelect:(JMSliderSelection)selection;
+{
+ switch (selection)
+ {
+ case JMSliderSelectionLeft:
+ NSLog(@"invoked: left");
+ break;
+
+ case JMSliderSelectionCenter:
+ NSLog(@"invoked: center");
+ break;
+
+ case JMSliderSelectionRight:
+ NSLog(@"invoked: right");
+ break;
+
+ default:
+ break;
+ }
+}
+
+@end
@@ -0,0 +1,17 @@
+// Created by Jason Morrissey - jasonmorrissey.org
+
+#import <UIKit/UIKit.h>
+
+@interface UIView (JMNoise)
+
+// Can be used directly on UIView
+- (void)applyNoise;
+- (void)applyNoiseWithOpacity:(CGFloat)opacity atLayerIndex:(NSUInteger) layerIndex;
+- (void)applyNoiseWithOpacity:(CGFloat)opacity;
+
+// Can be invoked from a drawRect() method
+- (void)drawCGNoise;
+- (void)drawCGNoiseWithOpacity:(CGFloat)opacity;
+- (void)drawCGNoiseWithOpacity:(CGFloat)opacity blendMode:(CGBlendMode)blendMode;
+
+@end
@@ -0,0 +1,141 @@
+// Created by Jason Morrissey - jasonmorrissey.org
+
+#import <QuartzCore/QuartzCore.h>
+#import "UIView+JMNoise.h"
+#include <stdlib.h>
+
+#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
+
+#define kNoiseTileDimension 100
+#define kNoiseIntensity 100
+#define kNoiseDefaultOpacity 0.3
+#define kNoisePixelWidth 0.25
+
+#pragma Mark -
+#pragma Mark - Noise Layer
+
+@interface NoiseLayer : CALayer
++ (UIImage *)noiseTileImage;
++ (void)drawPixelInContext:(CGContextRef)context point:(CGPoint)point width:(CGFloat)width opacity:(CGFloat)opacity whiteLevel:(CGFloat)whiteLevel;
+@end
+
+@implementation NoiseLayer
+
+static UIImage * JMNoiseImage;
+
+- (void)setFrame:(CGRect)frame;
+{
+ [super setFrame:frame];
+ [self setNeedsDisplay];
+}
+
++ (void)drawPixelInContext:(CGContextRef)context point:(CGPoint)point width:(CGFloat)width opacity:(CGFloat)opacity whiteLevel:(CGFloat)whiteLevel;
+{
+ CGColorRef fillColor = [UIColor colorWithWhite:whiteLevel alpha:opacity].CGColor;
+ CGContextSetFillColor(context, CGColorGetComponents(fillColor));
+ CGRect pointRect = CGRectMake(point.x - (width/2), point.y - (width/2), width, width);
+ CGContextFillEllipseInRect(context, pointRect);
+}
+
++ (UIImage *)noiseTileImage;
+{
+ if (!JMNoiseImage)
+ {
+ CGFloat imageScale;
+
+ if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
+ {
+ imageScale = [[UIScreen mainScreen] scale];
+ }
+ else
+ {
+ imageScale = 1;
+ }
+
+ NSUInteger imageDimension = imageScale * kNoiseTileDimension;
+
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ CGContextRef context = CGBitmapContextCreate(nil,imageDimension,imageDimension,8,0,
+ colorSpace,kCGImageAlphaPremultipliedLast);
+ CFRelease(colorSpace);
+
+ for (int i=0; i<(imageDimension * kNoiseIntensity); i++)
+ {
+ int x = arc4random() % (imageDimension + 1);
+ int y = arc4random() % (imageDimension + 1);
+ int opacity = arc4random() % 100;
+ CGFloat whiteLevel = arc4random() % 100;
+ [NoiseLayer drawPixelInContext:context point:CGPointMake(x, y) width:(kNoisePixelWidth * imageScale) opacity:(opacity) whiteLevel:(whiteLevel / 100.)];
+ }
+
+ CGImageRef imageRef = CGBitmapContextCreateImage(context);
+ CGContextRelease(context);
+ if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"4.0"))
+ {
+ JMNoiseImage = [[UIImage alloc] initWithCGImage:imageRef scale:imageScale orientation:UIImageOrientationUp];
+ }
+ else
+ {
+ JMNoiseImage = [[UIImage alloc] initWithCGImage:imageRef];
+ }
+ }
+ return JMNoiseImage;
+}
+
+- (void)drawInContext:(CGContextRef)ctx;
+{
+ UIGraphicsPushContext(ctx);
+ [[NoiseLayer noiseTileImage] drawAsPatternInRect:self.bounds];
+ UIGraphicsPopContext();
+}
+
+@end
+
+#pragma Mark -
+#pragma Mark - UIView implementations
+
+@implementation UIView (JMNoise)
+
+- (void)applyNoise;
+{
+ [self applyNoiseWithOpacity:kNoiseDefaultOpacity];
+}
+
+- (void)applyNoiseWithOpacity:(CGFloat)opacity atLayerIndex:(NSUInteger) layerIndex;
+{
+ NoiseLayer * noiseLayer = [[[NoiseLayer alloc] init] autorelease];
+ [noiseLayer setFrame:self.bounds];
+ noiseLayer.masksToBounds = YES;
+ noiseLayer.opacity = opacity;
+ [self.layer insertSublayer:noiseLayer atIndex:layerIndex];
+}
+
+- (void)applyNoiseWithOpacity:(CGFloat)opacity;
+{
+ [self applyNoiseWithOpacity:opacity atLayerIndex:0];
+}
+
+- (void)drawCGNoise;
+{
+ [self drawCGNoiseWithOpacity:kNoiseDefaultOpacity];
+}
+
+- (void)drawCGNoiseWithOpacity:(CGFloat)opacity;
+{
+ [self drawCGNoiseWithOpacity:opacity blendMode:kCGBlendModeNormal];
+}
+
+- (void)drawCGNoiseWithOpacity:(CGFloat)opacity blendMode:(CGBlendMode)blendMode;
+{
+ CGContextRef context = UIGraphicsGetCurrentContext();
+ CGContextSaveGState(context);
+ UIBezierPath * path = [UIBezierPath bezierPathWithRect:self.bounds];
+ CGContextAddPath(context, [path CGPath]);
+ CGContextClip(context);
+ CGContextSetBlendMode(context, blendMode);
+ CGContextSetAlpha(context, opacity);
+ [[NoiseLayer noiseTileImage] drawAsPatternInRect:self.bounds];
+ CGContextRestoreGState(context);
+}
+
+@end
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.designshed.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+ <key>UIStatusBarStyle</key>
+ <string>UIStatusBarStyleBlackOpaque</string>
+</dict>
+</plist>
@@ -0,0 +1,14 @@
+//
+// Prefix header for all source files of the 'Demo' target in the 'Demo' project
+//
+
+#import <Availability.h>
+
+#ifndef __IPHONE_3_0
+#warning "This project uses features only available in iPhone SDK 3.0 and later."
+#endif
+
+#ifdef __OBJC__
+ #import <UIKit/UIKit.h>
+ #import <Foundation/Foundation.h>
+#endif
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
@@ -0,0 +1,11 @@
+// Created by Jason Morrissey - jasonmorrissey.org
+
+#import <UIKit/UIKit.h>
+
+int main(int argc, char *argv[])
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ int retVal = UIApplicationMain(argc, argv, nil, @"DemoAppDelegate");
+ [pool release];
+ return retVal;
+}
Oops, something went wrong.

0 comments on commit 157554a

Please sign in to comment.