adds code to show bandwidth details upon click and adds a checkbox to the menu to set visibility of the bandwidth bars

This commit is contained in:
tosh 2013-06-30 17:08:01 +02:00
parent 435b958671
commit f1e5a56347
5 changed files with 46 additions and 6 deletions

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -11,6 +11,7 @@
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/component_wise.hpp>
#include <UDPSocket.h>