Skip to content

Commit

Permalink
Move FindCursorView into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
gnachman committed Dec 27, 2013
1 parent 3832901 commit 2384194
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 46 deletions.
17 changes: 17 additions & 0 deletions FindCursorView.h
@@ -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
52 changes: 52 additions & 0 deletions FindCursorView.m
@@ -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
9 changes: 1 addition & 8 deletions PTYTextView.h
Expand Up @@ -43,6 +43,7 @@
#define VMARGIN 2
#define COLOR_KEY_SIZE 4

@class FindCursorView;
@class MovingAverage;
@class PTYScrollView;
@class PTYSession; // TODO: Remove this after PTYTextView doesn't depend directly on PTYSession
Expand Down Expand Up @@ -89,14 +90,6 @@ enum {
SELECT_WHOLE_LINE
};

@interface FindCursorView : NSView {
NSPoint cursor;
}

@property (nonatomic, assign) NSPoint cursor;

@end

@class CRunStorage;

@interface PTYTextView : NSView <NSTextInput, PointerControllerDelegate, TrouterDelegate>
Expand Down
39 changes: 1 addition & 38 deletions PTYTextView.m
Expand Up @@ -57,6 +57,7 @@
#import "AsyncHostLookupController.h"
#import "CharacterRun.h"
#import "CharacterRunInline.h"
#import "FindCursorView.h"
#import "FontSizeEstimator.h"
#import "FutureMethods.h"
#import "FutureMethods.h"
Expand Down Expand Up @@ -91,11 +92,6 @@
#include <math.h>
#include <sys/time.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;

const int kDragPaneModifiers = (NSAlternateKeyMask | NSCommandKeyMask | NSShiftKeyMask);
// If the cursor's background color is too close to nearby background colors,
// force it to the "most different" color. This is the difference threshold
Expand All @@ -113,39 +109,6 @@
static NSString *const kHostnameLookupSucceeded = @"kHostnameLookupSucceeded";
static PTYTextView *gCurrentKeyEventTextView; // See comment in -keyDown:

@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


