Skip to content

Commit 7dfa2dd

Browse files
author
Erik Terwan
committed
Fixed Retina Mac resizing issue
Fixed the Retina resizing issue, also put the model related stuff into a ResizeModel.
1 parent bc264c8 commit 7dfa2dd

File tree

49 files changed

+279
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+279
-169
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Build/Intermediates/Retini.build/Debug/Retini.build/Objects-normal/x86_64/Retini.LinkFileList

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/Users/Erik/Mac Apps/Retini/Build/Intermediates/Retini.build/Debug/Retini.build/Objects-normal/x86_64/AppDelegate.o
33
/Users/Erik/Mac Apps/Retini/Build/Intermediates/Retini.build/Debug/Retini.build/Objects-normal/x86_64/DragDropView.o
44
/Users/Erik/Mac Apps/Retini/Build/Intermediates/Retini.build/Debug/Retini.build/Objects-normal/x86_64/NSImage+Resize.o
5+
/Users/Erik/Mac Apps/Retini/Build/Intermediates/Retini.build/Debug/Retini.build/Objects-normal/x86_64/ResizeModel.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Retini.xcodeproj/project.pbxproj

100644100755
Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
038880BC1B305F6300F8807F /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 038880BA1B305F6300F8807F /* MainMenu.xib */; };
1414
038880C81B305F6300F8807F /* RetiniTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 038880C71B305F6300F8807F /* RetiniTests.m */; };
1515
038880D31B305FDB00F8807F /* DragDropView.m in Sources */ = {isa = PBXBuildFile; fileRef = 038880D21B305FDB00F8807F /* DragDropView.m */; };
16+
03C461981C2760CD00F1572A /* ResizeModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 03C461971C2760CD00F1572A /* ResizeModel.m */; };
1617
03CB44F21BC80603003C4879 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03CB44F11BC80603003C4879 /* QuartzCore.framework */; };
1718
03CB44F51BC8118E003C4879 /* pngout in Resources */ = {isa = PBXBuildFile; fileRef = 03CB44F41BC8118E003C4879 /* pngout */; };
1819
03D63F7C1BB9804200CC8485 /* NSImage+Resize.m in Sources */ = {isa = PBXBuildFile; fileRef = 03D63F7B1BB9804200CC8485 /* NSImage+Resize.m */; };
@@ -43,6 +44,8 @@
4344
038880C71B305F6300F8807F /* RetiniTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RetiniTests.m; sourceTree = "<group>"; };
4445
038880D11B305FDB00F8807F /* DragDropView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragDropView.h; sourceTree = "<group>"; };
4546
038880D21B305FDB00F8807F /* DragDropView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DragDropView.m; sourceTree = "<group>"; };
47+
03C461961C2760CD00F1572A /* ResizeModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResizeModel.h; sourceTree = "<group>"; };
48+
03C461971C2760CD00F1572A /* ResizeModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ResizeModel.m; sourceTree = "<group>"; };
4649
03CB44F11BC80603003C4879 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
4750
03CB44F41BC8118E003C4879 /* pngout */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = pngout; sourceTree = "<group>"; };
4851
03D63F7A1BB9804200CC8485 /* NSImage+Resize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+Resize.h"; sourceTree = "<group>"; };
@@ -94,13 +97,12 @@
9497
038880B01B305F6300F8807F /* Retini */ = {
9598
isa = PBXGroup;
9699
children = (
97-
03CB44F31BC8117F003C4879 /* 3rd party */,
98-
03D63F7A1BB9804200CC8485 /* NSImage+Resize.h */,
99-
03D63F7B1BB9804200CC8485 /* NSImage+Resize.m */,
100100
038880B31B305F6300F8807F /* AppDelegate.h */,
101101
038880B41B305F6300F8807F /* AppDelegate.m */,
102-
038880D11B305FDB00F8807F /* DragDropView.h */,
103-
038880D21B305FDB00F8807F /* DragDropView.m */,
102+
03C461951C27608F00F1572A /* Frameworks */,
103+
03C461941C27608500F1572A /* Views */,
104+
03C461931C27607D00F1572A /* Models */,
105+
03CB44F31BC8117F003C4879 /* 3rd party */,
104106
038880B81B305F6300F8807F /* Images.xcassets */,
105107
038880BA1B305F6300F8807F /* MainMenu.xib */,
106108
038880B11B305F6300F8807F /* Supporting Files */,
@@ -134,6 +136,33 @@
134136
name = "Supporting Files";
135137
sourceTree = "<group>";
136138
};
139+
03C461931C27607D00F1572A /* Models */ = {
140+
isa = PBXGroup;
141+
children = (
142+
03C461961C2760CD00F1572A /* ResizeModel.h */,
143+
03C461971C2760CD00F1572A /* ResizeModel.m */,
144+
);
145+
name = Models;
146+
sourceTree = "<group>";
147+
};
148+
03C461941C27608500F1572A /* Views */ = {
149+
isa = PBXGroup;
150+
children = (
151+
038880D11B305FDB00F8807F /* DragDropView.h */,
152+
038880D21B305FDB00F8807F /* DragDropView.m */,
153+
);
154+
name = Views;
155+
sourceTree = "<group>";
156+
};
157+
03C461951C27608F00F1572A /* Frameworks */ = {
158+
isa = PBXGroup;
159+
children = (
160+
03D63F7A1BB9804200CC8485 /* NSImage+Resize.h */,
161+
03D63F7B1BB9804200CC8485 /* NSImage+Resize.m */,
162+
);
163+
name = Frameworks;
164+
sourceTree = "<group>";
165+
};
137166
03CB44F31BC8117F003C4879 /* 3rd party */ = {
138167
isa = PBXGroup;
139168
children = (
@@ -299,6 +328,7 @@
299328
038880B51B305F6300F8807F /* AppDelegate.m in Sources */,
300329
038880D31B305FDB00F8807F /* DragDropView.m in Sources */,
301330
03D63F7C1BB9804200CC8485 /* NSImage+Resize.m in Sources */,
331+
03C461981C2760CD00F1572A /* ResizeModel.m in Sources */,
302332
);
303333
runOnlyForDeploymentPostprocessing = 0;
304334
};

Retini.xcodeproj/project.xcworkspace/contents.xcworkspacedata

100644100755
File mode changed.

Retini.xcodeproj/xcuserdata/Erik.xcuserdatad/xcschemes/Retini.xcscheme

100644100755
File mode changed.

Retini.xcodeproj/xcuserdata/Erik.xcuserdatad/xcschemes/xcschememanagement.plist

100644100755
File mode changed.

Retini.xcworkspace/contents.xcworkspacedata

100644100755
File mode changed.
Binary file not shown.

Retini.zip

663 Bytes
Binary file not shown.

Retini/AppDelegate.h

100644100755
File mode changed.

Retini/AppDelegate.m

100644100755
File mode changed.

Retini/Base.lproj/MainMenu.xib

100644100755
File mode changed.

Retini/DragDropView.h

100644100755
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@
77
//
88

99
#import <Cocoa/Cocoa.h>
10+
#import "ResizeModel.h"
1011

1112
@interface DragDropView : NSView
1213

14+
// Models
15+
@property (nonatomic, retain) ResizeModel *resizeModel;
16+
17+
// UI
1318
@property (nonatomic, retain) IBOutlet NSProgressIndicator *pngCrushLoader;
1419

1520
@property BOOL highlight; // If should show the highlighted image
1621
@property BOOL notFound; // If no retina (@2x, @3x) files where found
1722

18-
// Method to check if dragged item is directory or single file
23+
// Methods
1924
- (void)checkFiles:(NSArray *)fileNames;
2025

2126
@end

Retini/DragDropView.m

100644100755
Lines changed: 14 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#import "DragDropView.h"
1010
#import "NSImage+Resize.h" // File from https://github.com/nate-parrott/Flashlight
1111

12-
// I'm going to refractor this aswell, put everything that should be in a model, in a model.
13-
1412
@implementation DragDropView
1513

1614
@synthesize pngCrushLoader;
@@ -24,6 +22,8 @@ - (id)initWithFrame:(NSRect)frame
2422
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
2523

2624
[pngCrushLoader setAlphaValue:0.0];
25+
26+
_resizeModel = [[ResizeModel alloc] initWithLoader:pngCrushLoader];
2727
}
2828

