|
|
@@ -39,7 +39,7 @@
|
|
|
#include "../UI/Text.h"
|
|
|
#include "../UI/UI.h"
|
|
|
|
|
|
-#ifdef EMSCRIPTEN
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
#include <emscripten/html5.h>
|
|
|
#endif
|
|
|
|
|
|
@@ -77,7 +77,7 @@ UIElement* TouchState::GetTouchedElement()
|
|
|
return touchedElement_.Get();
|
|
|
}
|
|
|
|
|
|
-#ifdef EMSCRIPTEN
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
#define EM_TRUE 1
|
|
|
|
|
|
/// Glue between Urho Input and Emscripten HTML5
|
|
|
@@ -212,7 +212,7 @@ Input::Input(Context* context) :
|
|
|
lastMouseVisible_(false),
|
|
|
mouseGrabbed_(false),
|
|
|
mouseMode_(MM_ABSOLUTE),
|
|
|
-#ifdef EMSCRIPTEN
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
emscriptenExitingPointerLock_(false),
|
|
|
emscriptenEnteredPointerLock_(false),
|
|
|
#endif
|
|
|
@@ -230,7 +230,7 @@ Input::Input(Context* context) :
|
|
|
|
|
|
SubscribeToEvent(E_SCREENMODE, HANDLER(Input, HandleScreenMode));
|
|
|
|
|
|
-#ifdef EMSCRIPTEN
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
emscriptenInput_ = new EmscriptenInput(this);
|
|
|
#endif
|
|
|
|
|
|
@@ -240,7 +240,7 @@ Input::Input(Context* context) :
|
|
|
|
|
|
Input::~Input()
|
|
|
{
|
|
|
-#ifdef EMSCRIPTEN
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
delete emscriptenInput_;
|
|
|
emscriptenInput_ = 0;
|
|
|
#endif
|
|
|
@@ -279,7 +279,7 @@ void Input::Update()
|
|
|
// Check for focus change this frame
|
|
|
SDL_Window* window = graphics_->GetImpl()->GetWindow();
|
|
|
unsigned flags = window ? SDL_GetWindowFlags(window) & (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS) : 0;
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
if (window)
|
|
|
{
|
|
|
#ifdef REQUIRE_CLICK_TO_FOCUS
|
|
|
@@ -360,7 +360,7 @@ void Input::Update()
|
|
|
|
|
|
// Check for relative mode mouse move
|
|
|
// Note that Emscripten will use SDL mouse move events for relative mode instead
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
if (!touchEmulation_ && (graphics_->GetExternalWindow() || ((!mouseVisible_ && mouseMode_ != MM_FREE) && inputFocus_ && (flags & SDL_WINDOW_MOUSE_FOCUS))))
|
|
|
#else
|
|
|
if (!touchEmulation_ && mouseMode_ != MM_RELATIVE && (graphics_->GetExternalWindow() || (!mouseVisible_ && inputFocus_ && (flags & SDL_WINDOW_MOUSE_FOCUS))))
|
|
|
@@ -368,7 +368,7 @@ void Input::Update()
|
|
|
{
|
|
|
IntVector2 mousePosition = GetMousePosition();
|
|
|
mouseMove_ = mousePosition - lastMousePosition_;
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
if (graphics_->GetExternalWindow())
|
|
|
lastMousePosition_ = mousePosition;
|
|
|
else
|
|
|
@@ -443,7 +443,7 @@ void Input::SetMouseVisible(bool enable, bool suppressEvent)
|
|
|
if (!mouseVisible_ && inputFocus_)
|
|
|
{
|
|
|
SDL_ShowCursor(SDL_FALSE);
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
if (mouseMode_ != MM_FREE)
|
|
|
{
|
|
|
// Recenter the mouse cursor manually when hiding it to avoid erratic mouse move for one frame
|
|
|
@@ -460,7 +460,7 @@ void Input::SetMouseVisible(bool enable, bool suppressEvent)
|
|
|
else
|
|
|
{
|
|
|
SDL_ShowCursor(SDL_TRUE);
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
if (lastVisibleMousePosition_.x_ != MOUSE_POSITION_OFFSCREEN.x_ &&
|
|
|
lastVisibleMousePosition_.y_ != MOUSE_POSITION_OFFSCREEN.y_)
|
|
|
SetMousePosition(lastVisibleMousePosition_);
|
|
|
@@ -487,14 +487,14 @@ void Input::SetMouseVisible(bool enable, bool suppressEvent)
|
|
|
|
|
|
void Input::ResetMouseVisible()
|
|
|
{
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
SetMouseVisible(lastMouseVisible_, true);
|
|
|
#else
|
|
|
SetMouseVisibleEmscripten(lastMouseVisible_);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-#ifdef EMSCRIPTEN
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
void Input::SetMouseVisibleEmscripten(bool enable)
|
|
|
{
|
|
|
if (enable != mouseVisible_)
|
|
|
@@ -545,7 +545,7 @@ void Input::SetMouseMode(MouseMode mode)
|
|
|
// Handle changing away from previous mode
|
|
|
if (previousMode == MM_RELATIVE)
|
|
|
{
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
/// \todo Use SDL_SetRelativeMouseMode() for MM_RELATIVE mode
|
|
|
ResetMouseVisible();
|
|
|
#else
|
|
|
@@ -554,7 +554,7 @@ void Input::SetMouseMode(MouseMode mode)
|
|
|
|
|
|
SDL_SetWindowGrab(window, SDL_FALSE);
|
|
|
}
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
else if (previousMode == MM_WRAP)
|
|
|
SDL_SetWindowGrab(window, SDL_FALSE);
|
|
|
#endif
|
|
|
@@ -562,7 +562,7 @@ void Input::SetMouseMode(MouseMode mode)
|
|
|
// Handle changing to new mode
|
|
|
if (mode == MM_ABSOLUTE || mode == MM_FREE)
|
|
|
{
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
SetMouseGrabbed(false);
|
|
|
VariantMap& eventData = GetEventDataMap();
|
|
|
eventData[MouseModeChanged::P_MODE] = mode;
|
|
|
@@ -578,7 +578,7 @@ void Input::SetMouseMode(MouseMode mode)
|
|
|
if (mode == MM_RELATIVE)
|
|
|
{
|
|
|
SDL_SetWindowGrab(window, SDL_TRUE);
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
SetMouseVisible(false, true);
|
|
|
|
|
|
VariantMap& eventData = GetEventDataMap();
|
|
|
@@ -591,7 +591,7 @@ void Input::SetMouseMode(MouseMode mode)
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
else if (mode == MM_WRAP)
|
|
|
{
|
|
|
/// \todo When SDL 2.0.4 is integrated, use SDL_CaptureMouse() and global mouse functions for MM_WRAP mode.
|
|
|
@@ -935,7 +935,7 @@ unsigned Input::LoadGestures(Deserializer& source)
|
|
|
|
|
|
bool Input::RemoveGesture(unsigned gestureID)
|
|
|
{
|
|
|
-#ifdef EMSCRIPTEN
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
return false;
|
|
|
#else
|
|
|
return SDL_RemoveDollarTemplate(gestureID) != 0;
|
|
|
@@ -944,7 +944,7 @@ bool Input::RemoveGesture(unsigned gestureID)
|
|
|
|
|
|
void Input::RemoveAllGestures()
|
|
|
{
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
SDL_RemoveAllDollarTemplates();
|
|
|
#endif
|
|
|
}
|
|
|
@@ -1169,7 +1169,7 @@ void Input::Initialize()
|
|
|
|
|
|
// Set the initial activation
|
|
|
initialized_ = true;
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
focusedThisFrame_ = true;
|
|
|
#else
|
|
|
// Note: Page visibility and focus are slightly different, however we can't query last focus with Emscripten (1.29.0)
|
|
|
@@ -1356,7 +1356,7 @@ void Input::SendInputFocusEvent()
|
|
|
|
|
|
void Input::SetMouseButton(int button, bool newState)
|
|
|
{
|
|
|
-#ifdef EMSCRIPTEN
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
if (emscriptenEnteredPointerLock_)
|
|
|
{
|
|
|
// Suppress mouse jump on initial Pointer Lock
|
|
|
@@ -1489,7 +1489,7 @@ void Input::HandleSDLEvent(void* sdlEvent)
|
|
|
{
|
|
|
case SDL_KEYDOWN:
|
|
|
// Convert to uppercase to match Win32 virtual key codes
|
|
|
-#ifdef EMSCRIPTEN
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
SetKey(ConvertSDLKeyCode(evt.key.keysym.sym, evt.key.keysym.scancode), evt.key.keysym.scancode, 0, true);
|
|
|
#else
|
|
|
SetKey(ConvertSDLKeyCode(evt.key.keysym.sym, evt.key.keysym.scancode), evt.key.keysym.scancode, evt.key.keysym.raw, true);
|
|
|
@@ -1497,7 +1497,7 @@ void Input::HandleSDLEvent(void* sdlEvent)
|
|
|
break;
|
|
|
|
|
|
case SDL_KEYUP:
|
|
|
-#ifdef EMSCRIPTEN
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
SetKey(ConvertSDLKeyCode(evt.key.keysym.sym, evt.key.keysym.scancode), evt.key.keysym.scancode, 0, false);
|
|
|
#else
|
|
|
SetKey(ConvertSDLKeyCode(evt.key.keysym.sym, evt.key.keysym.scancode), evt.key.keysym.scancode, evt.key.keysym.raw, false);
|
|
|
@@ -1567,7 +1567,7 @@ void Input::HandleSDLEvent(void* sdlEvent)
|
|
|
case SDL_MOUSEMOTION:
|
|
|
// Emscripten will use SDL mouse move events for relative mode, as repositioning the mouse and
|
|
|
// measuring distance from window center is not supported
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
if ((mouseVisible_ || mouseMode_ == MM_FREE) && !touchEmulation_)
|
|
|
#else
|
|
|
if ((mouseVisible_ || mouseMode_ == MM_RELATIVE || mouseMode_ == MM_FREE) && !touchEmulation_)
|
|
|
@@ -1620,7 +1620,7 @@ void Input::HandleSDLEvent(void* sdlEvent)
|
|
|
int touchID = GetTouchIndexFromID(evt.tfinger.fingerId & 0x7ffffff);
|
|
|
TouchState& state = touches_[touchID];
|
|
|
state.touchID_ = touchID;
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
state.lastPosition_ = state.position_ = IntVector2((int)(evt.tfinger.x * graphics_->GetWidth()),
|
|
|
(int)(evt.tfinger.y * graphics_->GetHeight()));
|
|
|
#else
|
|
|
@@ -1676,7 +1676,7 @@ void Input::HandleSDLEvent(void* sdlEvent)
|
|
|
break;
|
|
|
TouchState& state = touches_[touchID];
|
|
|
state.touchID_ = touchID;
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
state.position_ = IntVector2((int)(evt.tfinger.x * graphics_->GetWidth()),
|
|
|
(int)(evt.tfinger.y * graphics_->GetHeight()));
|
|
|
#else
|
|
|
@@ -1691,7 +1691,7 @@ void Input::HandleSDLEvent(void* sdlEvent)
|
|
|
eventData[P_TOUCHID] = touchID;
|
|
|
eventData[P_X] = state.position_.x_;
|
|
|
eventData[P_Y] = state.position_.y_;
|
|
|
-#ifndef EMSCRIPTEN
|
|
|
+#ifndef __EMSCRIPTEN__
|
|
|
eventData[P_DX] = (int)(evt.tfinger.dx * graphics_->GetWidth());
|
|
|
eventData[P_DY] = (int)(evt.tfinger.dy * graphics_->GetHeight());
|
|
|
#else
|