History

Merge pull request #6022 from jherico/lisa

Fix mouse events for entity scripts

Brad Hefta-Gaub committed 11 years ago

Commit e1b69a12 parents 7c286a4 50592a81 file · +30 −32Browse files

Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all

Unified · Split

interface/src/Application.cpp+30−32
@@ -1825,17 +1825,16 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { · 1824 unmodified lines
18251825 }
18261826 #endif
18271827
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());
18281834
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
18391838
18401839 // if one of our scripts have asked to capture this event, then stop processing it
18411840 if (_controllerScriptingInterface.isMouseCaptured()) {
@@ -1851,19 +1850,19 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { · 9 unmodified lines
18511850 void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
18521851 // Inhibit the menu if the user is using alt-mouse dragging
18531852 _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+
18541861 if (!_aboutToQuit) {
1855− _entities.mousePressEvent(event, deviceID);
1862+ _entities.mousePressEvent(&mappedEvent, deviceID);
18561863 }
18571864
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
18671866
18681867 // if one of our scripts have asked to capture this event, then stop processing it
18691868 if (_controllerScriptingInterface.isMouseCaptured()) {
@@ -1879,7 +1878,7 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { · 9 unmodified lines
18791878 if (event->button() == Qt::LeftButton) {
18801879 // nobody handled this - make it an action event on the _window object
18811880 HFActionEvent actionEvent(HFActionEvent::startType(),
1882− computePickRay(event->x(), event->y()));
1881+ computePickRay(mappedEvent.x(), mappedEvent.y()));
18831882 sendEvent(this, &actionEvent);
18841883
18851884 } else if (event->button() == Qt::RightButton) {
@@ -1907,19 +1906,18 @@ void Application::mouseDoublePressEvent(QMouseEvent* event, unsigned int deviceI · 21 unmodified lines
19071906
19081907 void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
19091908
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+
19101916 if (!_aboutToQuit) {
1911− _entities.mouseReleaseEvent(event, deviceID);
1917+ _entities.mouseReleaseEvent(&mappedEvent, deviceID);
19121918 }
19131919
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
19231921
19241922 // if one of our scripts have asked to capture this event, then stop processing it
19251923 if (_controllerScriptingInterface.isMouseCaptured()) {
@@ -1934,7 +1932,7 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { · 8 unmodified lines
19341932 if (event->button() == Qt::LeftButton) {
19351933 // fire an action end event
19361934 HFActionEvent actionEvent(HFActionEvent::endType(),
1937− computePickRay(event->x(), event->y()));
1935+ computePickRay(mappedEvent.x(), mappedEvent.y()));
19381936 sendEvent(this, &actionEvent);
19391937 }
19401938 }