More UI improvements

This commit is contained in:
atlante45 2013-07-01 16:34:43 +02:00
parent 60bea894d8
commit 45e13fda15
8 changed files with 165 additions and 69 deletions

106
interface/src/Application.cpp Normal file → Executable file
View file

@ -58,11 +58,13 @@
#include "Application.h"
#include "InterfaceConfig.h"
#include "LogDisplay.h"
#include "LeapManager.h"
#include "OculusManager.h"
#include "Util.h"
#include "renderer/ProgramObject.h"
#include "ui/TextRenderer.h"
#include "Swatch.h"
#include "fvupdater.h"
using namespace std;
@ -248,10 +250,28 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_window->setCentralWidget(_glWidget);
// these are used, for example, to identify the application settings
setApplicationName("Interface");
setOrganizationDomain("highfidelity.io");
setOrganizationName("High Fidelity");
#ifdef Q_WS_MAC
QString resourcesPath = QCoreApplication::applicationDirPath() + "/../Resources";
#else
QString resourcesPath = QCoreApplication::applicationDirPath() + "/resources";
#endif
// read the ApplicationInfo.ini file for Name/Version/Domain information
QSettings applicationInfo(resourcesPath + "/info/ApplicationInfo.ini", QSettings::IniFormat);
// set the associated application properties
applicationInfo.beginGroup("INFO");
setApplicationName(applicationInfo.value("name").toString());
setApplicationVersion(applicationInfo.value("version").toString());
setOrganizationName(applicationInfo.value("organizationName").toString());
setOrganizationDomain(applicationInfo.value("organizationDomain").toString());
#if defined(Q_WS_MAC) && defined(QT_NO_DEBUG)
// if this is a release OS X build use fervor to check for an update
FvUpdater::sharedUpdater()->SetFeedURL("https://s3-us-west-1.amazonaws.com/highfidelity/appcast.xml");
FvUpdater::sharedUpdater()->CheckForUpdatesSilent();
#endif
initMenu();
@ -845,9 +865,26 @@ void Application::wheelEvent(QWheelEvent* event) {
}
}
void sendPingPackets() {
char agentTypesOfInterest[] = {AGENT_TYPE_VOXEL_SERVER, AGENT_TYPE_AUDIO_MIXER, AGENT_TYPE_AVATAR_MIXER};
long long currentTime = usecTimestampNow();
char pingPacket[1 + sizeof(currentTime)];
pingPacket[0] = PACKET_HEADER_PING;
memcpy(&pingPacket[1], &currentTime, sizeof(currentTime));
AgentList::getInstance()->broadcastToAgents((unsigned char*)pingPacket, 1 + sizeof(currentTime), agentTypesOfInterest, 3);
}
// Every second, check the frame rates and other stuff
void Application::timer() {
gettimeofday(&_timerEnd, NULL);
if (_testPing->isChecked()) {
sendPingPackets();
}
_fps = (float)_frameCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
_packetsPerSecond = (float)_packetCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
_bytesPerSecond = (float)_bytesCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
@ -972,10 +1009,6 @@ void Application::editPreferences() {
headCameraPitchYawScale->setValue(_headCameraPitchYawScale);
form->addRow("Head Camera Pitch/Yaw Scale:", headCameraPitchYawScale);
QCheckBox* audioEchoCancellation = new QCheckBox();
audioEchoCancellation->setChecked(_audio.isCancellingEcho());
form->addRow("Audio Echo Cancellation", audioEchoCancellation);
QDoubleSpinBox* leanScale = new QDoubleSpinBox();
leanScale->setValue(_myAvatar.getLeanScale());
form->addRow("Lean Scale:", leanScale);
@ -997,7 +1030,6 @@ void Application::editPreferences() {
QUrl url(avatarURL->text());
_myAvatar.getVoxels()->setVoxelURL(url);
sendAvatarVoxelURLMessage(url);
_audio.setIsCancellingEcho( audioEchoCancellation->isChecked() );
_headCameraPitchYawScale = headCameraPitchYawScale->value();
_myAvatar.setLeanScale(leanScale->value());
_audioJitterBufferSamples = audioJitterBufferSamples->value();
@ -1143,7 +1175,11 @@ void Application::decreaseVoxelSize() {
void Application::increaseVoxelSize() {
_mouseVoxelScale *= 2;
}
void Application::resetSwatchColors() {
_swatch->reset();
}
static QIcon createSwatchIcon(const QColor& color) {
QPixmap map(16, 16);
map.fill(color);
@ -1355,6 +1391,8 @@ void Application::initMenu() {
(_gravityUse = optionsMenu->addAction("Use Gravity"))->setCheckable(true);
_gravityUse->setChecked(true);
_gravityUse->setShortcut(Qt::SHIFT | Qt::Key_G);
(_testPing = optionsMenu->addAction("Test Ping"))->setCheckable(true);
_testPing->setChecked(true);
(_fullScreenMode = optionsMenu->addAction("Fullscreen", this, SLOT(setFullscreen(bool)), Qt::Key_F))->setCheckable(true);
optionsMenu->addAction("Webcam", &_webcam, SLOT(setEnabled(bool)))->setCheckable(true);
@ -1414,7 +1452,8 @@ void Application::initMenu() {
voxelMenu->addAction("Decrease Voxel Size", this, SLOT(decreaseVoxelSize()), QKeySequence::ZoomOut);
voxelMenu->addAction("Increase Voxel Size", this, SLOT(increaseVoxelSize()), QKeySequence::ZoomIn);
voxelMenu->addAction("Reset Swatch Colors", this, SLOT(resetSwatchColors()));
_voxelPaintColor = voxelMenu->addAction("Voxel Paint Color", this,
SLOT(chooseVoxelPaintColor()), Qt::META | Qt::Key_C);
QColor paintColor(128, 128, 128);
@ -1697,7 +1736,11 @@ void Application::update(float deltaTime) {
_touchAvgY - _touchDragStartedAvgY);
}
// Read serial port interface devices
// Leap finger-sensing device
LeapManager::nextFrame();
_myAvatar.getHand().setLeapFingers(LeapManager::getFingerPositions());
// Read serial port interface devices
if (_serialHeadSensor.isActive()) {
_serialHeadSensor.readData(deltaTime);
}
@ -2294,11 +2337,11 @@ void Application::displayOverlay() {
if (_eyedropperMode->isChecked() && _voxelPaintColor->data().value<QColor>() != _swatch->getColor()) {
QColor color(_voxelPaintColor->data().value<QColor>());
TextRenderer textRenderer(SANS_FONT_FAMILY, -1, 100);
TextRenderer textRenderer(SANS_FONT_FAMILY, 11, 50);
const char* line1("Assign this color to a swatch");
const char* line2("by choosing a key from 1 to 8.");
double step(0.05f);
int left((_glWidget->width() - 320)/2);
int left((_glWidget->width() - 300)/2);
int top(_glWidget->height()/40.0f);
double margin(10.0f);
@ -2308,10 +2351,10 @@ void Application::displayOverlay() {
glVertex2f(left + margin*cos(a), top + margin*sin(a));
}
for (double a(1.5f*M_PI); a < 2.0f*M_PI; a += step) {
glVertex2f(left + 300 + margin*cos(a), top + margin*sin(a));
glVertex2f(left + 280 + margin*cos(a), top + margin*sin(a));
}
for (double a(0.0f); a < 0.5f*M_PI; a += step) {
glVertex2f(left + 300 + margin*cos(a), top + 30 + margin*sin(a));
glVertex2f(left + 280 + margin*cos(a), top + 30 + margin*sin(a));
}
for (double a(0.5f*M_PI); a < 1.0f*M_PI; a += step) {
glVertex2f(left + margin*cos(a), top + 30 + margin*sin(a));
@ -2330,7 +2373,10 @@ void Application::displayOverlay() {
glColor3f(1.0f, 1.0f, 1.0f);
textRenderer.draw(left + 74, top + 12, line1);
textRenderer.draw(left + 74, top + 27, line2);
textRenderer.draw(left + 74, top + 28, line2);
}
else {
_swatch->checkColor();
}
glPopMatrix();
@ -2343,7 +2389,24 @@ void Application::displayStats() {
sprintf(stats, "%3.0f FPS, %d Pkts/sec, %3.2f Mbps",
_fps, _packetsPerSecond, (float)_bytesPerSecond * 8.f / 1000000.f);
drawtext(10, statsVerticalOffset + 15, 0.10f, 0, 1.0, 0, stats);
if (_testPing->isChecked()) {
int pingAudio = 0, pingAvatar = 0, pingVoxel = 0;
AgentList *agentList = AgentList::getInstance();
Agent *audioMixerAgent = agentList->soloAgentOfType(AGENT_TYPE_AUDIO_MIXER);
Agent *avatarMixerAgent = agentList->soloAgentOfType(AGENT_TYPE_AVATAR_MIXER);
Agent *voxelServerAgent = agentList->soloAgentOfType(AGENT_TYPE_VOXEL_SERVER);
pingAudio = audioMixerAgent ? audioMixerAgent->getPingMs() : 0;
pingAvatar = avatarMixerAgent ? avatarMixerAgent->getPingMs() : 0;
pingVoxel = voxelServerAgent ? voxelServerAgent->getPingMs() : 0;
char pingStats[200];
sprintf(pingStats, "Ping audio/avatar/voxel: %d / %d / %d ", pingAudio, pingAvatar, pingVoxel);
drawtext(10, statsVerticalOffset + 35, 0.10f, 0, 1.0, 0, pingStats);
}
std::stringstream voxelStats;
voxelStats.precision(4);
voxelStats << "Voxels Rendered: " << _voxels.getVoxelsRendered() / 1000.f << "K Updated: " << _voxels.getVoxelsUpdated()/1000.f << "K";
@ -2384,6 +2447,7 @@ void Application::displayStats() {
}
drawtext(10, statsVerticalOffset + 330, 0.10f, 0, 1.0, 0, avatarMixerStats);
drawtext(10, statsVerticalOffset + 450, 0.10f, 0, 1.0, 0, (char *)LeapManager::statusString().c_str());
if (_perfStatsOn) {
// Get the PerfStats group details. We need to allocate and array of char* long enough to hold 1+groups
@ -2858,9 +2922,6 @@ void Application::loadSettings(QSettings* settings) {
_viewFrustumOffsetDistance = loadSetting(settings, "viewFrustumOffsetDistance", 0.0f);
_viewFrustumOffsetUp = loadSetting(settings, "viewFrustumOffsetUp" , 0.0f);
settings->endGroup();
settings->beginGroup("Audio Echo Cancellation");
_audio.setIsCancellingEcho(settings->value("enabled", false).toBool());
settings->endGroup();
scanMenuBar(&Application::loadAction, settings);
getAvatar()->loadData(settings);
@ -2882,9 +2943,6 @@ void Application::saveSettings(QSettings* settings) {
settings->setValue("viewFrustumOffsetDistance", _viewFrustumOffsetDistance);
settings->setValue("viewFrustumOffsetUp", _viewFrustumOffsetUp);
settings->endGroup();
settings->beginGroup("Audio");
settings->setValue("echoCancellation", _audio.isCancellingEcho());
settings->endGroup();

View file

@ -9,9 +9,9 @@
#ifndef __interface__Application__
#define __interface__Application__
#include <map>
#include <pthread.h>
#include <time.h>
#include <map>
#include <QApplication>
#include <QAction>
@ -33,6 +33,7 @@
#include "ViewFrustum.h"
#include "VoxelSystem.h"
#include "Webcam.h"
#include "renderer/GeometryCache.h"
#include "ui/ChatEntry.h"
#include "ToolsPalette.h"
#include "Swatch.h"
@ -91,6 +92,7 @@ public:
bool shouldDynamicallySetJitterBuffer() { return _audioJitterBufferSamples == 0; }
QNetworkAccessManager* getNetworkAccessManager() { return _networkAccessManager; }
GeometryCache* getGeometryCache() { return &_geometryCache; }
private slots:
@ -132,6 +134,7 @@ private slots:
void updateVoxelModeActions();
void decreaseVoxelSize();
void increaseVoxelSize();
void resetSwatchColors();
void chooseVoxelPaintColor();
void loadSettings(QSettings* set = NULL);
void saveSettings(QSettings* set = NULL);
@ -199,6 +202,7 @@ private:
QAction* _showHeadMouse; // Whether the have the mouse near edge of screen move your view
QAction* _transmitterDrives; // Whether to have Transmitter data move/steer the Avatar
QAction* _gravityUse; // Whether gravity is on or not
QAction* _testPing; // Whether to display ping or not
QAction* _renderVoxels; // Whether to render voxels
QAction* _renderVoxelTextures; // Whether to render noise textures on voxels
QAction* _renderStarsOn; // Whether to display the stars
@ -320,6 +324,8 @@ private:
int _scaleInLocation;
int _hmdWarpParamLocation;
GeometryCache _geometryCache;
#ifndef _WIN32
Audio _audio;
#endif

View file

@ -4,18 +4,30 @@
Swatch::Swatch(QAction* action) : Tool(action, 0, -1, -1),
_selected(1),
_margin(4),
_textRenderer(SANS_FONT_FAMILY, -1, 100) {
_textRenderer(MONO_FONT_FAMILY, 10, 100) {
_width = 62;
_height = 30;
}
_colors[0].setRgb(128, 128, 128);
_colors[1].setRgb(255, 0, 0);
_colors[2].setRgb(0, 255, 0);
_colors[3].setRgb(0, 0, 255);
_colors[4].setRgb(255, 0, 255);
_colors[5].setRgb(255, 255, 0);
_colors[6].setRgb(0, 255, 255);
_colors[7].setRgb(0, 0, 0);
void Swatch::reset() {
_colors[0].setRgb(237, 175, 0);
_colors[1].setRgb(161, 211, 72);
_colors[2].setRgb(51, 204, 204);
_colors[3].setRgb(63, 169, 245);
_colors[4].setRgb(193, 99, 122);
_colors[5].setRgb(255, 54, 69);
_colors[6].setRgb(124, 36, 36);
_colors[7].setRgb(63, 35, 19);
}
QColor Swatch::getColor() {
return _colors[_selected - 1];
}
void Swatch::checkColor() {
if (_action->data().value<QColor>() == _colors[_selected - 1]) {
return;
}
QPixmap map(16, 16);
map.fill(_colors[_selected - 1]);
@ -23,15 +35,11 @@ Swatch::Swatch(QAction* action) : Tool(action, 0, -1, -1),
_action->setIcon(map);
}
QColor Swatch::getColor() {
return _colors[_selected - 1];
}
void Swatch::saveData(QSettings* settings) {
settings->beginGroup("Swatch");
for (int i(0); i < SWATCH_SIZE; ++i) {
QString name("R0");
QString name("R1");
name[1] = '1' + i;
settings->setValue(name, _colors[i].red());
name[0] = 'G';
@ -45,33 +53,35 @@ void Swatch::saveData(QSettings* settings) {
void Swatch::loadData(QSettings* settings) {
settings->beginGroup("Swatch");
_colors[0].setRgb(settings->value("R1", 128).toInt(),
settings->value("G1", 128).toInt(),
settings->value("B1", 128).toInt());
_colors[1].setRgb(settings->value("R2", 128).toInt(),
settings->value("G2", 128).toInt(),
settings->value("B2", 128).toInt());
_colors[2].setRgb(settings->value("R3", 128).toInt(),
settings->value("G3", 128).toInt(),
settings->value("B3", 128).toInt());
_colors[3].setRgb(settings->value("R4", 128).toInt(),
settings->value("G4", 128).toInt(),
settings->value("B4", 128).toInt());
_colors[4].setRgb(settings->value("R5", 128).toInt(),
settings->value("G5", 128).toInt(),
settings->value("B5", 128).toInt());
_colors[5].setRgb(settings->value("R6", 128).toInt(),
settings->value("G6", 128).toInt(),
settings->value("B6", 128).toInt());
_colors[6].setRgb(settings->value("R7", 128).toInt(),
settings->value("G7", 128).toInt(),
settings->value("B7", 128).toInt());
_colors[7].setRgb(settings->value("R8", 128).toInt(),
settings->value("G8", 128).toInt(),
settings->value("B8", 128).toInt());
_colors[0].setRgb(settings->value("R1", 237).toInt(),
settings->value("G1", 175).toInt(),
settings->value("B1", 0).toInt());
_colors[1].setRgb(settings->value("R2", 161).toInt(),
settings->value("G2", 211).toInt(),
settings->value("B2", 72).toInt());
_colors[2].setRgb(settings->value("R3", 51).toInt(),
settings->value("G3", 204).toInt(),
settings->value("B3", 204).toInt());
_colors[3].setRgb(settings->value("R4", 63).toInt(),
settings->value("G4", 169).toInt(),
settings->value("B4", 245).toInt());
_colors[4].setRgb(settings->value("R5", 193).toInt(),
settings->value("G5", 99).toInt(),
settings->value("B5", 122).toInt());
_colors[5].setRgb(settings->value("R6", 255).toInt(),
settings->value("G6", 54).toInt(),
settings->value("B6", 69).toInt());
_colors[6].setRgb(settings->value("R7", 124).toInt(),
settings->value("G7", 36).toInt(),
settings->value("B7", 36).toInt());
_colors[7].setRgb(settings->value("R8", 63).toInt(),
settings->value("G8", 35).toInt(),
settings->value("B8", 19).toInt());
settings->endGroup();
checkColor();
}
void Swatch::handleEvent(int key, bool getColor) {

View file

@ -16,10 +16,14 @@
class Swatch : public Tool {
public:
Swatch(QAction* action);
QColor getColor();
void checkColor();
void saveData(QSettings* settings);
void loadData(QSettings* settings);
void reset();
void render(int screenWidth, int screenHeight);
void handleEvent(int key, bool getColor);

View file

@ -12,6 +12,10 @@ Tool::Tool(QAction *action, GLuint texture, int x, int y) : _texture(texture),
_height(40) {
}
bool Tool::isActive() {
return _action->isChecked();
}
void Tool::render(int screenWidth, int screenHeight) {
glEnable(GL_TEXTURE_2D);

View file

@ -23,6 +23,7 @@ class Tool {
public:
Tool(QAction *action, GLuint texture, int x, int y);
bool isActive();
virtual void render(int screenWidth, int screenHeight);
protected:

View file

@ -3,10 +3,12 @@
#include <QSvgRenderer>
#include <QPainter>
#include <QGLWidget>
#include <SharedUtil.h>
ToolsPalette::ToolsPalette() {
// Load SVG
QSvgRenderer renderer(QString("/Users/graysonstebbins/Documents/hifi/interface/resources/images/hifi-interface-tools.svg"));
switchToResourcesParentIfRequired();
QSvgRenderer renderer(QString("./resources/images/hifi-interface-tools.svg"));
// Prepare a QImage with desired characteritisc
QImage image(124, 400, QImage::Format_ARGB32);
@ -52,8 +54,18 @@ void ToolsPalette::render(int screenWidth, int screenHeight) {
glPushMatrix();
glTranslated(_left, _top, 0);
bool show(false);
for (unsigned int i(0); i < _tools.size(); ++i) {
_tools[i]->render(screenWidth, screenHeight);
if (_tools[i]->isActive()) {
show = true;
break;
}
}
if (show) {
for (unsigned int i(0); i < _tools.size(); ++i) {
_tools[i]->render(screenWidth, screenHeight);
}
}
glPopMatrix();

View file

@ -8,7 +8,8 @@
#ifndef __interface__ToolsPalette__
#define __interface__ToolsPalette__
#include <Tool.h>
#include "Tool.h"
#include "Swatch.h"
#include <vector>