History

Merge branch 'master' of https://github.com/worklist/hifi into 20216

Thijs Wenker committed 11 years ago

Commit 821e9dd2 parents 3f26e1b 1ea25db71 files · +693 −5289Browse files

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

Unified · Split

interface/src/Application.cpp+68−91
@@ -37,6 +37,7 @@ · 36 unmodified lines
37#include <QOpenGLFramebufferObject>37#include <QOpenGLFramebufferObject>
38#include <QObject>38#include <QObject>
39#include <QWheelEvent>39#include <QWheelEvent>
40#include <QScreen>
40#include <QSettings>41#include <QSettings>
41#include <QShortcut>42#include <QShortcut>
42#include <QTimer>43#include <QTimer>
@@ -142,6 +143,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 99 unmodified lines
142 QApplication(argc, argv),143 QApplication(argc, argv),
143 _window(new MainWindow(desktop())),144 _window(new MainWindow(desktop())),
144 _glWidget(new GLCanvas()),145 _glWidget(new GLCanvas()),
146 _toolWindow(NULL),
145 _nodeThread(new QThread(this)),147 _nodeThread(new QThread(this)),
146 _datagramProcessor(),148 _datagramProcessor(),
147 _undoStack(),149 _undoStack(),
@@ -168,8 +170,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 20 unmodified lines
168 _raiseMirror(0.0f),170 _raiseMirror(0.0f),
169 _lastMouseMove(usecTimestampNow()),171 _lastMouseMove(usecTimestampNow()),
170 _lastMouseMoveWasSimulated(false),172 _lastMouseMoveWasSimulated(false),
171 _mouseHidden(false),
172 _seenMouseMove(false),
173 _touchAvgX(0.0f),173 _touchAvgX(0.0f),
174 _touchAvgY(0.0f),174 _touchAvgY(0.0f),
175 _isTouchPressed(false),175 _isTouchPressed(false),
@@ -418,9 +418,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 242 unmodified lines
418 _previousScriptLocation = _settings->value("LastScriptLocation", QVariant("")).toString();418 _previousScriptLocation = _settings->value("LastScriptLocation", QVariant("")).toString();
419 }419 }
420 420
421 connect(_window, &MainWindow::windowGeometryChanged,
422 _runningScriptsWidget, &RunningScriptsWidget::setBoundary);
423
424 _trayIcon->show();421 _trayIcon->show();
425 422
426 // set the local loopback interface for local sounds from audio scripts423 // set the local loopback interface for local sounds from audio scripts
@@ -1131,7 +1128,8 @@ void Application::keyPressEvent(QKeyEvent* event) { · 704 unmodified lines
1131 if (!event->isAutoRepeat()) {1128 if (!event->isAutoRepeat()) {
1132 // this starts an HFActionEvent1129 // this starts an HFActionEvent
1133 HFActionEvent startActionEvent(HFActionEvent::startType(),1130 HFActionEvent startActionEvent(HFActionEvent::startType(),
1134 _myCamera.computeViewPickRay(0.5f, 0.5f));1131 _myCamera.computePickRay(getTrueMouseX(),
1132 getTrueMouseY()));
1135 sendEvent(this, &startActionEvent);1133 sendEvent(this, &startActionEvent);
1136 }1134 }
1137 1135
@@ -1222,10 +1220,11 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 84 unmodified lines
1222 case Qt::Key_Space: {1220 case Qt::Key_Space: {
1223 if (!event->isAutoRepeat()) {1221 if (!event->isAutoRepeat()) {
1224 // this ends the HFActionEvent1222 // this ends the HFActionEvent
1225 HFActionEvent endActionEvent(HFActionEvent::endType(), _myCamera.computeViewPickRay(0.5f, 0.5f));1223 HFActionEvent endActionEvent(HFActionEvent::endType(),
1224 _myCamera.computePickRay(getTrueMouseX(),
1225 getTrueMouseY()));
1226 sendEvent(this, &endActionEvent);1226 sendEvent(this, &endActionEvent);
1227 }1227 }
1228
1229 break;1228 break;
1230 }1229 }
1231 case Qt::Key_Escape: {1230 case Qt::Key_Escape: {
@@ -1234,7 +1233,6 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 2 unmodified lines
1234 HFBackEvent endBackEvent(HFBackEvent::endType());1233 HFBackEvent endBackEvent(HFBackEvent::endType());
1235 sendEvent(this, &endBackEvent);1234 sendEvent(this, &endBackEvent);
1236 }1235 }
1237
1238 break;1236 break;
1239 }1237 }
1240 default:1238 default:
@@ -1253,34 +1251,24 @@ void Application::focusOutEvent(QFocusEvent* event) { · 12 unmodified lines
1253}1251}
1254 1252
1255void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {1253void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
1256 bool showMouse = true;
1257
1258 // Used by application overlay to determine how to draw cursor(s)1254 // Used by application overlay to determine how to draw cursor(s)
1259 _lastMouseMoveWasSimulated = deviceID > 0;1255 _lastMouseMoveWasSimulated = deviceID > 0;
1260 1256 if (!_lastMouseMoveWasSimulated) {
1261 // If this mouse move event is emitted by a controller, dont show the mouse cursor1257 _lastMouseMove = usecTimestampNow();
1262 if (_lastMouseMoveWasSimulated) {
1263 showMouse = false;
1264 }1258 }
1265 1259
1266 if (!_aboutToQuit) {1260 if (_aboutToQuit) {
1267 _entities.mouseMoveEvent(event, deviceID);1261 return;
1268 }1262 }
1269 1263
1264 _entities.mouseMoveEvent(event, deviceID);
1265
1270 _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts1266 _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts
1271
1272 // if one of our scripts have asked to capture this event, then stop processing it1267 // if one of our scripts have asked to capture this event, then stop processing it
1273 if (_controllerScriptingInterface.isMouseCaptured()) {1268 if (_controllerScriptingInterface.isMouseCaptured()) {
1274 return;1269 return;
1275 }1270 }
1276 1271
1277 _lastMouseMove = usecTimestampNow();
1278
1279 if (_mouseHidden && showMouse && !OculusManager::isConnected() && !TV3DManager::isConnected()) {
1280 getGLWidget()->setCursor(Qt::ArrowCursor);
1281 _mouseHidden = false;
1282 _seenMouseMove = true;
1283 }
1284}1272}
1285 1273
1286void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {1274void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
@@ -1929,8 +1917,6 @@ void Application::init() { · 642 unmodified lines
1929 _deferredLightingEffect.init();1917 _deferredLightingEffect.init();
1930 _glowEffect.init();1918 _glowEffect.init();
1931 _ambientOcclusionEffect.init();1919 _ambientOcclusionEffect.init();
1932 _voxelShader.init();
1933 _pointShader.init();
1934 1920
1935 // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager1921 // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager
1936 _avatarManager.init();1922 _avatarManager.init();
@@ -2002,8 +1988,6 @@ void Application::init() { · 65 unmodified lines
2002 1988
2003 // Set up VoxelSystem after loading preferences so we can get the desired max voxel count1989 // Set up VoxelSystem after loading preferences so we can get the desired max voxel count
2004 _voxels.setMaxVoxels(Menu::getInstance()->getMaxVoxels());1990 _voxels.setMaxVoxels(Menu::getInstance()->getMaxVoxels());
2005 _voxels.setUseVoxelShader(false);
2006 _voxels.setVoxelsAsPoints(false);
2007 _voxels.setDisableFastVoxelPipeline(false);1991 _voxels.setDisableFastVoxelPipeline(false);
2008 _voxels.init();1992 _voxels.init();
2009 1993
@@ -2047,17 +2031,6 @@ void Application::init() { · 37 unmodified lines
2047 connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));2031 connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));
2048 connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors()));2032 connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors()));
2049 2033
2050 // set up our audio reflector
2051 _audioReflector.setMyAvatar(getAvatar());
2052 _audioReflector.setVoxels(_voxels.getTree());
2053 _audioReflector.setAudio(getAudio());
2054 _audioReflector.setAvatarManager(&_avatarManager);
2055
2056 connect(getAudio(), &Audio::processInboundAudio, &_audioReflector, &AudioReflector::processInboundAudio,Qt::DirectConnection);
2057 connect(getAudio(), &Audio::processLocalAudio, &_audioReflector, &AudioReflector::processLocalAudio,Qt::DirectConnection);
2058 connect(getAudio(), &Audio::preProcessOriginalInboundAudio, &_audioReflector,
2059 &AudioReflector::preProcessOriginalInboundAudio,Qt::DirectConnection);
2060
2061 connect(getAudio(), &Audio::muteToggled, AudioDeviceScriptingInterface::getInstance(),2034 connect(getAudio(), &Audio::muteToggled, AudioDeviceScriptingInterface::getInstance(),
2062 &AudioDeviceScriptingInterface::muteToggled, Qt::DirectConnection);2035 &AudioDeviceScriptingInterface::muteToggled, Qt::DirectConnection);
2063 2036
@@ -2113,13 +2086,7 @@ void Application::updateMouseRay() { · 49 unmodified lines
2113 // make sure the frustum is up-to-date2086 // make sure the frustum is up-to-date
2114 loadViewFrustum(_myCamera, _viewFrustum);2087 loadViewFrustum(_myCamera, _viewFrustum);
2115 2088
2116 // if the mouse pointer isn't visible, act like it's at the center of the screen2089 PickRay pickRay = _myCamera.computePickRay(getTrueMouseX(), getTrueMouseY());
2117 float x = 0.5f, y = 0.5f;
2118 if (!_mouseHidden) {
2119 x = getTrueMouseX() / (float)_glWidget->width();
2120 y = getTrueMouseY() / (float)_glWidget->height();
2121 }
2122 PickRay pickRay = _myCamera.computeViewPickRay(x, y);
2123 _mouseRayOrigin = pickRay.origin;2090 _mouseRayOrigin = pickRay.origin;
2124 _mouseRayDirection = pickRay.direction;2091 _mouseRayDirection = pickRay.direction;
2125 2092
@@ -2315,22 +2282,30 @@ void Application::updateCursor(float deltaTime) { · 189 unmodified lines
2315 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);2282 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
2316 PerformanceWarning warn(showWarnings, "Application::updateCursor()");2283 PerformanceWarning warn(showWarnings, "Application::updateCursor()");
2317 2284
2318 // watch mouse position, if it hasn't moved, hide the cursor2285 bool hideMouse = false;
2319 bool underMouse = _glWidget->underMouse();2286 bool underMouse = QGuiApplication::topLevelAt(QCursor::pos()) ==
2320 if (!_mouseHidden) {2287 Application::getInstance()->getWindow()->windowHandle();
2321 quint64 now = usecTimestampNow();2288
2322 int elapsed = now - _lastMouseMove;2289 static const int HIDE_CURSOR_TIMEOUT = 3 * USECS_PER_SECOND; // 3 second
2323 const int HIDE_CURSOR_TIMEOUT = 1 * 1000 * 1000; // 1 second2290 int elapsed = usecTimestampNow() - _lastMouseMove;
2324 if (elapsed > HIDE_CURSOR_TIMEOUT && (underMouse || !_seenMouseMove)) {2291 if ((elapsed > HIDE_CURSOR_TIMEOUT) ||
2325 getGLWidget()->setCursor(Qt::BlankCursor);2292 (OculusManager::isConnected() && Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode))) {
2326 _mouseHidden = true;2293 hideMouse = underMouse;
2294 }
2295
2296 setCursorVisible(!hideMouse);
2297}
2298
2299void Application::setCursorVisible(bool visible) {
2300 if (visible) {
2301 if (overrideCursor() != NULL) {
2302 restoreOverrideCursor();
2327 }2303 }
2328 } else {2304 } else {
2329 // if the mouse is hidden, but we're not inside our window, then consider ourselves to be moving2305 if (overrideCursor() != NULL) {
2330 if (!underMouse && _seenMouseMove) {2306 changeOverrideCursor(Qt::BlankCursor);
2331 _lastMouseMove = usecTimestampNow();2307 } else {
2332 getGLWidget()->setCursor(Qt::ArrowCursor);2308 setOverrideCursor(Qt::BlankCursor);
2333 _mouseHidden = false;
2334 }2309 }
2335 }2310 }
2336}2311}
@@ -2352,17 +2327,6 @@ void Application::update(float deltaTime) { · 15 unmodified lines
2352 2327
2353 }2328 }
2354 2329
2355 static QCursor cursor;
2356 if (OculusManager::isConnected() &&
2357 Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)){
2358 if (_window->cursor().shape() != Qt::BlankCursor) {
2359 cursor = _window->cursor();
2360 _window->setCursor(QCursor(Qt::BlankCursor));
2361 }
2362 } else if(_window->cursor().shape() == Qt::BlankCursor) {
2363 _window->setCursor(cursor);
2364 }
2365
2366 // Dispatch input events2330 // Dispatch input events
2367 _controllerScriptingInterface.updateInputControllers();2331 _controllerScriptingInterface.updateInputControllers();
2368 2332
@@ -2740,6 +2704,29 @@ bool Application::isHMDMode() const { · 371 unmodified lines
2740 }2704 }
2741}2705}
2742 2706
2707QRect Application::getDesirableApplicationGeometry() {
2708 QRect applicationGeometry = getWindow()->geometry();
2709
2710 // If our parent window is on the HMD, then don't use it's geometry, instead use
2711 // the "main screen" geometry.
2712 HMDToolsDialog* hmdTools = Menu::getInstance()->getHMDToolsDialog();
2713 if (hmdTools && hmdTools->hasHMDScreen()) {
2714 QScreen* hmdScreen = hmdTools->getHMDScreen();
2715 QWindow* appWindow = getWindow()->windowHandle();
2716 QScreen* appScreen = appWindow->screen();
2717
2718 // if our app's screen is the hmd screen, we don't want to place the
2719 // running scripts widget on it. So we need to pick a better screen.
2720 // we will use the screen for the HMDTools since it's a guarenteed
2721 // better screen.
2722 if (appScreen == hmdScreen) {
2723 QScreen* betterScreen = hmdTools->windowHandle()->screen();
2724 applicationGeometry = betterScreen->geometry();
2725 }
2726 }
2727 return applicationGeometry;
2728}
2729
2743/////////////////////////////////////////////////////////////////////////////////////2730/////////////////////////////////////////////////////////////////////////////////////
2744// loadViewFrustum()2731// loadViewFrustum()
2745//2732//
@@ -2876,8 +2863,13 @@ void Application::updateShadowMap() { · 130 unmodified lines
2876 2863
2877 // store view matrix without translation, which we'll use for precision-sensitive objects2864 // store view matrix without translation, which we'll use for precision-sensitive objects
2878 updateUntranslatedViewMatrix();2865 updateUntranslatedViewMatrix();
2879 // TODO: assign an equivalent viewTransform object to the application to match the current path which uses glMatrixStack 2866
2880 // setViewTransform(viewTransform);2867 // Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation
2868 // the viewTransofmr object is updatded with the correct values and saved,
2869 // this is what is used for rendering the Entities and avatars
2870 Transform viewTransform;
2871 viewTransform.setRotation(rotation);
2872 setViewTransform(viewTransform);
2881 2873
2882 glEnable(GL_POLYGON_OFFSET_FILL);2874 glEnable(GL_POLYGON_OFFSET_FILL);
2883 glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt2875 glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt
@@ -3082,12 +3074,6 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr · 198 unmodified lines
3082 glColor3f(1,0,0);3074 glColor3f(1,0,0);
3083 _geometryCache.renderSphere(originSphereRadius, 15, 15);3075 _geometryCache.renderSphere(originSphereRadius, 15, 15);
3084 3076
3085 // draw the audio reflector overlay
3086 {
3087 PerformanceTimer perfTimer("audio");
3088 _audioReflector.render();
3089 }
3090
3091 // Draw voxels3077 // Draw voxels
3092 if (Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) {3078 if (Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) {
3093 PerformanceTimer perfTimer("voxels");3079 PerformanceTimer perfTimer("voxels");
@@ -4015,7 +4001,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 921 unmodified lines
4015 scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());4001 scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
4016 scriptEngine->registerGlobalObject("AnimationCache", &_animationCache);4002 scriptEngine->registerGlobalObject("AnimationCache", &_animationCache);
4017 scriptEngine->registerGlobalObject("SoundCache", &SoundCache::getInstance());4003 scriptEngine->registerGlobalObject("SoundCache", &SoundCache::getInstance());
4018 scriptEngine->registerGlobalObject("AudioReflector", &_audioReflector);
4019 scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());4004 scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());
4020 scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels);4005 scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels);
4021 4006
@@ -4374,14 +4359,6 @@ void Application::skipVersion(QString latestVersion) { · 352 unmodified lines
4374 skipFile.write(latestVersion.toStdString().c_str());4359 skipFile.write(latestVersion.toStdString().c_str());
4375}4360}
4376 4361
4377void Application::setCursorVisible(bool visible) {
4378 if (visible) {
4379 restoreOverrideCursor();
4380 } else {
4381 setOverrideCursor(Qt::BlankCursor);
4382 }
4383}
4384
4385void Application::takeSnapshot() {4362void Application::takeSnapshot() {
4386 QMediaPlayer* player = new QMediaPlayer();4363 QMediaPlayer* player = new QMediaPlayer();
4387 QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav");4364 QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t