Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Make the HSL example more concrete, add a bunch of labels, and do som…
Browse files Browse the repository at this point in the history
…e refactoring.
  • Loading branch information
SlaunchaMan committed Mar 22, 2013
1 parent 7b035ce commit 9bc8f68
Show file tree
Hide file tree
Showing 8 changed files with 845 additions and 633 deletions.
24 changes: 12 additions & 12 deletions AmazeKit/AmazeKit.xcodeproj/project.pbxproj
Expand Up @@ -73,8 +73,8 @@
1FDCA6381587E0040010B272 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1FDCA6361587E0040010B272 /* InfoPlist.strings */; };
1FDCA63A1587E0040010B272 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDCA6391587E0040010B272 /* main.m */; };
1FDCA63E1587E0040010B272 /* AKAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDCA63D1587E0040010B272 /* AKAppDelegate.m */; };
1FDCA6411587E0040010B272 /* AKViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDCA6401587E0040010B272 /* AKViewController.m */; };
1FDCA6441587E0040010B272 /* AKViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1FDCA6421587E0040010B272 /* AKViewController.xib */; };
1FDCA6411587E0040010B272 /* AKHSLAdjustingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FDCA6401587E0040010B272 /* AKHSLAdjustingViewController.m */; };
1FDCA6441587E0040010B272 /* AKHSLAdjustingViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1FDCA6421587E0040010B272 /* AKHSLAdjustingViewController.xib */; };
1FEC1AC315C1C33E00C5C0D1 /* AKPatternImageEffect.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FEC1AC115C1C33E00C5C0D1 /* AKPatternImageEffect.h */; };
1FEC1AC415C1C33E00C5C0D1 /* AKPatternImageEffect.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FEC1AC215C1C33E00C5C0D1 /* AKPatternImageEffect.m */; };
1FFDAC2D1587828A00837D3A /* UIImage+AKPixelData.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FFDAC2B1587828A00837D3A /* UIImage+AKPixelData.h */; };
Expand Down Expand Up @@ -163,9 +163,9 @@
1FDCA63B1587E0040010B272 /* SampleApp-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SampleApp-Prefix.pch"; sourceTree = "<group>"; };
1FDCA63C1587E0040010B272 /* AKAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AKAppDelegate.h; sourceTree = "<group>"; };
1FDCA63D1587E0040010B272 /* AKAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AKAppDelegate.m; sourceTree = "<group>"; };
1FDCA63F1587E0040010B272 /* AKViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AKViewController.h; sourceTree = "<group>"; };
1FDCA6401587E0040010B272 /* AKViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AKViewController.m; sourceTree = "<group>"; };
1FDCA6431587E0040010B272 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/AKViewController.xib; sourceTree = "<group>"; };
1FDCA63F1587E0040010B272 /* AKHSLAdjustingViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AKHSLAdjustingViewController.h; sourceTree = "<group>"; };
1FDCA6401587E0040010B272 /* AKHSLAdjustingViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AKHSLAdjustingViewController.m; sourceTree = "<group>"; };
1FDCA6431587E0040010B272 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/AKHSLAdjustingViewController.xib; sourceTree = "<group>"; };
1FEC1AC115C1C33E00C5C0D1 /* AKPatternImageEffect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AKPatternImageEffect.h; sourceTree = "<group>"; };
1FEC1AC215C1C33E00C5C0D1 /* AKPatternImageEffect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AKPatternImageEffect.m; sourceTree = "<group>"; };
1FFDAC2B1587828A00837D3A /* UIImage+AKPixelData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+AKPixelData.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -357,9 +357,9 @@
children = (
1FDCA63C1587E0040010B272 /* AKAppDelegate.h */,
1FDCA63D1587E0040010B272 /* AKAppDelegate.m */,
1FDCA63F1587E0040010B272 /* AKViewController.h */,
1FDCA6401587E0040010B272 /* AKViewController.m */,
1FDCA6421587E0040010B272 /* AKViewController.xib */,
1FDCA63F1587E0040010B272 /* AKHSLAdjustingViewController.h */,
1FDCA6401587E0040010B272 /* AKHSLAdjustingViewController.m */,
1FDCA6421587E0040010B272 /* AKHSLAdjustingViewController.xib */,
1FDCA6341587E0040010B272 /* Supporting Files */,
);
path = SampleApp;
Expand Down Expand Up @@ -528,7 +528,7 @@
buildActionMask = 2147483647;
files = (
1FDCA6381587E0040010B272 /* InfoPlist.strings in Resources */,
1FDCA6441587E0040010B272 /* AKViewController.xib in Resources */,
1FDCA6441587E0040010B272 /* AKHSLAdjustingViewController.xib in Resources */,
1FA95AE8160B5FF00039106B /* Default-568h@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -596,7 +596,7 @@
files = (
1FDCA63A1587E0040010B272 /* main.m in Sources */,
1FDCA63E1587E0040010B272 /* AKAppDelegate.m in Sources */,
1FDCA6411587E0040010B272 /* AKViewController.m in Sources */,
1FDCA6411587E0040010B272 /* AKHSLAdjustingViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -632,12 +632,12 @@
name = InfoPlist.strings;
sourceTree = "<group>";
};
1FDCA6421587E0040010B272 /* AKViewController.xib */ = {
1FDCA6421587E0040010B272 /* AKHSLAdjustingViewController.xib */ = {
isa = PBXVariantGroup;
children = (
1FDCA6431587E0040010B272 /* en */,
);
name = AKViewController.xib;
name = AKHSLAdjustingViewController.xib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
Expand Down
4 changes: 1 addition & 3 deletions AmazeKit/SampleApp/AKAppDelegate.h
Expand Up @@ -20,12 +20,10 @@

#import <UIKit/UIKit.h>

@class AKViewController;

@interface AKAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) AKViewController *viewController;
@property (strong, nonatomic) UIViewController *viewController;

@end
8 changes: 3 additions & 5 deletions AmazeKit/SampleApp/AKAppDelegate.m
Expand Up @@ -20,18 +20,16 @@

#import "AKAppDelegate.h"

#import "AKViewController.h"
#import "AKHSLAdjustingViewController.h"

@implementation AKAppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;
@implementation AKAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[AKViewController alloc] initWithNibName:@"AKViewController" bundle:nil];
self.viewController = [[AKHSLAdjustingViewController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
Expand Down
@@ -1,5 +1,5 @@
//
// AKViewController.h
// AKHSLAdjustingViewController.h
// SmapleApp
//
// Created by Jeffrey Kelley on 6/12/12.
Expand All @@ -18,8 +18,10 @@
// limitations under the License.
//


#import <UIKit/UIKit.h>

@interface AKViewController : UIViewController

@interface AKHSLAdjustingViewController : UIViewController

@end
216 changes: 216 additions & 0 deletions AmazeKit/SampleApp/AKHSLAdjustingViewController.m
@@ -0,0 +1,216 @@
//
// AKHSLAdjustingViewController.m
// SmapleApp
//
// Created by Jeffrey Kelley on 6/12/12.
// Copyright (c) 2013 Detroit Labs. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.
//


#import "AKHSLAdjustingViewController.h"

#import <QuartzCore/QuartzCore.h>

#import "AmazeKit.h"


@interface AKHSLAdjustingViewController () {
NSNumberFormatter *_sliderNumberFormatter;
}

// AmazeKit Components
@property (strong, nonatomic) AKMutableColorImageEffect *colorImageEffect;
@property (strong, nonatomic) AKImageCoordinator *imageCoordinator;

// UI Components
@property (strong, nonatomic) IBOutlet UIButton *button;
@property (strong, nonatomic) IBOutlet UILabel *hashLabel;
@property (strong, nonatomic) IBOutlet UILabel *hueLabel;
@property (strong, nonatomic) IBOutlet UISlider *hueSlider;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) IBOutlet UILabel *luminanceLabel;
@property (strong, nonatomic) IBOutlet UISlider *luminanceSlider;
@property (strong, nonatomic) IBOutlet UILabel *saturationLabel;
@property (strong, nonatomic) IBOutlet UISlider *saturationSlider;

- (void)adjustColorEffect;

// IBActions
- (IBAction)sliderValueChanged:(id)sender;

@end


@implementation AKHSLAdjustingViewController

#pragma mark - View Controller Lifecycle

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {
_sliderNumberFormatter = [[NSNumberFormatter alloc] init];

[_sliderNumberFormatter setMaximumFractionDigits:3];
[_sliderNumberFormatter setMinimumFractionDigits:1];
}

return self;
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

[self sliderValueChanged:nil];
[[self imageCoordinator] addImageView:[self imageView]];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];

[[self imageCoordinator] removeImageView:[self imageView]];
}

