Skip to content
Snippets Groups Projects
Commit a20e4164 authored by George Nachman's avatar George Nachman
Browse files

Use lighter scrollbar scolor when background is dark.

parent ebc2c46f
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -33,6 +33,9 @@
{
BOOL userScroll;
}
@property (nonatomic, assign) BOOL hasDarkBackground;
+ (BOOL)isCompatibleWithOverlayScrollers;
- (id)init;
- (void) mouseDown: (NSEvent *)theEvent;
Loading
Loading
Loading
Loading
@@ -559,5 +559,6 @@ typedef enum {
// Returns true if any onscreen char is blinking.
- (BOOL)_markChangedSelectionAndBlinkDirty:(BOOL)redrawBlink width:(int)width;
 
- (double)_perceivedBrightness:(NSColor*)c;
@end
 
// From http://www.cocoadev.com/index.pl?NSImageCategory
//
// NSBitmapImageRep+CoreImage.h
// iTerm2
//
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
@interface NSBitmapImageRep (CoreImage)
/* Draws the specified image representation using Core Image. */
- (void)drawAtPoint:(NSPoint)point
fromRect:(NSRect)fromRect
coreImageFilter:(NSString *)filterName
arguments:(NSDictionary *)arguments;
@end
// From http://www.cocoadev.com/index.pl?NSImageCategory
// NSBitmapImageRep+CoreImage.m
// iTerm2
#import <QuartzCore/QuartzCore.h>
#import "NSBitmapImageRep+CoreImage.h"
#import "NSImage+CoreImage.h"
#define CIIMAGE_PADDING 16.0f
@implementation NSBitmapImageRep (CoreImage)
- (void)drawAtPoint: (NSPoint)point fromRect: (NSRect)fromRect coreImageFilter: (NSString *)filterName arguments: (NSDictionary *)arguments {
NSAutoreleasePool *pool;
CIFilter *filter;
CIImage *before;
CIImage *after;
CIContext *ciContext;
CGContextRef cgContext;
pool = [[NSAutoreleasePool alloc] init];
before = nil;
@try {
before = [[CIImage alloc] initWithBitmapImageRep: self];
if (before) {
filter = [CIFilter filterWithName: filterName];
[filter setDefaults];
if (arguments)
[filter setValuesForKeysWithDictionary: arguments];
[filter setValue: before forKey: @"inputImage"];
} else {
filter = nil;
}
after = [filter valueForKey: @"outputImage"];
if (after) {
if (![[arguments objectForKey: @"gt_noRenderPadding"] boolValue]) {
/* Add a wide berth to the bounds -- the padding can be turned
off by passing an NSNumber with a YES value in the argument
"gt_noRenderPadding" in the argument dictionary. */
fromRect.origin.x -= CIIMAGE_PADDING;
fromRect.origin.y -= CIIMAGE_PADDING;
fromRect.size.width += CIIMAGE_PADDING * 2.0f;
fromRect.size.height += CIIMAGE_PADDING * 2.0f;
point.x -= CIIMAGE_PADDING;
point.y -= CIIMAGE_PADDING;
}
cgContext = CGContextRetain((CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]);
if (cgContext) {
ciContext = [CIContext contextWithCGContext: cgContext options: nil];
[ciContext
drawImage: after
atPoint: *(CGPoint *)(&point)
fromRect: *(CGRect *)(&fromRect)];
CGContextRelease(cgContext);
}
}
} @catch (NSException *e) {
NSLog("exception encountered during core image filtering: %@", e);
} @finally {
[before release];
}
[pool release];
}
@end
// From http://www.cocoadev.com/index.pl?NSImageCategory
//
// NSImage+CoreImage.h
// iTerm2
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
@interface NSImage (CoreImage)
/* Draws the specified image using Core Image. */
- (void)drawAtPoint: (NSPoint)point fromRect: (NSRect)fromRect coreImageFilter: (NSString *)filterName arguments: (NSDictionary *)arguments;
/* Gets a bitmap representation of the image, or creates one if the image does not have any. */
- (NSBitmapImageRep *)bitmapImageRepresentation;
@end
// From http://www.cocoadev.com/index.pl?NSImageCategory
//
// NSImage+CoreImage.m
// iTerm2
#import "NSImage+CoreImage.h"
@implementation NSImage (CoreImage)
- (void)drawAtPoint: (NSPoint)point fromRect: (NSRect)fromRect coreImageFilter: (NSString *)filterName arguments: (NSDictionary *)arguments {
NSAutoreleasePool *pool;
NSBitmapImageRep *rep;
pool = [[NSAutoreleasePool alloc] init];
if (filterName) {
rep = [self bitmapImageRepresentation];
[rep
drawAtPoint: point
fromRect: fromRect
coreImageFilter: filterName
arguments: arguments];
} else {
/* bypass core image if no filter is specified */
[self
drawAtPoint: point
fromRect: fromRect
operation: NSCompositeSourceOver
fraction: 1.0f];
}
[pool release];
}
- (NSBitmapImageRep *)bitmapImageRepresentation {
NSImageRep *rep;
NSEnumerator *e;
Class bitmapImageRep;
bitmapImageRep = [NSBitmapImageRep class];
e = [[self representations] objectEnumerator];
while ((rep = [e nextObject]) != nil) {
if ([rep isKindOfClass: bitmapImageRep])
break;
rep = nil;
}
if (!rep)
rep = [NSBitmapImageRep imageRepWithData: [self TIFFRepresentation]];
return (NSBitmapImageRep *)rep;
}
@end
Loading
Loading
@@ -35,9 +35,12 @@
#import <iTerm/PTYScrollView.h>
#import <iTerm/PTYTextView.h>
#import <PreferencePanel.h>
#import <Cocoa/Cocoa.h>
 
@implementation PTYScroller
 
@synthesize hasDarkBackground;
- (id)init
{
userScroll=NO;
Loading
Loading
@@ -97,6 +100,31 @@
return [super hitPart];
}
 
- (void)drawRect:(NSRect)dirtyRect {
if (IsLionOrLater() && self.hasDarkBackground) {
NSImage *superDrawn = [[NSImage alloc] initWithSize:NSMakeSize(dirtyRect.origin.x + dirtyRect.size.width,
dirtyRect.origin.y + dirtyRect.size.height)];
[superDrawn lockFocus];
[super drawRect:dirtyRect];
[superDrawn unlockFocus];
NSImage *temp = [[NSImage alloc] initWithSize:[superDrawn size]];
[temp lockFocus];
[superDrawn drawAtPoint:dirtyRect.origin
fromRect:dirtyRect
coreImageFilter:@"CIColorControls"
arguments:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithDouble:0.5], @"inputBrightness", nil]];
[temp unlockFocus];
[temp drawAtPoint:dirtyRect.origin
fromRect:dirtyRect
operation:NSCompositeCopy
fraction:1.0];
} else {
[super drawRect:dirtyRect];
}
}
@end
 
