Permalink
Browse files

Animate NSImageView if gif was given as screenshot.

Add "[GIF]" suffix to image preview title for gif images.
#432
  • Loading branch information...
1 parent 665299f commit 241f043c9e31d6ef91a2152260f1018500676aa1 @OdNairy OdNairy committed with Roman Gardukevich Mar 5, 2016
@@ -57,8 +57,9 @@
8AD5249F174102F9008B451F /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8AD524A2174102F9008B451F /* Localizable.strings */; };
8ADC22341A2AD5B800DB7BCA /* ATZPreviewImageButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 8ADC22331A2AD5B800DB7BCA /* ATZPreviewImageButton.m */; };
8AF670C919C2DE8A00E1C168 /* ATZSegmentedControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 8AF670C819C2DE8A00E1C168 /* ATZSegmentedControl.m */; };
- F0DF961E1B40416400DF68CC /* ATZSegmentedCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F0DF961D1B40416400DF68CC /* ATZSegmentedCell.m */; };
F07E55521B551BA800161E61 /* ATZXcodePrefsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F07E55511B551BA800161E61 /* ATZXcodePrefsManager.m */; };
+ F0DF961E1B40416400DF68CC /* ATZSegmentedCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F0DF961D1B40416400DF68CC /* ATZSegmentedCell.m */; };
+ FE4405531D6E3635000C58A4 /* NSImage+Alcatraz.m in Sources */ = {isa = PBXBuildFile; fileRef = FE4405521D6E3635000C58A4 /* NSImage+Alcatraz.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -144,10 +145,12 @@
8ADC22331A2AD5B800DB7BCA /* ATZPreviewImageButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ATZPreviewImageButton.m; path = Views/ATZPreviewImageButton.m; sourceTree = "<group>"; };
8AF670C719C2DE8A00E1C168 /* ATZSegmentedControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ATZSegmentedControl.h; path = Views/ATZSegmentedControl.h; sourceTree = "<group>"; };
8AF670C819C2DE8A00E1C168 /* ATZSegmentedControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ATZSegmentedControl.m; path = Views/ATZSegmentedControl.m; sourceTree = "<group>"; };
- F0DF961C1B40416300DF68CC /* ATZSegmentedCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATZSegmentedCell.h; sourceTree = "<group>"; };
- F0DF961D1B40416400DF68CC /* ATZSegmentedCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ATZSegmentedCell.m; sourceTree = "<group>"; };
F07E55501B551BA800161E61 /* ATZXcodePrefsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATZXcodePrefsManager.h; sourceTree = "<group>"; };
F07E55511B551BA800161E61 /* ATZXcodePrefsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ATZXcodePrefsManager.m; sourceTree = "<group>"; };
+ F0DF961C1B40416300DF68CC /* ATZSegmentedCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATZSegmentedCell.h; sourceTree = "<group>"; };
+ F0DF961D1B40416400DF68CC /* ATZSegmentedCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ATZSegmentedCell.m; sourceTree = "<group>"; };
+ FE4405511D6E3635000C58A4 /* NSImage+Alcatraz.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+Alcatraz.h"; sourceTree = "<group>"; };
+ FE4405521D6E3635000C58A4 /* NSImage+Alcatraz.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSImage+Alcatraz.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -289,6 +292,8 @@
8917DA0C1726B57B00F0B2D2 /* NSFileManager+Alcatraz.m */,
8A1732A61A2694BB002033D6 /* NSColor+Alcatraz.h */,
8A1732A71A2694BB002033D6 /* NSColor+Alcatraz.m */,
+ FE4405511D6E3635000C58A4 /* NSImage+Alcatraz.h */,
+ FE4405521D6E3635000C58A4 /* NSImage+Alcatraz.m */,
);
path = Categories;
sourceTree = "<group>";
@@ -457,6 +462,7 @@
8AF670C919C2DE8A00E1C168 /* ATZSegmentedControl.m in Sources */,
8A6025C419C29B0C00D47F3F /* ATZPackageTableViewDelegate.m in Sources */,
8917DA071726B53000F0B2D2 /* ATZPluginInstaller.m in Sources */,
+ FE4405531D6E3635000C58A4 /* NSImage+Alcatraz.m in Sources */,
8917DA081726B53000F0B2D2 /* ATZProjectTemplateInstaller.m in Sources */,
8917DA091726B53000F0B2D2 /* ATZTemplateInstaller.m in Sources */,
8AA0F57D19C2225A00556AAF /* ATZStyleKit.m in Sources */,
@@ -0,0 +1,27 @@
+// NSImage+Alcatraz.h
+//
+// Copyright (c) 2016 Roman Gardukevich
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <Cocoa/Cocoa.h>
+
+@interface NSImage (Alcatraz)
+@property (nonatomic, readonly) NSInteger frameCount;
+@end
@@ -0,0 +1,40 @@
+// NSImage+Alcatraz.m
+//
+// Copyright (c) 2016 Roman Gardukevich
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import "NSImage+Alcatraz.h"
+
+@implementation NSImage (Alcatraz)
+-(NSInteger)frameCount{
+ // Find the NSBitmapImageRep representation to check frame count GIF-specific value
+ // returns 1 for common image
+
+ for (NSImageRep * rep in self.representations){
+ if ([rep isKindOfClass:[NSBitmapImageRep class]]){
+ NSBitmapImageRep * bitmapRep = (NSBitmapImageRep *)rep;
+ NSInteger numFrame = [[bitmapRep valueForProperty:NSImageFrameCount] integerValue];
+ return numFrame;
+ }
+ }
+ return 1;
+}
+@end
@@ -37,6 +37,8 @@
#import "ATZFillableButton.h"
#import "ATZPackageTableViewDelegate.h"
+#import "NSImage+Alcatraz.h"
+
static NSString *const CLASS_PREDICATE_FORMAT = @"(self isKindOfClass: %@)";
static NSString *const SEARCH_PREDICATE_FORMAT = @"(name contains[cd] %@ OR summary contains[cd] %@)";
static NSString *const INSTALLED_PREDICATE_FORMAT = @"(installed == YES)";
@@ -266,15 +268,26 @@ - (void)openWebsite:(NSString *)address {
- (void)displayScreenshotForPackage:(ATZPackage *)package {
[self.previewPanel.animator setAlphaValue:0.f];
- self.previewPanel.title = package.name;
[self.tableViewDelegate fetchAndCacheImageForPackage:package progress:NULL completion:^(NSImage *image) {
- [self displayImage:image withTitle:package.name];
+ [self displayImage:image forPackage:package];
}];
}
-- (void)displayImage:(NSImage *)image withTitle:(NSString*)title {
+- (void)displayImage:(NSImage *)image forPackage:(ATZPackage*)package {
+ self.previewPanel.title = package.name;
+ if (image.frameCount > 1) {
+ self.previewImageView.imageScaling = NSImageScaleNone;
+ self.previewImageView.animates = YES;
+ self.previewImageView.canDrawSubviewsIntoLayer = YES;
+ self.previewPanel.title = [self.previewPanel.title stringByAppendingString:@" [GIF]"];
+ } else {
+ self.previewImageView.imageScaling = NSImageScaleProportionallyDown;
+ self.previewImageView.animates = NO;
+ self.previewImageView.canDrawSubviewsIntoLayer = NO;
+ }
self.previewImageView.image = image;
+
[NSAnimationContext beginGrouping];
[self.previewImageView.animator setFrame:(CGRect){ .origin = CGPointMake(0, 0), .size = image.size }];
View
@@ -1,3 +1,6 @@
+## Unreleased
+- Support GIF image on screenshot preview (#432)
+
## 1.2.0
- Plugins are no longer required to have a .xcodeproj filename matching their `name` in `packages.json` (#471)

0 comments on commit 241f043

Please sign in to comment.