// Minimum distance that the mouse must move before a cmd+drag will be
// recognized as a drag.
Expand Down
10 changes: 10 additions & 0 deletions iTerm.xcodeproj/project.pbxproj
Expand Up @@ -591,6 +591,9 @@
A63F40A9183F3CED003A6A6D /* LineBufferHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = A63F40A7183F3CED003A6A6D /* LineBufferHelpers.h */; };
A63F40AA183F3CED003A6A6D /* LineBufferHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = A63F40A8183F3CED003A6A6D /* LineBufferHelpers.m */; };
A63F40AB183F3CED003A6A6D /* LineBufferHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = A63F40A8183F3CED003A6A6D /* LineBufferHelpers.m */; };
A68A30C1186D0DC1007F550F /* FindCursorView.h in Headers */ = {isa = PBXBuildFile; fileRef = A68A30BF186D0DC1007F550F /* FindCursorView.h */; };
A68A30C2186D0DC1007F550F /* FindCursorView.m in Sources */ = {isa = PBXBuildFile; fileRef = A68A30C0186D0DC1007F550F /* FindCursorView.m */; };
A68A30C3186D0DC1007F550F /* FindCursorView.m in Sources */ = {isa = PBXBuildFile; fileRef = A68A30C0186D0DC1007F550F /* FindCursorView.m */; };
A693395C1851A61D00EBEA20 /* VT100ScreenMark.h in Headers */ = {isa = PBXBuildFile; fileRef = A693395A1851A61D00EBEA20 /* VT100ScreenMark.h */; };
A693395D1851A61D00EBEA20 /* VT100ScreenMark.m in Sources */ = {isa = PBXBuildFile; fileRef = A693395B1851A61D00EBEA20 /* VT100ScreenMark.m */; };
A693395E1851A61D00EBEA20 /* VT100ScreenMark.m in Sources */ = {isa = PBXBuildFile; fileRef = A693395B1851A61D00EBEA20 /* VT100ScreenMark.m */; };
Expand Down Expand Up @@ -1003,6 +1006,8 @@
A63F40A3183F3B78003A6A6D /* LineBlock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LineBlock.m; sourceTree = "<group>"; };
A63F40A7183F3CED003A6A6D /* LineBufferHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineBufferHelpers.h; sourceTree = "<group>"; };
A63F40A8183F3CED003A6A6D /* LineBufferHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LineBufferHelpers.m; sourceTree = "<group>"; };
A68A30BF186D0DC1007F550F /* FindCursorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FindCursorView.h; sourceTree = "<group>"; };
A68A30C0186D0DC1007F550F /* FindCursorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FindCursorView.m; sourceTree = "<group>"; };
A693395A1851A61D00EBEA20 /* VT100ScreenMark.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VT100ScreenMark.h; sourceTree = "<group>"; };
A693395B1851A61D00EBEA20 /* VT100ScreenMark.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VT100ScreenMark.m; sourceTree = "<group>"; };
A6C4E8DC1846E13800CFAA77 /* IntervalTree.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IntervalTree.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1148,6 +1153,8 @@
0464AB0D006CD2EC7F000001 /* JTerminal */ = {
isa = PBXGroup;
children = (
A68A30BF186D0DC1007F550F /* FindCursorView.h */,
A68A30C0186D0DC1007F550F /* FindCursorView.m */,
0464AB0E006CD2EC7F000001 /* Classes */,
0464AB15006CD2EC7F000001 /* Headers */,
0464AB1F006CD2EC7F000001 /* Other Sources */,
Expand Down Expand Up @@ -1888,6 +1895,7 @@
1D5FDD5D1208E8F000C46BA3 /* PSMRolloverButton.h in Headers */,
1D5FDD5E1208E8F000C46BA3 /* PSMTabBarCell.h in Headers */,
1D5FDD5F1208E8F000C46BA3 /* PSMTabBarControl.h in Headers */,
A68A30C1186D0DC1007F550F /* FindCursorView.h in Headers */,
1D81F0C3183C3CCD00910838 /* SBSystemPreferences.h in Headers */,
1D5FDD601208E8F000C46BA3 /* PSMTabStyle.h in Headers */,
1D5FDD611208E8F000C46BA3 /* NSBezierPath_AMShading.h in Headers */,
Expand Down Expand Up @@ -2336,6 +2344,7 @@
1D9A5585180FA87000B42CE9 /* iTermKeyBindingMgr.m in Sources */,
1D9A5595180FA87000B42CE9 /* PTYSession.m in Sources */,
1D9A555E180FA83900B42CE9 /* PreferencePanel.m in Sources */,
A68A30C3186D0DC1007F550F /* FindCursorView.m in Sources */,
1D9A558B180FA87000B42CE9 /* PasteEvent.m in Sources */,
1D9A556E180FA85900B42CE9 /* ToolJobs.m in Sources */,
1D9A55A1180FA87000B42CE9 /* TextViewWrapper.m in Sources */,
Expand Down Expand Up @@ -2565,6 +2574,7 @@
1DD6707814934ADE008E4361 /* PTYSplitView.m in Sources */,
1DD39B1B180B82F5004E56D5 /* DebugLogging.m in Sources */,
1DD4CE8114A51C0D00ED182E /* TmuxDashboardController.m in Sources */,
A68A30C2186D0DC1007F550F /* FindCursorView.m in Sources */,
1DA9AEEB14A51CA000BEB37B /* TmuxSessionsTable.m in Sources */,
1D0B613914A7BC1200C57C33 /* TmuxControllerRegistry.m in Sources */,
1D0B613D14A7C76500C57C33 /* TmuxWindowsTable.m in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions iTermTests/VT100ScreenTest.m
Expand Up @@ -419,6 +419,9 @@ - (void)screenDidAppendStringToCurrentLine:(NSString *)string {
[triggerLine_ appendString:string];
}

- (void)screenDidReset {
}

- (void)screenPrintString:(NSString *)s {
if (!printed_) {
printed_ = [NSMutableString string];
Expand Down

0 comments on commit 2384194

Please sign in to comment.