forked from sprang/Inkpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWDGradientController.m
More file actions
118 lines (92 loc) · 2.9 KB
/
WDGradientController.m
File metadata and controls
118 lines (92 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// WDGradientController.m
// Inkpad
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2010-2013 Steve Sprang
//
#import "WDColorController.h"
#import "WDColorWell.h"
#import "WDColor.h"
#import "WDGradient.h"
#import "WDGradientController.h"
#import "WDGradientEditor.h"
#define kInactiveAlpha 0.5
@implementation WDGradientController
@synthesize gradient = gradient_;
@synthesize target = target_;
@synthesize action = action_;
@synthesize colorController = colorController_;
@synthesize inactive = inactive_;
- (IBAction) takeGradientTypeFrom:(id)sender
{
if (gradient_.type == kWDRadialGradient) {
[self setGradient:[gradient_ gradientWithType:kWDLinearGradient]];
} else {
[self setGradient:[gradient_ gradientWithType:kWDRadialGradient]];
}
[[UIApplication sharedApplication] sendAction:action_ to:target_ from:self forEvent:nil];
}
- (void) setGradient:(WDGradient *)gradient
{
gradient_ = gradient;
[colorWell_ setPainter:gradient_];
[gradientEditor_ setGradient:gradient_];
if (gradient_.type == kWDLinearGradient) {
[typeButton_ setImage:[UIImage imageNamed:@"linear.png"] forState:UIControlStateNormal];
} else {
[typeButton_ setImage:[UIImage imageNamed:@"radial.png"] forState:UIControlStateNormal];
}
}
- (IBAction) takeGradientStopsFrom:(id)sender
{
WDGradientEditor *editor = (WDGradientEditor *) sender;
self.gradient = [self.gradient gradientWithStops:[editor stops]];
[[UIApplication sharedApplication] sendAction:action_ to:target_ from:self forEvent:nil];
}
- (void) setColor:(WDColor *)color
{
[gradientEditor_ setColor:color];
}
- (void) colorSelected:(WDColor *)color
{
[colorController_ setColor:color];
}
- (void) setInactive:(BOOL)inactive
{
if (inactive_ == inactive) {
return;
}
inactive_ = inactive;
gradientEditor_.inactive = inactive;
}
- (void) reverseGradient:(id)sender
{
self.gradient = [self.gradient gradientByReversing];
[[UIApplication sharedApplication] sendAction:action_ to:target_ from:self forEvent:nil];
}
- (void) distributeGradientStops:(id)sender
{
self.gradient = [self.gradient gradientByDistributingEvenly];
[[UIApplication sharedApplication] sendAction:action_ to:target_ from:self forEvent:nil];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (!self) {
return nil;
}
self.gradient = [WDGradient defaultGradient];
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = nil;
self.view.opaque = NO;
gradientEditor_.controller = self;
}
@end