Showing the changes to interface/src/Application.cpp (1 of 12 files). Show all
Unified · Split
| @@ -8,6 +8,7 @@ · 7 unmodified lines | ||
| 8 | 8 | #include <sstream> |
| 9 | 9 | |
| 10 | 10 | #include <stdlib.h> |
| 11 | +#include <cmath> | |
| 11 | 12 | |
| 12 | 13 | #ifdef _WIN32 |
| 13 | 14 | #include "Syssocket.h" |
| @@ -63,6 +64,7 @@ · 49 unmodified lines | ||
| 63 | 64 | #include "Util.h" |
| 64 | 65 | #include "renderer/ProgramObject.h" |
| 65 | 66 | #include "ui/TextRenderer.h" |
| 67 | +#include "Swatch.h" | |
| 66 | 68 | #include "fvupdater.h" |
| 67 | 69 | |
| 68 | 70 | using namespace std; |
| @@ -198,7 +200,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 129 unmodified lines | ||
| 198 | 200 | _packetCount(0), |
| 199 | 201 | _packetsPerSecond(0), |
| 200 | 202 | _bytesPerSecond(0), |
| 201 | − _bytesCount(0) | |
| 203 | + _bytesCount(0), | |
| 204 | + _swatch(NULL) | |
| 202 | 205 | { |
| 203 | 206 | _applicationStartupTime = startup_time; |
| 204 | 207 | _window->setWindowTitle("Interface"); |
| @@ -274,7 +277,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 69 unmodified lines | ||
| 274 | 277 | FvUpdater::sharedUpdater()->SetFeedURL("https://s3-us-west-1.amazonaws.com/highfidelity/appcast.xml"); |
| 275 | 278 | FvUpdater::sharedUpdater()->CheckForUpdatesSilent(); |
| 276 | 279 | #endif |
| 277 | − | |
| 280 | + | |
| 278 | 281 | initMenu(); |
| 279 | 282 | |
| 280 | 283 | QRect available = desktop()->availableGeometry(); |
| @@ -728,7 +731,16 @@ void Application::keyPressEvent(QKeyEvent* event) { · 447 unmodified lines | ||
| 728 | 731 | deleteVoxelUnderCursor(); |
| 729 | 732 | } |
| 730 | 733 | 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; | |
| 732 | 744 | default: |
| 733 | 745 | event->ignore(); |
| 734 | 746 | break; |
| @@ -1263,7 +1275,11 @@ void Application::decreaseVoxelSize() { · 528 unmodified lines | ||
| 1263 | 1275 | void Application::increaseVoxelSize() { |
| 1264 | 1276 | _mouseVoxelScale *= 2; |
| 1265 | 1277 | } |
| 1266 | − | |
| 1278 | + | |
| 1279 | +void Application::resetSwatchColors() { | |
| 1280 | + _swatch.reset(); | |
| 1281 | +} | |
| 1282 | + | |
| 1267 | 1283 | static QIcon createSwatchIcon(const QColor& color) { |
| 1268 | 1284 | QPixmap map(16, 16); |
| 1269 | 1285 | map.fill(color); |
| @@ -1503,7 +1519,7 @@ void Application::initMenu() { · 233 unmodified lines | ||
| 1503 | 1519 | QMenu* renderMenu = menuBar->addMenu("Render"); |
| 1504 | 1520 | (_renderVoxels = renderMenu->addAction("Voxels"))->setCheckable(true); |
| 1505 | 1521 | _renderVoxels->setChecked(true); |
| 1506 | − _renderVoxels->setShortcut(Qt::Key_V); | |
| 1522 | + _renderVoxels->setShortcut(Qt::SHIFT | Qt::Key_V); | |
| 1507 | 1523 | (_renderVoxelTextures = renderMenu->addAction("Voxel Textures"))->setCheckable(true); |
| 1508 | 1524 | (_renderStarsOn = renderMenu->addAction("Stars"))->setCheckable(true); |
| 1509 | 1525 | _renderStarsOn->setChecked(true); |
| @@ -1545,26 +1561,29 @@ void Application::initMenu() { · 35 unmodified lines | ||
| 1545 | 1561 | _voxelModeActions->setExclusive(false); // exclusivity implies one is always checked |
| 1546 | 1562 | |
| 1547 | 1563 | (_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); | |
| 1549 | 1565 | _voxelModeActions->addAction(_addVoxelMode); |
| 1550 | 1566 | (_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); | |
| 1552 | 1568 | _voxelModeActions->addAction(_deleteVoxelMode); |
| 1553 | 1569 | (_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); | |
| 1555 | 1571 | _voxelModeActions->addAction(_colorVoxelMode); |
| 1556 | 1572 | (_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); | |
| 1558 | 1574 | _voxelModeActions->addAction(_selectVoxelMode); |
| 1559 | 1575 | (_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); | |
| 1561 | 1577 | _voxelModeActions->addAction(_eyedropperMode); |
| 1562 | − | |
| 1578 | + | |
| 1563 | 1579 | voxelMenu->addAction("Decrease Voxel Size", this, SLOT(decreaseVoxelSize()), QKeySequence::ZoomOut); |
| 1564 | 1580 | voxelMenu->addAction("Increase Voxel Size", this, SLOT(increaseVoxelSize()), QKeySequence::ZoomIn); |
| 1565 | − | |
| 1581 | + voxelMenu->addAction("Reset Swatch Colors", this, SLOT(resetSwatchColors())); | |
| 1582 | + | |
| 1566 | 1583 | _voxelPaintColor = voxelMenu->addAction("Voxel Paint Color", this, |
| 1567 | 1584 | SLOT(chooseVoxelPaintColor()), Qt::META | Qt::Key_C); |
| 1585 | + _swatch.setAction(_voxelPaintColor); | |
| 1586 | + | |
| 1568 | 1587 | QColor paintColor(128, 128, 128); |
| 1569 | 1588 | _voxelPaintColor->setData(paintColor); |
| 1570 | 1589 | _voxelPaintColor->setIcon(createSwatchIcon(paintColor)); |
| @@ -1695,6 +1714,14 @@ void Application::init() { · 124 unmodified lines | ||
| 1695 | 1714 | |
| 1696 | 1715 | |
| 1697 | 1716 | 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); | |
| 1698 | 1725 | } |
| 1699 | 1726 | |
| 1700 | 1727 | const float MAX_AVATAR_EDIT_VELOCITY = 1.0f; |
| @@ -1926,7 +1953,7 @@ void Application::update(float deltaTime) { · 225 unmodified lines | ||
| 1926 | 1953 | if (_bandwidthDialog) { |
| 1927 | 1954 | _bandwidthDialog->update(); |
| 1928 | 1955 | } |
| 1929 | − | |
| 1956 | + | |
| 1930 | 1957 | // Update audio stats for procedural sounds |
| 1931 | 1958 | #ifndef _WIN32 |
| 1932 | 1959 | _audio.setLastAcceleration(_myAvatar.getThrust()); |
| @@ -2440,7 +2467,52 @@ void Application::displayOverlay() { · 507 unmodified lines | ||
| 2440 | 2467 | |
| 2441 | 2468 | // render the webcam input frame |
| 2442 | 2469 | _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 | + | |
| 2444 | 2516 | glPopMatrix(); |
| 2445 | 2517 | } |
| 2446 | 2518 | |
| @@ -2990,7 +3062,8 @@ void Application::loadSettings(QSettings* settings) { · 543 unmodified lines | ||
| 2990 | 3062 | settings->endGroup(); |
| 2991 | 3063 | |
| 2992 | 3064 | scanMenuBar(&Application::loadAction, settings); |
| 2993 | − getAvatar()->loadData(settings); | |
| 3065 | + getAvatar()->loadData(settings); | |
| 3066 | + _swatch.loadData(settings); | |
| 2994 | 3067 | } |
| 2995 | 3068 | |
| 2996 | 3069 | |
| @@ -3012,6 +3085,7 @@ void Application::saveSettings(QSettings* settings) { · 15 unmodified lines | ||
| 3012 | 3085 | |
| 3013 | 3086 | scanMenuBar(&Application::saveAction, settings); |
| 3014 | 3087 | getAvatar()->saveData(settings); |
| 3088 | + _swatch.saveData(settings); | |
| 3015 | 3089 | } |
| 3016 | 3090 | |
| 3017 | 3091 | void Application::importSettings() { |