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];

View File

@@ -473,7 +473,7 @@ void App::init()
uirtt.create(width, height, -1, GL_RGBA8, true);
if (Settings::value_or<Serializer::Boolean>("auto-timelapse", false))
if (Settings::value_or<Serializer::Boolean>("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
}
}