blob: ca1d064419e415a1b205ddee95eb6335591a417e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
//
// SDLTouch.m
// SmartDeviceLink-iOS
//
// Created by Muller, Alexander (A.) on 6/14/16.
// Copyright © 2016 smartdevicelink. All rights reserved.
//
#import "SDLTouch.h"
#import "SDLTouchCoord.h"
#import "SDLTouchEvent.h"
NS_ASSUME_NONNULL_BEGIN
@implementation SDLTouch
- (instancetype)init {
self = [super init];
if (!self) {
return nil;
}
_identifier = -1;
_location = CGPointZero;
_timeStamp = 0;
return self;
}
- (instancetype)initWithTouchEvent:(SDLTouchEvent *)touchEvent {
self = [self init];
if (self) {
_identifier = touchEvent.touchEventId.unsignedIntegerValue;
id firstTimeStamp = touchEvent.timeStamp.firstObject;
// In the event we receive a null timestamp, we will supply a device timestamp.
if ([firstTimeStamp isKindOfClass:[NSNull class]] && [firstTimeStamp isEqual:[NSNull null]]) {
_timeStamp = [[NSDate date] timeIntervalSince1970] * 1000.0;
} else {
NSNumber *timeStampNumber = (NSNumber *)firstTimeStamp;
_timeStamp = timeStampNumber.unsignedIntegerValue;
}
SDLTouchCoord *coord = touchEvent.coord.firstObject;
_location = CGPointMake(coord.x.floatValue,
coord.y.floatValue);
}
return self;
}
#pragma mark - Getters
- (BOOL)isFirstFinger {
return self.identifier == SDLTouchIdentifierFirstFinger;
}
- (BOOL)isSecondFinger {
return self.identifier == SDLTouchIdentifierSecondFinger;
}
@end
NS_ASSUME_NONNULL_END
|