OS X: Have the memory card images be represented as gif files.

This makes it less of a chore handling the animation, as the OS will do it automatically for us now.

git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@91357 e17a0e51-4ae3-4d35-97c3-1a29b211df97
This commit is contained in:
SND\MaddTheSane_cp 2014-09-08 14:27:51 +00:00
parent 20b807f045
commit b96092d6fb
7 changed files with 32 additions and 72 deletions

View File

@ -102,7 +102,7 @@ static OSStatus GeneratePreviewForMemCard(void *thisInterface, QLPreviewRequestR
NSDictionary *gifPrep = @{(NSString *) kCGImagePropertyGIFDictionary: @{(NSString *) kCGImagePropertyGIFDelayTime: @0.30f}}; NSDictionary *gifPrep = @{(NSString *) kCGImagePropertyGIFDictionary: @{(NSString *) kCGImagePropertyGIFDelayTime: @0.30f}};
for (PcsxrMemoryObject *obj in memCards) { for (PcsxrMemoryObject *obj in memCards) {
if (obj.memImageIndex == -1 || obj.memIconCount == 1) { if (!obj.hasImages || obj.memIconCount == 1) {
NSMutableData *pngData = [NSMutableData new]; NSMutableData *pngData = [NSMutableData new];
{ {
CGImageDestinationRef dst = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)pngData, kUTTypePNG, 1, NULL); CGImageDestinationRef dst = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)pngData, kUTTypePNG, 1, NULL);

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6185.7" systemVersion="13E28" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6206.9" systemVersion="13E28" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment defaultVersion="1080" identifier="macosx"/> <deployment defaultVersion="1080" identifier="macosx"/>
<development version="5100" identifier="xcode"/> <development version="5100" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6185.7"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6206.9"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="ConfigurationController"> <customObject id="-2" userLabel="File's Owner" customClass="ConfigurationController">
@ -34,7 +34,7 @@
</connections> </connections>
</customObject> </customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/> <customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="PCSXR Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" visibleAtLaunch="NO" animationBehavior="documentWindow" id="21"> <window title="PCSXR Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" visibleAtLaunch="NO" animationBehavior="documentWindow" id="21">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" topStrut="YES"/> <windowPositionMask key="initialPositionMask" leftStrut="YES" topStrut="YES"/>
@ -1162,7 +1162,7 @@
<constraint firstAttribute="width" constant="48" id="kIh-n8-gJw"/> <constraint firstAttribute="width" constant="48" id="kIh-n8-gJw"/>
<constraint firstAttribute="height" constant="48" id="vPq-qO-hYs"/> <constraint firstAttribute="height" constant="48" id="vPq-qO-hYs"/>
</constraints> </constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="NSAdvanced" id="986"/> <imageCell key="cell" refusesFirstResponder="YES" alignment="left" animates="YES" imageScaling="proportionallyUpOrDown" image="NSAdvanced" id="986"/>
<connections> <connections>
<binding destination="958" name="value" keyPath="representedObject.memImage" id="1057"/> <binding destination="958" name="value" keyPath="representedObject.memImage" id="1057"/>
</connections> </connections>

View File

@ -169,16 +169,6 @@ NSString *const memCardChangeNumberKey = @"PcsxrMemoryCardThatChangedKey";
} }
} }
- (void)windowWillClose:(NSNotification *)notification
{
[memCardEdit stopMemoryAnimation];
}
- (void)windowDidBecomeMain:(NSNotification *)notification
{
[memCardEdit beginMemoryAnimation];
}
- (void)awakeFromNib - (void)awakeFromNib
{ {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

View File

@ -24,7 +24,4 @@
- (IBAction)deleteMemoryObject:(id)sender; - (IBAction)deleteMemoryObject:(id)sender;
- (void)loadMemoryCardInfoForCard:(int)theCard; - (void)loadMemoryCardInfoForCard:(int)theCard;
- (void)beginMemoryAnimation;
- (void)stopMemoryAnimation;
@end @end

View File

@ -18,27 +18,12 @@
@interface PcsxrMemCardController () @interface PcsxrMemCardController ()
@property (readwrite, strong) PcsxrMemCardArray *memCard1Array; @property (readwrite, strong) PcsxrMemCardArray *memCard1Array;
@property (readwrite, strong) PcsxrMemCardArray *memCard2Array; @property (readwrite, strong) PcsxrMemCardArray *memCard2Array;
@property (strong) NSTimer *imageAnimateTimer;
@end @end
@implementation PcsxrMemCardController @implementation PcsxrMemCardController
@synthesize memCard1Array; @synthesize memCard1Array;
@synthesize memCard2Array; @synthesize memCard2Array;
- (void)stopMemoryAnimation
{
[self.imageAnimateTimer invalidate];
self.imageAnimateTimer = nil;
}
- (void)beginMemoryAnimation
{
if (!_imageAnimateTimer) {
self.imageAnimateTimer = [[NSTimer alloc] initWithFireDate:[NSDate date] interval:0.30 target:self selector:@selector(animateMemCards:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.imageAnimateTimer forMode:NSRunLoopCommonModes];
}
}
- (void)setupValues:(int)theCards - (void)setupValues:(int)theCards
{ {
NSParameterAssert(theCards < 4 && theCards > 0); NSParameterAssert(theCards < 4 && theCards > 0);
@ -97,13 +82,6 @@
[self setupValues:3]; [self setupValues:3];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memoryCardDidChangeNotification:) name:memChangeNotifier object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memoryCardDidChangeNotification:) name:memChangeNotifier object:nil];
[self beginMemoryAnimation];
}
- (void)animateMemCards:(NSTimer*)theTimer
{
[[NSNotificationCenter defaultCenter] postNotificationName:memoryAnimateTimerKey object:self];
} }
- (IBAction)moveBlock:(id)sender - (IBAction)moveBlock:(id)sender
@ -232,7 +210,6 @@
- (void)dealloc - (void)dealloc
{ {
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[self.imageAnimateTimer invalidate];
} }
@end @end