2929
return self;
@@ -37,6 +37,8 @@ - (id)initWithCoder:(NSCoder *)coder
3737
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
3838

3939
[pngCrushLoader setAlphaValue:0.0];
40+
41+
_resizeModel = [[ResizeModel alloc] initWithLoader:pngCrushLoader];
4042
}
4143

4244
return self;
@@ -54,7 +56,7 @@ - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
5456

5557
NSArray *draggedFilenames = [[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
5658

57-
if(![self hasRetinaFiles:draggedFilenames]){
59+
if(![_resizeModel hasRetinaFiles:draggedFilenames]){
5860
notFound = YES;
5961
}
6062

@@ -85,7 +87,7 @@ - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
8587
{
8688
NSArray *draggedFilenames = [[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
8789

88-
if(![self hasRetinaFiles:draggedFilenames]){
90+
if(![_resizeModel hasRetinaFiles:draggedFilenames]){
8991
notFound = YES;
9092

9193
[self setNeedsDisplay:YES];
@@ -94,176 +96,26 @@ - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
9496
return YES;
9597
}
9698

97-
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
99+
- (void)checkFiles:(NSArray *)fileNames
98100
{
99-
NSArray *draggedFilenames = [[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
100-
101-
[self checkFiles:draggedFilenames];
101+
[_resizeModel checkFiles:fileNames];
102102

103103
highlight = NO;
104104
notFound = NO;
105105

106106
[self setNeedsDisplay:YES];
107107
}
108108

109-
- (BOOL)hasRetinaFiles:(NSArray *)fileNames
110-
{
111-
NSFileManager *fileManager = [NSFileManager defaultManager];
112-
113-
for(NSString *filename in fileNames){
114-
BOOL isDir;
115-
116-
if([fileManager fileExistsAtPath:filename isDirectory:&isDir]){
117-
if(!isDir){
118-
if([filename containsString:@"@2x"] || [filename containsString:@"@3x"]){
119-
return YES;
120-
}
121-
} else{
122-
NSMutableArray *dirContents = [NSMutableArray array];
123-
124-
for(NSString *file in [fileManager contentsOfDirectoryAtPath:filename error:nil]){
125-
[dirContents addObject:[[filename stringByAppendingString:@"/"] stringByAppendingString:file]];
126-
}
127-
128-
return [self hasRetinaFiles:dirContents];
129-
}
130-
}
131-
}
132-
133-
return NO;
134-
}
135-
136-
- (void)checkFiles:(NSArray *)fileNames
137-
{
138-
NSFileManager *fileManager = [NSFileManager defaultManager];
139-
140-
for(NSString *filename in fileNames){
141-
BOOL isDir;
142-
143-
if([fileManager fileExistsAtPath:filename isDirectory:&isDir]){
144-
if(!isDir){
145-
[self workFile:filename];
146-
} else{
147-
NSMutableArray *dirContents = [NSMutableArray array];
148-
149-
for(NSString *file in [fileManager contentsOfDirectoryAtPath:filename error:nil]){
150-
[dirContents addObject:[[filename stringByAppendingString:@"/"] stringByAppendingString:file]];
151-
}
152-
153-
[self checkFiles:dirContents];
154-
}
155-
}
156-
}
157-
}
158-
159-
- (void)workFile:(NSString *)file
160-
{
161-
if([[file lowercaseString] containsString:@"png"] || [[file lowercaseString] containsString:@"jpeg"] || [[file lowercaseString] containsString:@"jpg"]){
162-
if([[file lowercaseString] containsString:@"@3x"]){
163-
[self resize3x:file];
164-
} else if([[file lowercaseString] containsString:@"@2x"]){
165-
[self resize2x:file];
166-
}
167-
}
168-
}
169-
170-
171-
- (void)resize3x:(NSString *)fileName
172-
{
173-
NSImage *original = [[NSImage alloc] initWithContentsOfFile:fileName];
174-
NSImage *newImg2x = [self imageResize:[original copy] newSize:NSMakeSize(original.size.width * 2, original.size.height * 2)];
175-
176-
if([self saveImage:newImg2x toPath:[fileName stringByReplacingOccurrencesOfString:@"@3x" withString:@"@2x"]]){
177-
NSImage *newImg = [self imageResize:[original copy] newSize:NSMakeSize(original.size.width, original.size.height)];
178-
[self saveImage:newImg toPath:[fileName stringByReplacingOccurrencesOfString:@"@3x" withString:@""]];
179-
}
180-
181-
if([[NSUserDefaults standardUserDefaults] integerForKey:@"pngOut"] == 1){
182-
[self crushPng:fileName];
183-
}
184-
}
185-
186-
- (void)resize2x:(NSString *)fileName
187-
{
188-
NSImage *original = [[NSImage alloc] initWithContentsOfFile:fileName];
189-
NSImage *newImg = [self imageResize:original newSize:NSMakeSize(original.size.width, original.size.height)];
190-
191-
[self saveImage:newImg toPath:[fileName stringByReplacingOccurrencesOfString:@"@2x" withString:@""]];
192-
193-
if([[NSUserDefaults standardUserDefaults] integerForKey:@"pngOut"] == 1){
194-
[self crushPng:fileName];
195-
}
196-
}
197-
198-
- (NSImage *)imageResize:(NSImage *)anImage newSize:(NSSize)newSize
199-
{
200-
return [anImage resizeImageToSize:newSize];
201-
}
202-
203-
- (BOOL)saveImage:(NSImage *)image toPath:(NSString *)path
204-
{
205-
if(image != nil){
206-
[image lockFocus];
207-
208-
NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0.0, 0.0, [image size].width, [image size].height)];
209-
210-
[image unlockFocus] ;
211-
212-
NSUInteger fileType = NSJPEGFileType;
213-
214-
if([path containsString:@"png"]){
215-
fileType = NSPNGFileType;
216-
}
217-
218-
float quality = 1.0;
219-
220-
if([[NSUserDefaults standardUserDefaults] integerForKey:@"jpegQuality"]){
221-
quality = [[NSUserDefaults standardUserDefaults] integerForKey:@"jpegQuality"] / 10;
222-
}
223-
224-
NSData *data = [bitmapRep representationUsingType:fileType properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:quality] forKey:NSImageCompressionFactor]];
225-
226-
if([[NSUserDefaults standardUserDefaults] integerForKey:@"pngOut"] == 1){
227-
if([data writeToFile:path atomically:YES]){
228-
return [self crushPng:path];
229-
}
230-
}
231-
232-
return [data writeToFile:path atomically:YES];
233-
}
234-
235-
return NO;
236-
}
237-
238-
- (BOOL)crushPng:(NSString *)fileName
109+
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
239110
{
240-
if(![[fileName lowercaseString] containsString:@"png"]){
241-
return NO;
242-
}
111+
NSArray *draggedFilenames = [[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
243112

244-
[pngCrushLoader setMaxValue:pngCrushLoader.maxValue + 1];
245-
[pngCrushLoader setAlphaValue:1.0];
113+
[_resizeModel checkFiles:draggedFilenames];
246114

247-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
248-
NSTask *task = [[NSTask alloc] init];
249-
task.launchPath = [[NSBundle mainBundle] pathForResource:@"pngout" ofType:@""];
250-
task.arguments = @[@"-y", fileName, fileName];
251-
252-
[task launch];
253-
[task waitUntilExit];
254-
255-
dispatch_async(dispatch_get_main_queue(), ^{
256-
[pngCrushLoader setDoubleValue:pngCrushLoader.doubleValue + 1];
257-
258-
if(pngCrushLoader.doubleValue == pngCrushLoader.maxValue){
259-
[pngCrushLoader setAlphaValue:0.0];
260-
[pngCrushLoader setDoubleValue:0];
261-
[pngCrushLoader setMaxValue:0];
262-
}
263-
});
264-
});
115+
highlight = NO;
116+
notFound = NO;
265117

266-
return YES;
118+
[self setNeedsDisplay:YES];
267119
}
268120

269121
- (void)drawRect:(NSRect)rect

Retini/Images.xcassets/AppIcon.appiconset/Contents.json

100644100755
File mode changed.

Retini/Images.xcassets/AppIcon.appiconset/Icon~128.png

100644100755
File mode changed.

Retini/Images.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

Retini/Images.xcassets/AppIcon.appiconset/Icon~16.png

100644100755
File mode changed.

Retini/Images.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

Retini/Images.xcassets/AppIcon.appiconset/Icon~256.png

100644100755
File mode changed.

Retini/Images.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

Retini/Images.xcassets/AppIcon.appiconset/Icon~32.png

100644100755
File mode changed.

Retini/Images.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

Retini/Images.xcassets/AppIcon.appiconset/Icon~512.png

100644100755
File mode changed.

Retini/Images.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

Retini/Images.xcassets/homeScreen.imageset/Contents.json

100644100755
File mode changed.

Retini/Images.xcassets/homeScreen.imageset/homeScreen.png

100644100755
File mode changed.

Retini/Images.xcassets/homeScreen.imageset/[email protected]

100644100755
File mode changed.

Retini/Images.xcassets/homeScreen~drop.imageset/Contents.json

100644100755
File mode changed.

Retini/Images.xcassets/homeScreen~drop.imageset/homeScreen~drop.png

100644100755
File mode changed.

Retini/Images.xcassets/homeScreen~drop.imageset/[email protected]

100644100755
File mode changed.

Retini/Images.xcassets/homeScreen~noFind.imageset/Contents.json

100644100755
File mode changed.

Retini/Images.xcassets/homeScreen~noFind.imageset/homeScreen~noFind.png

100644100755
File mode changed.

Retini/Images.xcassets/homeScreen~noFind.imageset/[email protected]

100644100755
File mode changed.

Retini/Info.plist

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<key>CFBundlePackageType</key>
3939
<string>APPL</string>
4040
<key>CFBundleShortVersionString</key>
41-
<string>1.0.7</string>
41+
<string>1.0.8</string>
4242
<key>CFBundleSignature</key>
4343
<string>????</string>
4444
<key>CFBundleVersion</key>

Retini/NSImage+Resize.h

100644100755
File mode changed.

Retini/NSImage+Resize.m

100644100755
File mode changed.

Retini/ResizeModel.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// ResizeModel.h
3+
// Retini
4+
//
5+
// Created by Erik Terwan on 20/12/15.
6+
// Copyright © 2015 ET-ID. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
#import <Foundation/Foundation.h>
11+
12+
@interface ResizeModel : NSObject
13+
14+
// UI
15+
@property (nonatomic, retain) NSProgressIndicator *pngCrushLoader;
16+
17+
18+
// METHODS
19+
- (id)initWithLoader:(NSProgressIndicator *)indicator;
20+
- (BOOL)hasRetinaFiles:(NSArray *)fileNames;
21+
22+
// Check if dragged item is directory or single file
23+
- (void)checkFiles:(NSArray *)fileNames;
24+
25+
@end

0 commit comments

Comments
 (0)