-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQSMouseTriggerDisplayView.m
46 lines (38 loc) · 1.61 KB
/
QSMouseTriggerDisplayView.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
#import "QSMouseTriggerDisplayView.h"
@implementation QSMouseTriggerDisplayView
- (id)initWithFrame:(NSRect)frame anchor:(NSUInteger)thisAnchor{
self = [super initWithFrame:frame];
if (self) {
anchor=thisAnchor;
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)rect {
NSColor *highlight=[NSColor alternateSelectedControlColor];
if (anchor<5){
// [[NSColor whiteColor]set];
// NSRectFill(rect);
NSImage *image=[[NSBundle bundleForClass:[QSMouseTriggerDisplayView class]]imageNamed:@"Flare"];
NSRect drawRect=alignRectInRect(rectFromSize([image size]),rect,anchor);
[image drawInRect:drawRect fromRect:rectFromSize([image size]) operation:NSCompositeSourceOver fraction:1.0];
[highlight set];
NSRectFillUsingOperation(rect,NSCompositeSourceIn);
} else {
[self _drawRect:(NSRect)rect withGradientFrom:highlight to:[[NSColor selectedTextBackgroundColor] colorWithAlphaComponent:0.0] start:anchor-5];
}
}
- (void)_drawRect:(NSRect)rect withGradientFrom:(NSColor*)colorStart to:(NSColor*)colorEnd start:(NSRectEdge)edge{
NSRect remainingRect;
int i;
int index = (int)(edge==NSMinXEdge||edge==NSMaxXEdge)?rect.size.width:rect.size.height;
remainingRect = rect;
NSColor *colors[index];
NSRect rects[index];
for ( i = 0; i < index; i++ ){
NSDivideRect ( remainingRect, &rects[i], &remainingRect, 1.0, edge);
colors[i]=[colorStart blendedColorWithFraction:(CGFloat)i/(CGFloat)index ofColor:colorEnd];
}
NSRectFillListWithColors(&rects[0],&colors[0],index);
}
@end