From cda88bf4afcc4dc2b21fc89b2c672a50f7b30e57 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Mon, 30 Jun 2014 12:06:32 -0700 Subject: [PATCH 1/3] Add backgroundColor to TextOverlay --- interface/src/ui/overlays/TextOverlay.cpp | 14 +++++++++++++- interface/src/ui/overlays/TextOverlay.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index 797d0be1a2..5fc98810be 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -33,7 +33,7 @@ void TextOverlay::render() { } const float MAX_COLOR = 255; - glColor4f(0 / MAX_COLOR, 0 / MAX_COLOR, 0 / MAX_COLOR, _alpha); + glColor4f(_backgroundColor.red / MAX_COLOR, _backgroundColor.green / MAX_COLOR, _backgroundColor.blue / MAX_COLOR, _alpha); glBegin(GL_QUADS); glVertex2f(_bounds.left(), _bounds.top()); @@ -82,6 +82,18 @@ void TextOverlay::setProperties(const QScriptValue& properties) { setText(text.toVariant().toString()); } + QScriptValue backgroundColor = properties.property("backgroundColor"); + if (backgroundColor.isValid()) { + QScriptValue red = backgroundColor.property("red"); + QScriptValue green = backgroundColor.property("green"); + QScriptValue blue = backgroundColor.property("blue"); + if (red.isValid() && green.isValid() && blue.isValid()) { + _backgroundColor.red = red.toVariant().toInt(); + _backgroundColor.green = green.toVariant().toInt(); + _backgroundColor.blue = blue.toVariant().toInt(); + } + } + if (properties.property("leftMargin").isValid()) { setLeftMargin(properties.property("leftMargin").toVariant().toInt()); } diff --git a/interface/src/ui/overlays/TextOverlay.h b/interface/src/ui/overlays/TextOverlay.h index 78a037762e..6de415dcc7 100644 --- a/interface/src/ui/overlays/TextOverlay.h +++ b/interface/src/ui/overlays/TextOverlay.h @@ -55,6 +55,7 @@ public: private: QString _text; + xColor _backgroundColor; int _leftMargin; int _topMargin; int _fontSize; From 9ae65e443999d7fa9e1bb9848b413fd966c32f37 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Mon, 30 Jun 2014 12:06:50 -0700 Subject: [PATCH 2/3] Update locationsMenu.js to use backgroundColor --- examples/locationsMenu.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/locationsMenu.js b/examples/locationsMenu.js index 6f4a28fe38..24b0dabf46 100644 --- a/examples/locationsMenu.js +++ b/examples/locationsMenu.js @@ -57,7 +57,7 @@ var LocationMenu = function(opts) { y: 0, width: menuWidth + 10, height: (menuHeight * (pageSize + 1)) + 10, - color: { red: 0, green: 0, blue: 0}, + backgroundColor: { red: 0, green: 0, blue: 0}, topMargin: 4, leftMargin: 4, text: "", @@ -71,7 +71,7 @@ var LocationMenu = function(opts) { y: 0, width: menuWidth, height: menuHeight, - color: inactiveColor, + backgroundColor: inactiveColor, topMargin: margin, leftMargin: margin, text: (i == 0) ? "Loading..." : "", @@ -85,7 +85,7 @@ var LocationMenu = function(opts) { y: 0, width: menuWidth / 2, height: menuHeight, - color: disabledColor, + backgroundColor: disabledColor, topMargin: margin, leftMargin: margin, text: "Previous", @@ -97,7 +97,7 @@ var LocationMenu = function(opts) { y: 0, width: menuWidth / 2, height: menuHeight, - color: disabledColor, + backgroundColor: disabledColor, topMargin: margin, leftMargin: margin, text: "Next", @@ -175,10 +175,10 @@ var LocationMenu = function(opts) { if (start + i < this.locations.length) { location = this.locations[start + i]; update.text = (start + i + 1) + ". " + location.username; - update.color = inactiveColor; + update.backgroundColor = inactiveColor; } else { update.text = ""; - update.color = disabledColor; + update.backgroundColor = disabledColor; } Overlays.editOverlay(this.menuItems[i].overlay, update); this.menuItems[i].location = location; @@ -187,8 +187,8 @@ var LocationMenu = function(opts) { this.previousEnabled = pageNumber > 0; this.nextEnabled = pageNumber < (this.numPages - 1); - Overlays.editOverlay(this.previousButton, { color: this.previousEnabled ? prevNextColor : disabledColor}); - Overlays.editOverlay(this.nextButton, { color: this.nextEnabled ? prevNextColor : disabledColor }); + Overlays.editOverlay(this.previousButton, { backgroundColor: this.previousEnabled ? prevNextColor : disabledColor}); + Overlays.editOverlay(this.nextButton, { backgroundColor: this.nextEnabled ? prevNextColor : disabledColor }); } this.mousePressEvent = function(event) { @@ -198,17 +198,17 @@ var LocationMenu = function(opts) { self.toggleMenu(); } else if (clickedOverlay == self.previousButton) { if (self.previousEnabled) { - Overlays.editOverlay(clickedOverlay, { color: activeColor }); + Overlays.editOverlay(clickedOverlay, { backgroundColor: activeColor }); } } else if (clickedOverlay == self.nextButton) { if (self.nextEnabled) { - Overlays.editOverlay(clickedOverlay, { color: activeColor }); + Overlays.editOverlay(clickedOverlay, { backgroundColor: activeColor }); } } else { for (var i = 0; i < self.menuItems.length; i++) { if (clickedOverlay == self.menuItems[i].overlay) { if (self.menuItems[i].location != null) { - Overlays.editOverlay(clickedOverlay, { color: activeColor }); + Overlays.editOverlay(clickedOverlay, { backgroundColor: activeColor }); } break; } @@ -221,19 +221,19 @@ var LocationMenu = function(opts) { if (clickedOverlay == self.previousButton) { if (self.previousEnabled) { - Overlays.editOverlay(clickedOverlay, { color: inactiveColor }); + Overlays.editOverlay(clickedOverlay, { backgroundColor: inactiveColor }); self.goToPage(self.page - 1); } } else if (clickedOverlay == self.nextButton) { if (self.nextEnabled) { - Overlays.editOverlay(clickedOverlay, { color: inactiveColor }); + Overlays.editOverlay(clickedOverlay, { backgroundColor: inactiveColor }); self.goToPage(self.page + 1); } } else { for (var i = 0; i < self.menuItems.length; i++) { if (clickedOverlay == self.menuItems[i].overlay) { if (self.menuItems[i].location != null) { - Overlays.editOverlay(clickedOverlay, { color: inactiveColor }); + Overlays.editOverlay(clickedOverlay, { backgroundColor: inactiveColor }); var location = self.menuItems[i].location; Window.location = "hifi://" + location.domain + "/" + location.x + "," + location.y + "," + location.z; From 123773a8e384e56e52c120ab78fa4efced831ab1 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Mon, 30 Jun 2014 12:20:05 -0700 Subject: [PATCH 3/3] Add default background color and initialize property --- interface/src/ui/overlays/Overlay.cpp | 2 +- interface/src/ui/overlays/Overlay.h | 2 +- interface/src/ui/overlays/TextOverlay.cpp | 1 + interface/src/ui/overlays/TextOverlay.h | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/interface/src/ui/overlays/Overlay.cpp b/interface/src/ui/overlays/Overlay.cpp index 8ec7cbace1..bc7096c471 100644 --- a/interface/src/ui/overlays/Overlay.cpp +++ b/interface/src/ui/overlays/Overlay.cpp @@ -22,7 +22,7 @@ Overlay::Overlay() : _parent(NULL), _alpha(DEFAULT_ALPHA), - _color(DEFAULT_BACKGROUND_COLOR), + _color(DEFAULT_OVERLAY_COLOR), _visible(true), _anchor(NO_ANCHOR) { diff --git a/interface/src/ui/overlays/Overlay.h b/interface/src/ui/overlays/Overlay.h index 7667b3d3fd..f8d6400bf6 100644 --- a/interface/src/ui/overlays/Overlay.h +++ b/interface/src/ui/overlays/Overlay.h @@ -21,7 +21,7 @@ #include // for xColor -const xColor DEFAULT_BACKGROUND_COLOR = { 255, 255, 255 }; +const xColor DEFAULT_OVERLAY_COLOR = { 255, 255, 255 }; const float DEFAULT_ALPHA = 0.7f; class Overlay : public QObject { diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index 5fc98810be..691179ec54 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -18,6 +18,7 @@ #include "ui/TextRenderer.h" TextOverlay::TextOverlay() : + _backgroundColor(DEFAULT_BACKGROUND_COLOR), _leftMargin(DEFAULT_MARGIN), _topMargin(DEFAULT_MARGIN), _fontSize(DEFAULT_FONTSIZE) diff --git a/interface/src/ui/overlays/TextOverlay.h b/interface/src/ui/overlays/TextOverlay.h index 6de415dcc7..6484b6a38f 100644 --- a/interface/src/ui/overlays/TextOverlay.h +++ b/interface/src/ui/overlays/TextOverlay.h @@ -28,6 +28,7 @@ #include "Overlay.h" #include "Overlay2D.h" +const xColor DEFAULT_BACKGROUND_COLOR = { 0, 0, 0 }; const int DEFAULT_MARGIN = 10; const int DEFAULT_FONTSIZE = 11;