-
Notifications
You must be signed in to change notification settings - Fork 10
/
Rik+Menu.m
176 lines (154 loc) · 5.07 KB
/
Rik+Menu.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#import "Rik.h"
#include <AppKit/AppKit.h>
#import <Foundation/NSUserDefaults.h>
@interface Rik(RikMenu)
@end
@implementation Rik(RikMenu)
- (NSColor *) menuBorderColor
{
NSColor *color = [NSColor colorWithCalibratedRed: 0.212 green: 0.184 blue: 0.176 alpha: 1.0];
return color;
}
- (NSColor *) menuBackgroundColor
{
NSColor *color = [NSColor colorWithCalibratedRed: 0.992 green: 0.992 blue: 0.992 alpha: 1.0];
return color;
}
- (NSColor *) menuItemBackgroundColor
{
NSColor *color = [NSColor colorWithCalibratedRed: 0.992 green: 0.992 blue: 0.992 alpha: 0.9];
return color;
}
- (CGFloat) menuSubmenuHorizontalOverlap
{
return 3;
}
-(CGFloat) menuSubmenuVerticalOverlap
{
return 6;
}
- (CGFloat) menuBarHeight
{
return 26;
}
- (CGFloat) menuItemHeight
{
return 26;
}
- (CGFloat) menuSeparatorHeight
{
return 20;
}
- (void) drawMenuRect: (NSRect)rect
inView: (NSView *)view
isHorizontal: (BOOL)horizontal
itemCells: (NSArray *)itemCells
{
int i = 0;
int howMany = [itemCells count];
NSMenuView *menuView = (NSMenuView *)view;
NSRect bounds = [view bounds];
NSRect r = NSIntersectionRect(bounds, rect);
NSRectFillUsingOperation(bounds, NSCompositeClear);
NSBezierPath * menuPath;
NSColor *borderColor = [self menuBorderColor];
[borderColor setStroke];
if(horizontal == YES)
{
// here the semitrasparent status bar...
// TODO the transparency sould be optional
menuPath = [NSBezierPath bezierPathWithRect:bounds];
NSColor* fillColor = [self menuBackgroundColor];
[fillColor setFill];
NSRectFill(bounds);
NSBezierPath* linePath = [NSBezierPath bezierPath];
[linePath moveToPoint: NSMakePoint(bounds.origin.x, bounds.origin.y)];
[linePath lineToPoint: NSMakePoint(bounds.origin.x+ bounds.size.width, bounds.origin.y)];
[linePath setLineWidth: 1];
[linePath stroke];
}
else
{
// here the vertical menus
CGFloat radius = 6;
menuPath = [NSBezierPath bezierPathWithRoundedRect: bounds
xRadius: radius
yRadius: radius];
[[self menuBackgroundColor] setFill];
[menuPath fill];
NSBezierPath * strokemenuPath = [NSBezierPath bezierPathWithRoundedRect: bounds
xRadius: radius
yRadius: radius];
[strokemenuPath stroke];
}
// Draw the menu cells.
for (i = 0; i < howMany; i++)
{
NSRect aRect;
NSMenuItemCell *aCell;
aRect = [menuView rectOfItemAtIndex: i];
if (NSIntersectsRect(rect, aRect) == YES)
{
aCell = [menuView menuItemCellForItemAtIndex: i];
[aCell drawWithFrame: aRect inView: menuView];
}
}
}
- (void) drawBackgroundForMenuView: (NSMenuView*)menuView
withFrame: (NSRect)bounds
dirtyRect: (NSRect)dirtyRect
horizontal: (BOOL)horizontal
{
NSString *name = horizontal ? GSMenuHorizontalBackground :
GSMenuVerticalBackground;
NSRectEdge sides[4] = { NSMinXEdge, NSMaxYEdge, NSMaxXEdge, NSMinYEdge };
[[self menuBackgroundColor] setFill];
NSRect r = NSIntersectionRect(bounds, dirtyRect);
NSRectFillUsingOperation(r, NSCompositeClear);
NSBezierPath * roundedRectanglePath = [NSBezierPath bezierPathWithRoundedRect:r xRadius: 4 yRadius: 4];
NSColor *borderColor = [self menuBorderColor];
[borderColor setStroke];
[roundedRectanglePath fill];
[roundedRectanglePath stroke];
}
- (void) drawBorderAndBackgroundForMenuItemCell: (NSMenuItemCell *)cell
withFrame: (NSRect)cellFrame
inView: (NSView *)controlView
state: (GSThemeControlState)state
isHorizontal: (BOOL)isHorizontal
{
NSColor * backgroundColor = [self menuBackgroundColor];
NSColor* selectedBackgroundColor1 = [NSColor colorWithCalibratedRed: 0.392 green: 0.533 blue: 0.953 alpha: 1];
NSColor* selectedBackgroundColor2 = [NSColor colorWithCalibratedRed: 0.165 green: 0.373 blue: 0.929 alpha: 1];
NSColor* menuItemBackground = [self menuBackgroundColor];
NSGradient* menuitemgradient = [[NSGradient alloc] initWithStartingColor: selectedBackgroundColor1
endingColor: selectedBackgroundColor2];
NSColor * c;
cellFrame = [cell drawingRectForBounds: cellFrame];
if(isHorizontal)
{
cellFrame.origin.y = 1;
}
if (state == GSThemeSelectedState || state == GSThemeHighlightedState)
{
NSRectFillUsingOperation(cellFrame, NSCompositeClear);
[menuitemgradient drawInRect:cellFrame angle: -90];
return;
}
else
{
if(isHorizontal)
{
return;
}
else
{
c = menuItemBackground;
}
}
// Set cell's background color
[c setFill];
NSRectFillUsingOperation(cellFrame, NSCompositeClear);
NSRectFill(cellFrame);
}
@end