summaryrefslogtreecommitdiff
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
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
-rwxr-xr-xmacosx/PcsxrMemCardController.h1
-rwxr-xr-xmacosx/PcsxrMemCardController.m11
-rwxr-xr-xmacosx/PcsxrMemoryObject.h9
-rwxr-xr-xmacosx/PcsxrMemoryObject.m75
4 files changed, 79 insertions, 17 deletions
diff --git a/macosx/PcsxrMemCardController.h b/macosx/PcsxrMemCardController.h
index 8b5598cd..8e9eb906 100755
--- a/macosx/PcsxrMemCardController.h
+++ b/macosx/PcsxrMemCardController.h
@@ -15,6 +15,7 @@
IBOutlet NSCollectionView *memCard2view;
NSMutableArray *memCard1Array;
NSMutableArray *memCard2Array;
+ NSTimer *imageAnimateTimer;
}
- (IBAction)moveBlock:(id)sender;
diff --git a/macosx/PcsxrMemCardController.m b/macosx/PcsxrMemCardController.m
index eebc0fc6..d1bc8e4d 100755
--- a/macosx/PcsxrMemCardController.m
+++ b/macosx/PcsxrMemCardController.m
@@ -80,7 +80,6 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
return memCard2Array;
}
-
- (id)init
{
self = [self initWithWindowNibName:@"MemCardManager"];
@@ -159,6 +158,13 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
[[self window] setDelegate:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memoryCardDidChangeNotification:) name:memChangeNotifier object:nil];
+ imageAnimateTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:2] interval:2.0/3.0 target:self selector:@selector(animateMemCards:) userInfo:nil repeats:YES];
+ [[NSRunLoop mainRunLoop] addTimer:imageAnimateTimer forMode:NSDefaultRunLoopMode];
+}
+
+- (void)animateMemCards:(NSTimer*)theTimer
+{
+ [[NSNotificationCenter defaultCenter] postNotificationName:memoryAnimateTimerKey object:self];
}
- (void)windowDidBecomeKey:(NSNotification *)notification
@@ -404,6 +410,9 @@ static inline void CopyMemcardData(char *from, char *to, int srci, int dsti, cha
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
+ [imageAnimateTimer invalidate];
+
+ RELEASEOBJ(imageAnimateTimer);
RELEASEOBJ(memCard1Array);
RELEASEOBJ(memCard2Array);
diff --git a/macosx/PcsxrMemoryObject.h b/macosx/PcsxrMemoryObject.h
index 556d2acd..e197c21a 100755
--- a/macosx/PcsxrMemoryObject.h
+++ b/macosx/PcsxrMemoryObject.h
@@ -11,6 +11,9 @@
@class NSImage;
@class NSString;
+@class NSArray;
+
+extern NSString *const memoryAnimateTimerKey;
@interface PcsxrMemoryObject : NSObject
{
@@ -19,11 +22,13 @@
NSString *memName;
NSString *memID;
NSImage *memImage;
+ NSArray *memImages;
int memIconCount;
BOOL notDeleted;
unsigned char memFlags;
}
-+ (NSImage *)imageFromMcd:(short *)icon;
++ (NSImage *)imageFromMcd:(McdBlock *)block index:(int)idx;
++ (NSArray *)imagesFromMcd:(McdBlock *)block;
- (id)initWithMcdBlock:(McdBlock *)infoBlock;
@@ -31,7 +36,7 @@
@property(readonly, retain) NSString *sjisName;
@property(readonly, retain) NSString *memName;
@property(readonly, retain) NSString *memID;
-@property(readonly, retain) NSImage *memImage;
+@property(readwrite, retain) NSImage *memImage;
@property(readonly) int memIconCount;
@property(readonly, getter = isNotDeleted) BOOL notDeleted;
@property(readonly) unsigned char memFlags;
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
{