|
@@ -93,8 +93,6 @@ UIElement* TouchState::GetTouchedElement()
|
|
|
* - The user can press 'escape' key and browser will force user out of pointer lock. Urho will send the E_MOUSEMODECHANGED event.
|
|
* - The user can press 'escape' key and browser will force user out of pointer lock. Urho will send the E_MOUSEMODECHANGED event.
|
|
|
* - SetMouseMode(MM_ABSOLUTE) will leave pointer lock.
|
|
* - SetMouseMode(MM_ABSOLUTE) will leave pointer lock.
|
|
|
* - MM_WRAP is unsupported.
|
|
* - MM_WRAP is unsupported.
|
|
|
- *
|
|
|
|
|
- * Touch Input:
|
|
|
|
|
*/
|
|
*/
|
|
|
/// % Emscripten Input glue. Intended to be used by the Input subsystem only.
|
|
/// % Emscripten Input glue. Intended to be used by the Input subsystem only.
|
|
|
class EmscriptenInput
|
|
class EmscriptenInput
|
|
@@ -104,11 +102,9 @@ public:
|
|
|
EmscriptenInput(Input* inputInst);
|
|
EmscriptenInput(Input* inputInst);
|
|
|
|
|
|
|
|
/// Static callback method for Pointer Lock API. Handles change in Pointer Lock state and sends events for mouse mode change.
|
|
/// Static callback method for Pointer Lock API. Handles change in Pointer Lock state and sends events for mouse mode change.
|
|
|
- static EM_BOOL PointerLockCallback(int eventType, const EmscriptenPointerlockChangeEvent* keyEvent, void* userData);
|
|
|
|
|
- /// Static callback method for tracking lose focus event.
|
|
|
|
|
- static EM_BOOL LoseFocus(int eventType, const EmscriptenFocusEvent* keyEvent, void* userData);
|
|
|
|
|
- /// Static callback method for tracking gain focus event.
|
|
|
|
|
- static EM_BOOL GainFocus(int eventType, const EmscriptenFocusEvent* keyEvent, void* userData);
|
|
|
|
|
|
|
+ static EM_BOOL HandlePointerLockChange(int eventType, const EmscriptenPointerlockChangeEvent* keyEvent, void* userData);
|
|
|
|
|
+ /// Static callback method for tracking focus change events.
|
|
|
|
|
+ static EM_BOOL HandleFocusChange(int eventType, const EmscriptenFocusEvent* keyEvent, void* userData);
|
|
|
|
|
|
|
|
/// Send request to user to gain pointer lock. This requires a user-browser interaction on the first call.
|
|
/// Send request to user to gain pointer lock. This requires a user-browser interaction on the first call.
|
|
|
void RequestPointerLock();
|
|
void RequestPointerLock();
|
|
@@ -125,11 +121,12 @@ private:
|
|
|
EmscriptenInput::EmscriptenInput(Input* inputInst)
|
|
EmscriptenInput::EmscriptenInput(Input* inputInst)
|
|
|
{
|
|
{
|
|
|
inputInst_ = inputInst;
|
|
inputInst_ = inputInst;
|
|
|
- emscripten_set_pointerlockchange_callback(NULL, (void*)inputInst, false, EmscriptenInput::PointerLockCallback);
|
|
|
|
|
|
|
+ void* vInputInst = (void*)inputInst;
|
|
|
|
|
+ emscripten_set_pointerlockchange_callback(NULL, vInputInst, false, EmscriptenInput::HandlePointerLockChange);
|
|
|
|
|
|
|
|
// Handle focus changes:
|
|
// Handle focus changes:
|
|
|
- emscripten_set_blur_callback(NULL, (void*)inputInst, false, EmscriptenInput::LoseFocus);
|
|
|
|
|
- emscripten_set_focus_callback(NULL, (void*)inputInst, false, EmscriptenInput::GainFocus);
|
|
|
|
|
|
|
+ emscripten_set_blur_callback(NULL, vInputInst, false, EmscriptenInput::HandleFocusChange);
|
|
|
|
|
+ emscripten_set_focus_callback(NULL, vInputInst, false, EmscriptenInput::HandleFocusChange);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void EmscriptenInput::RequestPointerLock()
|
|
void EmscriptenInput::RequestPointerLock()
|
|
@@ -154,7 +151,7 @@ bool EmscriptenInput::IsVisible()
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-EM_BOOL EmscriptenInput::PointerLockCallback(int eventType, const EmscriptenPointerlockChangeEvent* keyEvent, void* userData)
|
|
|
|
|
|
|
+EM_BOOL EmscriptenInput::HandlePointerLockChange(int eventType, const EmscriptenPointerlockChangeEvent* keyEvent, void* userData)
|
|
|
{
|
|
{
|
|
|
Input* inputInst = (Input*)userData;
|
|
Input* inputInst = (Input*)userData;
|
|
|
if (keyEvent->isActive >= EM_TRUE)
|
|
if (keyEvent->isActive >= EM_TRUE)
|
|
@@ -171,18 +168,12 @@ EM_BOOL EmscriptenInput::PointerLockCallback(int eventType, const EmscriptenPoin
|
|
|
return EM_TRUE;
|
|
return EM_TRUE;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-EM_BOOL EmscriptenInput::LoseFocus(int eventType, const EmscriptenFocusEvent* keyEvent, void* userData)
|
|
|
|
|
|
|
+EM_BOOL EmscriptenInput::HandleFocusChange(int eventType, const EmscriptenFocusEvent* keyEvent, void* userData)
|
|
|
{
|
|
{
|
|
|
Input* inputInst = (Input*)userData;
|
|
Input* inputInst = (Input*)userData;
|
|
|
if (eventType == EMSCRIPTEN_EVENT_BLUR)
|
|
if (eventType == EMSCRIPTEN_EVENT_BLUR)
|
|
|
inputInst->LoseFocus();
|
|
inputInst->LoseFocus();
|
|
|
- return EM_TRUE;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-EM_BOOL EmscriptenInput::GainFocus(int eventType, const EmscriptenFocusEvent* keyEvent, void* userData)
|
|
|
|
|
-{
|
|
|
|
|
- Input* inputInst = (Input*)userData;
|
|
|
|
|
- if (eventType == EMSCRIPTEN_EVENT_FOCUS)
|
|
|
|
|
|
|
+ else if (eventType == EMSCRIPTEN_EVENT_FOCUS)
|
|
|
inputInst->GainFocus();
|
|
inputInst->GainFocus();
|
|
|
return EM_TRUE;
|
|
return EM_TRUE;
|
|
|
}
|
|
}
|
|
@@ -1627,8 +1618,12 @@ void Input::HandleSDLEvent(void* sdlEvent)
|
|
|
int touchID = GetTouchIndexFromID(evt.tfinger.fingerId & 0x7ffffff);
|
|
int touchID = GetTouchIndexFromID(evt.tfinger.fingerId & 0x7ffffff);
|
|
|
TouchState& state = touches_[touchID];
|
|
TouchState& state = touches_[touchID];
|
|
|
state.touchID_ = touchID;
|
|
state.touchID_ = touchID;
|
|
|
|
|
+ #ifndef EMSCRIPTEN
|
|
|
state.lastPosition_ = state.position_ = IntVector2((int)(evt.tfinger.x * graphics_->GetWidth()),
|
|
state.lastPosition_ = state.position_ = IntVector2((int)(evt.tfinger.x * graphics_->GetWidth()),
|
|
|
(int)(evt.tfinger.y * graphics_->GetHeight()));
|
|
(int)(evt.tfinger.y * graphics_->GetHeight()));
|
|
|
|
|
+ #else
|
|
|
|
|
+ state.position_ = IntVector2((int)(evt.tfinger.x), (int)(evt.tfinger.y));
|
|
|
|
|
+ #endif
|
|
|
state.delta_ = IntVector2::ZERO;
|
|
state.delta_ = IntVector2::ZERO;
|
|
|
state.pressure_ = evt.tfinger.pressure;
|
|
state.pressure_ = evt.tfinger.pressure;
|
|
|
|
|
|
|
@@ -1675,8 +1670,12 @@ void Input::HandleSDLEvent(void* sdlEvent)
|
|
|
break;
|
|
break;
|
|
|
TouchState& state = touches_[touchID];
|
|
TouchState& state = touches_[touchID];
|
|
|
state.touchID_ = touchID;
|
|
state.touchID_ = touchID;
|
|
|
|
|
+ #ifndef EMSCRIPTEN
|
|
|
state.position_ = IntVector2((int)(evt.tfinger.x * graphics_->GetWidth()),
|
|
state.position_ = IntVector2((int)(evt.tfinger.x * graphics_->GetWidth()),
|
|
|
(int)(evt.tfinger.y * graphics_->GetHeight()));
|
|
(int)(evt.tfinger.y * graphics_->GetHeight()));
|
|
|
|
|
+ #else
|
|
|
|
|
+ state.position_ = IntVector2((int)(evt.tfinger.x), (int)(evt.tfinger.y));
|
|
|
|
|
+ #endif
|
|
|
state.delta_ = state.position_ - state.lastPosition_;
|
|
state.delta_ = state.position_ - state.lastPosition_;
|
|
|
state.pressure_ = evt.tfinger.pressure;
|
|
state.pressure_ = evt.tfinger.pressure;
|
|
|
|
|
|
|
@@ -1686,8 +1685,13 @@ void Input::HandleSDLEvent(void* sdlEvent)
|
|
|
eventData[P_TOUCHID] = touchID;
|
|
eventData[P_TOUCHID] = touchID;
|
|
|
eventData[P_X] = state.position_.x_;
|
|
eventData[P_X] = state.position_.x_;
|
|
|
eventData[P_Y] = state.position_.y_;
|
|
eventData[P_Y] = state.position_.y_;
|
|
|
|
|
+ #ifndef EMSCRIPTEN
|
|
|
eventData[P_DX] = (int)(evt.tfinger.dx * graphics_->GetWidth());
|
|
eventData[P_DX] = (int)(evt.tfinger.dx * graphics_->GetWidth());
|
|
|
eventData[P_DY] = (int)(evt.tfinger.dy * graphics_->GetHeight());
|
|
eventData[P_DY] = (int)(evt.tfinger.dy * graphics_->GetHeight());
|
|
|
|
|
+ #else
|
|
|
|
|
+ eventData[P_DX] = (int)(evt.tfinger.dx);
|
|
|
|
|
+ eventData[P_DY] = (int)(evt.tfinger.dy);
|
|
|
|
|
+ #endif
|
|
|
eventData[P_PRESSURE] = state.pressure_;
|
|
eventData[P_PRESSURE] = state.pressure_;
|
|
|
SendEvent(E_TOUCHMOVE, eventData);
|
|
SendEvent(E_TOUCHMOVE, eventData);
|
|
|
}
|
|
}
|