fix ios touch

This commit is contained in:
2019-11-30 15:54:44 +01:00
parent 2fd2542be7
commit 22de2dedc4

View File

@@ -353,11 +353,9 @@ int max_touch_count = 0;
bool is_tap = true;
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
NSUInteger n = [[event allTouches] count];
max_touch_count = (int)[[event allTouches] count];
UITouch *touch = [[event allTouches] anyObject];
max_touch_count = n;
CGPoint touchLocation = [touch locationInView:self.view];
float scale = self.view.contentScaleFactor;
@@ -390,14 +388,17 @@ bool is_tap = true;
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
is_tap = false;
NSUInteger n = [[event allTouches] count];
int n = (int)[[event allTouches] count];
float scale = self.view.contentScaleFactor;
max_touch_count = std::max<int>(max_touch_count, n);
UITouch* stylus_touch = nullptr;
std::vector<UITouch*> valid_touches;
for (int i = 0; i < n; i++)
{
auto t = [[[event allTouches] allObjects] objectAtIndex:i];
if (t.type == UITouchType::UITouchTypeStylus)
stylus_touch = t;
auto it = ignored_touch.find(t);
if (it == ignored_touch.end())
{
@@ -413,7 +414,7 @@ bool is_tap = true;
NSLog(@"ignored moved");
}
}
n = valid_touches.size();
n = (int)valid_touches.size();
if (n == 0)
return;
@@ -433,13 +434,31 @@ bool is_tap = true;
if (pen_down)
{
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)
App::I->mouse_move(p1.x, p1.y, f1, kEventSource::Stylus, 0);
if (stylus_touch)
{
auto loc = [stylus_touch locationInView:self.view];
auto p = glm::vec2(loc.x, loc.y) * scale;
App::I->ui_task_async([tt=stylus_touch.type,p,f=get_force(stylus_touch)] {
App::I->mouse_move(p.x, p.y, f, kEventSource::Stylus, 0);
});
}
}
else if (stylus_touch)
{
pen_down = true;
auto loc = [stylus_touch locationInView:self.view];
auto p = glm::vec2(loc.x, loc.y) * scale;
float f = get_force(stylus_touch);
App::I->ui_task_async([tc=t_count, p, f] {
if (tc == 2)
App::I->gesture_end();
else if (tc == 1)
App::I->mouse_cancel(0);
App::I->mouse_down(0, p.x, p.y, f, kEventSource::Stylus, 0);
App::I->mouse_move(p.x, p.y, f, kEventSource::Stylus, 0);
});
t_count = 0;
}
else if (n == 2)
{
App::I->ui_task_async([c=t_count, p0, p1] {