From 903315240147a6c58c8210e9cb30ce09bbda956b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 14 May 2013 13:49:24 -0700 Subject: [PATCH 1/5] Color selection for painting. --- interface/src/Application.cpp | 33 ++++++++++++++++++++++++++------- interface/src/Application.h | 2 ++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7844f08686..b7761a7042 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -18,6 +18,7 @@ #include #endif +#include #include #include #include @@ -848,9 +849,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 @@ -1035,7 +1037,21 @@ void Application::setWantsMonochrome(bool wantsMonochrome) { void Application::setWantsResIn(bool wantsResIn) { _myAvatar.setWantResIn(wantsResIn); } - + +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)); + } +} + void Application::initMenu() { QMenuBar* menuBar = new QMenuBar(); _window->setMenuBar(menuBar); @@ -1071,6 +1087,8 @@ 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); + _voxelPaintColor->setIcon(createSwatchIcon(QColor())); QMenu* frustumMenu = menuBar->addMenu("Frustum"); (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true); @@ -1866,9 +1884,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(); sendVoxelEditMessage(PACKET_HEADER_SET_VOXEL, detail); diff --git a/interface/src/Application.h b/interface/src/Application.h index 035f705b41..6ad644de63 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -87,6 +87,7 @@ private slots: void doTreeStats(); void setWantsMonochrome(bool wantsMonochrome); void setWantsResIn(bool wantsResIn); + void chooseVoxelPaintColor(); private: @@ -133,6 +134,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 From ebc612f87aeef6e4b8ecc7ea22381d28b41a08b0 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 14 May 2013 14:23:08 -0700 Subject: [PATCH 2/5] Start out with gray, fix coloring smaller portions by (similar to deleting) breaking up leaf nodes into their components. --- interface/src/Application.cpp | 4 +++- libraries/voxels/src/VoxelTree.cpp | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 289c2b7a45..0275de2d9f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1093,7 +1093,9 @@ void Application::initMenu() { (_logOn = toolsMenu->addAction("Log"))->setCheckable(true); _logOn->setChecked(true); _voxelPaintColor = toolsMenu->addAction("Voxel Paint Color", this, SLOT(chooseVoxelPaintColor()), Qt::Key_7); - _voxelPaintColor->setIcon(createSwatchIcon(QColor())); + QColor paintColor(128, 128, 128); + _voxelPaintColor->setData(paintColor); + _voxelPaintColor->setIcon(createSwatchIcon(paintColor)); QMenu* frustumMenu = menuBar->addMenu("Frustum"); (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true); diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index d22073a54b..fb9e33dc47 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); } From 053c0d1ca57201b036790cef78c1f430719d2e40 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 14 May 2013 14:34:36 -0700 Subject: [PATCH 3/5] Focus tweak; focus isn't returning to the GL widget after closing the color dialog on OS X. --- interface/src/Application.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0275de2d9f..a0c0a151a8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -222,6 +222,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 From b4ca7ca5e350391b86c564d0791cd9a3f08c8b8b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 14 May 2013 14:36:43 -0700 Subject: [PATCH 4/5] Just manually request focus. --- interface/src/Application.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a0c0a151a8..0f50d67a69 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1056,6 +1056,7 @@ void Application::chooseVoxelPaintColor() { _voxelPaintColor->setData(selected); _voxelPaintColor->setIcon(createSwatchIcon(selected)); } + _glWidget->setFocus(); } void Application::initMenu() { From e1016ad902edef66bd587c9899d7c3b010f82c18 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 14 May 2013 14:40:18 -0700 Subject: [PATCH 5/5] What matters is the active state, not the focus. --- interface/src/Application.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0f50d67a69..4816d96c87 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1056,7 +1056,9 @@ void Application::chooseVoxelPaintColor() { _voxelPaintColor->setData(selected); _voxelPaintColor->setIcon(createSwatchIcon(selected)); } - _glWidget->setFocus(); + + // restore the main window's active state + _window->activateWindow(); } void Application::initMenu() {