summaryrefslogtreecommitdiff
path: root/macosx/Source/PcsxrMemoryObject.m
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2014-09-08 14:27:51 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2014-09-08 14:27:51 +0000
commitb96092d6fbde83d1e3036a6591b0bed356526733 (patch)
treee39d02ffcea9aaa5a6d446771ee34040fdd0d157 /macosx/Source/PcsxrMemoryObject.m
parent20b807f0450f8dbd02e1c78043b64113dae0cb73 (diff)
downloadpcsxr-b96092d6fbde83d1e3036a6591b0bed356526733.tar.gz
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
Diffstat (limited to 'macosx/Source/PcsxrMemoryObject.m')
-rw-r--r--macosx/Source/PcsxrMemoryObject.m52
1 files changed, 25 insertions, 27 deletions
diff --git a/macosx/Source/PcsxrMemoryObject.m b/macosx/Source/PcsxrMemoryObject.m
index a04a4379..4f564b86 100644
--- a/macosx/Source/PcsxrMemoryObject.m
+++ b/macosx/Source/PcsxrMemoryObject.m
@@ -9,8 +9,6 @@
#import <Cocoa/Cocoa.h>
#import "PcsxrMemoryObject.h"
-NSString *const memoryAnimateTimerKey = @"PCSXR Memory Card Image Animate";
-
@interface PcsxrMemoryObject ()
@property (readwrite, strong) NSString *englishName;
@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 blockSize;
-@property (readwrite, nonatomic) NSInteger memImageIndex;
@property (readwrite, strong) NSArray *memoryCardImages;
@property (readwrite) PCSXRMemFlags flagNameIndex;
+@property (readwrite, nonatomic, strong) NSImage *memImage;
+@property (readwrite) BOOL hasImages;
@end
@implementation PcsxrMemoryObject
@@ -76,7 +75,7 @@ static NSString *MemLabelEndLink;
- (NSImage*)memoryImageAtIndex:(NSInteger)idx
{
- if (memImageIndex == -1 || idx > self.memIconCount) {
+ if (!self.hasImages || idx > self.memIconCount) {
return [PcsxrMemoryObject blankImage];
}
return memImages[idx];
@@ -152,7 +151,7 @@ static NSString *MemLabelEndLink;
self.flagNameIndex = [PcsxrMemoryObject memFlagsFromBlockFlags:infoBlock->Flags];
if (self.flagNameIndex == memFlagFree) {
self.memoryCardImages = @[];
- self.memImageIndex = -1;
+ self.hasImages = NO;
self.englishName = self.sjisName = @"Free block";
self.memID = self.memName = @"";
} else {
@@ -171,18 +170,9 @@ static NSString *MemLabelEndLink;
}
if ([memImages count] == 0) {
- self.memImageIndex = -1;
- } else if ([memImages count] == 1) {
- self.memImageIndex = 0;
+ self.hasImages = NO;
} else {
- self.memImageIndex = 0;
- [[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.hasImages = YES;
}
self.memName = @(infoBlock->Name);
self.memID = @(infoBlock->ID);
@@ -194,20 +184,13 @@ static NSString *MemLabelEndLink;
#pragma mark - Property Synthesizers
@synthesize englishName;
@synthesize sjisName;
-@synthesize memImageIndex;
-- (void)setMemImageIndex:(NSInteger)theMemImageIndex
-{
- [self willChangeValueForKey:@"memImage"];
- memImageIndex = theMemImageIndex;
- [self didChangeValueForKey:@"memImage"];
-}
-
@synthesize memName;
@synthesize memID;
@synthesize memoryCardImages = memImages;
@synthesize flagNameIndex;
@synthesize blockSize;
@synthesize startingIndex;
+@synthesize memImage = _memImage;
#pragma mark Non-synthesized Properties
- (NSUInteger)memIconCount
@@ -217,7 +200,7 @@ static NSString *MemLabelEndLink;
- (NSImage*)firstMemImage
{
- if (memImageIndex == -1) {
+ if (self.hasImages == NO) {
return [PcsxrMemoryObject blankImage];
}
return memImages[0];
@@ -225,10 +208,25 @@ static NSString *MemLabelEndLink;
- (NSImage*)memImage
{
- if (memImageIndex == -1) {
+ if (self.hasImages == NO) {
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