-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApMenuControl.m
executable file
·135 lines (110 loc) · 3.32 KB
/
ApMenuControl.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#import "ApMenuControl.h"
@implementation ApMenuControl
@synthesize thisFloatMenu, label, bundleController, dark,appControll;
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
dark= 0;
}
return self;
}
- (void)drawRect:(NSRect)rect{
NSRect bounds = [self bounds];
[[NSColor clearColor] set];
NSRectFill(bounds);
NSBezierPath * roundrect= [NSBezierPath bezierPathWithRoundedRect:bounds xRadius:10.0 yRadius:10.0];
NSGradient* aGradient =
[[[NSGradient alloc]
initWithColorsAndLocations:
[NSColor colorWithDeviceCyan:(0.46 + dark) magenta:(0.38 + dark) yellow:(0.39 + dark) black:(0.03 + dark) alpha:.8], (CGFloat)0.0,
[NSColor colorWithDeviceCyan:(0.24 + dark) magenta:(0.19 + dark) yellow:(0.19 + dark) black:(0 + dark) alpha:.8], (CGFloat)1.0,
nil]
autorelease];
[aGradient drawInBezierPath:roundrect angle:90];
[[[NSColor whiteColor] colorWithAlphaComponent:0.6] set];
//[roundrect stroke];
}
- (void)mouseDown:(NSEvent *)theEvent{
dark=0.1;
if(thisFloatMenu == nil){
[self menuFromBundle:bundleController];
}
[self setNeedsDisplay:YES];
}
-(void)mouseUp:(NSEvent *)theEvent{
dark=0;
[self setNeedsDisplay:YES];
if(thisFloatMenu == nil){
NSLog(@"qui");
/*
[[thisFloatMenu animator] setAlphaValue:1.0];
[[thisFloatMenu animator] setFrame:endPosition];
*/
}
else {
NSRect endPosition = [thisFloatMenu frame];
if([thisFloatMenu alphaValue] < 1.0){
endPosition.origin.y += ANIMATION_VALUE;
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.15f];
[[thisFloatMenu animator] setAlphaValue:1.0];
[[thisFloatMenu animator] setFrame:endPosition];
[NSAnimationContext endGrouping];
[self setNeedsDisplay:YES];
}
else {
endPosition.origin.y += -ANIMATION_VALUE;
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.2f];
[[thisFloatMenu animator] setAlphaValue:0.0];
[[thisFloatMenu animator] setFrame:endPosition];
[NSAnimationContext endGrouping];
[self setNeedsDisplay:YES];
}
}
}
-(void)releaseMenu{
[bundleController release];
[thisFloatMenu setAlphaValue:0.0];
thisFloatMenu = nil;
[thisFloatMenu autorelease];
}
-(void)menuFromBundle:(PieBundle *)bundle{
int menuX;
NSArray * methods = [bundle scripts];
NSRect frame = [self frame];
if(frame.origin.x == 67){
menuX = frame.origin.x - 32;
}
else if(frame.origin.x == 160){
menuX = frame.origin.x;
}
else if (frame.origin.x == 253) {
menuX = frame.origin.x + 32;
}
NSRect menuRect = NSMakeRect(menuX, (frame.origin.y - (([methods count]*CELL_HEIGHT)+10)-5)-ANIMATION_VALUE, frame.size.width, ([methods count]*CELL_HEIGHT)+10);
thisFloatMenu = [[FloatMenu alloc] initWithFrame:menuRect];
thisFloatMenu.menuController = bundle;
thisFloatMenu.myMenuControl = self;
[[[self window] contentView] addSubview:thisFloatMenu];
[thisFloatMenu setWantsLayer:YES];
[thisFloatMenu setAlphaValue:0.0];
//[thisFloatMenu setHidden:NO];
[thisFloatMenu addCells];
[self setWantsLayer:YES];
}
- (void)clickDone{
[appControll loadTransparentWindow];
}
- (void)configureMenuWithTitle:(NSString *)title andActive:(BOOL)type{
if(type){
[label setStringValue:title];
}
else{
[self setHidden:YES];
}
}
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent{
return YES;
}
@end