summaryrefslogtreecommitdiff
path: root/macosx/Source
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
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')
-rw-r--r--macosx/Source/ConfigurationController.m10
-rw-r--r--macosx/Source/PcsxrMemCardController.h3
-rw-r--r--macosx/Source/PcsxrMemCardController.m23
-rw-r--r--macosx/Source/PcsxrMemoryObject.h6
-rw-r--r--macosx/Source/PcsxrMemoryObject.m52
5 files changed, 27 insertions, 67 deletions
diff --git a/macosx/Source/ConfigurationController.m b/macosx/Source/ConfigurationController.m
index aef8f7f4..c2e65a4a 100644
--- a/macosx/Source/ConfigurationController.m
+++ b/macosx/Source/ConfigurationController.m
@@ -169,16 +169,6 @@ NSString *const memCardChangeNumberKey = @"PcsxrMemoryCardThatChangedKey";
}
}
-- (void)windowWillClose:(NSNotification *)notification
-{
- [memCardEdit stopMemoryAnimation];
-}
-
-- (void)windowDidBecomeMain:(NSNotification *)notification
-{
- [memCardEdit beginMemoryAnimation];
-}
-
- (void)awakeFromNib
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
diff --git a/macosx/Source/PcsxrMemCardController.h b/macosx/Source/PcsxrMemCardController.h
index d4a71088..d3b43aae 100644
--- a/macosx/Source/PcsxrMemCardController.h
+++ b/macosx/Source/PcsxrMemCardController.h
@@ -24,7 +24,4 @@
- (IBAction)deleteMemoryObject:(id)sender;
- (void)loadMemoryCardInfoForCard:(int)theCard;
-- (void)beginMemoryAnimation;
-- (void)stopMemoryAnimation;
-
@end
diff --git a/macosx/Source/PcsxrMemCardController.m b/macosx/Source/PcsxrMemCardController.m
index 7fb139ea..7dbc271a 100644
--- a/macosx/Source/PcsxrMemCardController.m
+++ b/macosx/Source/PcsxrMemCardController.m
@@ -18,27 +18,12 @@
@interface PcsxrMemCardController ()
@property (readwrite, strong) PcsxrMemCardArray *memCard1Array;
@property (readwrite, strong) PcsxrMemCardArray *memCard2Array;
-@property (strong) NSTimer *imageAnimateTimer;
@end
@implementation PcsxrMemCardController
@synthesize memCard1Array;
@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
{
NSParameterAssert(theCards < 4 && theCards > 0);
@@ -97,13 +82,6 @@
[self setupValues:3];
[[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
@@ -232,7 +210,6 @@
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
- [self.imageAnimateTimer invalidate];
}
@end
diff --git a/macosx/Source/PcsxrMemoryObject.h b/macosx/Source/PcsxrMemoryObject.h
index 9ae756b2..39b44be5 100644
--- a/macosx/Source/PcsxrMemoryObject.h
+++ b/macosx/Source/PcsxrMemoryObject.h
@@ -9,8 +9,6 @@
#import <Cocoa/Cocoa.h>
#include "sio.h"
-extern NSString *const memoryAnimateTimerKey;
-
typedef NS_ENUM(char, PCSXRMemFlags) {
memFlagDeleted,
memFlagFree,
@@ -35,13 +33,13 @@ typedef NS_ENUM(char, PCSXRMemFlags) {
@property (readonly, strong) NSString *memName;
@property (readonly, strong) NSString *memID;
@property (readonly, strong) NSArray *memoryCardImages;
-@property (readonly, nonatomic) NSInteger memImageIndex;
+@property (readonly, strong, nonatomic) NSImage *memImage;
@property (readonly) PCSXRMemFlags flagNameIndex;
@property (readonly) uint8_t startingIndex;
@property (readonly) uint8_t blockSize;
+@property (readonly) BOOL hasImages;
@property (readonly, copy) NSImage *firstMemImage;
-@property (readonly, unsafe_unretained, nonatomic) NSImage *memImage;
@property (readonly, nonatomic) NSUInteger memIconCount;
@property (readonly, unsafe_unretained, nonatomic) NSString *flagName;
@property (readonly, unsafe_unretained, nonatomic) NSAttributedString *attributedFlagName;
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