From 78aa3ac9f902d28159eaa04f5358252f479a625c Mon Sep 17 00:00:00 2001 From: atlante45 Date: Tue, 2 Jul 2013 16:17:25 +0200 Subject: [PATCH] Added UI responsivness --- .../resources/images/hifi-interface-tools.svg | 259 +++++++++--------- interface/src/Application.cpp | 2 +- interface/src/Swatch.cpp | 47 ++-- interface/src/Swatch.h | 4 +- interface/src/Tool.cpp | 14 +- interface/src/Tool.h | 10 +- interface/src/ToolsPalette.cpp | 30 +- interface/src/ToolsPalette.h | 5 +- 8 files changed, 194 insertions(+), 177 deletions(-) diff --git a/interface/resources/images/hifi-interface-tools.svg b/interface/resources/images/hifi-interface-tools.svg index 60b5a02fba..311514581f 100644 --- a/interface/resources/images/hifi-interface-tools.svg +++ b/interface/resources/images/hifi-interface-tools.svg @@ -1,166 +1,177 @@ - + - - - - - - - - - + width="124px" height="400px" viewBox="-0.5 0.5 124 400" enable-background="new -0.5 0.5 124 400" xml:space="preserve"> - - - - - - - - - - + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 33482aeb50..33289e4e61 100755 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1585,7 +1585,7 @@ void Application::init() { sendAvatarVoxelURLMessage(_myAvatar.getVoxels()->getVoxelURL()); - _palette.init(); + _palette.init(_glWidget->width(), _glWidget->height()); _palette.addAction(_addVoxelMode, 0, 0); _palette.addAction(_deleteVoxelMode, 0, 1); _palette.addTool(_swatch); diff --git a/interface/src/Swatch.cpp b/interface/src/Swatch.cpp index cdfde34212..3b2e4ca4a4 100644 --- a/interface/src/Swatch.cpp +++ b/interface/src/Swatch.cpp @@ -3,10 +3,7 @@ Swatch::Swatch(QAction* action) : Tool(action, 0, -1, -1), _selected(1), - _margin(4), _textRenderer(MONO_FONT_FAMILY, 10, 100) { - _width = 62; - _height = 30; } void Swatch::reset() { @@ -131,14 +128,16 @@ void Swatch::handleEvent(int key, bool getColor) { } } -void Swatch::render(int screenWidth, int screenHeight) { +void Swatch::render(int width, int height) { char str[2]; + 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(_width, 0); + glVertex2f(0, 8*(height - margin) + margin); + glVertex2f(width, 8*(height - margin) + margin); + glVertex2f(width, 0); glVertex2f(0, 0); glEnd(); @@ -147,26 +146,26 @@ void Swatch::render(int screenWidth, int screenHeight) { 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(); @@ -177,15 +176,15 @@ void Swatch::render(int screenWidth, int screenHeight) { 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) - 6, str); + _textRenderer.draw(3*width/4, (i + 1)*(height - margin) - 0.2f*height, str); } - glTranslated(0, 8*(_height - _margin) + _margin + 5, 0); + glTranslated(0, 8*(height - margin) + margin + 0.075f*height, 0); } diff --git a/interface/src/Swatch.h b/interface/src/Swatch.h index 35da266078..6727f90086 100644 --- a/interface/src/Swatch.h +++ b/interface/src/Swatch.h @@ -24,15 +24,13 @@ public: void loadData(QSettings* settings); void reset(); - void render(int screenWidth, int screenHeight); + void render(int width, int height); void handleEvent(int key, bool getColor); private: TextRenderer _textRenderer; QColor _colors[SWATCH_SIZE]; int _selected; - - int _margin; }; #endif /* defined(__interface__Swatch__) */ diff --git a/interface/src/Tool.cpp b/interface/src/Tool.cpp index c8fc4430f6..48bcfe5af6 100644 --- a/interface/src/Tool.cpp +++ b/interface/src/Tool.cpp @@ -7,16 +7,14 @@ Tool::Tool(QAction *action, GLuint texture, int x, int y) : _texture(texture), _action(action), _x(x), - _y(y), - _width(62), - _height(40) { + _y(y) { } bool Tool::isActive() { return _action->isChecked(); } -void Tool::render(int screenWidth, int screenHeight) { +void Tool::render(int width, int height) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, _texture); @@ -31,13 +29,13 @@ void Tool::render(int screenWidth, int screenHeight) { glBegin(GL_QUADS); glTexCoord2f(_x/TOOLS_COLS, 1.0f - (_y + 1)/TOOLS_ROWS); - glVertex2f(0, _height); + glVertex2f(0, height); glTexCoord2f((_x + 1)/TOOLS_COLS, 1.0f - (_y + 1)/TOOLS_ROWS); - glVertex2f(_width, _height); + glVertex2f(width, height); glTexCoord2f((_x + 1)/TOOLS_COLS, 1.0f - _y/TOOLS_ROWS); - glVertex2f(_width, 0); + glVertex2f(width, 0); glTexCoord2f(_x/TOOLS_COLS, 1.0f - _y/TOOLS_ROWS); glVertex2f(0, 0); @@ -45,5 +43,5 @@ void Tool::render(int screenWidth, int screenHeight) { glDisable(GL_TEXTURE_2D); - glTranslated(0, _height + 5, 0); + glTranslated(0, 1.10f*height, 0); } diff --git a/interface/src/Tool.h b/interface/src/Tool.h index 4b564e8578..1ff854372e 100644 --- a/interface/src/Tool.h +++ b/interface/src/Tool.h @@ -15,16 +15,12 @@ class QAction; -// tool size -static double _width; -static double _height; - class Tool { public: Tool(QAction *action, GLuint texture, int x, int y); bool isActive(); - virtual void render(int screenWidth, int screenHeight); + virtual void render(int width, int height); protected: QAction* _action; @@ -33,10 +29,6 @@ protected: // position in the SVG grid double _x; double _y; - - // tool size - double _width; - double _height; }; #endif /* defined(__interface__Tool__) */ diff --git a/interface/src/ToolsPalette.cpp b/interface/src/ToolsPalette.cpp index 5b0f550f15..2829ac3d58 100644 --- a/interface/src/ToolsPalette.cpp +++ b/interface/src/ToolsPalette.cpp @@ -6,12 +6,24 @@ #include ToolsPalette::ToolsPalette() { +} + +void ToolsPalette::init(int screenWidth, int screenHeight) { + _width = 3*screenWidth/100; + if (_width < 47) { + _width = 47; + } + _height = 40*_width/62; + + _left = screenWidth/100; + _top = (screenHeight - 12*_height)/2; + // Load SVG switchToResourcesParentIfRequired(); QSvgRenderer renderer(QString("./resources/images/hifi-interface-tools.svg")); // Prepare a QImage with desired characteritisc - QImage image(124, 400, QImage::Format_ARGB32); + QImage image(TOOLS_COLS*_width, TOOLS_ROWS*_height, QImage::Format_ARGB32); // Get QPainter that paints to the image QPainter painter(&image); @@ -19,11 +31,6 @@ ToolsPalette::ToolsPalette() { //get the OpenGL-friendly image _textureImage = QGLWidget::convertToGLFormat(image); -} - -void ToolsPalette::init(int top, int left) { - _top = top; - _left = left; glGenTextures(1, &_textureID); glBindTexture(GL_TEXTURE_2D, _textureID); @@ -51,6 +58,15 @@ void ToolsPalette::addTool(Tool *tool) { } void ToolsPalette::render(int screenWidth, int screenHeight) { + _width = 3*screenWidth/100; + if (_width < 47) { + _width = 47; + } + _height = 40*_width/62; + + _left = screenWidth/150; + _top = (screenHeight - 13*_height)/2; + glPushMatrix(); glTranslated(_left, _top, 0); @@ -64,7 +80,7 @@ void ToolsPalette::render(int screenWidth, int screenHeight) { if (show) { for (unsigned int i(0); i < _tools.size(); ++i) { - _tools[i]->render(screenWidth, screenHeight); + _tools[i]->render(_width, _height); } } diff --git a/interface/src/ToolsPalette.h b/interface/src/ToolsPalette.h index a1c99d63f6..ed1aea7e40 100644 --- a/interface/src/ToolsPalette.h +++ b/interface/src/ToolsPalette.h @@ -17,7 +17,7 @@ class ToolsPalette { public: ToolsPalette(); - void init(int top = 200, int left = 10); + void init(int screenWidth, int screenHeight); void addAction(QAction* action, int x, int y); void addTool(Tool *tool); void render(int screenWidth, int screenHeight); @@ -30,6 +30,9 @@ private: int _top; int _left; + + int _width; + int _height; }; #endif /* defined(__interface__ToolsPalette__) */