fix ios touch
This commit is contained in:
@@ -353,11 +353,9 @@ int max_touch_count = 0;
|
|||||||
bool is_tap = true;
|
bool is_tap = true;
|
||||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
- (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];
|
UITouch *touch = [[event allTouches] anyObject];
|
||||||
|
|
||||||
max_touch_count = n;
|
|
||||||
|
|
||||||
CGPoint touchLocation = [touch locationInView:self.view];
|
CGPoint touchLocation = [touch locationInView:self.view];
|
||||||
float scale = self.view.contentScaleFactor;
|
float scale = self.view.contentScaleFactor;
|
||||||
|
|
||||||
@@ -390,14 +388,17 @@ bool is_tap = true;
|
|||||||
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
||||||
{
|
{
|
||||||
is_tap = false;
|
is_tap = false;
|
||||||
NSUInteger n = [[event allTouches] count];
|
int n = (int)[[event allTouches] count];
|
||||||
float scale = self.view.contentScaleFactor;
|
float scale = self.view.contentScaleFactor;
|
||||||
max_touch_count = std::max<int>(max_touch_count, n);
|
max_touch_count = std::max<int>(max_touch_count, n);
|
||||||
|
UITouch* stylus_touch = nullptr;
|
||||||
|
|
||||||
std::vector<UITouch*> valid_touches;
|
std::vector<UITouch*> valid_touches;
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
auto t = [[[event allTouches] allObjects] objectAtIndex:i];
|
auto t = [[[event allTouches] allObjects] objectAtIndex:i];
|
||||||
|
if (t.type == UITouchType::UITouchTypeStylus)
|
||||||
|
stylus_touch = t;
|
||||||
auto it = ignored_touch.find(t);
|
auto it = ignored_touch.find(t);
|
||||||
if (it == ignored_touch.end())
|
if (it == ignored_touch.end())
|
||||||
{
|
{
|
||||||
@@ -413,7 +414,7 @@ bool is_tap = true;
|
|||||||
NSLog(@"ignored moved");
|
NSLog(@"ignored moved");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n = valid_touches.size();
|
n = (int)valid_touches.size();
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -433,12 +434,30 @@ bool is_tap = true;
|
|||||||
|
|
||||||
if (pen_down)
|
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 (stylus_touch)
|
||||||
if (tt0 == UITouchType::UITouchTypeStylus)
|
{
|
||||||
App::I->mouse_move(p0.x, p0.y, f0, kEventSource::Stylus, 0);
|
auto loc = [stylus_touch locationInView:self.view];
|
||||||
else if (tt1 == UITouchType::UITouchTypeStylus)
|
auto p = glm::vec2(loc.x, loc.y) * scale;
|
||||||
App::I->mouse_move(p1.x, p1.y, f1, kEventSource::Stylus, 0);
|
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)
|
else if (n == 2)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user