Skip to content

Commit

Permalink
better screen detection. Improved preview quality
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardelben committed Sep 15, 2011
1 parent b6e799d commit eed8d0a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 115 deletions.
6 changes: 0 additions & 6 deletions Color Picker Pro.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
555BB72D141DE18A00AE82A9 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 555BB72C141DE18A00AE82A9 /* Sparkle.framework */; };
555BB730141DE1B700AE82A9 /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 555BB72C141DE18A00AE82A9 /* Sparkle.framework */; };
555BB733141DE5E500AE82A9 /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 555BB732141DE5E500AE82A9 /* dsa_pub.pem */; };
55A8833714151D5D0076BB4A /* NSScreen+PointConversion.m in Sources */ = {isa = PBXBuildFile; fileRef = 55A8833614151D5D0076BB4A /* NSScreen+PointConversion.m */; };
55A8833A1415357E0076BB4A /* ColorPicker_menubar.png in Resources */ = {isa = PBXBuildFile; fileRef = 55A883391415357E0076BB4A /* ColorPicker_menubar.png */; };
55A8833C141539E10076BB4A /* APPL.icns in Resources */ = {isa = PBXBuildFile; fileRef = 55A8833B141539E10076BB4A /* APPL.icns */; };
55A8833E14153BCA0076BB4A /* close.png in Resources */ = {isa = PBXBuildFile; fileRef = 55A8833D14153BCA0076BB4A /* close.png */; };
Expand Down Expand Up @@ -67,8 +66,6 @@
555BB72C141DE18A00AE82A9 /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Sparkle.framework; sourceTree = "<group>"; };
555BB732141DE5E500AE82A9 /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsa_pub.pem; sourceTree = "<group>"; };
558D25E61417BB69004031C3 /* Color Picker Pro.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Color Picker Pro.entitlements"; sourceTree = "<group>"; };
55A8833514151D5D0076BB4A /* NSScreen+PointConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSScreen+PointConversion.h"; sourceTree = "<group>"; };
55A8833614151D5D0076BB4A /* NSScreen+PointConversion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSScreen+PointConversion.m"; sourceTree = "<group>"; };
55A883391415357E0076BB4A /* ColorPicker_menubar.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ColorPicker_menubar.png; sourceTree = "<group>"; };
55A8833B141539E10076BB4A /* APPL.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = APPL.icns; sourceTree = "<group>"; };
55A8833D14153BCA0076BB4A /* close.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = close.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -244,8 +241,6 @@
55C9F189140236EA00321C9E /* RSLoginItems.m */,
550A63CD1406567B00864125 /* NSColorFormatter.h */,
550A63CE1406567B00864125 /* NSColorFormatter.m */,
55A8833514151D5D0076BB4A /* NSScreen+PointConversion.h */,
55A8833614151D5D0076BB4A /* NSScreen+PointConversion.m */,
55A8833F1415F8EE0076BB4A /* PreferencesController.h */,
55A883401415F8EE0076BB4A /* PreferencesController.m */,
55A8834E14162EF80076BB4A /* HelpController.h */,
Expand Down Expand Up @@ -370,7 +365,6 @@
55C9F1A81402E00E00321C9E /* ColorHistoryView.m in Sources */,
55C9F1B61402F29800321C9E /* DDHotKeyCenter.m in Sources */,
550A63CF1406567B00864125 /* NSColorFormatter.m in Sources */,
55A8833714151D5D0076BB4A /* NSScreen+PointConversion.m in Sources */,
55A883421415F8EF0076BB4A /* PreferencesController.m in Sources */,
55A8835014162EF80076BB4A /* HelpController.m in Sources */,
5510B8FE141E4EF3005FD2CA /* EventsResponderView.m in Sources */,
Expand Down
12 changes: 5 additions & 7 deletions ColorPicker/AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#import "RSLoginItems.h"
#import "DDHotKeyCenter.h"
#import "NSColorFormatter.h"
#import "NSScreen+PointConversion.h"
#import "PreferencesController.h"
#import "HelpController.h"
#import "EventsResponderView.h"
Expand Down Expand Up @@ -104,12 +103,11 @@ - (void)toggleShowWindow
- (void)updateViews
{
NSPoint mouseLocation = [NSEvent mouseLocation];

NSScreen *screen = [NSScreen currentScreenForMouseLocation];
NSPoint normalizedPoint = [screen flipPoint:[screen convertPointToScreenCoordinates:mouseLocation]];

statusItemView.mouseLocation = normalizedPoint;
viewController.mouseLocation = normalizedPoint;
NSScreen *principalScreen = [[NSScreen screens] objectAtIndex:0];
mouseLocation = NSMakePoint(mouseLocation.x, principalScreen.frame.size.height - mouseLocation.y);

statusItemView.mouseLocation = mouseLocation;
viewController.mouseLocation = mouseLocation;

[statusItemView setNeedsDisplay:YES];
[viewController updateView];
Expand Down
41 changes: 5 additions & 36 deletions ColorPicker/ColorPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,19 @@
//

#import "ColorPicker.h"
#import "NSScreen+PointConversion.h"

#define kWidth 28
#define kHeight 28

@implementation ColorPicker

#pragma mark Utils

+ (CGImageRef)getImageRefForScreen:(NSScreen *)aScreen forRect:(CGRect)aRect
{
NSNumber *screenNumber = [[aScreen deviceDescription] objectForKey:@"NSScreenNumber"];
CGDirectDisplayID displayID = (CGDirectDisplayID) [screenNumber pointerValue];

return CGDisplayCreateImageForRect(displayID, aRect);
}

+(CGImageRef)getImageRefForRect:(CGRect)aRect
{
CGImageRef imageRef = [self getImageRefForScreen:[NSScreen currentScreenForMouseLocation] forRect:aRect];

if (imageRef == NULL) {
NSLog(@"Warning: imageRef returned NULL. DisplayID was probably invalid. Using the default screen as fallback.");

imageRef = [self getImageRefForScreen:[NSScreen mainScreen] forRect:aRect];

// Check if NULL again
if (imageRef == NULL) {
NSLog(@"Warning: imageRef NULL after using the default monitor. Returning");
return nil;
}
}

return imageRef;
}


#pragma mark -

+ (NSImage *)imageForLocation:(NSPoint)mouseLocation
+ (NSImage *)imageForLocation:(NSPoint)mouseLocation;
{
CGRect imageRect = CGRectMake(fabs(mouseLocation.x) - kWidth / 2, fabs(mouseLocation.y) - kHeight / 2, kWidth, kHeight);
CGRect imageRect = CGRectMake(mouseLocation.x - kWidth / 2, mouseLocation.y - kHeight / 2, kWidth, kHeight);

CGImageRef imageRef = [self getImageRefForRect:imageRect];
CGImageRef imageRef = CGWindowListCreateImage(imageRect, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageShouldBeOpaque);

NSImage *image = [[NSImage alloc] initWithCGImage:imageRef size:NSMakeSize(kWidth, kHeight)];

Expand All @@ -62,9 +31,9 @@ + (NSImage *)imageForLocation:(NSPoint)mouseLocation

+ (NSColor *)colorAtLocation:(NSPoint)mouseLocation
{
CGRect imageRect = CGRectMake(fabs(mouseLocation.x), fabs(mouseLocation.y), 1, 1);
CGRect imageRect = CGRectMake(mouseLocation.x, mouseLocation.y, 1, 1);

CGImageRef imageRef = [self getImageRefForRect:imageRect];
CGImageRef imageRef = CGWindowListCreateImage(imageRect, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);

NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:imageRef];

Expand Down
28 changes: 0 additions & 28 deletions ColorPicker/NSScreen+PointConversion.h

This file was deleted.

38 changes: 0 additions & 38 deletions ColorPicker/NSScreen+PointConversion.m

This file was deleted.

0 comments on commit eed8d0a

Please sign in to comment.