diff --git a/Uberlayer/Classes/ULAppDelegate.m b/Uberlayer/Classes/ULAppDelegate.m index 2e242ef..0a596c6 100644 --- a/Uberlayer/Classes/ULAppDelegate.m +++ b/Uberlayer/Classes/ULAppDelegate.m @@ -49,14 +49,11 @@ @implementation ULAppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - [self startApplication]; } - (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename { - [self.imageWindowController.window close]; - NSURL *imageURL = [NSURL fileURLWithPath:filename]; [self loadImage:imageURL]; @@ -140,7 +137,7 @@ - (void)loadImage:(NSURL *)url NSError *error; - CGSize calculatedSize = [NSImage sizeOfImageAtURL:url error:&error]; + CGSize calculatedSize = [NSImage ptSizeOfImageAtURL:url error:&error]; NSString *currentFileExtension = [[url pathExtension] lowercaseString]; NSArray *regularImageExtensions = [NSArray arrayWithObjects:@"jpg", @"jpeg", @"png", nil]; @@ -167,35 +164,38 @@ - (void)loadImage:(NSURL *)url - (void)showImage:(NSImage *)image { - [self.welcomeWindowController close]; NSRect oldRect = self.imageWindowController.window.frame; - NSSize imageSize = [image size]; - NSRect imageFrame = NSMakeRect(0, 0, imageSize.width, imageSize.height); + loadedImageSize = [image size]; - ULMouseDownCanMoveWindowImageView *imageView = [[ULMouseDownCanMoveWindowImageView alloc] initWithFrame:imageFrame]; + ULMouseDownCanMoveWindowImageView *imageView = [[ULMouseDownCanMoveWindowImageView alloc] initWithFrame:NSMakeRect(0, 0, loadedImageSize.width, loadedImageSize.height)]; imageView.image = image; + [self.imageWindowController.window close]; self.imageWindowController = [[ULImageWindowController alloc] initWithWindowNibName:@"ULImageWindowController"]; [self.imageWindowController.window.contentView addSubview:imageView]; - NSRect newFrame = NSMakeRect(oldRect.origin.x, oldRect.origin.y + (oldRect.size.height - imageFrame.size.height), imageFrame.size.width, imageFrame.size.height); - - loadedImageSize = newFrame.size; + NSRect newFrame = NSMakeRect(oldRect.origin.x, + oldRect.origin.y + (oldRect.size.height - loadedImageSize.height), + loadedImageSize.width, + loadedImageSize.height + ); - // if a window less than 0 on the x scale, put in back on the screen - if (!NSPointInRect(newFrame.origin, self.imageWindowController.window.screen.frame)) + // if a window is outside visible range, put in back on the screen + // this happens if the top left corner of the previous window is moved off screen + // and the new window is smaller than the old window + if (newFrame.origin.x + newFrame.size.width < 10) { - newFrame.origin.x = 1; + newFrame.origin.x = 0; } [self.imageWindowController.window setFrame:newFrame display:YES]; // if this is the first window, put it in the center - if ((oldRect.origin.x == 0.0 && oldRect.origin.y == 0)) + if (oldRect.origin.x == 0.0 && oldRect.origin.y == 0 && oldRect.size.width == 0 && oldRect.size.height == 0) { [self.imageWindowController.window center]; } @@ -423,20 +423,28 @@ - (IBAction)didSetTransparent:(id)sender [self setAlphaWindows:0]; } -- (IBAction)didClickHalfSize:(id)sender -{ +// necessary screen resolutions +// throw into haskell interpreter like ghc's ghci +// let pointAccurate imageScale = 1/imageScale +// let pixelAccurate imageScale screenScale simScale = (simScale/screenScale)/imageScale +// let necessaryResolutions = nub . sort . concat $ [ [pointAccurate imageScale, pixelAccurate imageScale screenScale simScale] | imageScale <- [1,2,3], screenScale <- [1,2], simScale <- [2,3]] +// necessaryResolutions +// [0.3333333333333333,0.5,0.6666666666666666,0.75,1.0,1.5,2.0,3.0] - [self setImageSize:NSMakeSize(loadedImageSize.width / 2, loadedImageSize.height / 2)]; -} - -- (IBAction)didClickActualSize:(id)sender -{ - [self setImageSize:NSMakeSize(loadedImageSize.width, loadedImageSize.height)]; -} - -- (IBAction)didClickDoubleSize:(id)sender +- (IBAction)didClickZoomLevel:(NSMenuItem *)sender { - [self setImageSize:NSMakeSize(loadedImageSize.width * 2, loadedImageSize.height * 2)]; + NSDictionary *dictionary = @{ + @1: @(1./3.), + @2: @0.5, + @3: @(2./3.), + @4: @0.75, + @5: @1, + @6: @1.5, + @7: @2, + @8: @3 + }; + CGFloat scale = [dictionary objectForKey:@(sender.tag)].doubleValue; + [self setImageSize:NSMakeSize(loadedImageSize.width * scale, loadedImageSize.height * scale)]; } - (void)setImageSize:(NSSize)size @@ -526,4 +534,4 @@ - (void)moveWindowX:(float)x windowY:(float)y welcomeFrame.origin.x += x; [self.welcomeWindowController.window setFrame:welcomeFrame display:YES animate:YES]; } -@end \ No newline at end of file +@end diff --git a/Uberlayer/External/MattGemmell/NSImageQuickLook/NSImage+QuickLook.h b/Uberlayer/External/MattGemmell/NSImageQuickLook/NSImage+QuickLook.h index 6c43bf2..e287740 100644 --- a/Uberlayer/External/MattGemmell/NSImageQuickLook/NSImage+QuickLook.h +++ b/Uberlayer/External/MattGemmell/NSImageQuickLook/NSImage+QuickLook.h @@ -12,6 +12,6 @@ + (NSImage *)imageWithPreviewOfFileAtPath:(NSString *)path ofSize:(NSSize)size asIcon:(BOOL)icon; -+ (CGSize)sizeOfImageAtURL:(NSURL *)fileURL error:(NSError **)error; ++ (CGSize)ptSizeOfImageAtURL:(NSURL *)fileURL error:(NSError **)error; @end diff --git a/Uberlayer/External/MattGemmell/NSImageQuickLook/NSImage+QuickLook.m b/Uberlayer/External/MattGemmell/NSImageQuickLook/NSImage+QuickLook.m index 3a12aab..4b186e7 100644 --- a/Uberlayer/External/MattGemmell/NSImageQuickLook/NSImage+QuickLook.m +++ b/Uberlayer/External/MattGemmell/NSImageQuickLook/NSImage+QuickLook.m @@ -54,7 +54,7 @@ + (NSImage *)imageWithPreviewOfFileAtPath:(NSString *)path ofSize:(NSSize)size a return nil; } -+ (CGSize)sizeOfImageAtURL:(NSURL *)fileURL error:(NSError **)error ++ (CGSize)ptSizeOfImageAtURL:(NSURL *)fileURL error:(NSError **)error { NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:(__bridge NSString *) kCGImageSourceShouldCache]; @@ -69,8 +69,19 @@ + (CGSize)sizeOfImageAtURL:(NSURL *)fileURL error:(NSError **)error if (imageProperties) { - CGFloat width = [(__bridge NSNumber *) CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth) floatValue]; - CGFloat height = [(__bridge NSNumber *) CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight) floatValue]; + CGFloat width = [(__bridge NSNumber *) CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth) doubleValue]; + CGFloat height = [(__bridge NSNumber *) CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight) doubleValue]; + if (@available(macOS 10.13, *)) + { + CGFloat dpiWidth = [(__bridge NSNumber *) CFDictionaryGetValue(imageProperties, kCGImagePropertyDPIHeight) doubleValue]; + CGFloat dpiHeight = [(__bridge NSNumber *) CFDictionaryGetValue(imageProperties, kCGImagePropertyDPIWidth) doubleValue]; + + if (dpiWidth >= 1. && dpiHeight >= 1.) + { + width = width * 72. / dpiWidth; + height = height * 72. / dpiHeight; + } + } int rotation = [(__bridge NSNumber *) CFDictionaryGetValue(imageProperties, kCGImagePropertyOrientation) intValue]; diff --git a/Uberlayer/Uberlayer-Info.plist b/Uberlayer/Uberlayer-Info.plist index c0df061..a0dbcf7 100644 --- a/Uberlayer/Uberlayer-Info.plist +++ b/Uberlayer/Uberlayer-Info.plist @@ -40,11 +40,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.4.1 + 1.5.0 CFBundleSignature ???? CFBundleVersion - 99 + 100 DMAppId 4f5dfd4aa14ad732e0000000 LSApplicationCategoryType diff --git a/Uberlayer/en.lproj/MainMenu.xib b/Uberlayer/en.lproj/MainMenu.xib index 66cb81a..20b6608 100644 --- a/Uberlayer/en.lproj/MainMenu.xib +++ b/Uberlayer/en.lproj/MainMenu.xib @@ -1,8 +1,8 @@ - - + + - - + + @@ -12,7 +12,7 @@ - + @@ -82,19 +82,44 @@ - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -218,6 +243,7 @@ + @@ -386,6 +412,7 @@ + - \ No newline at end of file +