Modified code according to review for UI job

This commit is contained in:
atlante45 2013-07-09 10:25:46 +02:00
parent b062295ecb
commit d38c1f081c
9 changed files with 132 additions and 146 deletions

View file

@ -200,7 +200,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_packetCount(0),
_packetsPerSecond(0),
_bytesPerSecond(0),
_bytesCount(0)
_bytesCount(0),
_swatch(NULL)
{
_applicationStartupTime = startup_time;
_window->setWindowTitle("Interface");
@ -276,11 +277,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
FvUpdater::sharedUpdater()->SetFeedURL("https://s3-us-west-1.amazonaws.com/highfidelity/appcast.xml");
FvUpdater::sharedUpdater()->CheckForUpdatesSilent();
#endif
initMenu();
_swatch = new Swatch(_voxelPaintColor);
QRect available = desktop()->availableGeometry();
_window->resize(available.size());
_window->setVisible(true);
@ -727,7 +726,7 @@ void Application::keyPressEvent(QKeyEvent* event) {
case Qt::Key_6:
case Qt::Key_7:
case Qt::Key_8:
_swatch->handleEvent(event->key(), _eyedropperMode->isChecked());
_swatch.handleEvent(event->key(), _eyedropperMode->isChecked());
break;
default:
event->ignore();
@ -1241,7 +1240,7 @@ void Application::increaseVoxelSize() {
}
void Application::resetSwatchColors() {
_swatch->reset();
_swatch.reset();
}
static QIcon createSwatchIcon(const QColor& color) {
@ -1547,6 +1546,8 @@ void Application::initMenu() {
_voxelPaintColor = voxelMenu->addAction("Voxel Paint Color", this,
SLOT(chooseVoxelPaintColor()), Qt::META | Qt::Key_C);
_swatch.setAction(_voxelPaintColor);
QColor paintColor(128, 128, 128);
_voxelPaintColor->setData(paintColor);
_voxelPaintColor->setIcon(createSwatchIcon(paintColor));
@ -1679,7 +1680,7 @@ void Application::init() {
_palette.init(_glWidget->width(), _glWidget->height());
_palette.addAction(_addVoxelMode, 0, 0);
_palette.addAction(_deleteVoxelMode, 0, 1);
_palette.addTool(_swatch);
_palette.addTool(&_swatch);
_palette.addAction(_colorVoxelMode, 0, 2);
_palette.addAction(_eyedropperMode, 0, 3);
_palette.addAction(_selectVoxelMode, 0, 4);
@ -2434,28 +2435,28 @@ void Application::displayOverlay() {
_palette.render(_glWidget->width(), _glWidget->height());
if (_eyedropperMode->isChecked() && _voxelPaintColor->data().value<QColor>() != _swatch->getColor()) {
QColor color(_voxelPaintColor->data().value<QColor>());
if (_eyedropperMode->isChecked() && _voxelPaintColor->data().value<QColor>() != _swatch.getColor()) {
QColor color = _voxelPaintColor->data().value<QColor>();
TextRenderer textRenderer(SANS_FONT_FAMILY, 11, 50);
const char* line1("Assign this color to a swatch");
const char* line2("by choosing a key from 1 to 8.");
double step(0.05f);
int left((_glWidget->width() - 300)/2);
int top(_glWidget->height()/40.0f);
double margin(10.0f);
const char line1[] = "Assign this color to a swatch";
const char line2[] = "by choosing a key from 1 to 8.";
double step = 0.05f;
int left = (_glWidget->width() - 300) / 2;
int top = _glWidget->height() / 40.0f;
double margin = 10.0f;
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
for (double a(M_PI); a < 1.5f*M_PI; a += step) {
glVertex2f(left + margin*cos(a), top + margin*sin(a));
for (double a = M_PI; a < 1.5f * M_PI; a += step) {
glVertex2f(left + margin * cos(a), top + margin * sin(a));
}
for (double a(1.5f*M_PI); a < 2.0f*M_PI; a += step) {
glVertex2f(left + 280 + margin*cos(a), top + margin*sin(a));
for (double a = 1.5f * M_PI; a < 2.0f*M_PI; a += step) {
glVertex2f(left + 280 + margin * cos(a), top + margin * sin(a));
}
for (double a(0.0f); a < 0.5f*M_PI; a += step) {
glVertex2f(left + 280 + margin*cos(a), top + 30 + margin*sin(a));
for (double a = 0.0f; a < 0.5f * M_PI; a += step) {
glVertex2f(left + 280 + margin * cos(a), top + 30 + margin * sin(a));
}
for (double a(0.5f*M_PI); a < 1.0f*M_PI; a += step) {
for (double a = 0.5f*M_PI; a < 1.0f*M_PI; a += step) {
glVertex2f(left + margin*cos(a), top + 30 + margin*sin(a));
}
glEnd();
@ -2475,7 +2476,7 @@ void Application::displayOverlay() {
textRenderer.draw(left + 74, top + 28, line2);
}
else {
_swatch->checkColor();
_swatch.checkColor();
}
glPopMatrix();
@ -3027,7 +3028,7 @@ void Application::loadSettings(QSettings* settings) {
scanMenuBar(&Application::loadAction, settings);
getAvatar()->loadData(settings);
_swatch->loadData(settings);
_swatch.loadData(settings);
}
@ -3049,7 +3050,7 @@ void Application::saveSettings(QSettings* settings) {
scanMenuBar(&Application::saveAction, settings);
getAvatar()->saveData(settings);
_swatch->saveData(settings);
_swatch.saveData(settings);
}
void Application::importSettings() {

View file

@ -361,7 +361,7 @@ private:
int _bytesCount;
ToolsPalette _palette;
Swatch* _swatch;
Swatch _swatch;
};
#endif /* defined(__interface__Application__) */

View file

@ -1,20 +1,18 @@
#include "Swatch.h"
#include <iostream>
Swatch::Swatch(QAction* action) : Tool(action, 0, -1, -1),
_selected(1),
_textRenderer(MONO_FONT_FAMILY, 10, 100) {
Swatch::Swatch(QAction* action) :
Tool(action, 0, -1, -1),
_selected(1),
_textRenderer(MONO_FONT_FAMILY, 10, 100) {
}
void Swatch::reset() {
_colors[0].setRgb(237, 175, 0);
_colors[1].setRgb(161, 211, 72);
_colors[2].setRgb(51, 204, 204);
_colors[3].setRgb(63, 169, 245);
_colors[4].setRgb(193, 99, 122);
_colors[5].setRgb(255, 54, 69);
_colors[6].setRgb(124, 36, 36);
_colors[7].setRgb(63, 35, 19);
for (int i = 0; i < 8; ++i) {
_colors[i].setRgb(colorBase[i][0],
colorBase[i][1],
colorBase[i][2]);
}
}
QColor Swatch::getColor() {
@ -36,13 +34,13 @@ void Swatch::saveData(QSettings* settings) {
settings->beginGroup("Swatch");
for (int i(0); i < SWATCH_SIZE; ++i) {
QString name("R1");
name[1] = '1' + i;
settings->setValue(name, _colors[i].red());
name[0] = 'G';
settings->setValue(name, _colors[i].green());
name[0] = 'B';
settings->setValue(name, _colors[i].blue());
QString rx("R1"), gx("G1"), bx("B1");
rx[1] = '1' + i;
gx[1] = rx[1];
bx[1] = rx[1];
settings->setValue(rx, _colors[i].red());
settings->setValue(gx, _colors[i].green());
settings->setValue(bx, _colors[i].blue());
}
settings->endGroup();
@ -51,30 +49,15 @@ void Swatch::saveData(QSettings* settings) {
void Swatch::loadData(QSettings* settings) {
settings->beginGroup("Swatch");
_colors[0].setRgb(settings->value("R1", 237).toInt(),
settings->value("G1", 175).toInt(),
settings->value("B1", 0).toInt());
_colors[1].setRgb(settings->value("R2", 161).toInt(),
settings->value("G2", 211).toInt(),
settings->value("B2", 72).toInt());
_colors[2].setRgb(settings->value("R3", 51).toInt(),
settings->value("G3", 204).toInt(),
settings->value("B3", 204).toInt());
_colors[3].setRgb(settings->value("R4", 63).toInt(),
settings->value("G4", 169).toInt(),
settings->value("B4", 245).toInt());
_colors[4].setRgb(settings->value("R5", 193).toInt(),
settings->value("G5", 99).toInt(),
settings->value("B5", 122).toInt());
_colors[5].setRgb(settings->value("R6", 255).toInt(),
settings->value("G6", 54).toInt(),
settings->value("B6", 69).toInt());
_colors[6].setRgb(settings->value("R7", 124).toInt(),
settings->value("G7", 36).toInt(),
settings->value("B7", 36).toInt());
_colors[7].setRgb(settings->value("R8", 63).toInt(),
settings->value("G8", 35).toInt(),
settings->value("B8", 19).toInt());
for (int i = 0; i < SWATCH_SIZE; ++i) {
QString rx("R1"), gx("G1"), bx("B1");
rx[1] = '1' + i;
gx[1] = rx[1];
bx[1] = rx[1];
_colors[i].setRgb(settings->value(rx, colorBase[i][0]).toInt(),
settings->value(gx, colorBase[i][1]).toInt(),
settings->value(bx, colorBase[i][2]).toInt());
}
settings->endGroup();
@ -118,8 +101,7 @@ void Swatch::handleEvent(int key, bool getColor) {
_selected = next;
_colors[_selected - 1] = _action->data().value<QColor>();
}
}
else {
} else {
_selected = next;
QPixmap map(16, 16);
map.fill(_colors[_selected - 1]);
@ -130,61 +112,58 @@ void Swatch::handleEvent(int key, bool getColor) {
void Swatch::render(int width, int height) {
char str[2];
int margin = 0.10f*height;
height = 0.75f*height;
int margin = 0.10f * height;
height = 0.75f * height;
glBegin(GL_QUADS);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex2f(0, 8*(height - margin) + margin);
glVertex2f(width, 8*(height - margin) + margin);
glVertex2f(0, 8 * (height - margin) + margin);
glVertex2f(width, 8 * (height - margin) + margin);
glVertex2f(width, 0);
glVertex2f(0, 0);
glEnd();
for (unsigned int i(0); i < SWATCH_SIZE; ++i) {
for (unsigned int i = 0; i < SWATCH_SIZE; ++i) {
glBegin(GL_QUADS);
glColor3f(_colors[i].redF(),
_colors[i].greenF(),
_colors[i].blueF());
glVertex2f(margin, (i + 1)*(height - margin));
glVertex2f(width - margin, (i + 1)*(height - margin));
glVertex2f(width - margin, i*(height - margin) + margin);
glVertex2f(margin, i*(height - margin) + margin);
glVertex2f(margin , (i + 1) * (height - margin));
glVertex2f(width - margin, (i + 1) * (height - margin));
glVertex2f(width - margin, i * (height - margin) + margin);
glVertex2f(margin , i * (height - margin) + margin);
glEnd();
if (_colors[i].lightness() < 50) {
glBegin(GL_LINES);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex2f(margin, (i + 1)*(height - margin));
glVertex2f(width - margin, (i + 1)*(height - margin));
glVertex2f(margin , (i + 1) * (height - margin));
glVertex2f(width - margin, (i + 1) * (height - margin));
glVertex2f(width - margin, (i + 1)*(height - margin));
glVertex2f(width - margin, i*(height - margin) + margin);
glVertex2f(width - margin, (i + 1) * (height - margin));
glVertex2f(width - margin, i * (height - margin) + margin);
glVertex2f(width - margin, i*(height - margin) + margin);
glVertex2f(margin, i*(height - margin) + margin);
glVertex2f(width - margin, i * (height - margin) + margin);
glVertex2f(margin , i * (height - margin) + margin);
glVertex2f(margin, i*(height - margin) + margin);
glVertex2f(margin, (i + 1)*(height - margin));
glVertex2f(margin , i * (height - margin) + margin);
glVertex2f(margin , (i + 1) * (height - margin));
glEnd();
}
else {
} else {
glColor3f(0.0f, 0.0f, 0.0f);
}
if (_selected == i + 1) {
glBegin(GL_TRIANGLES);
glVertex2f(margin, (i + 1)*(height - margin) - margin);
glVertex2f(width/4 - margin, i*(height - margin) + height/2.0f);
glVertex2f(margin, i*(height - margin) + margin + margin);
glVertex2f(margin , (i + 1) * (height - margin) - margin);
glVertex2f(width/4 - margin, i * (height - margin) + height / 2.0f);
glVertex2f(margin , i * (height - margin) + margin + margin);
glEnd();
}
sprintf(str, "%d", i + 1);
_textRenderer.draw(3*width/4, (i + 1)*(height - margin) - 0.2f*height, str);
_textRenderer.draw(3 * width/4, (i + 1) * (height - margin) - 0.2f * height, str);
}
glTranslated(0, 8*(height - margin) + margin + 0.075f*height, 0);
glTranslated(0, 8 * (height - margin) + margin + 0.075f * height, 0);
}

View file

@ -8,16 +8,23 @@
#ifndef __interface__Swatch__
#define __interface__Swatch__
#define SWATCH_SIZE 8
#include "Tool.h"
#include "ui/TextRenderer.h"
static const int SWATCH_SIZE = 8;
static const int colorBase[8][3] = {{237, 175, 0},
{61, 211, 72},
{51, 204, 204},
{63, 169, 245},
{193, 99, 122},
{255, 54, 69},
{124, 36, 36},
{63, 35, 19}};
class Swatch : public Tool {
public:
Swatch(QAction* action);
QColor getColor();
void checkColor();
void saveData(QSettings* settings);

View file

@ -4,10 +4,15 @@
#include <QPainter>
#include <QGLWidget>
Tool::Tool(QAction *action, GLuint texture, int x, int y) : _texture(texture),
_action(action),
_x(x),
_y(y) {
Tool::Tool(QAction *action, GLuint texture, int x, int y) :
_texture(texture),
_action(action),
_x(x),
_y(y) {
}
void Tool::setAction(QAction* action) {
_action = action;
}
bool Tool::isActive() {
@ -22,26 +27,25 @@ void Tool::render(int width, int height) {
if (_action == 0 || _action->isChecked()) {
glColor3f(1.0f, 1.0f, 1.0f); // reset gl color
}
else {
} else {
glColor3f(0.3f, 0.3f, 0.3f);
}
glBegin(GL_QUADS);
glTexCoord2f(_x/TOOLS_COLS, 1.0f - (_y + 1)/TOOLS_ROWS);
glVertex2f(0, height);
glTexCoord2f( _x / NUM_TOOLS_COLS, 1.0f - (_y + 1) / NUM_TOOLS_ROWS);
glVertex2f(0 , height);
glTexCoord2f((_x + 1)/TOOLS_COLS, 1.0f - (_y + 1)/TOOLS_ROWS);
glTexCoord2f((_x + 1) / NUM_TOOLS_COLS, 1.0f - (_y + 1) / NUM_TOOLS_ROWS);
glVertex2f(width, height);
glTexCoord2f((_x + 1)/TOOLS_COLS, 1.0f - _y/TOOLS_ROWS);
glVertex2f(width, 0);
glTexCoord2f((_x + 1) / NUM_TOOLS_COLS, 1.0f - _y / NUM_TOOLS_ROWS);
glVertex2f(width, 0);
glTexCoord2f(_x/TOOLS_COLS, 1.0f - _y/TOOLS_ROWS);
glVertex2f(0, 0);
glTexCoord2f( _x / NUM_TOOLS_COLS, 1.0f - _y / NUM_TOOLS_ROWS);
glVertex2f(0 , 0);
glEnd();
glDisable(GL_TEXTURE_2D);
glTranslated(0, 1.10f*height, 0);
glTranslated(0, 1.10f * height, 0);
}

View file

@ -15,10 +15,21 @@
class QAction;
// Number of rows and columns in the SVG file for the tool palette
static const int NUM_TOOLS_ROWS = 10;
static const int NUM_TOOLS_COLS = 2;
static const int SWATCHS_TOOLS_COUNT = 13; // 8 swatch + 5 tools
static const int WIDTH_MIN = 47; // Minimal tools width
static const float TOOLS_RATIO = 40.0f / 60.0f; // ratio height/width of tools icons
static const float PAL_SCREEN_RATIO = 3.0f / 100.0f; // Percentage of the screeen width the palette is going to occupy
class Tool {
public:
Tool(QAction *action, GLuint texture, int x, int y);
Tool(QAction* action, GLuint texture, int x, int y);
void setAction(QAction* action);
bool isActive();
virtual void render(int width, int height);

View file

@ -5,25 +5,19 @@
#include <QGLWidget>
#include <SharedUtil.h>
ToolsPalette::ToolsPalette() {
}
void ToolsPalette::init(int screenWidth, int screenHeight) {
_width = 3*screenWidth/100;
if (_width < 47) {
_width = 47;
}
_height = 40*_width/62;
_width = (PAL_SCREEN_RATIO * screenWidth < WIDTH_MIN) ? WIDTH_MIN : PAL_SCREEN_RATIO * screenWidth;
_height = TOOLS_RATIO * _width;
_left = screenWidth/100;
_top = (screenHeight - 12*_height)/2;
_left = screenWidth / 150;
_top = (screenHeight - SWATCHS_TOOLS_COUNT * _height) / 2;
// Load SVG
switchToResourcesParentIfRequired();
QSvgRenderer renderer(QString("./resources/images/hifi-interface-tools.svg"));
// Prepare a QImage with desired characteritisc
QImage image(TOOLS_COLS*_width, TOOLS_ROWS*_height, QImage::Format_ARGB32);
QImage image(NUM_TOOLS_COLS * _width, NUM_TOOLS_ROWS * _height, QImage::Format_ARGB32);
// Get QPainter that paints to the image
QPainter painter(&image);
@ -36,11 +30,11 @@ void ToolsPalette::init(int screenWidth, int screenHeight) {
glBindTexture(GL_TEXTURE_2D, _textureID);
//generate the texture
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
_textureImage.width(),
_textureImage.height(),
0, GL_RGBA, GL_UNSIGNED_BYTE,
_textureImage.bits() );
_textureImage.bits());
//texture parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -53,25 +47,22 @@ void ToolsPalette::addAction(QAction* action, int x, int y) {
_tools.push_back(tmp);
}
void ToolsPalette::addTool(Tool *tool) {
void ToolsPalette::addTool(Tool* tool) {
_tools.push_back(tool);
}
void ToolsPalette::render(int screenWidth, int screenHeight) {
_width = 3*screenWidth/100;
if (_width < 47) {
_width = 47;
}
_height = 40*_width/62;
_width = (PAL_SCREEN_RATIO * screenWidth < WIDTH_MIN) ? WIDTH_MIN : PAL_SCREEN_RATIO * screenWidth;
_height = TOOLS_RATIO * _width;
_left = screenWidth/150;
_top = (screenHeight - 13*_height)/2;
_left = screenWidth / 150;
_top = (screenHeight - SWATCHS_TOOLS_COUNT * _height) / 2;
glPushMatrix();
glTranslated(_left, _top, 0);
bool show(false);
for (unsigned int i(0); i < _tools.size(); ++i) {
bool show = false;
for (unsigned int i = 0; i < _tools.size(); ++i) {
if (_tools[i]->isActive()) {
show = true;
break;
@ -79,7 +70,7 @@ void ToolsPalette::render(int screenWidth, int screenHeight) {
}
if (show) {
for (unsigned int i(0); i < _tools.size(); ++i) {
for (unsigned int i = 0; i < _tools.size(); ++i) {
_tools[i]->render(_width, _height);
}
}

View file

@ -15,14 +15,11 @@
class ToolsPalette {
public:
ToolsPalette();
void init(int screenWidth, int screenHeight);
void addAction(QAction* action, int x, int y);
void addTool(Tool *tool);
void addTool(Tool* tool);
void render(int screenWidth, int screenHeight);
private:
QImage _textureImage;
GLuint _textureID;

View file

@ -25,10 +25,6 @@
// the standard mono font family
#define MONO_FONT_FAMILY "Courier"
// Number of rows and columns in the SVG file for the tool palette
#define TOOLS_ROWS 10
#define TOOLS_COLS 2
void eulerToOrthonormals(glm::vec3 * angles, glm::vec3 * fwd, glm::vec3 * left, glm::vec3 * up);
float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos);