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
3737 #include <QOpenGLFramebufferObject>
3838 #include <QObject>
3939 #include <QWheelEvent>
40+#include <QScreen>
4041 #include <QSettings>
4142 #include <QShortcut>
4243 #include <QTimer>
@@ -142,6 +143,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 99 unmodified lines
142143 QApplication(argc, argv),
143144 _window(new MainWindow(desktop())),
144145 _glWidget(new GLCanvas()),
146+ _toolWindow(NULL),
145147 _nodeThread(new QThread(this)),
146148 _datagramProcessor(),
147149 _undoStack(),
@@ -168,8 +170,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 20 unmodified lines
168170 _raiseMirror(0.0f),
169171 _lastMouseMove(usecTimestampNow()),
170172 _lastMouseMoveWasSimulated(false),
171− _mouseHidden(false),
172− _seenMouseMove(false),
173173 _touchAvgX(0.0f),
174174 _touchAvgY(0.0f),
175175 _isTouchPressed(false),
@@ -418,9 +418,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 242 unmodified lines
418418 _previousScriptLocation = _settings->value("LastScriptLocation", QVariant("")).toString();
419419 }
420420
421− connect(_window, &MainWindow::windowGeometryChanged,
422− _runningScriptsWidget, &RunningScriptsWidget::setBoundary);
423−
424421 _trayIcon->show();
425422
426423 // set the local loopback interface for local sounds from audio scripts
@@ -1131,7 +1128,8 @@ void Application::keyPressEvent(QKeyEvent* event) { · 704 unmodified lines
11311128 if (!event->isAutoRepeat()) {
11321129 // this starts an HFActionEvent
11331130 HFActionEvent startActionEvent(HFActionEvent::startType(),
1134− _myCamera.computeViewPickRay(0.5f, 0.5f));
1131+ _myCamera.computePickRay(getTrueMouseX(),
1132+ getTrueMouseY()));
11351133 sendEvent(this, &startActionEvent);
11361134 }
11371135
@@ -1222,10 +1220,11 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 84 unmodified lines
12221220 case Qt::Key_Space: {
12231221 if (!event->isAutoRepeat()) {
12241222 // 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()));
12261226 sendEvent(this, &endActionEvent);
12271227 }
1228−
12291228 break;
12301229 }
12311230 case Qt::Key_Escape: {
@@ -1234,7 +1233,6 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 2 unmodified lines
12341233 HFBackEvent endBackEvent(HFBackEvent::endType());
12351234 sendEvent(this, &endBackEvent);
12361235 }
1237−
12381236 break;
12391237 }
12401238 default:
@@ -1253,34 +1251,24 @@ void Application::focusOutEvent(QFocusEvent* event) { · 12 unmodified lines
12531251 }
12541252
12551253 void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
1256− bool showMouse = true;
1257−
12581254 // Used by application overlay to determine how to draw cursor(s)
12591255 _lastMouseMoveWasSimulated = deviceID > 0;
1260−
1261− // If this mouse move event is emitted by a controller, dont show the mouse cursor
1262− if (_lastMouseMoveWasSimulated) {
1263− showMouse = false;
1256+ if (!_lastMouseMoveWasSimulated) {
1257+ _lastMouseMove = usecTimestampNow();
12641258 }
12651259
1266− if (!_aboutToQuit) {
1267− _entities.mouseMoveEvent(event, deviceID);
1260+ if (_aboutToQuit) {
1261+ return;
12681262 }
1269−
1263+
1264+ _entities.mouseMoveEvent(event, deviceID);
1265+
12701266 _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts
1271−
12721267 // if one of our scripts have asked to capture this event, then stop processing it
12731268 if (_controllerScriptingInterface.isMouseCaptured()) {
12741269 return;
12751270 }
1276−
1277− _lastMouseMove = usecTimestampNow();
1278−
1279− if (_mouseHidden && showMouse && !OculusManager::isConnected() && !TV3DManager::isConnected()) {
1280− getGLWidget()->setCursor(Qt::ArrowCursor);
1281− _mouseHidden = false;
1282− _seenMouseMove = true;
1283− }
1271+
12841272 }
12851273
12861274 void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
@@ -1929,8 +1917,6 @@ void Application::init() { · 642 unmodified lines
19291917 _deferredLightingEffect.init();
19301918 _glowEffect.init();
19311919 _ambientOcclusionEffect.init();
1932− _voxelShader.init();
1933− _pointShader.init();
19341920
19351921 // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager
19361922 _avatarManager.init();
@@ -2002,8 +1988,6 @@ void Application::init() { · 65 unmodified lines
20021988
20031989 // Set up VoxelSystem after loading preferences so we can get the desired max voxel count
20041990 _voxels.setMaxVoxels(Menu::getInstance()->getMaxVoxels());
2005− _voxels.setUseVoxelShader(false);
2006− _voxels.setVoxelsAsPoints(false);
20071991 _voxels.setDisableFastVoxelPipeline(false);
20081992 _voxels.init();
20091993
@@ -2047,17 +2031,6 @@ void Application::init() { · 37 unmodified lines
20472031 connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));
20482032 connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors()));
20492033
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−
20612034 connect(getAudio(), &Audio::muteToggled, AudioDeviceScriptingInterface::getInstance(),
20622035 &AudioDeviceScriptingInterface::muteToggled, Qt::DirectConnection);
20632036
@@ -2113,13 +2086,7 @@ void Application::updateMouseRay() { · 49 unmodified lines
21132086 // make sure the frustum is up-to-date
21142087 loadViewFrustum(_myCamera, _viewFrustum);
21152088
2116− // if the mouse pointer isn't visible, act like it's at the center of the screen
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);
2089+ PickRay pickRay = _myCamera.computePickRay(getTrueMouseX(), getTrueMouseY());
21232090 _mouseRayOrigin = pickRay.origin;
21242091 _mouseRayDirection = pickRay.direction;
21252092
@@ -2315,22 +2282,30 @@ void Application::updateCursor(float deltaTime) { · 189 unmodified lines
23152282 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
23162283 PerformanceWarning warn(showWarnings, "Application::updateCursor()");
23172284
2318− // watch mouse position, if it hasn't moved, hide the cursor
2319− bool underMouse = _glWidget->underMouse();
2320− if (!_mouseHidden) {
2321− quint64 now = usecTimestampNow();
2322− int elapsed = now - _lastMouseMove;
2323− const int HIDE_CURSOR_TIMEOUT = 1 * 1000 * 1000; // 1 second
2324− if (elapsed > HIDE_CURSOR_TIMEOUT && (underMouse || !_seenMouseMove)) {
2325− getGLWidget()->setCursor(Qt::BlankCursor);
2326− _mouseHidden = true;
2285+ bool hideMouse = false;
2286+ bool underMouse = QGuiApplication::topLevelAt(QCursor::pos()) ==
2287+ Application::getInstance()->getWindow()->windowHandle();
2288+
2289+ static const int HIDE_CURSOR_TIMEOUT = 3 * USECS_PER_SECOND; // 3 second
2290+ int elapsed = usecTimestampNow() - _lastMouseMove;
2291+ if ((elapsed > HIDE_CURSOR_TIMEOUT) ||
2292+ (OculusManager::isConnected() && Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode))) {
2293+ hideMouse = underMouse;
2294+ }
2295+
2296+ setCursorVisible(!hideMouse);
2297+}
2298+
2299+void Application::setCursorVisible(bool visible) {
2300+ if (visible) {
2301+ if (overrideCursor() != NULL) {
2302+ restoreOverrideCursor();
23272303 }
23282304 } else {
2329− // if the mouse is hidden, but we're not inside our window, then consider ourselves to be moving
2330− if (!underMouse && _seenMouseMove) {
2331− _lastMouseMove = usecTimestampNow();
2332− getGLWidget()->setCursor(Qt::ArrowCursor);
2333− _mouseHidden = false;
2305+ if (overrideCursor() != NULL) {
2306+ changeOverrideCursor(Qt::BlankCursor);
2307+ } else {
2308+ setOverrideCursor(Qt::BlankCursor);
23342309 }
23352310 }
23362311 }
@@ -2352,17 +2327,6 @@ void Application::update(float deltaTime) { · 15 unmodified lines
23522327
23532328 }
23542329
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−
23662330 // Dispatch input events
23672331 _controllerScriptingInterface.updateInputControllers();
23682332
@@ -2740,6 +2704,29 @@ bool Application::isHMDMode() const { · 371 unmodified lines
27402704 }
27412705 }
27422706
2707+QRect 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+
27432730 /////////////////////////////////////////////////////////////////////////////////////
27442731 // loadViewFrustum()
27452732 //
@@ -2876,8 +2863,13 @@ void Application::updateShadowMap() { · 130 unmodified lines
28762863
28772864 // store view matrix without translation, which we'll use for precision-sensitive objects
28782865 updateUntranslatedViewMatrix();
2879− // TODO: assign an equivalent viewTransform object to the application to match the current path which uses glMatrixStack
2880− // setViewTransform(viewTransform);
2866+
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);
28812873
28822874 glEnable(GL_POLYGON_OFFSET_FILL);
28832875 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
30823074 glColor3f(1,0,0);
30833075 _geometryCache.renderSphere(originSphereRadius, 15, 15);
30843076
3085− // draw the audio reflector overlay
3086− {
3087− PerformanceTimer perfTimer("audio");
3088− _audioReflector.render();
3089− }
3090−
30913077 // Draw voxels
30923078 if (Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) {
30933079 PerformanceTimer perfTimer("voxels");
@@ -4015,7 +4001,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 921 unmodified lines
40154001 scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
40164002 scriptEngine->registerGlobalObject("AnimationCache", &_animationCache);
40174003 scriptEngine->registerGlobalObject("SoundCache", &SoundCache::getInstance());
4018− scriptEngine->registerGlobalObject("AudioReflector", &_audioReflector);
40194004 scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());
40204005 scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels);
40214006
@@ -4374,14 +4359,6 @@ void Application::skipVersion(QString latestVersion) { · 352 unmodified lines
43744359 skipFile.write(latestVersion.toStdString().c_str());
43754360 }
43764361
4377−void Application::setCursorVisible(bool visible) {
4378− if (visible) {
4379− restoreOverrideCursor();
4380− } else {
4381− setOverrideCursor(Qt::BlankCursor);
4382− }
4383−}
4384−
43854362 void Application::takeSnapshot() {
43864363 QMediaPlayer* player = new QMediaPlayer();
43874364 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