@implementation PTYScrollView
Loading
Loading
Loading
Loading
@@ -66,6 +66,7 @@ static const int MAX_WORKING_DIR_COUNT = 50;
// Minimum distance that the mouse must move before a cmd+drag will be
// recognized as a drag.
static const int kDragThreshold = 3;
static const double kBackgroundConsideredDarkThreshold = 0.5;
 
// When drawing lines, we use this structure to represent a run of cells of
// the same font, color, and attributes.
Loading
Loading
@@ -113,6 +114,10 @@ static NSImage* bellImage = nil;
static NSImage* wrapToTopImage = nil;
static NSImage* wrapToBottomImage = nil;
 
static CGFloat PerceivedBrightness(CGFloat r, CGFloat g, CGFloat b) {
return (RED_COEFFICIENT * r) + (GREEN_COEFFICIENT * g) + (BLUE_COEFFICIENT * b);
}
@interface Coord : NSObject
{
@public
Loading
Loading
@@ -425,6 +430,9 @@ static NSImage* wrapToBottomImage = nil;
[defaultBGColor release];
[color retain];
defaultBGColor = color;
PTYScroller *scroller = (PTYScroller*)[[[dataSource session] SCROLLVIEW] verticalScroller];
BOOL isDark = ([self _perceivedBrightness:color] < kBackgroundConsideredDarkThreshold);
[scroller setHasDarkBackground:isDark];
[self setNeedsDisplay:YES];
}
 
Loading
Loading
@@ -4477,10 +4485,6 @@ static double EuclideanDistance(NSPoint p1, NSPoint p2) {
return newRuns;
}
 
static CGFloat PerceivedBrightness(CGFloat r, CGFloat g, CGFloat b) {
return (RED_COEFFICIENT * r) + (GREEN_COEFFICIENT * g) + (BLUE_COEFFICIENT * b);
}
- (double)_perceivedBrightness:(NSColor*) c
{
return PerceivedBrightness([c redComponent], [c greenComponent], [c blueComponent]);
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment