mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-22 18:58:21 +00:00
Move RANumberFormatter to cocoatouch_menu.m
This commit is contained in:
parent
f435958371
commit
dcac3bf21f
@ -217,13 +217,7 @@ extern id<RetroArch_Platform> apple_platform;
|
||||
|
||||
extern void apple_display_alert(const char *message, const char *title);
|
||||
|
||||
@interface RANumberFormatter : NSNumberFormatter
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
<UITextFieldDelegate>
|
||||
#endif
|
||||
|
||||
- (id)initWithSetting:(const rarch_setting_t*)setting;
|
||||
@end
|
||||
|
||||
#define BOXSTRING(x) [NSString stringWithUTF8String:x]
|
||||
#define BOXINT(x) [NSNumber numberWithInt:x]
|
||||
|
@ -18,55 +18,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include "cocoa_common.h"
|
||||
|
||||
// Number formatter class for setting strings
|
||||
@implementation RANumberFormatter
|
||||
- (id)initWithSetting:(const rarch_setting_t*)setting
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
[self setAllowsFloats:(setting->type == ST_FLOAT)];
|
||||
|
||||
if (setting->flags & SD_FLAG_HAS_RANGE)
|
||||
{
|
||||
[self setMinimum:BOXFLOAT(setting->min)];
|
||||
[self setMaximum:BOXFLOAT(setting->max)];
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error
|
||||
{
|
||||
unsigned i;
|
||||
bool hasDot = false;
|
||||
|
||||
if (partialString.length)
|
||||
for (i = 0; i < partialString.length; i ++)
|
||||
{
|
||||
unichar ch = [partialString characterAtIndex:i];
|
||||
|
||||
if (i == 0 && (!self.minimum || self.minimum.intValue < 0) && ch == '-')
|
||||
continue;
|
||||
else if (self.allowsFloats && !hasDot && ch == '.')
|
||||
hasDot = true;
|
||||
else if (!isdigit(ch))
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
#if defined(HAVE_COCOATOUCH)
|
||||
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
||||
{
|
||||
NSString* text = (NSString*)[[textField text] stringByReplacingCharactersInRange:range withString:string];
|
||||
return [self isPartialStringValid:text newEditingString:nil errorDescription:nil];
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
/* Define compatibility symbols and categories. */
|
||||
|
||||
#ifdef HAVE_AVFOUNDATION
|
||||
|
@ -27,6 +27,58 @@
|
||||
#include "../../../menu/menu_entries.h"
|
||||
#include "../../../menu/drivers/shared.h"
|
||||
|
||||
@interface RANumberFormatter : NSNumberFormatter<UITextFieldDelegate>
|
||||
|
||||
- (id)initWithSetting:(const rarch_setting_t*)setting;
|
||||
@end
|
||||
|
||||
// Number formatter class for setting strings
|
||||
@implementation RANumberFormatter
|
||||
- (id)initWithSetting:(const rarch_setting_t*)setting
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
[self setAllowsFloats:(setting->type == ST_FLOAT)];
|
||||
|
||||
if (setting->flags & SD_FLAG_HAS_RANGE)
|
||||
{
|
||||
[self setMinimum:BOXFLOAT(setting->min)];
|
||||
[self setMaximum:BOXFLOAT(setting->max)];
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error
|
||||
{
|
||||
unsigned i;
|
||||
bool hasDot = false;
|
||||
|
||||
if (partialString.length)
|
||||
for (i = 0; i < partialString.length; i ++)
|
||||
{
|
||||
unichar ch = [partialString characterAtIndex:i];
|
||||
|
||||
if (i == 0 && (!self.minimum || self.minimum.intValue < 0) && ch == '-')
|
||||
continue;
|
||||
else if (self.allowsFloats && !hasDot && ch == '.')
|
||||
hasDot = true;
|
||||
else if (!isdigit(ch))
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
||||
{
|
||||
NSString* text = (NSString*)[[textField text] stringByReplacingCharactersInRange:range withString:string];
|
||||
return [self isPartialStringValid:text newEditingString:nil errorDescription:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/*********************************************/
|
||||
/* RunActionSheet */
|
||||
/* Creates and displays a UIActionSheet with */
|
||||
|
Loading…
Reference in New Issue
Block a user