diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0a6fd4e948..2cf67b6b8c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -18,6 +18,7 @@ #include #endif +#include #include #include #include @@ -222,6 +223,7 @@ Application::Application(int& argc, char** argv) : QRect available = desktop()->availableGeometry(); _window->resize(available.size()); _window->setVisible(true); + _glWidget->setFocusPolicy(Qt::StrongFocus); _glWidget->setFocus(); // enable mouse tracking; otherwise, we only get drag events @@ -849,9 +851,10 @@ void Application::idle() { } if (_mouseMode == COLOR_VOXEL_MODE) { - _mouseVoxel.red = 0; - _mouseVoxel.green = 255; - _mouseVoxel.blue = 0; + QColor paintColor = _voxelPaintColor->data().value(); + _mouseVoxel.red = paintColor.red(); + _mouseVoxel.green = paintColor.green(); + _mouseVoxel.blue = paintColor.blue(); } else if (_mouseMode == DELETE_VOXEL_MODE) { // red indicates deletion @@ -1041,9 +1044,27 @@ void Application::setWantsResIn(bool wantsResIn) { _myAvatar.setWantResIn(wantsResIn); } + void Application::setWantsDelta(bool wantsDelta) { _myAvatar.setWantDelta(wantsDelta); } + +static QIcon createSwatchIcon(const QColor& color) { + QPixmap map(16, 16); + map.fill(color); + return QIcon(map); +} + +void Application::chooseVoxelPaintColor() { + QColor selected = QColorDialog::getColor(_voxelPaintColor->data().value(), _glWidget, "Voxel Paint Color"); + if (selected.isValid()) { + _voxelPaintColor->setData(selected); + _voxelPaintColor->setIcon(createSwatchIcon(selected)); + } + + // restore the main window's active state + _window->activateWindow(); +} void Application::initMenu() { QMenuBar* menuBar = new QMenuBar(); @@ -1080,6 +1101,10 @@ void Application::initMenu() { _renderStatsOn->setShortcut(Qt::Key_Slash); (_logOn = toolsMenu->addAction("Log"))->setCheckable(true); _logOn->setChecked(true); + _voxelPaintColor = toolsMenu->addAction("Voxel Paint Color", this, SLOT(chooseVoxelPaintColor()), Qt::Key_7); + QColor paintColor(128, 128, 128); + _voxelPaintColor->setData(paintColor); + _voxelPaintColor->setIcon(createSwatchIcon(paintColor)); toolsMenu->addAction("Create Voxel is Destructive", this, SLOT(setDestructivePaint(bool)))->setCheckable(true); QMenu* frustumMenu = menuBar->addMenu("Frustum"); @@ -1879,9 +1904,10 @@ void Application::addVoxelInFrontOfAvatar() { detail.x = detail.s * floor(position.x / detail.s); detail.y = detail.s * floor(position.y / detail.s); detail.z = detail.s * floor(position.z / detail.s); - detail.red = 128; - detail.green = 128; - detail.blue = 128; + QColor paintColor = _voxelPaintColor->data().value(); + detail.red = paintColor.red(); + detail.green = paintColor.green(); + detail.blue = paintColor.blue(); PACKET_HEADER message = (_destructiveAddVoxel ? PACKET_HEADER_SET_VOXEL_DESTRUCTIVE : PACKET_HEADER_SET_VOXEL); sendVoxelEditMessage(message, detail); diff --git a/interface/src/Application.h b/interface/src/Application.h index e22409a77b..5418d0740e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -89,6 +89,7 @@ private slots: void setWantsMonochrome(bool wantsMonochrome); void setWantsResIn(bool wantsResIn); void setWantsDelta(bool wantsDelta); + void chooseVoxelPaintColor(); private: @@ -135,6 +136,7 @@ private: QAction* _oculusOn; // Whether to configure the display for the Oculus Rift QAction* _renderStatsOn; // Whether to show onscreen text overlay with stats QAction* _logOn; // Whether to show on-screen log + QAction* _voxelPaintColor; // The color with which to paint voxels QAction* _frustumOn; // Whether or not to display the debug view frustum QAction* _viewFrustumFromOffset; // Whether or not to offset the view of the frustum QAction* _cameraFrustum; // which frustum to look at diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index e3cf16b753..249a70212e 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -103,7 +103,13 @@ VoxelNode* VoxelTree::createMissingNode(VoxelNode* lastParentNode, unsigned char int indexOfNewChild = branchIndexWithDescendant(lastParentNode->getOctalCode(), codeToReach); // we could be coming down a branch that was already created, so don't stomp on it. - if (!lastParentNode->getChildAtIndex(indexOfNewChild)) { + if (lastParentNode->isLeaf() && lastParentNode->isColored()) { + // for colored leaves, we must add *all* the children + for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { + lastParentNode->addChildAtIndex(i); + lastParentNode->getChildAtIndex(i)->setColor(lastParentNode->getColor()); + } + } else if (!lastParentNode->getChildAtIndex(indexOfNewChild)) { lastParentNode->addChildAtIndex(indexOfNewChild); }