fix iOS pencil force clamp

This commit is contained in:
2019-11-16 23:26:40 +01:00
parent cdd5f1a7ae
commit 983f4fd7f7
2 changed files with 10 additions and 14 deletions

View File

@@ -341,6 +341,12 @@ std::recursive_mutex lock_mutex;
t_count = 0;
}
float get_force(UITouch* t)
{
//glm::pow(t.force / t.maximumPossibleForce, 0.5);
return glm::clamp(t.force / 2.0, 0.0, 1.0);
}
std::set<UITouch*> ignored_touch;
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
@@ -349,7 +355,7 @@ std::set<UITouch*> ignored_touch;
CGPoint touchLocation = [touch locationInView:self.view];
float scale = self.view.contentScaleFactor;
float force = touch.force;
float force = get_force(touch);
AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
if ([app sonarpen_present])
force = [app sonarpen_pressure];
@@ -406,7 +412,7 @@ std::set<UITouch*> ignored_touch;
if (pen_down)
{
App::I->ui_task_async([tt0=t0.type,tt1=t1.type,p0,p1,f0=t0.force,f1=t1.force] {
App::I->ui_task_async([tt0=t0.type,tt1=t1.type,p0,p1,f0=get_force(t0),f1=get_force(t1)] {
if (tt0 == UITouchType::UITouchTypeStylus)
App::I->mouse_move(p0.x, p0.y, f0, kEventSource::Stylus, 0);
else if (tt1 == UITouchType::UITouchTypeStylus)
@@ -430,7 +436,7 @@ std::set<UITouch*> ignored_touch;
{
UITouch *touch = valid_touches[0];
CGPoint touchLocation = [touch locationInView:self.view];
float force = touch.type == UITouchType::UITouchTypeStylus ? touch.force : 1.0f;
float force = touch.type == UITouchType::UITouchTypeStylus ? get_force(touch) : 1.0f;
AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
if ([app sonarpen_present])
force = [app sonarpen_pressure];