add mouse input

This commit is contained in:
Jesús A. Álvarez 2016-05-01 23:44:47 +02:00
parent 7e813065fc
commit 9b4aa7a9e7
11 changed files with 198 additions and 4 deletions

View File

@ -24,6 +24,7 @@
28CE8EC31CD4C3B200FE25A8 /* VIAEMDEV.c in Sources */ = {isa = PBXBuildFile; fileRef = 28CE8EB31CD4C3B200FE25A8 /* VIAEMDEV.c */; };
28CE8ECC1CD4CDC500FE25A8 /* MYOSGLUE.m in Sources */ = {isa = PBXBuildFile; fileRef = 28CE8ECB1CD4CDC500FE25A8 /* MYOSGLUE.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
28CE8ED61CD4F56C00FE25A8 /* ScreenView.m in Sources */ = {isa = PBXBuildFile; fileRef = 28CE8ED51CD4F56C00FE25A8 /* ScreenView.m */; };
28D5A3FD1CD6868F001A33F6 /* TouchScreen.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D5A3FC1CD6868E001A33F6 /* TouchScreen.m */; };
28F676C21CD15E0B00FC6FA6 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 28F676C11CD15E0B00FC6FA6 /* main.m */; };
28F676C51CD15E0B00FC6FA6 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 28F676C41CD15E0B00FC6FA6 /* AppDelegate.m */; };
28F676C81CD15E0B00FC6FA6 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28F676C71CD15E0B00FC6FA6 /* ViewController.m */; };
@ -77,6 +78,8 @@
28CE8ECF1CD4D5B900FE25A8 /* INTLCHAR.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = INTLCHAR.h; sourceTree = "<group>"; };
28CE8ED41CD4F56C00FE25A8 /* ScreenView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScreenView.h; sourceTree = "<group>"; };
28CE8ED51CD4F56C00FE25A8 /* ScreenView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScreenView.m; sourceTree = "<group>"; };
28D5A3FB1CD6868E001A33F6 /* TouchScreen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TouchScreen.h; sourceTree = "<group>"; };
28D5A3FC1CD6868E001A33F6 /* TouchScreen.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TouchScreen.m; sourceTree = "<group>"; };
28F676BD1CD15E0B00FC6FA6 /* Mini vMac.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Mini vMac.app"; sourceTree = BUILT_PRODUCTS_DIR; };
28F676C11CD15E0B00FC6FA6 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
28F676C31CD15E0B00FC6FA6 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
@ -179,6 +182,8 @@
28CE8ECB1CD4CDC500FE25A8 /* MYOSGLUE.m */,
28CE8ED41CD4F56C00FE25A8 /* ScreenView.h */,
28CE8ED51CD4F56C00FE25A8 /* ScreenView.m */,
28D5A3FB1CD6868E001A33F6 /* TouchScreen.h */,
28D5A3FC1CD6868E001A33F6 /* TouchScreen.m */,
28F676C61CD15E0B00FC6FA6 /* ViewController.h */,
28F676C71CD15E0B00FC6FA6 /* ViewController.m */,
28F676C91CD15E0B00FC6FA6 /* Main.storyboard */,
@ -285,6 +290,7 @@
28CE8EBC1CD4C3B200FE25A8 /* ROMEMDEV.c in Sources */,
28CE8EBB1CD4C3B200FE25A8 /* PROGMAIN.c in Sources */,
28F676C81CD15E0B00FC6FA6 /* ViewController.m in Sources */,
28D5A3FD1CD6868F001A33F6 /* TouchScreen.m in Sources */,
28CE8EC21CD4C3B200FE25A8 /* SONYEMDV.c in Sources */,
28F676C51CD15E0B00FC6FA6 /* AppDelegate.m in Sources */,
28CE8EBE1CD4C3B200FE25A8 /* SCCEMDEV.c in Sources */,

View File

@ -11,8 +11,12 @@
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (assign, nonatomic, getter=isEmulatorRunning) BOOL emulatorRunning;
+ (instancetype)sharedInstance;
- (void)setMouseX:(NSInteger)x Y:(NSInteger)y;
- (void)moveMouseX:(NSInteger)x Y:(NSInteger)y;
- (void)setMouseButton:(BOOL)down;
@end

View File

