Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move FindCursorView into its own file
- Loading branch information
Showing
6 changed files
with
84 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// FindCursorView.h | ||
// iTerm | ||
// | ||
// Created by George Nachman on 12/26/13. | ||
// | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface FindCursorView : NSView { | ||
NSPoint cursor; | ||
} | ||
|
||
@property (nonatomic, assign) NSPoint cursor; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// FindCursorView.m | ||
// iTerm | ||
// | ||
// Created by George Nachman on 12/26/13. | ||
// | ||
// | ||
|
||
#import "FindCursorView.h" | ||
|
||
// When performing the "find cursor" action, a gray window is shown with a | ||
// transparent "hole" around the cursor. This is the radius of that hole in | ||
// pixels. | ||
const double kFindCursorHoleRadius = 30; | ||
|
||
@implementation FindCursorView | ||
|
||
@synthesize cursor; | ||
|
||
- (void)drawRect:(NSRect)dirtyRect | ||
{ | ||
const double initialAlpha = 0.7; | ||
NSGradient *grad = [[NSGradient alloc] initWithStartingColor:[NSColor whiteColor] | ||
endingColor:[NSColor blackColor]]; | ||
NSPoint relativeCursorPosition = NSMakePoint(2 * (cursor.x / self.frame.size.width - 0.5), | ||
2 * (cursor.y / self.frame.size.height - 0.5)); | ||
[grad drawInRect:NSMakeRect(0, 0, self.frame.size.width, self.frame.size.height) | ||
relativeCenterPosition:relativeCursorPosition]; | ||
[grad release]; | ||
|
||
double x = cursor.x; | ||
double y = cursor.y; | ||
|
||
const double numSteps = 1; | ||
const double stepSize = 1; | ||
const double initialRadius = kFindCursorHoleRadius + numSteps * stepSize; | ||
double a = initialAlpha; | ||
for (double focusRadius = initialRadius; | ||
a > 0 && focusRadius >= initialRadius - numSteps * stepSize; | ||
focusRadius -= stepSize) { | ||
[[NSGraphicsContext currentContext] setCompositingOperation:NSCompositeCopy]; | ||
NSBezierPath *circle = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(x - focusRadius, | ||
y - focusRadius, | ||
focusRadius * 2, | ||
focusRadius * 2)]; | ||
a -= initialAlpha / numSteps; | ||
a = MAX(0, a); | ||
[[NSColor colorWithDeviceWhite:0.5 alpha:a] set]; | ||
[circle fill]; | ||
} | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters