2013-06-14 00:45:35 -04:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2013-2014 - Jason Fetters
|
2013-06-14 00:45:35 -04:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-06-21 23:39:01 -04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2013-07-06 18:24:25 -04:00
|
|
|
#include "RetroArch_Apple.h"
|
|
|
|
|
2014-05-03 21:34:13 +02:00
|
|
|
void apple_display_alert(const char *message, const char *title)
|
2013-06-22 13:09:38 -04:00
|
|
|
{
|
2013-07-06 18:24:25 -04:00
|
|
|
#ifdef IOS
|
2014-05-03 21:34:13 +02:00
|
|
|
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:title ? BOXSTRING(title) : BOXSTRING("RetroArch")
|
|
|
|
message:BOXSTRING(message)
|
2013-06-22 13:09:38 -04:00
|
|
|
delegate:nil
|
2014-04-26 03:58:07 +02:00
|
|
|
cancelButtonTitle:BOXSTRING("OK")
|
2013-06-22 13:09:38 -04:00
|
|
|
otherButtonTitles:nil];
|
|
|
|
[alert show];
|
2013-07-07 14:46:16 -04:00
|
|
|
#else
|
2013-12-13 19:23:22 -05:00
|
|
|
NSAlert* alert = [[NSAlert new] autorelease];
|
|
|
|
|
2014-05-03 21:34:13 +02:00
|
|
|
[alert setMessageText:(*title) ? BOXSTRING(title) : BOXSTRING("RetroArch")];
|
|
|
|
[alert setInformativeText:BOXSTRING(message)];
|
2013-12-14 20:35:47 -05:00
|
|
|
[alert setAlertStyle:NSInformationalAlertStyle];
|
|
|
|
[alert beginSheetModalForWindow:[RetroArch_OSX get].window
|
2013-07-09 18:38:49 -04:00
|
|
|
modalDelegate:apple_platform
|
|
|
|
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
|
2013-07-07 14:46:16 -04:00
|
|
|
contextInfo:nil];
|
2013-12-14 20:35:47 -05:00
|
|
|
[[NSApplication sharedApplication] runModalForWindow:[alert window]];
|
2013-07-05 03:46:19 +02:00
|
|
|
#endif
|
2013-07-06 18:24:25 -04:00
|
|
|
}
|
2013-06-22 13:09:38 -04:00
|
|
|
|
2013-11-22 15:30:02 +01:00
|
|
|
// Number formatter class for setting strings
|
|
|
|
@implementation RANumberFormatter
|
|
|
|
- (id)initWithSetting:(const rarch_setting_t*)setting
|
2013-06-14 00:45:35 -04:00
|
|
|
{
|
2013-11-22 15:30:02 +01:00
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2013-12-14 20:35:47 -05:00
|
|
|
[self setAllowsFloats:(setting->type == ST_FLOAT)];
|
2013-11-22 15:30:02 +01:00
|
|
|
|
2013-12-29 16:00:21 -05:00
|
|
|
if (setting->flags & SD_FLAG_HAS_RANGE)
|
2013-11-22 15:30:02 +01:00
|
|
|
{
|
2013-12-14 20:35:47 -05:00
|
|
|
[self setMinimum:BOXFLOAT(setting->min)];
|
2013-12-29 16:00:21 -05:00
|
|
|
[self setMaximum:BOXFLOAT(setting->max)];
|
2013-11-22 15:30:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
2013-06-14 00:45:35 -04:00
|
|
|
}
|
|
|
|
|
2013-11-22 15:30:02 +01:00
|
|
|
- (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error
|
2013-06-14 00:45:35 -04:00
|
|
|
{
|
2013-11-22 15:30:02 +01:00
|
|
|
bool hasDot = false;
|
2013-06-14 00:45:35 -04:00
|
|
|
|
2014-04-26 03:58:07 +02:00
|
|
|
if (partialString.length)
|
2014-10-14 08:42:15 -04:00
|
|
|
for (NSUInteger i = 0; i < partialString.length; i ++)
|
2013-11-22 15:30:02 +01:00
|
|
|
{
|
|
|
|
unichar ch = [partialString characterAtIndex:i];
|
2014-10-14 08:42:15 -04:00
|
|
|
|
2014-05-12 15:17:08 +02:00
|
|
|
if (i == 0 && (!self.minimum || self.minimum.intValue < 0) && ch == '-')
|
2013-11-22 15:30:02 +01:00
|
|
|
continue;
|
2014-04-26 03:58:07 +02:00
|
|
|
else if (self.allowsFloats && !hasDot && ch == '.')
|
2013-11-22 15:30:02 +01:00
|
|
|
hasDot = true;
|
|
|
|
else if (!isdigit(ch))
|
|
|
|
return NO;
|
|
|
|
}
|
2013-06-14 00:45:35 -04:00
|
|
|
|
2013-11-22 15:30:02 +01:00
|
|
|
return YES;
|
2013-06-14 00:45:35 -04:00
|
|
|
}
|
|
|
|
|
2013-11-22 15:30:02 +01:00
|
|
|
#ifdef IOS
|
|
|
|
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
2013-08-24 20:36:03 -04:00
|
|
|
{
|
2014-04-19 20:16:29 +02:00
|
|
|
NSString* text = (NSString*)[[textField text] stringByReplacingCharactersInRange:range withString:string];
|
2013-11-22 15:30:02 +01:00
|
|
|
return [self isPartialStringValid:text newEditingString:nil errorDescription:nil];
|
2013-08-24 20:36:03 -04:00
|
|
|
}
|
2013-07-06 18:24:25 -04:00
|
|
|
#endif
|
2013-11-22 15:30:02 +01:00
|
|
|
|
|
|
|
@end
|