summaryrefslogtreecommitdiff
path: root/macosx/PcsxrMemoryObject.m
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-06-25 21:02:27 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2013-06-25 21:02:27 +0000
commit6c9a81db199b7c6f86cc28d14255ab81d25a0f58 (patch)
tree971dd7f0d2e61bc8d56541c0110f2348340fb6d1 /macosx/PcsxrMemoryObject.m
parent1e070eefdd97247bffec46c5553e435e2bcc9972 (diff)
downloadpcsxr-6c9a81db199b7c6f86cc28d14255ab81d25a0f58.tar.gz
Add animated memory card icons on OS X
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@85554 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/PcsxrMemoryObject.m')
-rwxr-xr-xmacosx/PcsxrMemoryObject.m75
1 files changed, 61 insertions, 14 deletions
diff --git a/macosx/PcsxrMemoryObject.m b/macosx/PcsxrMemoryObject.m
index 71ecb0d7..16989b67 100755
--- a/macosx/PcsxrMemoryObject.m
+++ b/macosx/PcsxrMemoryObject.m
@@ -8,33 +8,65 @@
#import "PcsxrMemoryObject.h"
#import <Foundation/NSString.h>
+#import <Foundation/NSArray.h>
#import <AppKit/NSColor.h>
#import <AppKit/NSImage.h>
+#import <AppKit/NSBezierPath.h>
#import "ARCBridge.h"
+NSString *const memoryAnimateTimerKey = @"PCSXR Memory Card Image Animate";
+
@interface PcsxrMemoryObject ()
//Mangle the setters' names so that if someone tries to use them, they won't work
-@property(readwrite, retain, setter = setEngName:) NSString *englishName;
-@property(readwrite, retain, setter = setJapaneseName:) NSString *sjisName;
-@property(readwrite, retain, setter = setTheMemName:) NSString *memName;
-@property(readwrite, retain, setter = setTheMemId:) NSString *memID;
-@property(readwrite, retain, setter = setTheMemImage:) NSImage *memImage;
-@property(readwrite, setter = setIconCount:) int memIconCount;
-@property(readwrite, getter = isNotDeleted, setter = setIsNotDeleted:) BOOL notDeleted;
-@property(readwrite, setter = setTheMemFlags:) unsigned char memFlags;
+@property (readwrite, retain, setter = setEngName:) NSString *englishName;
+@property (readwrite, retain, setter = setJapaneseName:) NSString *sjisName;
+@property (readwrite, retain, setter = setTheMemName:) NSString *memName;
+@property (readwrite, retain, setter = setTheMemId:) NSString *memID;
+@property (readwrite, setter = setIconCount:) int memIconCount;
+@property (readwrite, getter = isNotDeleted, setter = setIsNotDeleted:) BOOL notDeleted;
+@property (readwrite, setter = setTheMemFlags:) unsigned char memFlags;
+@property (retain) NSArray *memImages;
@end
@implementation PcsxrMemoryObject
-+ (NSImage *)imageFromMcd:(short *)icon
++ (NSArray *)imagesFromMcd:(McdBlock *)block
+{
+ NSMutableArray *imagesArray = [[NSMutableArray alloc] initWithCapacity:block->IconCount];
+ for (int i = 0; i < block->IconCount; i++) {
+ [imagesArray addObject:[self imageFromMcd:block index:i]];
+ }
+ NSArray *retArray = [[NSArray alloc] initWithArray:imagesArray];
+ RELEASEOBJ(imagesArray);
+ return AUTORELEASEOBJ(retArray);
+}
+
++ (NSImage *)blankImage
+{
+ static NSImage *imageBlank = nil;
+ if (imageBlank == nil) {
+ NSRect imageRect = NSMakeRect(0, 0, 32, 32);
+ imageBlank = [[NSImage alloc] initWithSize:imageRect.size];
+ [imageBlank lockFocus];
+ [[NSColor blackColor] set];
+ [NSBezierPath fillRect:imageRect];
+ [imageBlank unlockFocus];
+
+ }
+ return imageBlank;
+}
+
++ (NSImage *)imageFromMcd:(McdBlock *)block index:(int)idx
{
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:16 pixelsHigh:16 bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 bitsPerPixel:0];
+ short *icon = block->Icon;
+
int x, y, c, i, r, g, b;
- for (i = 0; i < 256; i++) {
+ for (i = 0; i < 256 * (idx + 1); i++) {
x = (i % 16);
y = (i / 16);
- c = icon[i];
+ c = icon[(idx * 256) + i];
r = (c & 0x001f) << 3;
g = ((c & 0x03e0) >> 5) << 3;
b = ((c & 0x7c00) >> 10) << 3;
@@ -53,7 +85,19 @@
self.englishName = [NSString stringWithCString:infoBlock->Title encoding:NSASCIIStringEncoding];
self.sjisName = [NSString stringWithCString:infoBlock->sTitle encoding:NSShiftJISStringEncoding];
@autoreleasepool {
- self.memImage = [PcsxrMemoryObject imageFromMcd:infoBlock->Icon];
+ self.memImages = [PcsxrMemoryObject imagesFromMcd:infoBlock];
+ }
+ if ([memImages count] == 0) {
+ self.memImage = [PcsxrMemoryObject blankImage];
+ } else {
+ self.memImage = [self.memImages objectAtIndex:0];
+ [[NSNotificationCenter defaultCenter] addObserverForName:memoryAnimateTimerKey object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
+ NSInteger index = [memImages indexOfObject:memImage];
+ if (++index >= [memImages count]) {
+ index = 0;
+ }
+ self.memImage = [memImages objectAtIndex:index];
+ }];
}
self.memName = [NSString stringWithCString:infoBlock->Name encoding:NSASCIIStringEncoding];
self.memID = [NSString stringWithCString:infoBlock->ID encoding:NSASCIIStringEncoding];
@@ -81,19 +125,22 @@
@synthesize memName;
@synthesize memID;
@synthesize memIconCount;
+@synthesize memImages;
-#if !__has_feature(objc_arc)
- (void)dealloc
{
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+#if !__has_feature(objc_arc)
self.englishName = nil;
self.sjisName = nil;
self.memName = nil;
self.memID = nil;
self.memImage = nil;
+ self.memImages = nil;
[super dealloc];
-}
#endif
+}
- (NSString *)description
{