From 97bb0560b9d2e2ef44e86bde2d52cf9093b0c0da Mon Sep 17 00:00:00 2001 From: "SND\\MaddTheSane_cp" Date: Sat, 29 Mar 2014 02:50:35 +0000 Subject: OS X: Refactoring. git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@89712 e17a0e51-4ae3-4d35-97c3-1a29b211df97 --- macosx/CheatController.h | 19 ++++- macosx/CheatController.m | 95 +++++++------------------ macosx/Pcsxr.xcodeproj/project.pbxproj | 6 ++ macosx/PcsxrHexadecimalFormatter.h | 4 -- macosx/PcsxrHexadecimalFormatter.m | 32 +++++---- macosx/Resources/Base.lproj/CheatWindow.xib | 106 +++++++++++++++------------- 6 files changed, 128 insertions(+), 134 deletions(-) diff --git a/macosx/CheatController.h b/macosx/CheatController.h index fc53129c..c56f2a68 100644 --- a/macosx/CheatController.h +++ b/macosx/CheatController.h @@ -4,8 +4,25 @@ // #import +#import "PcsxrHexadecimalFormatter.h" +#include "psxcommon.h" +#include "cheat.h" -@class PcsxrHexadecimalFormatter; +@interface PcsxrCheatTempObject : NSObject +@property (readwrite) uint32_t cheatAddress; +@property (readwrite) uint16_t cheatValue; + +- (instancetype)initWithAddress:(uint32_t)add value:(uint16_t)val; +- (instancetype)initWithCheatCode:(CheatCode *)theCheat; +@end + +@interface PcsxrCheatTemp : NSObject +@property (readwrite, strong) NSMutableArray *cheatValues; +@property (readwrite, strong) NSString *cheatName; +@property (readwrite, getter = isEnabled) BOOL enabled; + +- (instancetype)initWithCheat:(Cheat *)theCheat; +@end @interface CheatController : NSWindowController diff --git a/macosx/CheatController.m b/macosx/CheatController.m index acae6fbd..ebe73137 100644 --- a/macosx/CheatController.m +++ b/macosx/CheatController.m @@ -4,8 +4,6 @@ // #import -#include "psxcommon.h" -#include "cheat.h" #import "CheatController.h" #import "PcsxrCheatHandler.h" #import "PcsxrHexadecimalFormatter.h" @@ -13,75 +11,39 @@ #define kTempCheatCodesName @"tempCheatCodes" #define kCheatsName @"cheats" -@interface PcsxrCheatTempObject : NSObject -@property (readwrite) uint32_t address; -@property (readwrite, weak) NSNumber* addressNS; -@property (readwrite) uint16_t value; -@property (readwrite, weak) NSNumber* valueNS; - -- (id)initWithAddress:(uint32_t)add value:(uint16_t)val; -- (id)initWithCheatCode:(CheatCode *)theCheat; -@end - -@interface PcsxrCheatTemp : NSObject -@property (readwrite, strong) NSMutableArray *cheatValues; -@property (readwrite, strong) NSString *cheatName; -@property (readwrite, getter = isEnabled) BOOL enabled; - -- (id)initWithCheat:(Cheat *)theCheat; -@end - @implementation PcsxrCheatTempObject -@synthesize address, value; - -- (NSNumber *)addressNS -{ - return @(self.address); -} -- (void)setAddressNS:(NSNumber *)addressNS -{ - self.address = [addressNS unsignedIntValue]; -} - -- (NSNumber *)valueNS -{ - return @(self.value); -} -- (void)setValueNS:(NSNumber *)valueNS -{ - self.value = [valueNS unsignedShortValue]; -} +@synthesize cheatAddress, cheatValue; -- (id)init +- (instancetype)init { return [self initWithAddress:0x10000000 value:0]; } -- (id)initWithAddress:(uint32_t)add value:(uint16_t)val +- (instancetype)initWithAddress:(uint32_t)add value:(uint16_t)val { if (self = [super init]) { - self.address = add; - self.value = val; + self.cheatAddress = add; + self.cheatValue = val; } return self; } -- (id)initWithCheatCode:(CheatCode *)theCheat +- (instancetype)initWithCheatCode:(CheatCode *)theCheat { return [self initWithAddress:theCheat->Addr value:theCheat->Val]; } - (NSString*)description { - return [NSString stringWithFormat:@"%08x %04x", address, value]; + return [NSString stringWithFormat:@"%08x %04x", cheatAddress, cheatValue]; } - (BOOL)isEqual:(id)object { if ([object isKindOfClass:[PcsxrCheatTempObject class]]) { - if (address != [(PcsxrCheatTempObject*)object address]) { + if (cheatAddress != [object cheatAddress]) { return NO; - } else if (value != [(PcsxrCheatTempObject*)object value]) { + } else if (cheatValue != [object cheatValue]) { return NO; } else return YES; @@ -91,12 +53,12 @@ - (NSUInteger)hash { - return address ^ value; + return cheatAddress ^ cheatValue; } - (id)copyWithZone:(NSZone *)zone { - return [[[self class] allocWithZone:zone] initWithAddress:address value:value]; + return [[[self class] allocWithZone:zone] initWithAddress:cheatAddress value:cheatValue]; } @end @@ -106,7 +68,7 @@ @synthesize cheatValues; @synthesize enabled; -- (id)initWithCheat:(Cheat *)theCheat +- (instancetype)initWithCheat:(Cheat *)theCheat { if (self = [super init]) { self.cheatName = @(theCheat->Descr); @@ -143,12 +105,12 @@ return @"CheatWindow"; } -- (id)init +- (instancetype)init { return self = [self initWithWindowNibName:@"CheatWindow"]; } -- (id)initWithCoder:(NSCoder *)aDecoder +- (instancetype)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { self.tempCheatCodes = [NSMutableArray array]; @@ -156,7 +118,7 @@ return self; } -- (id)initWithWindow:(NSWindow *)window +- (instancetype)initWithWindow:(NSWindow *)window { if (self = [super initWithWindow:window]) { self.tempCheatCodes = [NSMutableArray array]; @@ -225,7 +187,7 @@ - (IBAction)clear:(id)sender { - self.cheats = [NSMutableArray array]; + self.cheats = [[NSMutableArray alloc] init]; } - (IBAction)closeCheatEdit:(id)sender @@ -269,19 +231,6 @@ [manager removeItemAtURL:tmpURL error:NULL]; } -- (void)editCheatCodeSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo -{ - if (returnCode == NSOKButton) { - PcsxrCheatTemp *tmpCheat = (self.cheats)[[cheatView selectedRow]]; - if (![tmpCheat.cheatValues isEqualToArray:self.tempCheatCodes]) { - tmpCheat.cheatValues = self.tempCheatCodes; - [self setDocumentEdited:YES]; - } - } - - [sheet orderOut:nil]; -} - - (IBAction)editCheat:(id)sender { if ([cheatView selectedRow] < 0) { @@ -291,7 +240,17 @@ NSMutableArray *tmpArray = [(self.cheats)[[cheatView selectedRow]] cheatValues]; NSMutableArray *newCheats = [[NSMutableArray alloc] initWithArray:tmpArray copyItems:YES]; self.tempCheatCodes = newCheats; - [NSApp beginSheet:editCheatWindow modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(editCheatCodeSheetDidEnd:returnCode:contextInfo:) contextInfo:NULL]; + [[self window] beginSheet:editCheatWindow completionHandler:^(NSModalResponse returnCode) { + if (returnCode == NSOKButton) { + PcsxrCheatTemp *tmpCheat = (self.cheats)[[cheatView selectedRow]]; + if (![tmpCheat.cheatValues isEqualToArray:self.tempCheatCodes]) { + tmpCheat.cheatValues = self.tempCheatCodes; + [self setDocumentEdited:YES]; + } + } + + [editCheatWindow orderOut:nil]; + }]; } - (IBAction)addCheat:(id)sender diff --git a/macosx/Pcsxr.xcodeproj/project.pbxproj b/macosx/Pcsxr.xcodeproj/project.pbxproj index 2477fe68..28d1cde0 100644 --- a/macosx/Pcsxr.xcodeproj/project.pbxproj +++ b/macosx/Pcsxr.xcodeproj/project.pbxproj @@ -3368,6 +3368,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 55858D2B17864DC90068B8FC /* Pcsxr-Instrument.xcconfig */; buildSettings = { + CLANG_ENABLE_MODULES = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; @@ -3395,6 +3396,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = PCSXR; + CLANG_ENABLE_MODULES = NO; GCC_ENABLE_ASM_KEYWORD = YES; GCC_ENABLE_CPP_EXCEPTIONS = NO; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -3590,6 +3592,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = PCSXR; + CLANG_ENABLE_MODULES = NO; DEBUG_INFORMATION_FORMAT = dwarf; DEBUG_PREPROCESSOR_DEFINITIONS = "$(inherited) EMU_LOG=__Log"; GCC_ENABLE_ASM_KEYWORD = YES; @@ -3616,6 +3619,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = PCSXR; + CLANG_ENABLE_MODULES = NO; GCC_ENABLE_ASM_KEYWORD = YES; GCC_ENABLE_CPP_EXCEPTIONS = NO; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -3642,6 +3646,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 55858D2A17864DC80068B8FC /* Pcsxr-Debug.xcconfig */; buildSettings = { + CLANG_ENABLE_MODULES = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; @@ -3670,6 +3675,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 55858D2C17864DC90068B8FC /* Pcsxr-Release.xcconfig */; buildSettings = { + CLANG_ENABLE_MODULES = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; diff --git a/macosx/PcsxrHexadecimalFormatter.h b/macosx/PcsxrHexadecimalFormatter.h index ef9c1601..63a3da44 100644 --- a/macosx/PcsxrHexadecimalFormatter.h +++ b/macosx/PcsxrHexadecimalFormatter.h @@ -9,10 +9,6 @@ #import @interface PcsxrHexadecimalFormatter : NSFormatter -{ - char hexPadding; - NSString *hexFormatString; -} @property (nonatomic) char hexPadding; @end diff --git a/macosx/PcsxrHexadecimalFormatter.m b/macosx/PcsxrHexadecimalFormatter.m index c6b5f849..550a7cb1 100644 --- a/macosx/PcsxrHexadecimalFormatter.m +++ b/macosx/PcsxrHexadecimalFormatter.m @@ -9,20 +9,19 @@ #import "PcsxrHexadecimalFormatter.h" @interface PcsxrHexadecimalFormatter () -@property (readwrite, retain) NSString *hexFormatString; - +@property (strong) NSString *hexFormatString; @end @implementation PcsxrHexadecimalFormatter @synthesize hexPadding; +@synthesize hexFormatString; + - (void)setHexPadding:(char)_hexPadding { hexPadding = _hexPadding; self.hexFormatString = [NSString stringWithFormat:@"0x%%0%ilx", hexPadding]; } -@synthesize hexFormatString; - - (id)init { if (self = [super init]) { @@ -64,18 +63,25 @@ - (BOOL)getObjectValue:(out id *)obj forString:(NSString *)string errorDescription:(out NSString **)error { NSString *tmpstr = nil; - if ([string hasPrefix:@"0x"]) { - NSRange zeroXRange = [string rangeOfString:@"0x"]; - tmpstr = [string stringByReplacingCharactersInRange:zeroXRange withString:@""]; - }else { - tmpstr = string; - } - long tmpNum = 0; - if (sscanf([tmpstr UTF8String], "%lx", &tmpNum) == 1) { + unsigned int tmpNum; + NSScanner *theScan = [[NSScanner alloc] initWithString:string]; + if ([theScan scanHexInt:&tmpNum]) { *obj = @(tmpNum); return YES; } else { - return NO; + if ([string hasPrefix:@"0x"]) { + NSRange zeroXRange = [string rangeOfString:@"0x"]; + tmpstr = [string stringByReplacingCharactersInRange:zeroXRange withString:@""]; + }else { + tmpstr = string; + } + long tmpNum = 0; + if (sscanf([tmpstr UTF8String], "%lx", &tmpNum) == 1) { + *obj = @(tmpNum); + return YES; + } else { + return NO; + } } } diff --git a/macosx/Resources/Base.lproj/CheatWindow.xib b/macosx/Resources/Base.lproj/CheatWindow.xib index a45561fb..2fbd6c0d 100644 --- a/macosx/Resources/Base.lproj/CheatWindow.xib +++ b/macosx/Resources/Base.lproj/CheatWindow.xib @@ -1,8 +1,8 @@ - + - - + + @@ -17,7 +17,7 @@ - + @@ -128,8 +128,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -247,7 +258,7 @@ - + @@ -264,7 +275,7 @@ - + @@ -321,7 +332,7 @@ Gw - + @@ -335,7 +346,7 @@ Gw - + @@ -359,9 +370,7 @@ Gw - - @@ -377,7 +386,8 @@ Gw + - \ No newline at end of file + -- cgit v1.2.3