- (void)viewDidUnload
{
[self setButton:nil];
[self setHashLabel:nil];
[self setHueLabel:nil];
[self setHueSlider:nil];
[self setImageView:nil];
[self setLuminanceLabel:nil];
[self setLuminanceSlider:nil];
[self setSaturationLabel:nil];
[self setSaturationSlider:nil];

[super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation = UIInterfaceOrientationPortrait);
}

#pragma mark - HSL Adjusting View Controller Lifecycle

- (void)adjustColorEffect
{
UIColor *newColor = [UIColor colorWithHue:[[self hueSlider] value]
saturation:[[self saturationSlider] value]
brightness:[[self luminanceSlider] value]
alpha:1.0f];

[[self colorImageEffect] setColor:newColor];

[[self hashLabel] setText:[[[self imageCoordinator] imageRenderer] representativeHash]];
}

- (AKMutableColorImageEffect *)colorImageEffect
{
if (_colorImageEffect == nil) {
_colorImageEffect =
[[AKMutableColorImageEffect alloc] initWithAlpha:1.0f
blendMode:kCGBlendModeColor];
}

return _colorImageEffect;
}

- (AKImageCoordinator *)imageCoordinator
{
if (_imageCoordinator == nil) {
// Noise Effect
AKNoiseImageEffect *noiseEffect =
[[AKNoiseImageEffect alloc] initWithAlpha:0.05f
blendMode:kCGBlendModeMultiply
noiseType:AKNoiseTypeBlackAndWhite];

// Gradient Effect
UIColor *beginColor = [UIColor colorWithRed:144.0f / 255.0f
green:144.0f / 255.0f
blue:144.0f / 255.0f
alpha:1.0f];

UIColor *endColor = [UIColor colorWithRed:103.0f / 255.0f
green:103.0f / 255.0f
blue:103.0f / 255.0f
alpha:1.0f];

AKGradientImageEffect *gradientEffect =
[[AKGradientImageEffect alloc] initWithAlpha:1.0f
blendMode:kCGBlendModeMultiply
colors:@[beginColor, endColor]
direction:AKGradientDirectionVertical
locations:nil];

// Rounded Corners
AKCornerRadii cornerRadii = AKCornerRadiiMake(40.0f,
10.0f,
5.0f,
80.0f);

AKImageEffect *roundedCornerEffect =
[[AKCornerRadiusImageEffect alloc] initWithAlpha:1.0f
blendMode:kCGBlendModeNormal
cornerRadii:cornerRadii];

// Inner Glow
AKInnerGlowImageEffect *innerGlowEffect =
[[AKInnerGlowImageEffect alloc] initWithAlpha:0.25f
blendMode:kCGBlendModeMultiply
color:[UIColor blackColor]
radius:10.0f];

AKImageRenderer *imageRenderer = [[AKImageRenderer alloc] init];

[imageRenderer setImageEffects:@[
noiseEffect,
gradientEffect,
[self colorImageEffect],
roundedCornerEffect,
innerGlowEffect
]];

_imageCoordinator = [[AKImageCoordinator alloc] init];
[_imageCoordinator setImageRenderer:imageRenderer];
}

return _imageCoordinator;
}

#pragma mark - IBActions

- (IBAction)sliderValueChanged:(id)sender
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self adjustColorEffect];

[[self hueLabel] setText:
[_sliderNumberFormatter stringFromNumber:@([[self hueSlider] value])]];

[[self luminanceLabel] setText:
[_sliderNumberFormatter stringFromNumber:@([[self luminanceSlider] value])]];

[[self saturationLabel] setText:
[_sliderNumberFormatter stringFromNumber:@([[self saturationSlider] value])]];
}];
}

#pragma mark -

@end

0 comments on commit 9bc8f68

Please sign in to comment.