add trackpad style input

This commit is contained in:
Jesús A. Álvarez 2016-05-14 13:12:21 +02:00
parent 33cdba3b13
commit c6f4b9e0f6
4 changed files with 116 additions and 1 deletions

View File

@ -13,6 +13,7 @@
28BA897F1CE7315400A98104 /* KBKeyboardLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 28BA89771CE7315400A98104 /* KBKeyboardLayout.m */; };
28BA89801CE7315400A98104 /* KBKeyboardView.m in Sources */ = {isa = PBXBuildFile; fileRef = 28BA89791CE7315400A98104 /* KBKeyboardView.m */; };
28BA89821CE7336500A98104 /* Keyboard Layouts in Resources */ = {isa = PBXBuildFile; fileRef = 28BA89811CE7336500A98104 /* Keyboard Layouts */; };
28BA89851CE73E7200A98104 /* TrackPad.m in Sources */ = {isa = PBXBuildFile; fileRef = 28BA89841CE73E7200A98104 /* TrackPad.m */; };
28CE8EB51CD4C3B200FE25A8 /* GLOBGLUE.c in Sources */ = {isa = PBXBuildFile; fileRef = 28CE8E931CD4C3B200FE25A8 /* GLOBGLUE.c */; };
28CE8EB61CD4C3B200FE25A8 /* IWMEMDEV.c in Sources */ = {isa = PBXBuildFile; fileRef = 28CE8E961CD4C3B200FE25A8 /* IWMEMDEV.c */; };
28CE8EB71CD4C3B200FE25A8 /* KBRDEMDV.c in Sources */ = {isa = PBXBuildFile; fileRef = 28CE8E981CD4C3B200FE25A8 /* KBRDEMDV.c */; };
@ -51,6 +52,8 @@
28BA89781CE7315400A98104 /* KBKeyboardView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KBKeyboardView.h; sourceTree = "<group>"; };
28BA89791CE7315400A98104 /* KBKeyboardView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KBKeyboardView.m; sourceTree = "<group>"; };
28BA89811CE7336500A98104 /* Keyboard Layouts */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "Keyboard Layouts"; sourceTree = "<group>"; };
28BA89831CE73E7200A98104 /* TrackPad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TrackPad.h; sourceTree = "<group>"; };
28BA89841CE73E7200A98104 /* TrackPad.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TrackPad.m; sourceTree = "<group>"; };
28CE8E881CD4C33E00FE25A8 /* CNFGGLOB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CNFGGLOB.h; sourceTree = "<group>"; };
28CE8E891CD4C33E00FE25A8 /* CNFGRAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CNFGRAPI.h; sourceTree = "<group>"; };
28CE8E8A1CD4C33E00FE25A8 /* EMCONFIG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EMCONFIG.h; sourceTree = "<group>"; };
@ -215,6 +218,8 @@
28CE8ED51CD4F56C00FE25A8 /* ScreenView.m */,
28D5A3FB1CD6868E001A33F6 /* TouchScreen.h */,
28D5A3FC1CD6868E001A33F6 /* TouchScreen.m */,
28BA89831CE73E7200A98104 /* TrackPad.h */,
28BA89841CE73E7200A98104 /* TrackPad.m */,
28F676C61CD15E0B00FC6FA6 /* ViewController.h */,
28F676C71CD15E0B00FC6FA6 /* ViewController.m */,
28848B601CDE97D600B86C45 /* InsertDiskViewController.h */,
@ -317,6 +322,7 @@
28CE8EC11CD4C3B200FE25A8 /* SNDEMDEV.c in Sources */,
28CE8EB51CD4C3B200FE25A8 /* GLOBGLUE.c in Sources */,
28CE8EBF1CD4C3B200FE25A8 /* SCRNEMDV.c in Sources */,
28BA89851CE73E7200A98104 /* TrackPad.m in Sources */,
28CE8EBD1CD4C3B200FE25A8 /* RTCEMDEV.c in Sources */,
28CE8EB61CD4C3B200FE25A8 /* IWMEMDEV.c in Sources */,
28CE8ED61CD4F56C00FE25A8 /* ScreenView.m in Sources */,

