Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions Uberlayer/Classes/ULAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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];
Expand All @@ -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];
}
Expand Down Expand Up @@ -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<NSNumber *, NSNumber *> *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
Expand Down Expand Up @@ -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
@end
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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];

Expand Down
4 changes: 2 additions & 2 deletions Uberlayer/Uberlayer-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.1</string>
<string>1.5.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>99</string>
<string>100</string>
<key>DMAppId</key>
<string>4f5dfd4aa14ad732e0000000</string>
<key>LSApplicationCategoryType</key>
Expand Down
51 changes: 39 additions & 12 deletions Uberlayer/en.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment version="1060" defaultVersion="1060" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
<deployment version="1060" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand All @@ -12,7 +12,7 @@
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="494" customClass="ULAppDelegate"/>
<customObject id="420" customClass="NSFontManager"/>
<menu title="AMainMenu" systemMenu="main" id="29">
Expand Down Expand Up @@ -82,19 +82,44 @@
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Zoom" id="778">
<items>
<menuItem title="50%" keyEquivalent="1" id="781">
<menuItem title="33%" tag="1" keyEquivalent="1" id="781">
<connections>
<action selector="didClickHalfSize:" target="494" id="783"/>
<action selector="didClickZoomLevel:" target="494" id="fn7-0s-o7Z"/>
</connections>
</menuItem>
<menuItem title="100%" keyEquivalent="2" id="779">
<menuItem title="50%" tag="2" keyEquivalent="2" id="779">
<connections>
<action selector="didClickActualSize:" target="494" id="784"/>
<action selector="didClickZoomLevel:" target="494" id="dor-wI-zbM"/>
</connections>
</menuItem>
<menuItem title="200%" keyEquivalent="3" id="782">
<menuItem title="67%" tag="3" keyEquivalent="3" id="782">
<connections>
<action selector="didClickDoubleSize:" target="494" id="785"/>
<action selector="didClickZoomLevel:" target="494" id="z76-yI-9AT"/>
</connections>
</menuItem>
<menuItem title="75%" tag="4" keyEquivalent="4" id="6Yi-Sz-ftx">
<connections>
<action selector="didClickZoomLevel:" target="494" id="4eY-BT-q3Q"/>
</connections>
</menuItem>
<menuItem title="100%" tag="5" keyEquivalent="5" id="1xm-4N-e5G">
<connections>
<action selector="didClickZoomLevel:" target="494" id="s9m-KD-g4Z"/>
</connections>
</menuItem>
<menuItem title="150%" tag="6" keyEquivalent="6" id="ytv-0d-hFa">
<connections>
<action selector="didClickZoomLevel:" target="494" id="qaF-KW-zvd"/>
</connections>
</menuItem>
<menuItem title="200%" tag="7" keyEquivalent="7" id="rqM-rj-gPg">
<connections>
<action selector="didClickZoomLevel:" target="494" id="MGi-6U-Lr9"/>
</connections>
</menuItem>
<menuItem title="300%" tag="8" keyEquivalent="8" id="rpl-Hz-JYX">
<connections>
<action selector="didClickZoomLevel:" target="494" id="0Zd-gX-byn"/>
</connections>
</menuItem>
</items>
Expand Down Expand Up @@ -218,6 +243,7 @@
</menu>
</menuItem>
</items>
<point key="canvasLocation" x="14" y="154"/>
</menu>
<menu id="536">
<items>
Expand Down Expand Up @@ -386,6 +412,7 @@
</connections>
</menuItem>
</items>
<point key="canvasLocation" x="14" y="-106"/>
</menu>
</objects>
</document>
</document>