View File

@ -9,8 +9,6 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include "sio.h" #include "sio.h"
extern NSString *const memoryAnimateTimerKey;
typedef NS_ENUM(char, PCSXRMemFlags) { typedef NS_ENUM(char, PCSXRMemFlags) {
memFlagDeleted, memFlagDeleted,
memFlagFree, memFlagFree,
@ -35,13 +33,13 @@ typedef NS_ENUM(char, PCSXRMemFlags) {
@property (readonly, strong) NSString *memName; @property (readonly, strong) NSString *memName;
@property (readonly, strong) NSString *memID; @property (readonly, strong) NSString *memID;
@property (readonly, strong) NSArray *memoryCardImages; @property (readonly, strong) NSArray *memoryCardImages;
@property (readonly, nonatomic) NSInteger memImageIndex; @property (readonly, strong, nonatomic) NSImage *memImage;
@property (readonly) PCSXRMemFlags flagNameIndex; @property (readonly) PCSXRMemFlags flagNameIndex;
@property (readonly) uint8_t startingIndex; @property (readonly) uint8_t startingIndex;
@property (readonly) uint8_t blockSize; @property (readonly) uint8_t blockSize;
@property (readonly) BOOL hasImages;
@property (readonly, copy) NSImage *firstMemImage; @property (readonly, copy) NSImage *firstMemImage;
@property (readonly, unsafe_unretained, nonatomic) NSImage *memImage;
@property (readonly, nonatomic) NSUInteger memIconCount; @property (readonly, nonatomic) NSUInteger memIconCount;
@property (readonly, unsafe_unretained, nonatomic) NSString *flagName; @property (readonly, unsafe_unretained, nonatomic) NSString *flagName;
@property (readonly, unsafe_unretained, nonatomic) NSAttributedString *attributedFlagName; @property (readonly, unsafe_unretained, nonatomic) NSAttributedString *attributedFlagName;

View File

@ -9,8 +9,6 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "PcsxrMemoryObject.h" #import "PcsxrMemoryObject.h"
NSString *const memoryAnimateTimerKey = @"PCSXR Memory Card Image Animate";
@interface PcsxrMemoryObject () @interface PcsxrMemoryObject ()
@property (readwrite, strong) NSString *englishName; @property (readwrite, strong) NSString *englishName;
@property (readwrite, strong) NSString *sjisName; @property (readwrite, strong) NSString *sjisName;
@ -19,9 +17,10 @@ NSString *const memoryAnimateTimerKey = @"PCSXR Memory Card Image Animate";
@property (readwrite) uint8_t startingIndex; @property (readwrite) uint8_t startingIndex;
@property (readwrite) uint8_t blockSize; @property (readwrite) uint8_t blockSize;
@property (readwrite, nonatomic) NSInteger memImageIndex;
@property (readwrite, strong) NSArray *memoryCardImages; @property (readwrite, strong) NSArray *memoryCardImages;
@property (readwrite) PCSXRMemFlags flagNameIndex; @property (readwrite) PCSXRMemFlags flagNameIndex;
@property (readwrite, nonatomic, strong) NSImage *memImage;
@property (readwrite) BOOL hasImages;
@end @end
@implementation PcsxrMemoryObject @implementation PcsxrMemoryObject
@ -76,7 +75,7 @@ static NSString *MemLabelEndLink;
- (NSImage*)memoryImageAtIndex:(NSInteger)idx - (NSImage*)memoryImageAtIndex:(NSInteger)idx
{ {
if (memImageIndex == -1 || idx > self.memIconCount) { if (!self.hasImages || idx > self.memIconCount) {
return [PcsxrMemoryObject blankImage]; return [PcsxrMemoryObject blankImage];
} }
return memImages[idx]; return memImages[idx];
@ -152,7 +151,7 @@ static NSString *MemLabelEndLink;
self.flagNameIndex = [PcsxrMemoryObject memFlagsFromBlockFlags:infoBlock->Flags]; self.flagNameIndex = [PcsxrMemoryObject memFlagsFromBlockFlags:infoBlock->Flags];
if (self.flagNameIndex == memFlagFree) { if (self.flagNameIndex == memFlagFree) {
self.memoryCardImages = @[]; self.memoryCardImages = @[];
self.memImageIndex = -1; self.hasImages = NO;
self.englishName = self.sjisName = @"Free block"; self.englishName = self.sjisName = @"Free block";
self.memID = self.memName = @""; self.memID = self.memName = @"";
} else { } else {
@ -171,18 +170,9 @@ static NSString *MemLabelEndLink;
} }
if ([memImages count] == 0) { if ([memImages count] == 0) {
self.memImageIndex = -1; self.hasImages = NO;
} else if ([memImages count] == 1) {
self.memImageIndex = 0;
} else { } else {
self.memImageIndex = 0; self.hasImages = YES;
[[NSNotificationCenter defaultCenter] addObserverForName:memoryAnimateTimerKey object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
NSInteger index = memImageIndex;
if (++index >= [memImages count]) {
index = 0;
}
self.memImageIndex = index;
}];
} }
self.memName = @(infoBlock->Name); self.memName = @(infoBlock->Name);
self.memID = @(infoBlock->ID); self.memID = @(infoBlock->ID);
@ -194,20 +184,13 @@ static NSString *MemLabelEndLink;
#pragma mark - Property Synthesizers #pragma mark - Property Synthesizers
@synthesize englishName; @synthesize englishName;
@synthesize sjisName; @synthesize sjisName;
@synthesize memImageIndex;
- (void)setMemImageIndex:(NSInteger)theMemImageIndex
{
[self willChangeValueForKey:@"memImage"];
memImageIndex = theMemImageIndex;
[self didChangeValueForKey:@"memImage"];
}
@synthesize memName; @synthesize memName;
@synthesize memID; @synthesize memID;
@synthesize memoryCardImages = memImages; @synthesize memoryCardImages = memImages;
@synthesize flagNameIndex; @synthesize flagNameIndex;
@synthesize blockSize; @synthesize blockSize;
@synthesize startingIndex; @synthesize startingIndex;
@synthesize memImage = _memImage;
#pragma mark Non-synthesized Properties #pragma mark Non-synthesized Properties
- (NSUInteger)memIconCount - (NSUInteger)memIconCount
@ -217,7 +200,7 @@ static NSString *MemLabelEndLink;
- (NSImage*)firstMemImage - (NSImage*)firstMemImage
{ {
if (memImageIndex == -1) { if (self.hasImages == NO) {
return [PcsxrMemoryObject blankImage]; return [PcsxrMemoryObject blankImage];
} }
return memImages[0]; return memImages[0];
@ -225,10 +208,25 @@ static NSString *MemLabelEndLink;
- (NSImage*)memImage - (NSImage*)memImage
{ {
if (memImageIndex == -1) { if (self.hasImages == NO) {
return [PcsxrMemoryObject blankImage]; return [PcsxrMemoryObject blankImage];
} }
return memImages[memImageIndex];
if (!_memImage) {
NSMutableData *gifData = [NSMutableData new];
CGImageDestinationRef dst = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)gifData, kUTTypeGIF, self.memIconCount, NULL);
NSDictionary *gifPrep = @{(NSString *) kCGImagePropertyGIFDictionary: @{(NSString *) kCGImagePropertyGIFDelayTime: @0.30f}};
for (NSImage *theImage in memImages) {
CGImageRef imageRef = [theImage CGImageForProposedRect:NULL context:nil hints:nil];
CGImageDestinationAddImage(dst, imageRef,(__bridge CFDictionaryRef)(gifPrep));
}
CGImageDestinationFinalize(dst);
CFRelease(dst);
_memImage = [[NSImage alloc] initWithData:gifData];
}
return _memImage;
} }
- (NSString*)flagName - (NSString*)flagName