13
Mini vMac/TrackPad.h Normal file
View File

@ -0,0 +1,13 @@
//
// TrackPad.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 TrackPad : UIControl
@end

93
Mini vMac/TrackPad.m Normal file
View File

@ -0,0 +1,93 @@
//
// TrackPad.m
// Mini vMac for iOS
//
// Created by Jesús A. Álvarez on 18/04/2016.
// Copyright © 2016 namedfork. All rights reserved.
//
#import "TrackPad.h"
#import "AppDelegate.h"
#define TRACKPAD_ACCEL_N 1
#define TRACKPAD_ACCEL_T 0.2
#define TRACKPAD_ACCEL_D 20
@implementation TrackPad
{
NSTimeInterval touchTimeThreshold;
NSTimeInterval previousClickTime, previousTouchTime;
CGFloat touchDistanceThreshold;
CGPoint previousTouchLoc;
BOOL click, drag;
NSMutableSet *currentTouches;
}
- (instancetype)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
touchTimeThreshold = 0.25;
touchDistanceThreshold = 16;
currentTouches = [NSMutableSet setWithCapacity:4];
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
click = YES;
CGPoint touchLoc = [touches.anyObject locationInView:self];
if ((event.timestamp - previousTouchTime < touchTimeThreshold) &&
fabs(previousTouchLoc.x - touchLoc.x) < touchDistanceThreshold &&
fabs(previousTouchLoc.y - touchLoc.y) < touchDistanceThreshold) {
drag = YES;
[[AppDelegate sharedInstance] setMouseButton:YES];
}
previousTouchTime = event.timestamp;
previousTouchLoc = touchLoc;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint touchLoc = [touches.anyObject locationInView:self];
CGPoint locDiff = touchLoc;
locDiff.x -= previousTouchLoc.x;
locDiff.y -= previousTouchLoc.y;
// acceleration
NSTimeInterval timeDiff = 100 * (event.timestamp - previousTouchTime);
NSTimeInterval accel = TRACKPAD_ACCEL_N / (TRACKPAD_ACCEL_T + ((timeDiff * timeDiff)/TRACKPAD_ACCEL_D));
locDiff.x *= accel;
locDiff.y *= accel;
click = NO;
[[AppDelegate sharedInstance] moveMouseX:locDiff.x Y:locDiff.y];
previousTouchTime = event.timestamp;
previousTouchLoc = touchLoc;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint touchLoc = [touches.anyObject locationInView:self];
if (click && (event.timestamp - previousTouchTime < touchTimeThreshold)) {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(mouseClick) object:nil];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(mouseUp) object:nil];
[self performSelector:@selector(mouseClick) withObject:nil afterDelay:touchTimeThreshold];
}
click = NO;
if (drag) {
[[AppDelegate sharedInstance] setMouseButton:NO];
drag = NO;
}
previousTouchLoc = touchLoc;
previousTouchTime = event.timestamp;
}
- (void)mouseClick {
if (drag) {
return;
}
[[AppDelegate sharedInstance] setMouseButton:YES];
[self performSelector:@selector(mouseUp) withObject:nil afterDelay:2.0/60.0];
}
- (void)mouseUp {
[[AppDelegate sharedInstance] setMouseButton:NO];
}
@end

View File

@ -8,6 +8,7 @@
#import "ViewController.h"
#import "TouchScreen.h"
#import "TrackPad.h"
#import "AppDelegate.h"
#import "KBKeyboardView.h"
#import "KBKeyboardLayout.h"
@ -47,7 +48,9 @@
[pointingDeviceView removeFromSuperview];
pointingDeviceView = nil;
}
pointingDeviceView = [[TouchScreen alloc] initWithFrame:self.view.bounds];
BOOL useTrackPad = [[NSUserDefaults standardUserDefaults] boolForKey:@"trackpad"];
Class pointingDeviceClass = useTrackPad ? [TrackPad class] : [TouchScreen class];
pointingDeviceView = [[pointingDeviceClass alloc] initWithFrame:self.view.bounds];
pointingDeviceView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view insertSubview:pointingDeviceView aboveSubview:self.screenView];
}