History

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

Philip Rosedale committed 13 years ago

Commit dae79d82 parents 2e854b5 0f011e012 files · +706 −19Browse files

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

Unified · Split

interface/src/Application.cpp+89−15
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 #include <sstream>
99
1010 #include <stdlib.h>
11+#include <cmath>
1112
1213 #ifdef _WIN32
1314 #include "Syssocket.h"
@@ -63,6 +64,7 @@ · 49 unmodified lines
6364 #include "Util.h"
6465 #include "renderer/ProgramObject.h"
6566 #include "ui/TextRenderer.h"
67+#include "Swatch.h"
6668 #include "fvupdater.h"
6769
6870 using namespace std;
@@ -198,7 +200,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 129 unmodified lines
198200 _packetCount(0),
199201 _packetsPerSecond(0),
200202 _bytesPerSecond(0),
201− _bytesCount(0)
203+ _bytesCount(0),
204+ _swatch(NULL)
202205 {
203206 _applicationStartupTime = startup_time;
204207 _window->setWindowTitle("Interface");
@@ -274,7 +277,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 69 unmodified lines
274277 FvUpdater::sharedUpdater()->SetFeedURL("https://s3-us-west-1.amazonaws.com/highfidelity/appcast.xml");
275278 FvUpdater::sharedUpdater()->CheckForUpdatesSilent();
276279 #endif
277−
280+
278281 initMenu();
279282
280283 QRect available = desktop()->availableGeometry();
@@ -728,7 +731,16 @@ void Application::keyPressEvent(QKeyEvent* event) { · 447 unmodified lines
728731 deleteVoxelUnderCursor();
729732 }
730733 break;
731−
734+ case Qt::Key_1:
735+ case Qt::Key_2:
736+ case Qt::Key_3:
737+ case Qt::Key_4:
738+ case Qt::Key_5:
739+ case Qt::Key_6:
740+ case Qt::Key_7:
741+ case Qt::Key_8:
742+ _swatch.handleEvent(event->key(), _eyedropperMode->isChecked());
743+ break;
732744 default:
733745 event->ignore();
734746 break;
@@ -1263,7 +1275,11 @@ void Application::decreaseVoxelSize() { · 528 unmodified lines
12631275 void Application::increaseVoxelSize() {
12641276 _mouseVoxelScale *= 2;
12651277 }
1266−
1278+
1279+void Application::resetSwatchColors() {
1280+ _swatch.reset();
1281+}
1282+
12671283 static QIcon createSwatchIcon(const QColor& color) {
12681284 QPixmap map(16, 16);
12691285 map.fill(color);
@@ -1503,7 +1519,7 @@ void Application::initMenu() { · 233 unmodified lines
15031519 QMenu* renderMenu = menuBar->addMenu("Render");
15041520 (_renderVoxels = renderMenu->addAction("Voxels"))->setCheckable(true);
15051521 _renderVoxels->setChecked(true);
1506− _renderVoxels->setShortcut(Qt::Key_V);
1522+ _renderVoxels->setShortcut(Qt::SHIFT | Qt::Key_V);
15071523 (_renderVoxelTextures = renderMenu->addAction("Voxel Textures"))->setCheckable(true);
15081524 (_renderStarsOn = renderMenu->addAction("Stars"))->setCheckable(true);
15091525 _renderStarsOn->setChecked(true);
@@ -1545,26 +1561,29 @@ void Application::initMenu() { · 35 unmodified lines
15451561 _voxelModeActions->setExclusive(false); // exclusivity implies one is always checked
15461562
15471563 (_addVoxelMode = voxelMenu->addAction(
1548− "Add Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::CTRL | Qt::Key_A))->setCheckable(true);
1564+ "Add Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_V))->setCheckable(true);
15491565 _voxelModeActions->addAction(_addVoxelMode);
15501566 (_deleteVoxelMode = voxelMenu->addAction(
1551− "Delete Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::CTRL | Qt::Key_D))->setCheckable(true);
1567+ "Delete Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_R))->setCheckable(true);
15521568 _voxelModeActions->addAction(_deleteVoxelMode);
15531569 (_colorVoxelMode = voxelMenu->addAction(
1554− "Color Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::CTRL | Qt::Key_B))->setCheckable(true);
1570+ "Color Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_B))->setCheckable(true);
15551571 _voxelModeActions->addAction(_colorVoxelMode);
15561572 (_selectVoxelMode = voxelMenu->addAction(
1557− "Select Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::CTRL | Qt::Key_S))->setCheckable(true);
1573+ "Select Voxel Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_O))->setCheckable(true);
15581574 _voxelModeActions->addAction(_selectVoxelMode);
15591575 (_eyedropperMode = voxelMenu->addAction(
1560− "Get Color Mode", this, SLOT(updateVoxelModeActions()), Qt::CTRL | Qt::Key_G))->setCheckable(true);
1576+ "Get Color Mode", this, SLOT(updateVoxelModeActions()), Qt::Key_G))->setCheckable(true);
15611577 _voxelModeActions->addAction(_eyedropperMode);
1562−
1578+
15631579 voxelMenu->addAction("Decrease Voxel Size", this, SLOT(decreaseVoxelSize()), QKeySequence::ZoomOut);
15641580 voxelMenu->addAction("Increase Voxel Size", this, SLOT(increaseVoxelSize()), QKeySequence::ZoomIn);
1565−
1581+ voxelMenu->addAction("Reset Swatch Colors", this, SLOT(resetSwatchColors()));
1582+
15661583 _voxelPaintColor = voxelMenu->addAction("Voxel Paint Color", this,
15671584 SLOT(chooseVoxelPaintColor()), Qt::META | Qt::Key_C);
1585+ _swatch.setAction(_voxelPaintColor);
1586+
15681587 QColor paintColor(128, 128, 128);
15691588 _voxelPaintColor->setData(paintColor);
15701589 _voxelPaintColor->setIcon(createSwatchIcon(paintColor));
@@ -1695,6 +1714,14 @@ void Application::init() { · 124 unmodified lines
16951714
16961715
16971716 sendAvatarVoxelURLMessage(_myAvatar.getVoxels()->getVoxelURL());
1717+
1718+ _palette.init(_glWidget->width(), _glWidget->height());
1719+ _palette.addAction(_addVoxelMode, 0, 0);
1720+ _palette.addAction(_deleteVoxelMode, 0, 1);
1721+ _palette.addTool(&_swatch);
1722+ _palette.addAction(_colorVoxelMode, 0, 2);
1723+ _palette.addAction(_eyedropperMode, 0, 3);
1724+ _palette.addAction(_selectVoxelMode, 0, 4);
16981725 }
16991726
17001727 const float MAX_AVATAR_EDIT_VELOCITY = 1.0f;
@@ -1926,7 +1953,7 @@ void Application::update(float deltaTime) { · 225 unmodified lines
19261953 if (_bandwidthDialog) {
19271954 _bandwidthDialog->update();
19281955 }
1929−
1956+
19301957 // Update audio stats for procedural sounds
19311958 #ifndef _WIN32
19321959 _audio.setLastAcceleration(_myAvatar.getThrust());
@@ -2440,7 +2467,52 @@ void Application::displayOverlay() { · 507 unmodified lines
24402467
24412468 // render the webcam input frame
24422469 _webcam.renderPreview(_glWidget->width(), _glWidget->height());
2443−
2470+
2471+ _palette.render(_glWidget->width(), _glWidget->height());
2472+
2473+ if (_eyedropperMode->isChecked() && _voxelPaintColor->data().value<QColor>() != _swatch.getColor()) {
2474+ QColor color = _voxelPaintColor->data().value<QColor>();
2475+ TextRenderer textRenderer(SANS_FONT_FAMILY, 11, 50);
2476+ const char line1[] = "Assign this color to a swatch";
2477+ const char line2[] = "by choosing a key from 1 to 8.";
2478+
2479+ int left = (_glWidget->width() - POPUP_WIDTH - 2 * POPUP_MARGIN) / 2;
2480+ int top = _glWidget->height() / 40;
2481+
2482+ glBegin(GL_POLYGON);
2483+ glColor3f(0.0f, 0.0f, 0.0f);
2484+ for (double a = M_PI; a < 1.5f * M_PI; a += POPUP_STEP) {
2485+ glVertex2f(left + POPUP_MARGIN * cos(a) , top + POPUP_MARGIN * sin(a));
2486+ }
2487+ for (double a = 1.5f * M_PI; a < 2.0f * M_PI; a += POPUP_STEP) {
2488+ glVertex2f(left + POPUP_WIDTH + POPUP_MARGIN * cos(a), top + POPUP_MARGIN * sin(a));
2489+ }
2490+ for (double a = 0.0f; a < 0.5f * M_PI; a += POPUP_STEP) {
2491+ glVertex2f(left + POPUP_WIDTH + POPUP_MARGIN * cos(a), top + POPUP_HEIGHT + POPUP_MARGIN * sin(a));
2492+ }
2493+ for (double a = 0.5f * M_PI; a < 1.0f * M_PI; a += POPUP_STEP) {
2494+ glVertex2f(left + POPUP_MARGIN * cos(a) , top + POPUP_HEIGHT + POPUP_MARGIN * sin(a));
2495+ }
2496+ glEnd();
2497+
2498+ glBegin(GL_QUADS);
2499+ glColor3f(color.redF(),
2500+ color.greenF(),
2501+ color.blueF());
2502+ glVertex2f(left , top);
2503+ glVertex2f(left + SWATCH_WIDTH, top);
2504+ glVertex2f(left + SWATCH_WIDTH, top + SWATCH_HEIGHT);
2505+ glVertex2f(left , top + SWATCH_HEIGHT);
2506+ glEnd();
2507+
2508+ glColor3f(1.0f, 1.0f, 1.0f);
2509+ textRenderer.draw(left + SWATCH_WIDTH + POPUP_MARGIN, top + FIRST_LINE_OFFSET , line1);
2510+ textRenderer.draw(left + SWATCH_WIDTH + POPUP_MARGIN, top + SECOND_LINE_OFFSET, line2);
2511+ }
2512+ else {
2513+ _swatch.checkColor();
2514+ }
2515+
24442516 glPopMatrix();
24452517 }
24462518
@@ -2990,7 +3062,8 @@ void Application::loadSettings(QSettings* settings) { · 543 unmodified lines
29903062 settings->endGroup();
29913063
29923064 scanMenuBar(&Application::loadAction, settings);
2993− getAvatar()->loadData(settings);
3065+ getAvatar()->loadData(settings);
3066+ _swatch.loadData(settings);
29943067 }
29953068
29963069
@@ -3012,6 +3085,7 @@ void Application::saveSettings(QSettings* settings) { · 15 unmodified lines
30123085
30133086 scanMenuBar(&Application::saveAction, settings);
30143087 getAvatar()->saveData(settings);
3088+ _swatch.saveData(settings);
30153089 }
30163090
30173091 void Application::importSettings() {

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