diff --git a/modules/touch/include/touchinteraction.h b/modules/touch/include/touchinteraction.h index ff6fd329ad..7e28f4b49a 100644 --- a/modules/touch/include/touchinteraction.h +++ b/modules/touch/include/touchinteraction.h @@ -138,6 +138,11 @@ public: void setCamera(Camera* camera); private: + /* Returns true if the clicked position contains WebGui content and the event will + * be parsed to the webbrowser + */ + bool webContent(const std::vector& list); + /* Returns true if we have the GUI window open. If so, emulates the incoming touch * input to a mouse such that we can interact with the GUI */ diff --git a/modules/touch/src/touchinteraction.cpp b/modules/touch/src/touchinteraction.cpp index cdc5cb728e..53350b4ea1 100644 --- a/modules/touch/src/touchinteraction.cpp +++ b/modules/touch/src/touchinteraction.cpp @@ -22,8 +22,11 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +#include #include #include +#include +#include #include #include @@ -363,6 +366,8 @@ void TouchInteraction::updateStateFromInput(const std::vector& list, _time.initSession(); } + bool hasWebContent = webContent(list); + //Code for lower-right corner double-tap to zoom-out glm::ivec2 res = global::windowDelegate.currentWindowSize(); glm::dvec2 pos = glm::vec2( @@ -377,16 +382,16 @@ void TouchInteraction::updateStateFromInput(const std::vector& list, res.y * (1.0f - bottomCornerSizeForZoomTap_fraction) ); - bool isTapInLowerCorner = std::abs(pos.x) > zoomTapThresholdX && - std::abs(pos.y) > zoomTapThresholdY; + bool isTapInLowerRightCorner = + (std::abs(pos.x) > zoomTapThresholdX && std::abs(pos.y) > zoomTapThresholdY); - if (_doubleTap && isTapInLowerCorner) { + if (_doubleTap && isTapInLowerRightCorner) { _zoomOutTap = true; _tap = false; _doubleTap = false; } - if (!guiMode(list)) { + if (!guiMode(list) && !hasWebContent) { bool isThisFrameTransitionBetweenTouchModes = (_wasPrevModeDirectTouch != _directTouchMode); if (isThisFrameTransitionBetweenTouchModes) { @@ -425,6 +430,17 @@ void TouchInteraction::updateStateFromInput(const std::vector& list, } } +bool TouchInteraction::webContent(const std::vector& list) { + glm::ivec2 res = global::windowDelegate.currentWindowSize(); + glm::dvec2 pos = glm::vec2( + list.at(0).getScreenX(res.x), + list.at(0).getScreenY(res.y) + ); + + WebBrowserModule& module = *(global::moduleEngine.module()); + return module.eventHandler().hasContentCallback(pos.x, pos.y); +} + // Activates/Deactivates gui input mode (if active it voids all other interactions) bool TouchInteraction::guiMode(const std::vector& list) { if (_ignoreGui) { @@ -1305,12 +1321,15 @@ void TouchInteraction::step(double dt) { planetBoundaryRadius *= _zoomBoundarySphereMultiplier; double distToSurface = length(centerToCamera - planetBoundaryRadius); + WebGuiModule& module = *(global::moduleEngine.module()); + //Apply the velocity to update camera position - if (length(_vel.zoom*dt) < distToSurface && - length(centerToCamera + directionToCenter*_vel.zoom*dt) - > planetBoundaryRadius) - { - camPos += directionToCenter * _vel.zoom * dt; + glm::dvec3 velocityIncr = directionToCenter * _vel.zoom * dt; + bool isDeltaLessThanDistToSurface = (length(_vel.zoom * dt) < distToSurface); + bool isNewPosOutsidePlanetRadius = + (length(centerToCamera + velocityIncr) > planetBoundaryRadius); + if (isDeltaLessThanDistToSurface && isNewPosOutsidePlanetRadius) { + camPos += velocityIncr; } else { #ifdef TOUCH_DEBUG_PROPERTIES diff --git a/modules/touch/touchmodule.cpp b/modules/touch/touchmodule.cpp index b4022843ef..9084937aaf 100644 --- a/modules/touch/touchmodule.cpp +++ b/modules/touch/touchmodule.cpp @@ -23,9 +23,12 @@ ****************************************************************************************/ #include +#include +#include #include #include +#include #include #include #include @@ -71,6 +74,9 @@ bool TouchModule::hasNewInput() { return true; } + // Check if we need to parse touchevent to the webgui + hasNewWebInput(listOfContactPoints); + // Return true if we got new input if (listOfContactPoints.size() == lastProcessed.size() && !listOfContactPoints.empty()) @@ -104,7 +110,36 @@ bool TouchModule::hasNewInput() { } } -TouchModule::TouchModule() : OpenSpaceModule("Touch") { +void TouchModule::hasNewWebInput(const std::vector& listOfContactPoints) { + // If one point input and no data in webPosition callback send mouse click to webgui + bool isWebPositionCallbackZero = + (webPositionCallback.x == 0 && webPositionCallback.y == 0); + bool isSingleContactPoint = (listOfContactPoints.size() == 1); + if (isSingleContactPoint && isWebPositionCallbackZero) { + glm::ivec2 res = global::windowDelegate.currentWindowSize(); + glm::dvec2 pos = glm::vec2( + listOfContactPoints.at(0).getScreenX(res.x), + listOfContactPoints.at(0).getScreenY(res.y) + ); + + WebBrowserModule& module = *(global::moduleEngine.module()); + if (module.eventHandler().hasContentCallback(pos.x, pos.y)) { + webPositionCallback = glm::vec2(pos.x, pos.y); + module.eventHandler().touchPressCallback(pos.x, pos.y); + } + } + // Send mouse release if not same point input + else if (!isSingleContactPoint && !isWebPositionCallbackZero) { + WebBrowserModule& module = *(global::moduleEngine.module()); + module.eventHandler().touchReleaseCallback(webPositionCallback.x, + webPositionCallback.y); + webPositionCallback = glm::vec2(0, 0); + } +} + +TouchModule::TouchModule() + : OpenSpaceModule("Touch") +{ addPropertySubOwner(touch); addPropertySubOwner(markers); diff --git a/modules/touch/touchmodule.h b/modules/touch/touchmodule.h index c791f21900..654f1f84e8 100644 --- a/modules/touch/touchmodule.h +++ b/modules/touch/touchmodule.h @@ -42,6 +42,10 @@ namespace openspace { * Returns true if new touch input occured since the last frame */ bool hasNewInput(); + /** + * Checks if touchevent should be parsed to the webgui + */ + void hasNewWebInput(const std::vector& listOfContactPoints); TuioEar ear; TouchInteraction touch; @@ -49,6 +53,7 @@ namespace openspace { std::vector listOfContactPoints; // contains an id and the TuioPoint that was processed last frame std::vector lastProcessed; + glm::ivec2 webPositionCallback = glm::ivec2(0,0); }; } // namespace openspace diff --git a/modules/webbrowser/include/browserinstance.h b/modules/webbrowser/include/browserinstance.h index 99457043e9..a4f4f8d59b 100644 --- a/modules/webbrowser/include/browserinstance.h +++ b/modules/webbrowser/include/browserinstance.h @@ -84,6 +84,12 @@ public: void draw(); void close(bool force = false); + void sendTouchPressEvent(const CefMouseEvent & event, + CefBrowserHost::MouseButtonType button, const int clickCount); + + void sendResleasePressEvent(const CefMouseEvent & event, + CefBrowserHost::MouseButtonType button, const int clickCount); + bool sendKeyEvent(const CefKeyEvent& event); bool sendMouseClickEvent(const CefMouseEvent& event, CefBrowserHost::MouseButtonType button, bool mouseUp, diff --git a/modules/webbrowser/include/eventhandler.h b/modules/webbrowser/include/eventhandler.h index c90cf98ebc..006c13211d 100644 --- a/modules/webbrowser/include/eventhandler.h +++ b/modules/webbrowser/include/eventhandler.h @@ -60,6 +60,9 @@ public: void setBrowser(const CefRefPtr& browser); void setBrowserInstance(BrowserInstance* browserInstance); void detachBrowser(); + void touchPressCallback(const double x, const double y); + void touchReleaseCallback(const double x, const double y); + bool hasContentCallback(const double, const double); private: bool mouseButtonCallback(MouseButton button, MouseAction action, KeyModifier mods); diff --git a/modules/webbrowser/src/browserinstance.cpp b/modules/webbrowser/src/browserinstance.cpp index bc92ce429a..792e2e0321 100644 --- a/modules/webbrowser/src/browserinstance.cpp +++ b/modules/webbrowser/src/browserinstance.cpp @@ -131,6 +131,18 @@ bool BrowserInstance::sendMouseClickEvent(const CefMouseEvent& event, return hasContent(event.x, event.y); } +void BrowserInstance::sendTouchPressEvent(const CefMouseEvent &event, CefBrowserHost::MouseButtonType button, + const int clickCount) +{ + _browser->GetHost()->SendMouseClickEvent(event, button, false, clickCount); +} + +void BrowserInstance::sendResleasePressEvent(const CefMouseEvent &event, CefBrowserHost::MouseButtonType button, + const int clickCount) +{ + _browser->GetHost()->SendMouseClickEvent(event, button, true, clickCount); +} + bool BrowserInstance::sendMouseMoveEvent(const CefMouseEvent& event) { constexpr const bool DidNotLeaveWindow = false; diff --git a/modules/webbrowser/src/eventhandler.cpp b/modules/webbrowser/src/eventhandler.cpp index 1e976d4fb5..a551da8c68 100644 --- a/modules/webbrowser/src/eventhandler.cpp +++ b/modules/webbrowser/src/eventhandler.cpp @@ -143,6 +143,30 @@ void EventHandler::initialize() { ); } +void EventHandler::touchPressCallback(const double x, const double y) { + if (_browserInstance) { + _mousePosition.x = static_cast(x); + _mousePosition.y = static_cast(y); + + int clickCount = BrowserInstance::SingleClick; + _browserInstance->sendMouseClickEvent(mouseEvent(), MBT_LEFT, false, clickCount); + } +} + +void EventHandler::touchReleaseCallback(const double x, const double y) { + if (_browserInstance) { + _mousePosition.x = static_cast(x); + _mousePosition.y = static_cast(y); + + int clickCount = BrowserInstance::SingleClick; + _browserInstance->sendMouseClickEvent(mouseEvent(), MBT_LEFT, true, clickCount); + } +} + +bool EventHandler::hasContentCallback(const double x, const double y) { + return _browserInstance->hasContent(static_cast(x), static_cast(y)); +} + bool EventHandler::mouseButtonCallback(MouseButton button, MouseAction action, KeyModifier mods) diff --git a/modules/webbrowser/webbrowsermodule.cpp b/modules/webbrowser/webbrowsermodule.cpp index e5d1e5f8c0..d85f452c48 100644 --- a/modules/webbrowser/webbrowsermodule.cpp +++ b/modules/webbrowser/webbrowsermodule.cpp @@ -140,6 +140,10 @@ void WebBrowserModule::attachEventHandler(BrowserInstance* browserInstance) { } } +EventHandler WebBrowserModule::eventHandler() { + return _eventHandler; +} + void WebBrowserModule::detachEventHandler() { if (_enabled) { _eventHandler.setBrowserInstance(nullptr); diff --git a/modules/webbrowser/webbrowsermodule.h b/modules/webbrowser/webbrowsermodule.h index 349b6a12f2..0d8274413d 100644 --- a/modules/webbrowser/webbrowsermodule.h +++ b/modules/webbrowser/webbrowsermodule.h @@ -42,6 +42,7 @@ public: void addBrowser(BrowserInstance*); void removeBrowser(BrowserInstance*); + EventHandler eventHandler(); void attachEventHandler(BrowserInstance* browserInstance); void detachEventHandler(); bool isEnabled() const;