add tap event on iOS

This commit is contained in:
2019-11-26 21:44:01 +01:00
parent 9eafcecde9
commit 64f6b90911
5 changed files with 80 additions and 3 deletions

View File

@@ -220,6 +220,7 @@ public:
bool gesture_start(const glm::vec2& p0, const glm::vec2& p1);
bool gesture_move(const glm::vec2& p0, const glm::vec2& p1);
bool gesture_end();
bool touch_tap(const glm::vec2& pos, int fingers, int tap_count);
bool key_down(kKey key);
bool key_up(kKey key);
bool key_char(char key);

View File

@@ -454,6 +454,18 @@ bool App::gesture_end()
ret = main->on_event(&e);
return ret == kEventResult::Consumed;
}
bool App::touch_tap(const glm::vec2& pos, int fingers, int tap_count)
{
redraw = true;
TouchEvent e;
e.m_type = kEventType::TouchTap;
e.m_finger_count = fingers;
e.m_tap_count = tap_count;
kEventResult ret = kEventResult::Available;
if (auto* main = layout[main_id])
ret = main->on_event(&e);
return ret == kEventResult::Consumed;
}
bool App::key_down(kKey key)
{
if (key == kKey::KeySpacebar && vr_active)

View File

@@ -89,6 +89,7 @@ enum class kEventCategory : uint8_t
KeyEvent,
ButtonEvent,
GestureEvent,
TouchEvent,
};
enum class kEventType : uint8_t
@@ -107,6 +108,7 @@ enum class kEventType : uint8_t
GestureStart,
GestureMove,
GestureEnd,
TouchTap,
KeyDown,
KeyUp,
KeyChar,
@@ -158,3 +160,12 @@ public:
glm::vec2 m_pos;
glm::vec2 m_pos_delta;
};
class TouchEvent : public Event
{
public:
TouchEvent() { m_cat = kEventCategory::TouchEvent; }
glm::vec2 m_pos;
int m_finger_count;
int m_tap_count;
};

View File

@@ -543,6 +543,7 @@ kEventResult NodeCanvas::handle_event(Event* e)
MouseEvent* me = static_cast<MouseEvent*>(e);
KeyEvent* ke = static_cast<KeyEvent*>(e);
GestureEvent* ge = static_cast<GestureEvent*>(e);
TouchEvent* te = static_cast<TouchEvent*>(e);
auto loc = (me->m_pos - m_pos) * root()->m_zoom;
switch (e->m_type)
@@ -631,6 +632,10 @@ kEventResult NodeCanvas::handle_event(Event* e)
for (auto& mode : *m_canvas->m_mode)
mode->on_GestureEvent(ge);
break;
case kEventType::TouchTap:
if (te->m_finger_count == 2)
ActionManager::undo();
break;
default:
return kEventResult::Available;
break;