settings UI to change speed and mouse type

This commit is contained in:
Jesús A. Álvarez 2016-05-13 23:47:59 +02:00
parent c97bcb1b1c
commit 6ad6dc59c9
4 changed files with 185 additions and 91 deletions

View File

@ -11,10 +11,21 @@
extern NSString * const MNVMDidInsertDiskNotification;
extern NSString * const MNVMDidEjectDiskNotification;
typedef enum : NSUInteger {
EmulationSpeedMax = -1,
EmulationSpeed1x = 0,
EmulationSpeed2x,
EmulationSpeed4x,
EmulationSpeed8x,
EmulationSpeed16x,
EmulationSpeed32x
} EmulationSpeed;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (assign, nonatomic, getter=isEmulatorRunning) BOOL emulatorRunning;
@property (nonatomic, assign) EmulationSpeed emulationSpeed;
@property (nonatomic, readonly) NSString *documentsPath;
@property (nonatomic, readonly) NSArray<NSString*> *diskImageExtensions;

View File

@ -21,6 +21,7 @@ IMPORTPROC SetMouseLoc(ui4r h, ui4r v);
IMPORTPROC SetMouseDelta(ui4r dh, ui4r dv);
IMPORTFUNC blnr Sony_Insert1(NSString *filePath, blnr silentfail);
IMPORTFUNC blnr Sony_IsInserted(NSString *filePath);
EXPORTVAR(ui3b,SpeedValue);
static AppDelegate *sharedAppDelegate = nil;
NSString * const MNVMDidInsertDiskNotification = @"MNVMDidInsertDisk";
@ -38,6 +39,14 @@ NSString * const MNVMDidEjectDiskNotification = @"MNVMDidEjectDisk";
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
sharedAppDelegate = self;
// TODO: setup settings
NSDictionary *defaults = @{@"speedValue": @(WantInitSpeedValue),
@"trackpad": @([UIDevice currentDevice].userInterfaceIdiom != UIUserInterfaceIdiomPad),
@"frameskip": @(0)
};
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
[self performSelector:@selector(runEmulator) withObject:nil afterDelay:0.1];
return YES;
}
@ -162,6 +171,7 @@ NSString * const MNVMDidEjectDiskNotification = @"MNVMDidEjectDisk";
#pragma mark - Emulation
- (void)runEmulator {
SpeedValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"speedValue"];
RunEmulator();
}
@ -173,6 +183,15 @@ NSString * const MNVMDidEjectDiskNotification = @"MNVMDidEjectDisk";
SetSpeedStopped(emulatorRunning);
}
- (EmulationSpeed)emulationSpeed {
return SpeedValue;
}
- (void)setEmulationSpeed:(EmulationSpeed)emulationSpeed {
SpeedValue = emulationSpeed;
[[NSUserDefaults standardUserDefaults] setInteger:emulationSpeed forKey:@"speedValue"];
}
#pragma mark - Mouse
- (void)setMouseX:(NSInteger)x Y:(NSInteger)y {

View File

@ -3,6 +3,7 @@
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
<!--View Controller-->
@ -44,40 +45,110 @@
<scene sceneID="Lht-Fe-oRx">
<objects>
<tableViewController id="WUA-f8-k8g" customClass="SettingsViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="9gA-gD-7Wx">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="9gA-gD-7Wx">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<sections>
<tableViewSection id="fj2-dd-gR8">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="Mc2-kK-a9O">
<rect key="frame" x="0.0" y="79" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Mc2-kK-a9O" id="stF-6e-bDy">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="WLf-oW-n9a">
<rect key="frame" x="0.0" y="123" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="WLf-oW-n9a" id="gFz-UO-ARA">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="U80-vD-nDD">
<rect key="frame" x="0.0" y="167" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="U80-vD-nDD" id="6Of-5M-ffg">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="speed" id="v4I-0T-H8m">
<rect key="frame" x="0.0" y="93.5" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="v4I-0T-H8m" id="cO5-De-1JT">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<segmentedControl opaque="NO" tag="128" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="3" translatesAutoresizingMaskIntoConstraints="NO" id="gQ6-2l-dni">
<rect key="frame" x="8" y="8" width="584" height="29"/>
<segments>
<segment title="1x"/>
<segment title="2x"/>
<segment title="4x"/>
<segment title="8x"/>
<segment title="16x"/>
<segment title="Max"/>
</segments>
<connections>
<action selector="changeSpeed:" destination="WUA-f8-k8g" eventType="valueChanged" id="FDr-uw-7bN"/>
</connections>
</segmentedControl>
</subviews>
<constraints>
<constraint firstItem="gQ6-2l-dni" firstAttribute="leading" secondItem="cO5-De-1JT" secondAttribute="leadingMargin" id="bPN-8m-XyG"/>
<constraint firstItem="gQ6-2l-dni" firstAttribute="trailing" secondItem="cO5-De-1JT" secondAttribute="trailingMargin" id="i7k-mb-kpd"/>
<constraint firstItem="gQ6-2l-dni" firstAttribute="top" secondItem="cO5-De-1JT" secondAttribute="topMargin" id="jpw-Ur-qUi"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="mouse" id="JgY-zN-3ID">
<rect key="frame" x="0.0" y="137.5" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="JgY-zN-3ID" id="iUk-se-WGk">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<segmentedControl opaque="NO" tag="128" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="jgK-lW-V9w">
<rect key="frame" x="178" y="7" width="244" height="29"/>
<constraints>
<constraint firstAttribute="width" constant="244" id="5ej-m2-BJ6"/>
</constraints>
<segments>
<segment title="Touchscreen"/>
<segment title="Trackpad"/>
</segments>
<connections>
<action selector="changeMouseType:" destination="WUA-f8-k8g" eventType="valueChanged" id="NDq-Qh-7ry"/>
</connections>
</segmentedControl>
</subviews>
<constraints>
<constraint firstItem="jgK-lW-V9w" firstAttribute="centerY" secondItem="iUk-se-WGk" secondAttribute="centerY" id="h3J-dj-xrn"/>
<constraint firstItem="jgK-lW-V9w" firstAttribute="centerX" secondItem="iUk-se-WGk" secondAttribute="centerX" id="jma-Qa-lXw"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="keyboard" textLabel="6WO-0z-y7c" style="IBUITableViewCellStyleDefault" id="q7C-00-4ss">
<rect key="frame" x="0.0" y="181.5" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="q7C-00-4ss" id="yUn-mI-DwM">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="6WO-0z-y7c">
<rect key="frame" x="15" y="0.0" width="570" height="43.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="about" textLabel="znE-ML-UrQ" detailTextLabel="xcq-HY-ZDe" style="IBUITableViewCellStyleValue1" id="MGj-K1-5lZ">
<rect key="frame" x="0.0" y="225.5" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="MGj-K1-5lZ" id="ueO-zm-JQP">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="znE-ML-UrQ">
<rect key="frame" x="15" y="12" width="31.5" height="19.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="xcq-HY-ZDe">
<rect key="frame" x="543.5" y="12" width="41.5" height="19.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.55686274509803924" green="0.55686274509803924" blue="0.57647058823529407" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<sections/>
<connections>
<outlet property="dataSource" destination="WUA-f8-k8g" id="Cy8-ba-Ynt"/>
<outlet property="delegate" destination="WUA-f8-k8g" id="mWB-FI-bec"/>

View File

@ -17,12 +17,6 @@
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)showInsertDisk:(id)sender {
@ -33,70 +27,69 @@
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)changeSpeed:(UISegmentedControl*)sender {
if ([sender isKindOfClass:[UISegmentedControl class]]) {
EmulationSpeed speedValues[] = {
EmulationSpeed1x,
EmulationSpeed2x,
EmulationSpeed4x,
EmulationSpeed8x,
EmulationSpeed16x,
EmulationSpeedMax};
[AppDelegate sharedInstance].emulationSpeed = speedValues[sender.selectedSegmentIndex];
}
}
- (IBAction)changeMouseType:(UISegmentedControl*)sender {
if ([sender isKindOfClass:[UISegmentedControl class]]) {
[[NSUserDefaults standardUserDefaults] setBool:sender.selectedSegmentIndex == 1 forKey:@"trackpad"];
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
return 0;
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
return 0;
if (section == 2) {
// keyboard layout
return 0;
} else {
return 1;
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case 0: return NSLocalizedString(@"Speed", nil);
case 1: return NSLocalizedString(@"Mouse Type", nil);
case 2: return NSLocalizedString(@"Keyboard Layout", nil);
case 3: return NSLocalizedString(@"About", nil);
default: return nil;
}
}
/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
// Configure the cell...
UITableViewCell *cell = nil;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSInteger section = indexPath.section;
if (section == 0) {
cell = [tableView dequeueReusableCellWithIdentifier:@"speed" forIndexPath:indexPath];
UISegmentedControl *speedControl = (UISegmentedControl*)[cell viewWithTag:128];
EmulationSpeed speed = [AppDelegate sharedInstance].emulationSpeed;
speedControl.selectedSegmentIndex = speed == EmulationSpeedMax ? 5 : speed;
} else if (section == 1) {
cell = [tableView dequeueReusableCellWithIdentifier:@"mouse" forIndexPath:indexPath];
UISegmentedControl *mouseControl = (UISegmentedControl*)[cell viewWithTag:128];
mouseControl.selectedSegmentIndex = [defaults boolForKey:@"trackpad"] ? 1 : 0;
} else if (section == 2) {
cell = [tableView dequeueReusableCellWithIdentifier:@"keyboard" forIndexPath:indexPath];
} else if (section == 3) {
cell = [tableView dequeueReusableCellWithIdentifier:@"about" forIndexPath:indexPath];
}
return cell;
}
*/
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end