@ -12,7 +12,11 @@
#include "MYOSGLUE.h"
IMPORTPROC RunEmulator(void);
IMPORTFUNC blnr GetSpeedStopped(void);
IMPORTPROC SetSpeedStopped(blnr stopped);
IMPORTPROC SetMouseButton(blnr down);
IMPORTPROC SetMouseLoc(ui4r h, ui4r v);
IMPORTPROC SetMouseDelta(ui4r dh, ui4r dv);
static AppDelegate *sharedAppDelegate = nil;
@ -27,6 +31,7 @@ static AppDelegate *sharedAppDelegate = nil;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
sharedAppDelegate = self;
[self performSelector:@selector(runEmulator) withObject:nil afterDelay:1.0];
return YES;
}
@ -39,8 +44,30 @@ static AppDelegate *sharedAppDelegate = nil;
SetSpeedStopped(falseblnr);
}
#pragma mark - Emulation
- (void)runEmulator {
RunEmulator();
}
- (BOOL)isEmulatorRunning {
return !GetSpeedStopped();
}
- (void)setEmulatorRunning:(BOOL)emulatorRunning {
SetSpeedStopped(emulatorRunning);
}
- (void)setMouseX:(NSInteger)x Y:(NSInteger)y {
SetMouseLoc(x, y);
}
- (void)moveMouseX:(NSInteger)x Y:(NSInteger)y {
SetMouseDelta(x, y);
}
- (void)setMouseButton:(BOOL)down {
SetMouseButton(down);
}
@end

View File

@ -30,6 +30,9 @@
<constraint firstAttribute="trailing" secondItem="70W-4V-tYr" secondAttribute="trailing" id="kDH-sv-91j"/>
</constraints>
</view>
<connections>
<outlet property="screenView" destination="70W-4V-tYr" id="W9r-vA-9kk"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>

View File

