From 903315240147a6c58c8210e9cb30ce09bbda956b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 14 May 2013 13:49:24 -0700 Subject: [PATCH] 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