From 983f4fd7f703bbd0a87a605dd9c22184a054124a Mon Sep 17 00:00:00 2001 From: omigamedev Date: Sat, 16 Nov 2019 23:26:40 +0100 Subject: [PATCH] fix iOS pencil force clamp --- PanoPainter/GameViewController.m | 12 +++++++++--- src/app.cpp | 12 +----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/PanoPainter/GameViewController.m b/PanoPainter/GameViewController.m index 8231d21..a8fdd35 100644 --- a/PanoPainter/GameViewController.m +++ b/PanoPainter/GameViewController.m @@ -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 ignored_touch; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { @@ -349,7 +355,7 @@ std::set 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 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 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]; diff --git a/src/app.cpp b/src/app.cpp index 4b71b0d..979360f 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -473,7 +473,7 @@ void App::init() uirtt.create(width, height, -1, GL_RGBA8, true); - if (Settings::value_or("auto-timelapse", false)) + if (Settings::value_or("auto-timelapse", true)) rec_start(); if (!check_license()) @@ -756,18 +756,8 @@ void App::rec_start() { if (!rec_running) { -#if defined(__IOS__) || defined(__OSX__) - NSString* path = [NSString stringWithUTF8String:rec_path.c_str()]; - NSArray *dirFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil]; - NSArray *jpgFiles = [dirFiles filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.jpg'"]]; - rec_count = (int)[jpgFiles count]; update_rec_frames(); rec_thread = std::thread(&App::rec_loop, this); -#else - rec_count = Asset::list_files(rec_path, ".*\\.jpg").size(); - update_rec_frames(); - rec_thread = std::thread(&App::rec_loop, this); -#endif } }