OS X: Re-work PcsxrMemoryObject to make the properties more readable.
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@92297 e17a0e51-4ae3-4d35-97c3-1a29b211df97
This commit is contained in:
parent
eded81ac8a
commit
759e29705c
|
@ -102,11 +102,11 @@ static OSStatus GeneratePreviewForMemCard(void *thisInterface, QLPreviewRequestR
|
|||
NSDictionary *gifPrep = @{(NSString *) kCGImagePropertyGIFDictionary: @{(NSString *) kCGImagePropertyGIFDelayTime: @0.30f}};
|
||||
|
||||
for (PcsxrMemoryObject *obj in memCards) {
|
||||
if (!obj.hasImages || obj.memIconCount == 1) {
|
||||
if (!obj.hasImages || obj.iconCount == 1) {
|
||||
NSMutableData *pngData = [[NSMutableData alloc] init];
|
||||
{
|
||||
CGImageDestinationRef dst = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)pngData, kUTTypePNG, 1, NULL);
|
||||
NSImage *theImage = [obj firstMemImage];
|
||||
NSImage *theImage = [obj firstImage];
|
||||
|
||||
CGImageRef imageRef = [theImage CGImageForProposedRect:NULL context:nil hints:nil];
|
||||
CGImageDestinationAddImage(dst, imageRef, NULL);
|
||||
|
@ -124,8 +124,8 @@ static OSStatus GeneratePreviewForMemCard(void *thisInterface, QLPreviewRequestR
|
|||
}
|
||||
NSMutableData *gifData = [[NSMutableData alloc] init];
|
||||
|
||||
CGImageDestinationRef dst = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)gifData, kUTTypeGIF, obj.memIconCount, NULL);
|
||||
for (NSImage *theImage in obj.memoryCardImages) {
|
||||
CGImageDestinationRef dst = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)gifData, kUTTypeGIF, obj.iconCount, NULL);
|
||||
for (NSImage *theImage in obj.imageArray) {
|
||||
CGImageRef imageRef = [theImage CGImageForProposedRect:NULL context:nil hints:nil];
|
||||
CGImageDestinationAddImage(dst, imageRef, (__bridge CFDictionaryRef)(gifPrep));
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ static NSImage *MemoryImageAtIndex(NSArray *memArray, NSInteger my)
|
|||
for (PcsxrMemoryObject *obj in memArray) {
|
||||
NSIndexSet *idxSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(i, obj.blockSize)];
|
||||
if ([idxSet containsIndex:my]) {
|
||||
return obj.firstMemImage;
|
||||
return obj.firstImage;
|
||||
}
|
||||
i += obj.blockSize;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ static void GetSoloBlockInfo(unsigned char *data, int block, McdBlock *Info)
|
|||
strlcpy(Info->Name, ptr, 16);
|
||||
}
|
||||
|
||||
static inline PCSXRMemFlags MemBlockFlag(unsigned char blockFlags)
|
||||
static inline PCSXRMemFlag MemBlockFlag(unsigned char blockFlags)
|
||||
{
|
||||
if ((blockFlags & 0xF0) == 0xA0) {
|
||||
if ((blockFlags & 0xF) >= 1 && (blockFlags & 0xF) <= 3)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6249" systemVersion="14A386b" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6249"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="ConfigurationController">
|
||||
|
@ -1155,7 +1155,7 @@
|
|||
</constraints>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" animates="YES" imageScaling="proportionallyDown" image="NSAdvanced" id="986"/>
|
||||
<connections>
|
||||
<binding destination="958" name="value" keyPath="representedObject.memImage" id="1057"/>
|
||||
<binding destination="958" name="value" keyPath="representedObject.image" id="wKj-sJ-HxU"/>
|
||||
</connections>
|
||||
</imageView>
|
||||
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="979">
|
||||
|
@ -1169,7 +1169,7 @@
|
|||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<binding destination="958" name="value" keyPath="representedObject.name" id="Zcl-K6-pvX"/>
|
||||
<binding destination="958" name="value" keyPath="representedObject.title" id="ax9-dU-Vnf"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="977">
|
||||
|
@ -1210,7 +1210,7 @@
|
|||
<constraint firstAttribute="centerY" secondItem="1047" secondAttribute="centerY" id="nmd-M9-gSz"/>
|
||||
</constraints>
|
||||
<connections>
|
||||
<binding destination="958" name="hidden" keyPath="representedObject.isBiggerThanOne" id="1044">
|
||||
<binding destination="958" name="hidden" keyPath="representedObject.showCount" id="cGM-hT-0ur">
|
||||
<dictionary key="options">
|
||||
<string key="NSValueTransformerName">NSNegateBoolean</string>
|
||||
</dictionary>
|
||||
|
@ -1256,9 +1256,11 @@
|
|||
</collectionViewItem>
|
||||
<arrayController objectClassName="PcsxrMemoryObject" id="959" userLabel="MemCard2">
|
||||
<declaredKeys>
|
||||
<string>englishName</string>
|
||||
<string>sjisName</string>
|
||||
<string>memImage</string>
|
||||
<string>title</string>
|
||||
<string>name</string>
|
||||
<string>image</string>
|
||||
<string>showCount</string>
|
||||
<string>blockSize</string>
|
||||
</declaredKeys>
|
||||
<connections>
|
||||
<binding destination="955" name="contentArray" keyPath="self.memCard2Array.memoryArray" id="1033"/>
|
||||
|
@ -1266,9 +1268,11 @@
|
|||
</arrayController>
|
||||
<arrayController objectClassName="PcsxrMemoryObject" id="960" userLabel="MemCard1">
|
||||
<declaredKeys>
|
||||
<string>englishName</string>
|
||||
<string>sjisName</string>
|
||||
<string>memImage</string>
|
||||
<string>title</string>
|
||||
<string>name</string>
|
||||
<string>image</string>
|
||||
<string>blockSize</string>
|
||||
<string>showCount</string>
|
||||
</declaredKeys>
|
||||
<connections>
|
||||
<binding destination="955" name="contentArray" keyPath="self.memCard1Array.memoryArray" id="1034"/>
|
||||
|
|
|
@ -220,7 +220,7 @@ static inline void ClearMemcardData(char *to, int dsti, char *str)
|
|||
{
|
||||
int memSize = MAX_MEMCARD_BLOCKS;
|
||||
for (PcsxrMemoryObject *memObj in rawArray) {
|
||||
if (memObj.flagNameIndex != memFlagDeleted) {
|
||||
if (memObj.flag != memFlagDeleted) {
|
||||
memSize -= memObj.blockSize;
|
||||
}
|
||||
}
|
||||
|
@ -270,10 +270,10 @@ static inline void ClearMemcardData(char *to, int dsti, char *str)
|
|||
x = i;
|
||||
McdBlock baseBlock;
|
||||
GetMcdBlockInfo(cardNumber, i+1, &baseBlock);
|
||||
PCSXRMemFlags theFlags = [PcsxrMemoryObject memFlagsFromBlockFlags:baseBlock.Flags];
|
||||
PCSXRMemFlag theFlags = [PcsxrMemoryObject memFlagsFromBlockFlags:baseBlock.Flags];
|
||||
|
||||
if (theFlags == memFlagDeleted || theFlags == memFlagFree) {
|
||||
PCSXRMemFlags up1Flags = theFlags;
|
||||
PCSXRMemFlag up1Flags = theFlags;
|
||||
while ((up1Flags == memFlagDeleted || up1Flags == memFlagFree) && x < MAX_MEMCARD_BLOCKS) {
|
||||
x++;
|
||||
McdBlock up1Block;
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
|
||||
int cardSize, freeConsBlocks, availBlocks;
|
||||
|
||||
if ([[fromCard memoryArray][selectedIndex] flagNameIndex] == memFlagFree) {
|
||||
if ([[fromCard memoryArray][selectedIndex] flag] == memFlagFree) {
|
||||
NSBeep();
|
||||
return;
|
||||
}
|
||||
|
@ -193,7 +193,7 @@
|
|||
|
||||
PcsxrMemoryObject *tmpObj = [curCard memoryArray][selectedIndex];
|
||||
|
||||
if (tmpObj.flagNameIndex == memFlagFree) {
|
||||
if (tmpObj.flag == memFlagFree) {
|
||||
NSBeep();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
#include "sio.h"
|
||||
|
||||
typedef NS_ENUM(char, PCSXRMemFlags) {
|
||||
typedef NS_ENUM(char, PCSXRMemFlag) {
|
||||
memFlagDeleted,
|
||||
memFlagFree,
|
||||
memFlagUsed,
|
||||
|
@ -20,28 +20,28 @@ typedef NS_ENUM(char, PCSXRMemFlags) {
|
|||
@interface PcsxrMemoryObject : NSObject
|
||||
|
||||
+ (NSArray *)imagesFromMcd:(McdBlock *)block;
|
||||
+ (NSString*)memoryLabelFromFlag:(PCSXRMemFlags)flagNameIndex;
|
||||
+ (NSString*)memoryLabelFromFlag:(PCSXRMemFlag)flagNameIndex;
|
||||
+ (NSImage *)blankImage;
|
||||
+ (PCSXRMemFlags)memFlagsFromBlockFlags:(unsigned char)blockFlags;
|
||||
+ (PCSXRMemFlag)memFlagsFromBlockFlags:(unsigned char)blockFlags;
|
||||
|
||||
- (instancetype)initWithMcdBlock:(McdBlock *)infoBlockc startingIndex:(uint8_t)startIdx size:(uint8_t)memSize NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (NSImage*)memoryImageAtIndex:(NSInteger)idx;
|
||||
|
||||
@property (readonly, copy) NSString *title;
|
||||
@property (readonly, copy) NSString *name;
|
||||
@property (readonly, copy) NSString *memName;
|
||||
@property (readonly, copy) NSString *memID;
|
||||
@property (readonly, strong) NSArray *memoryCardImages;
|
||||
@property (readonly, strong, nonatomic) NSImage *memImage;
|
||||
@property (readonly) PCSXRMemFlags flagNameIndex;
|
||||
@property (readonly, copy) NSString *identifier;
|
||||
@property (readonly, strong) NSArray *imageArray;
|
||||
@property (readonly, strong, nonatomic) NSImage *image;
|
||||
@property (readonly) PCSXRMemFlag flag;
|
||||
@property (readonly) uint8_t startingIndex;
|
||||
@property (readonly) uint8_t blockSize;
|
||||
@property (readonly) BOOL hasImages;
|
||||
|
||||
@property (readonly, copy) NSImage *firstMemImage;
|
||||
@property (readonly, nonatomic) NSUInteger memIconCount;
|
||||
@property (readonly, copy) NSImage *firstImage;
|
||||
@property (readonly, nonatomic) NSUInteger iconCount;
|
||||
@property (readonly, unsafe_unretained, nonatomic) NSString *flagName;
|
||||
@property (readonly, unsafe_unretained, nonatomic) NSAttributedString *attributedFlagName;
|
||||
@property (readonly, nonatomic) BOOL isBiggerThanOne;
|
||||
@property (readonly, nonatomic) BOOL showCount;
|
||||
|
||||
@end
|
||||
|
|
|
@ -10,15 +10,15 @@
|
|||
#import "PcsxrMemoryObject.h"
|
||||
|
||||
@interface PcsxrMemoryObject ()
|
||||
@property (readwrite, copy) NSString *title;
|
||||
@property (readwrite, copy) NSString *name;
|
||||
@property (readwrite, copy) NSString *memName;
|
||||
@property (readwrite, copy) NSString *memID;
|
||||
@property (readwrite, copy) NSString *identifier;
|
||||
@property (readwrite) uint8_t startingIndex;
|
||||
@property (readwrite) uint8_t blockSize;
|
||||
|
||||
@property (readwrite, strong) NSArray *memoryCardImages;
|
||||
@property (readwrite) PCSXRMemFlags flagNameIndex;
|
||||
@property (readwrite, nonatomic, strong) NSImage *memImage;
|
||||
@property (readwrite, strong) NSArray *imageArray;
|
||||
@property (readwrite) PCSXRMemFlag flag;
|
||||
@property (readwrite, nonatomic, strong) NSImage *image;
|
||||
@property (readwrite) BOOL hasImages;
|
||||
@end
|
||||
|
||||
|
@ -74,13 +74,13 @@ static NSString *MemLabelEndLink;
|
|||
|
||||
- (NSImage*)memoryImageAtIndex:(NSInteger)idx
|
||||
{
|
||||
if (!self.hasImages || idx > self.memIconCount) {
|
||||
if (!self.hasImages || idx > self.iconCount) {
|
||||
return [PcsxrMemoryObject blankImage];
|
||||
}
|
||||
return memImages[idx];
|
||||
}
|
||||
|
||||
+ (NSString*)memoryLabelFromFlag:(PCSXRMemFlags)flagNameIndex
|
||||
+ (NSString*)memoryLabelFromFlag:(PCSXRMemFlag)flagNameIndex
|
||||
{
|
||||
switch (flagNameIndex) {
|
||||
default:
|
||||
|
@ -120,7 +120,7 @@ static NSString *MemLabelEndLink;
|
|||
return [imageBlank copy];
|
||||
}
|
||||
|
||||
+ (PCSXRMemFlags)memFlagsFromBlockFlags:(unsigned char)blockFlags
|
||||
+ (PCSXRMemFlag)memFlagsFromBlockFlags:(unsigned char)blockFlags
|
||||
{
|
||||
if ((blockFlags & 0xF0) == 0xA0) {
|
||||
if ((blockFlags & 0xF) >= 1 && (blockFlags & 0xF) <= 3)
|
||||
|
@ -147,45 +147,45 @@ static NSString *MemLabelEndLink;
|
|||
if (self = [super init]) {
|
||||
self.startingIndex = startIdx;
|
||||
self.blockSize = memSize;
|
||||
self.flagNameIndex = [PcsxrMemoryObject memFlagsFromBlockFlags:infoBlock->Flags];
|
||||
if (self.flagNameIndex == memFlagFree) {
|
||||
self.memoryCardImages = @[];
|
||||
self.flag = [PcsxrMemoryObject memFlagsFromBlockFlags:infoBlock->Flags];
|
||||
if (self.flag == memFlagFree) {
|
||||
self.imageArray = @[];
|
||||
self.hasImages = NO;
|
||||
self.name = @"Free block";
|
||||
self.memID = self.memName = @"";
|
||||
self.title = @"Free block";
|
||||
self.identifier = self.name = @"";
|
||||
} else {
|
||||
self.name = [NSString stringWithCString:infoBlock->sTitle encoding:NSShiftJISStringEncoding];
|
||||
self.memoryCardImages = [PcsxrMemoryObject imagesFromMcd:infoBlock];
|
||||
self.title = [NSString stringWithCString:infoBlock->sTitle encoding:NSShiftJISStringEncoding];
|
||||
self.imageArray = [PcsxrMemoryObject imagesFromMcd:infoBlock];
|
||||
|
||||
if ([memImages count] == 0) {
|
||||
self.hasImages = NO;
|
||||
} else {
|
||||
self.hasImages = YES;
|
||||
}
|
||||
self.memName = @(infoBlock->Name);
|
||||
self.memID = @(infoBlock->ID);
|
||||
self.name = @(infoBlock->Name);
|
||||
self.identifier = @(infoBlock->ID);
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Property Synthesizers
|
||||
@synthesize title;
|
||||
@synthesize name;
|
||||
@synthesize memName;
|
||||
@synthesize memID;
|
||||
@synthesize memoryCardImages = memImages;
|
||||
@synthesize flagNameIndex;
|
||||
@synthesize identifier;
|
||||
@synthesize imageArray = memImages;
|
||||
@synthesize flag;
|
||||
@synthesize blockSize;
|
||||
@synthesize startingIndex;
|
||||
@synthesize memImage = _memImage;
|
||||
@synthesize image = _memImage;
|
||||
|
||||
#pragma mark Non-synthesized Properties
|
||||
- (NSUInteger)memIconCount
|
||||
- (NSUInteger)iconCount
|
||||
{
|
||||
return [memImages count];
|
||||
}
|
||||
|
||||
- (NSImage*)firstMemImage
|
||||
- (NSImage*)firstImage
|
||||
{
|
||||
if (self.hasImages == NO) {
|
||||
return [PcsxrMemoryObject blankImage];
|
||||
|
@ -193,7 +193,7 @@ static NSString *MemLabelEndLink;
|
|||
return memImages[0];
|
||||
}
|
||||
|
||||
- (NSImage*)memImage
|
||||
- (NSImage*)image
|
||||
{
|
||||
if (self.hasImages == NO) {
|
||||
NSImage *tmpBlank = [PcsxrMemoryObject blankImage];
|
||||
|
@ -204,7 +204,7 @@ static NSString *MemLabelEndLink;
|
|||
if (!_memImage) {
|
||||
NSMutableData *gifData = [NSMutableData new];
|
||||
|
||||
CGImageDestinationRef dst = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)gifData, kUTTypeGIF, self.memIconCount, NULL);
|
||||
CGImageDestinationRef dst = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)gifData, kUTTypeGIF, self.iconCount, NULL);
|
||||
NSDictionary *gifPrep = @{(NSString *) kCGImagePropertyGIFDictionary: @{(NSString *) kCGImagePropertyGIFDelayTime: @0.30f}};
|
||||
for (NSImage *theImage in memImages) {
|
||||
CGImageRef imageRef = [theImage CGImageForProposedRect:NULL context:nil hints:nil];
|
||||
|
@ -221,7 +221,7 @@ static NSString *MemLabelEndLink;
|
|||
|
||||
- (NSString*)flagName
|
||||
{
|
||||
return [PcsxrMemoryObject memoryLabelFromFlag:flagNameIndex];
|
||||
return [PcsxrMemoryObject memoryLabelFromFlag:flag];
|
||||
}
|
||||
|
||||
static inline void SetupAttrStr(NSMutableAttributedString *mutStr, NSColor *txtclr)
|
||||
|
@ -278,7 +278,7 @@ static inline void SetupAttrStr(NSMutableAttributedString *mutStr, NSColor *txtc
|
|||
attribMemLabelDeleted = [tmpStr copy];
|
||||
});
|
||||
|
||||
switch (flagNameIndex) {
|
||||
switch (flag) {
|
||||
default:
|
||||
case memFlagFree:
|
||||
return attribMemLabelFree;
|
||||
|
@ -302,9 +302,9 @@ static inline void SetupAttrStr(NSMutableAttributedString *mutStr, NSColor *txtc
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL)isBiggerThanOne
|
||||
- (BOOL)showCount
|
||||
{
|
||||
if (flagNameIndex == memFlagFree) {
|
||||
if (flag == memFlagFree) {
|
||||
//Always show the size of the free blocks
|
||||
return YES;
|
||||
} else {
|
||||
|
@ -321,7 +321,7 @@ static inline void SetupAttrStr(NSMutableAttributedString *mutStr, NSColor *txtc
|
|||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"%@: Name: %@ ID: %@, type: %@ start: %i size: %i", name, memName, memID, self.flagName, startingIndex, blockSize];
|
||||
return [NSString stringWithFormat:@"%@: Name: %@ ID: %@, type: %@ start: %i size: %i", title, name, identifier, self.flagName, startingIndex, blockSize];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue