-
Notifications
You must be signed in to change notification settings - Fork 6
/
CTGradientView.m
102 lines (83 loc) · 2.55 KB
/
CTGradientView.m
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
//
// CTGradientView.m
//
// Created by Chad Weider on 12/2/05.
// Copyright (c) 2005 Chad Weider.
// Some rights reserved: <http://creativecommons.org/licenses/by/2.5/>
//
#import "CTGradientView.h"
@implementation CTGradientView
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self)
{
myGradient = [[CTGradient aquaSelectedGradient] retain];
angle = 90;
isRadial = NO;
}
return self;
}
- (void)dealloc
{
[myGradient release];
[super dealloc];
}
- (bool)isOpaque
{
return NO;
}
- (void)drawRect:(NSRect)rect
{
CTGradient *aGradient = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:myGradient]];
if(isRadial)
[aGradient radialFillRect:rect];
else
[aGradient fillRect:rect angle:angle];
//{
//rect = NSMakeRect(346,-300,50,600);
//NSAffineTransform *transform = [[NSAffineTransform alloc] init];
//[transform rotateByDegrees:45];
//NSBezierPath *path = [transform transformBezierPath:[NSBezierPath bezierPathWithOvalInRect:rect]];
//[aGradient fillBezierPath:path angle:angle];
//}
}
- (IBAction)changeAngle:(id)sender
{
angle = 90.0 - [sender floatValue];
[self setNeedsDisplay:YES];
}
- (IBAction)changeType:(id)sender
{
if([[[sender selectedCell] title] isEqualToString:@"Axial"])
isRadial = NO;
else
isRadial = YES;
[self setNeedsDisplay:YES];
}
- (IBAction)changeStyle:(id)sender
{
[myGradient release];
switch([sender indexOfSelectedItem])
{
case 1: myGradient = [CTGradient aquaSelectedGradient]; break;
case 2: myGradient = [CTGradient aquaNormalGradient ]; break;
case 3: myGradient = [CTGradient aquaPressedGradient ]; break;
case 4: myGradient = [CTGradient unifiedSelectedGradient]; break;
case 5: myGradient = [CTGradient unifiedNormalGradient ]; break;
case 6: myGradient = [CTGradient unifiedPressedGradient ]; break;
case 7: myGradient = [CTGradient unifiedDarkGradient ]; break;
case 8: myGradient = [CTGradient sourceListSelectedGradient ]; break;
case 9: myGradient = [CTGradient sourceListUnselectedGradient]; break;
case 10: myGradient = [CTGradient rainbowGradient]; break;
case 11: myGradient = [CTGradient hydrogenSpectrumGradient]; break;
default: myGradient = [CTGradient gradientWithBeginningColor:[NSColor blackColor]
endingColor:[NSColor whiteColor]];
}
[myGradient retain];
[self setNeedsDisplay:YES];
}
- (void)windowWillClose:(NSNotification *)aNotification
{
[NSApp terminate:self];
}
@end