@ -853,9 +853,16 @@ LOCALFUNC blnr InitLocationDat(void) {
#pragma mark - Mouse
LOCALFUNC blnr MyMoveMouse(si4b h, si4b v) {
// TODO: move mouse
return trueblnr;
GLOBALPROC SetMouseButton(blnr down) {
MyMouseButtonSet(down);
}
GLOBALPROC SetMouseLoc(ui4r h, ui4r v) {
MyMousePositionSet(h, v);
}
GLOBALPROC SetMouseDelta(ui4r dh, ui4r dv) {
MyMousePositionSetDelta(dh, dv);
}
#pragma mark - video out
@ -1551,6 +1558,10 @@ LOCALPROC EnterSpeedStopped(void) {
#endif
}
GLOBALFUNC blnr GetSpeedStopped(void) {
return CurSpeedStopped;
}
GLOBALPROC SetSpeedStopped(blnr stopped) {
CurSpeedStopped = stopped;
}

View File

@ -10,6 +10,9 @@
@interface ScreenView : UIView
@property (nonatomic, readonly) CGRect screenBounds;
@property (nonatomic, readonly) CGSize screenSize;
+ (instancetype)sharedScreenView;
- (void)updateScreen:(CGImageRef)screenImage;

View File

@ -15,17 +15,27 @@ static ScreenView *sharedScreenView = nil;
{
CGImageRef screenImage;
CGRect screenBounds;
CGSize screenSize;
}
- (void)awakeFromNib {
[super awakeFromNib];
sharedScreenView = self;
}
+ (instancetype)sharedScreenView {
return sharedScreenView;
}
- (CGRect)screenBounds {
return screenBounds;
}
- (CGSize)screenSize {
return screenSize;
}
- (void)updateScreen:(CGImageRef)newScreenImage {
CGImageRelease(screenImage);
screenImage = CGImageRetain(newScreenImage);
@ -33,7 +43,7 @@ static ScreenView *sharedScreenView = nil;
}
- (void)layoutSubviews {
CGSize screenSize = CGSizeMake(vMacScreenWidth, vMacScreenHeight);
screenSize = CGSizeMake(vMacScreenWidth, vMacScreenHeight);
CGRect viewBounds = self.bounds;
CGFloat screenScale = MAX(screenSize.width / viewBounds.size.width, screenSize.height / viewBounds.size.height);
screenBounds = CGRectMake(0, 0, screenSize.width / screenScale, screenSize.height / screenScale);

13
Mini vMac/TouchScreen.h Normal file
View File

@ -0,0 +1,13 @@
//
// TouchScreen.h
// Mini vMac for iOS
//
// Created by Jesús A. Álvarez on 18/04/2016.
// Copyright © 2016 namedfork. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TouchScreen : UIControl
@end

96
Mini vMac/TouchScreen.m Normal file
View File

@ -0,0 +1,96 @@
//
// TouchScreen.m
// Mini vMac for iOS
//
// Created by Jesús A. Álvarez on 18/04/2016.
// Copyright © 2016 namedfork. All rights reserved.
//
#import "TouchScreen.h"
#import "AppDelegate.h"
#import "ScreenView.h"
@implementation TouchScreen
{
// when using absolute mouse mode, button events are processed before the position is updated
NSTimeInterval mouseButtonDelay;
CGPoint previousTouchLoc;
NSTimeInterval previousTouchTime;
NSTimeInterval touchTimeThreshold;
CGFloat touchDistanceThreshold;
NSMutableSet *currentTouches;
}
- (instancetype)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
mouseButtonDelay = 0.05;
touchTimeThreshold = 0.25;
touchDistanceThreshold = 16;
currentTouches = [NSMutableSet setWithCapacity:4];
}
return self;
}
- (Point)mouseLocForCGPoint:(CGPoint)point {
Point mouseLoc;
CGRect screenBounds = [ScreenView sharedScreenView].screenBounds;
CGSize screenSize = [ScreenView sharedScreenView].screenSize;
mouseLoc.h = (point.x - screenBounds.origin.x) * (screenSize.width/screenBounds.size.width);
mouseLoc.v = (point.y - screenBounds.origin.y) * (screenSize.height/screenBounds.size.height);
return mouseLoc;
}
- (void)mouseDown {
[[AppDelegate sharedInstance] setMouseButton:YES];
}
- (void)mouseUp {
[[AppDelegate sharedInstance] setMouseButton:NO];
}
- (CGPoint)effectiveTouchPointForEvent:(UIEvent *)event {
CGPoint touchLoc = [[event touchesForView:self].anyObject locationInView:self];
if (event.timestamp - previousTouchTime < touchTimeThreshold &&
fabs(previousTouchLoc.x - touchLoc.x) < touchDistanceThreshold &&
fabs(previousTouchLoc.y - touchLoc.y) < touchDistanceThreshold)
return previousTouchLoc;
previousTouchLoc = touchLoc;
previousTouchTime = event.timestamp;
return touchLoc;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[currentTouches unionSet:touches];
if (![AppDelegate sharedInstance].emulatorRunning) return;
CGPoint touchLoc = [self effectiveTouchPointForEvent:event];
Point mouseLoc = [self mouseLocForCGPoint:touchLoc];
[[AppDelegate sharedInstance] setMouseX:mouseLoc.h Y:mouseLoc.v];
[self performSelector:@selector(mouseDown) withObject:nil afterDelay:mouseButtonDelay];
previousTouchLoc = touchLoc;
previousTouchTime = event.timestamp;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if (![AppDelegate sharedInstance].emulatorRunning) return;
CGPoint touchLoc = [self effectiveTouchPointForEvent:event];
Point mouseLoc = [self mouseLocForCGPoint:touchLoc];
[[AppDelegate sharedInstance] setMouseX:mouseLoc.h Y:mouseLoc.v];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[currentTouches minusSet:touches];
if (![AppDelegate sharedInstance].emulatorRunning) return;
if (currentTouches.count > 0) return;
CGPoint touchLoc = [self effectiveTouchPointForEvent:event];
Point mouseLoc = [self mouseLocForCGPoint:touchLoc];
[[AppDelegate sharedInstance] setMouseX:mouseLoc.h Y:mouseLoc.v];
[self performSelector:@selector(mouseUp) withObject:nil afterDelay:mouseButtonDelay];
previousTouchLoc = touchLoc;
previousTouchTime = event.timestamp;
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesEnded:touches withEvent:event];
}
@end

View File

@ -7,9 +7,11 @@
//
#import <UIKit/UIKit.h>
#import "ScreenView.h"
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet ScreenView *screenView;
@end

View File

@ -7,15 +7,34 @@
//
#import "ViewController.h"
#import "TouchScreen.h"
@interface ViewController ()
@end
@implementation ViewController
{
UIControl *pointingDeviceView;
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self setUpPointingDevice];
}
- (void)setUpPointingDevice {
if (pointingDeviceView) {
[pointingDeviceView removeFromSuperview];
pointingDeviceView = nil;
}
pointingDeviceView = [[TouchScreen alloc] initWithFrame:self.view.bounds];
pointingDeviceView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view insertSubview:pointingDeviceView aboveSubview:self.screenView];
}
@end