Fix mouse events for entity scripts
Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all
Unified · Split
| @@ -1825,17 +1825,16 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { · 1824 unmodified lines | ||
| 1825 | 1825 | } |
| 1826 | 1826 | #endif |
| 1827 | 1827 | |
| 1828 | + auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 1829 | + QPointF transformedPos = offscreenUi->mapToVirtualScreen(event->localPos(), _glWidget); | |
| 1830 | + QMouseEvent mappedEvent(event->type(), | |
| 1831 | + transformedPos, | |
| 1832 | + event->screenPos(), event->button(), | |
| 1833 | + event->buttons(), event->modifiers()); | |
| 1828 | 1834 | |
| 1829 | − _entities.mouseMoveEvent(event, deviceID); | |
| 1830 | − { | |
| 1831 | − auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 1832 | − QPointF transformedPos = offscreenUi->mapToVirtualScreen(event->localPos(), _glWidget); | |
| 1833 | − QMouseEvent mappedEvent(event->type(), | |
| 1834 | − transformedPos, | |
| 1835 | − event->screenPos(), event->button(), | |
| 1836 | − event->buttons(), event->modifiers()); | |
| 1837 | − _controllerScriptingInterface.emitMouseMoveEvent(&mappedEvent, deviceID); // send events to any registered scripts | |
| 1838 | − } | |
| 1835 | + | |
| 1836 | + _entities.mouseMoveEvent(&mappedEvent, deviceID); | |
| 1837 | + _controllerScriptingInterface.emitMouseMoveEvent(&mappedEvent, deviceID); // send events to any registered scripts | |
| 1839 | 1838 | |
| 1840 | 1839 | // if one of our scripts have asked to capture this event, then stop processing it |
| 1841 | 1840 | if (_controllerScriptingInterface.isMouseCaptured()) { |
| @@ -1851,19 +1850,19 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { · 9 unmodified lines | ||
| 1851 | 1850 | void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { |
| 1852 | 1851 | // Inhibit the menu if the user is using alt-mouse dragging |
| 1853 | 1852 | _altPressed = false; |
| 1853 | + | |
| 1854 | + auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 1855 | + QPointF transformedPos = offscreenUi->mapToVirtualScreen(event->localPos(), _glWidget); | |
| 1856 | + QMouseEvent mappedEvent(event->type(), | |
| 1857 | + transformedPos, | |
| 1858 | + event->screenPos(), event->button(), | |
| 1859 | + event->buttons(), event->modifiers()); | |
| 1860 | + | |
| 1854 | 1861 | if (!_aboutToQuit) { |
| 1855 | − _entities.mousePressEvent(event, deviceID); | |
| 1862 | + _entities.mousePressEvent(&mappedEvent, deviceID); | |
| 1856 | 1863 | } |
| 1857 | 1864 | |
| 1858 | − { | |
| 1859 | − auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 1860 | − QPointF transformedPos = offscreenUi->mapToVirtualScreen(event->localPos(), _glWidget); | |
| 1861 | − QMouseEvent mappedEvent(event->type(), | |
| 1862 | − transformedPos, | |
| 1863 | − event->screenPos(), event->button(), | |
| 1864 | − event->buttons(), event->modifiers()); | |
| 1865 | − _controllerScriptingInterface.emitMousePressEvent(&mappedEvent); // send events to any registered scripts | |
| 1866 | − } | |
| 1865 | + _controllerScriptingInterface.emitMousePressEvent(&mappedEvent); // send events to any registered scripts | |
| 1867 | 1866 | |
| 1868 | 1867 | // if one of our scripts have asked to capture this event, then stop processing it |
| 1869 | 1868 | if (_controllerScriptingInterface.isMouseCaptured()) { |
| @@ -1879,7 +1878,7 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { · 9 unmodified lines | ||
| 1879 | 1878 | if (event->button() == Qt::LeftButton) { |
| 1880 | 1879 | // nobody handled this - make it an action event on the _window object |
| 1881 | 1880 | HFActionEvent actionEvent(HFActionEvent::startType(), |
| 1882 | − computePickRay(event->x(), event->y())); | |
| 1881 | + computePickRay(mappedEvent.x(), mappedEvent.y())); | |
| 1883 | 1882 | sendEvent(this, &actionEvent); |
| 1884 | 1883 | |
| 1885 | 1884 | } else if (event->button() == Qt::RightButton) { |
| @@ -1907,19 +1906,18 @@ void Application::mouseDoublePressEvent(QMouseEvent* event, unsigned int deviceI · 21 unmodified lines | ||
| 1907 | 1906 | |
| 1908 | 1907 | void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { |
| 1909 | 1908 | |
| 1909 | + auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 1910 | + QPointF transformedPos = offscreenUi->mapToVirtualScreen(event->localPos(), _glWidget); | |
| 1911 | + QMouseEvent mappedEvent(event->type(), | |
| 1912 | + transformedPos, | |
| 1913 | + event->screenPos(), event->button(), | |
| 1914 | + event->buttons(), event->modifiers()); | |
| 1915 | + | |
| 1910 | 1916 | if (!_aboutToQuit) { |
| 1911 | − _entities.mouseReleaseEvent(event, deviceID); | |
| 1917 | + _entities.mouseReleaseEvent(&mappedEvent, deviceID); | |
| 1912 | 1918 | } |
| 1913 | 1919 | |
| 1914 | − { | |
| 1915 | − auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 1916 | − QPointF transformedPos = offscreenUi->mapToVirtualScreen(event->localPos(), _glWidget); | |
| 1917 | − QMouseEvent mappedEvent(event->type(), | |
| 1918 | − transformedPos, | |
| 1919 | − event->screenPos(), event->button(), | |
| 1920 | − event->buttons(), event->modifiers()); | |
| 1921 | − _controllerScriptingInterface.emitMouseReleaseEvent(&mappedEvent); // send events to any registered scripts | |
| 1922 | − } | |
| 1920 | + _controllerScriptingInterface.emitMouseReleaseEvent(&mappedEvent); // send events to any registered scripts | |
| 1923 | 1921 | |
| 1924 | 1922 | // if one of our scripts have asked to capture this event, then stop processing it |
| 1925 | 1923 | if (_controllerScriptingInterface.isMouseCaptured()) { |
| @@ -1934,7 +1932,7 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { · 8 unmodified lines | ||
| 1934 | 1932 | if (event->button() == Qt::LeftButton) { |
| 1935 | 1933 | // fire an action end event |
| 1936 | 1934 | HFActionEvent actionEvent(HFActionEvent::endType(), |
| 1937 | − computePickRay(event->x(), event->y())); | |
| 1935 | + computePickRay(mappedEvent.x(), mappedEvent.y())); | |
| 1938 | 1936 | sendEvent(this, &actionEvent); |
| 1939 | 1937 | } |
| 1940 | 1938 | } |