RetroArch/apple/common/utility.m

90 lines
3.1 KiB
Mathematica
Raw Normal View History

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>
#include "RetroArch_Apple.h"
void apple_display_alert(const char *message, const char *title)
2013-06-22 13:09:38 -04:00
{
#ifdef IOS
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
NSAlert* alert = [[NSAlert new] autorelease];
[alert setMessageText:(*title) ? BOXSTRING(title) : BOXSTRING("RetroArch")];
[alert setInformativeText:BOXSTRING(message)];
[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];
[[NSApplication sharedApplication] runModalForWindow:[alert window]];
#endif
}
2013-06-22 13:09:38 -04:00
// Number formatter class for setting strings
@implementation RANumberFormatter
- (id)initWithSetting:(const rarch_setting_t*)setting
2013-06-14 00:45:35 -04:00
{
if ((self = [super init]))
{
[self setAllowsFloats:(setting->type == ST_FLOAT)];
2013-12-29 16:00:21 -05:00
if (setting->flags & SD_FLAG_HAS_RANGE)
{
[self setMinimum:BOXFLOAT(setting->min)];
2013-12-29 16:00:21 -05:00
[self setMaximum:BOXFLOAT(setting->max)];
}
}
return self;
2013-06-14 00:45:35 -04:00
}
- (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error
2013-06-14 00:45:35 -04: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 ++)
{
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 == '-')
continue;
2014-04-26 03:58:07 +02:00
else if (self.allowsFloats && !hasDot && ch == '.')
hasDot = true;
else if (!isdigit(ch))
return NO;
}
2013-06-14 00:45:35 -04:00
return YES;
2013-06-14 00:45:35 -04:00
}
#ifdef IOS
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
2014-04-19 20:16:29 +02:00
NSString* text = (NSString*)[[textField text] stringByReplacingCharactersInRange:range withString:string];
return [self isPartialStringValid:text newEditingString:nil errorDescription:nil];
}
#endif
@end