-
-
Notifications
You must be signed in to change notification settings - Fork 979
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description This PR adds stylus support on `iOS`. >[!WARNING] > This PR lacks support for `Hover` since currently we are unable to test that. >[!NOTE] > You can read more about this feature in #3107 ## Test plan Tested on **_StylusData_** example
- Loading branch information
Showing
5 changed files
with
185 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// RNGHStylusData.h | ||
// Pods | ||
// | ||
// Created by Michał Bert on 18/09/2024. | ||
// | ||
|
||
#ifndef RNGHStylusData_h | ||
#define RNGHStylusData_h | ||
|
||
@interface RNGHStylusData : NSObject | ||
|
||
@property (atomic, assign) double tiltX; | ||
@property (atomic, assign) double tiltY; | ||
@property (atomic, assign) double altitudeAngle; | ||
@property (atomic, assign) double azimuthAngle; | ||
@property (atomic, assign) double pressure; | ||
|
||
- (NSDictionary *)toDictionary; | ||
|
||
@end | ||
|
||
static CGPoint ghSpherical2tilt(double altitudeAngle, double azimuthAngle) | ||
{ | ||
CGPoint tilts = {.x = 0.0, .y = 0.0}; | ||
|
||
const double radToDeg = 180 / M_PI; | ||
const double eps = 0.000000001; | ||
|
||
if (altitudeAngle < eps) { | ||
// the pen is in the X-Y plane | ||
if (azimuthAngle < eps || fabs(azimuthAngle - 2 * M_PI) < eps) { | ||
// pen is on positive X axis | ||
tilts.x = M_PI_2; | ||
} | ||
if (fabs(azimuthAngle - M_PI_2) < eps) { | ||
// pen is on positive Y axis | ||
tilts.y = M_PI_2; | ||
} | ||
if (fabs(azimuthAngle - M_PI) < eps) { | ||
// pen is on negative X axis | ||
tilts.x = -M_PI_2; | ||
} | ||
if (fabs(azimuthAngle - 3 * M_PI_2) < eps) { | ||
// pen is on negative Y axis | ||
tilts.y = -M_PI_2; | ||
} | ||
if (azimuthAngle > eps && fabs(azimuthAngle - M_PI_2) < eps) { | ||
tilts.x = M_PI_2; | ||
tilts.y = M_PI_2; | ||
} | ||
if (fabs(azimuthAngle - M_PI_2) > eps && fabs(azimuthAngle - M_PI) < eps) { | ||
tilts.x = -M_PI_2; | ||
tilts.y = M_PI_2; | ||
} | ||
if (azimuthAngle - M_PI > eps && fabs(azimuthAngle - 3 * M_PI_2) < eps) { | ||
tilts.x = -M_PI_2; | ||
tilts.y = -M_PI_2; | ||
} | ||
if (fabs(azimuthAngle - 3 * M_PI_2) > eps && fabs(azimuthAngle - 2 * M_PI) < eps) { | ||
tilts.x = M_PI_2; | ||
tilts.y = -M_PI_2; | ||
} | ||
} else { | ||
const double tanAlt = tan(altitudeAngle); | ||
|
||
tilts.x = atan(cos(azimuthAngle) / tanAlt); | ||
tilts.y = atan(sin(azimuthAngle) / tanAlt); | ||
} | ||
|
||
tilts.x = round(tilts.x * radToDeg); | ||
tilts.y = round(tilts.y * radToDeg); | ||
|
||
return tilts; | ||
} | ||
|
||
#endif /* RNGHStylusData_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// RNGHStylusData.m | ||
// DoubleConversion | ||
// | ||
// Created by Michał Bert on 18/09/2024. | ||
// | ||
|
||
#import "RNGHStylusData.h" | ||
#import <Foundation/Foundation.h> | ||
|
||
@implementation RNGHStylusData | ||
|
||
- (instancetype)init | ||
{ | ||
if (self = [super init]) { | ||
self.tiltX = 0; | ||
self.tiltY = 0; | ||
self.altitudeAngle = M_PI_2; | ||
self.azimuthAngle = 0; | ||
self.pressure = 0; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (NSDictionary *)toDictionary | ||
{ | ||
return @{ | ||
@"tiltX" : @(_tiltX), | ||
@"tiltY" : @(_tiltY), | ||
@"altitudeAngle" : @(_altitudeAngle), | ||
@"azimuthAngle" : @(_azimuthAngle), | ||
@"pressure" : @(_pressure), | ||
}; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters