diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e9022935a6..df84abe4c7 100755 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -801,6 +801,7 @@ void Application::mouseReleaseEvent(QMouseEvent* event) { _mouseX = event->x(); _mouseY = event->y(); _mousePressed = false; + checkBandwidthMeterClick(); } } } @@ -980,15 +981,28 @@ void Application::processAvatarVoxelURLMessage(unsigned char *packetData, size_t QMetaObject::invokeMethod(avatar->getVoxels(), "setVoxelURL", Q_ARG(QUrl, url)); } +void Application::checkBandwidthMeterClick() { + // ... to be called upon button release + + if (_bandwidthDisplayOn->isChecked() && + glm::compMax(glm::abs(glm::ivec2(_mouseX - _mouseDragStartedX, _mouseY - _mouseDragStartedY))) <= 6 && + _bandwidthMeter.isWithinArea(_mouseX, _mouseY, _glWidget->width(), _glWidget->height())) { + + // The bandwidth meter is visible, the click didn't get dragged too far and + // we actually hit the bandwidth meter + bandwidthDetails(); + } +} + void Application::bandwidthDetails() { if (! _bandwidthDialog) { _bandwidthDialog = new BandwidthDialog(_glWidget, getBandwidthMeter()); + connect(_bandwidthDialog, SIGNAL(closed()), SLOT(bandwidthDetailsClosed())); + _bandwidthDialog->show(); } _bandwidthDialog->raise(); - - connect(_bandwidthDialog, SIGNAL(closed()), SLOT(bandwidthDetailsClosed())); } void Application::bandwidthDetailsClosed() { @@ -1431,6 +1445,8 @@ void Application::initMenu() { (_logOn = toolsMenu->addAction("Log"))->setCheckable(true); _logOn->setChecked(false); _logOn->setShortcut(Qt::CTRL | Qt::Key_L); + (_bandwidthDisplayOn = toolsMenu->addAction("Bandwidth Display"))->setCheckable(true); + _bandwidthDisplayOn->setChecked(true); toolsMenu->addAction("Bandwidth Details", this, SLOT(bandwidthDetails())); @@ -2291,7 +2307,8 @@ void Application::displayOverlay() { if (_renderStatsOn->isChecked()) { displayStats(); } - _bandwidthMeter.render(_glWidget->width() - 400, 40, 380, 32); + if (_bandwidthDisplayOn->isChecked()) { _bandwidthMeter.render(_glWidget->width(), _glWidget->height()); } + if (_logOn->isChecked()) { LogDisplay::instance.render(_glWidget->width(), _glWidget->height()); } // Show chat entry field diff --git a/interface/src/Application.h b/interface/src/Application.h index 77520d0e85..be95f81c15 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -173,7 +173,9 @@ private: void displayOverlay(); void displayStats(); void renderViewFrustum(ViewFrustum& viewFrustum); - + + void checkBandwidthMeterClick(); + void setupPaintingVoxel(); void shiftPaintingColor(); void maybeEditVoxelUnderCursor(); @@ -224,6 +226,7 @@ private: QAction* _manualFirstPerson; // Whether to force first-person mode QAction* _manualThirdPerson; // Whether to force third-person mode QAction* _logOn; // Whether to show on-screen log + QAction* _bandwidthDisplayOn; // Whether to show on-screen bandwidth bars QActionGroup* _voxelModeActions; // The group of voxel edit mode actions QAction* _addVoxelMode; // Whether add voxel mode is enabled QAction* _deleteVoxelMode; // Whether delete voxel mode is enabled diff --git a/interface/src/BandwidthMeter.cpp b/interface/src/BandwidthMeter.cpp index 2d5aed37b9..c2a5b581c2 100644 --- a/interface/src/BandwidthMeter.cpp +++ b/interface/src/BandwidthMeter.cpp @@ -14,6 +14,11 @@ namespace { // .cpp-local + int const AREA_WIDTH = -400; // Width of the area used. Aligned to the right when negative. + int const AREA_HEIGHT = 32; // Height of the area used. Aligned to the bottom when negative. + int const BORDER_DISTANCE_HORIZ = -20; // Distance to edge of screen (use negative value when width is negative). + int const BORDER_DISTANCE_VERT = 20; // Distance to edge of screen (use negative value when height is negative). + char const* CAPTION_IN = "IN"; char const* CAPTION_OUT = "OUT"; char const* CAPTION_UNIT = "Mbps"; @@ -95,7 +100,20 @@ inline int BandwidthMeter::centered(int subject, int object) { return (object - subject) / 2; } -void BandwidthMeter::render(int x, int y, unsigned w, unsigned h) { +bool BandwidthMeter::isWithinArea(int x, int y, int screenWidth, int screenHeight) { + + int minX = BORDER_DISTANCE_HORIZ + (AREA_WIDTH >= 0 ? 0 : screenWidth + AREA_WIDTH); + int minY = BORDER_DISTANCE_VERT + (AREA_HEIGHT >= 0 ? 0 : screenHeight + AREA_HEIGHT); + + return x >= minX && x < minX + glm::abs(AREA_WIDTH) && + y >= minY && y < minY + glm::abs(AREA_HEIGHT); +} + +void BandwidthMeter::render(int screenWidth, int screenHeight) { + + int x = BORDER_DISTANCE_HORIZ + (AREA_WIDTH >= 0 ? 0 : screenWidth + AREA_WIDTH); + int y = BORDER_DISTANCE_VERT + (AREA_HEIGHT >= 0 ? 0 : screenHeight + AREA_HEIGHT); + int w = glm::abs(AREA_WIDTH), h = glm::abs(AREA_HEIGHT); // Determine total float totalIn = 0.0f, totalOut = 0.0f; diff --git a/interface/src/BandwidthMeter.h b/interface/src/BandwidthMeter.h index 3294e6e0e7..d3641a21f0 100644 --- a/interface/src/BandwidthMeter.h +++ b/interface/src/BandwidthMeter.h @@ -20,7 +20,8 @@ public: BandwidthMeter(); - void render(int x, int y, unsigned w, unsigned h); + void render(int screenWidth, int screenHeight); + bool isWithinArea(int x, int y, int screenWidth, int screenHeight); // Number of channels / streams. static size_t const N_CHANNELS = 3; diff --git a/libraries/audio/src/AudioInjector.h b/libraries/audio/src/AudioInjector.h index efe52bdf57..29ff920317 100644 --- a/libraries/audio/src/AudioInjector.h +++ b/libraries/audio/src/AudioInjector.h @@ -11,6 +11,7 @@ #include #include +#include #include