From fea1433cedc28e4f4beeb2166673207cce946cb1 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sat, 7 Jun 2014 10:32:36 +0200 Subject: [PATCH 01/11] Add initial mybalance script --- examples/myBalance.js | 104 ++++++++++++++++++++++++++++++++++ interface/src/Application.cpp | 1 + 2 files changed, 105 insertions(+) create mode 100644 examples/myBalance.js diff --git a/examples/myBalance.js b/examples/myBalance.js new file mode 100644 index 0000000000..8cfad159e5 --- /dev/null +++ b/examples/myBalance.js @@ -0,0 +1,104 @@ +// +// myBalance.js +// examples +// +// Created by Stojce Slavkovski on June 5, 2014 +// Copyright 2014 High Fidelity, Inc. +// +// Show wallet balance +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var Controller = Controller || {}; +var Overlays = Overlays || {}; +var Script = Script || {}; +var AccountManager = AccountManager || {}; + +(function () { + "use strict"; + var iconUrl = 'http://localhost/~stojce/', + overlayWidth = 150, + overlayHeight = 150, + redColor = { + red: 255, + green: 0, + blue: 0 + }, + greenColor = { + red: 0, + green: 255, + blue: 0 + }, + whiteColor = { + red: 255, + green: 255, + blue: 255 + }, + balance = 0, + voxelTool = Overlays.addOverlay("image", { + x: 0, + y: 0, + width: 50, + height: 50, + subImage: { + x: 0, + y: 50, + width: 50, + height: 50 + }, + imageURL: iconUrl + "wallet.svg", + alpha: 1 + }), + textOverlay = Overlays.addOverlay("text", { + x: 0, + y: 0, + width: 55, + height: 13, + topMargin: 5, + text: balance, + alpha: 0 + }); + + function scriptEnding() { + Overlays.deleteOverlay(voxelTool); + Overlays.deleteOverlay(textOverlay); + } + + function update(deltaTime) { + var xPos = Controller.getViewportDimensions().x; + Overlays.editOverlay(voxelTool, { + x: xPos - 150 + }); + + Overlays.editOverlay(textOverlay, { + x: xPos - 100 + }); + } + + function updateBalance(newBalance) { + if (balance === newBalance) { + return; + } + + var change = balance - newBalance, + textColor = change > 0 ? redColor : greenColor; + + balance = newBalance; + Overlays.editOverlay(textOverlay, { + text: balance, + color: textColor + }); + + Script.setTimeout(function () { + Overlays.editOverlay(textOverlay, { + color: whiteColor + }); + }, 1000); + } + + AccountManager.balanceChanged.connect(updateBalance); + Script.scriptEnding.connect(scriptEnding); + Script.update.connect(update); +}()); \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 533d03d9e7..e3df9c17bb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3475,6 +3475,7 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("AnimationCache", &_animationCache); scriptEngine->registerGlobalObject("AudioReflector", &_audioReflector); + scriptEngine->registerGlobalObject("AccountManager", &AccountManager::getInstance()); QThread* workerThread = new QThread(this); From 6365f6b85766fda91e9fbb6230e9054ce95bcfcf Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sat, 7 Jun 2014 22:24:35 +0200 Subject: [PATCH 02/11] Extend TextOverlay to accept font size Fix TextRenderer color rendering --- interface/src/ui/TextRenderer.cpp | 8 ++++---- interface/src/ui/TextRenderer.h | 7 ++++++- interface/src/ui/overlays/TextOverlay.cpp | 17 +++++++++++++---- interface/src/ui/overlays/TextOverlay.h | 4 +++- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/interface/src/ui/TextRenderer.cpp b/interface/src/ui/TextRenderer.cpp index 2743e3e572..18279d3914 100644 --- a/interface/src/ui/TextRenderer.cpp +++ b/interface/src/ui/TextRenderer.cpp @@ -26,9 +26,9 @@ Glyph::Glyph(int textureID, const QPoint& location, const QRect& bounds, int wid } TextRenderer::TextRenderer(const char* family, int pointSize, int weight, - bool italic, EffectType effectType, int effectThickness) + bool italic, EffectType effectType, int effectThickness, QColor color) : _font(family, pointSize, weight, italic), _metrics(_font), _effectType(effectType), - _effectThickness(effectThickness), _x(IMAGE_SIZE), _y(IMAGE_SIZE), _rowHeight(0) { + _effectThickness(effectThickness), _x(IMAGE_SIZE), _y(IMAGE_SIZE), _rowHeight(0), _color(color) { _font.setKerning(false); } @@ -157,7 +157,7 @@ const Glyph& TextRenderer::getGlyph(char c) { // render the glyph into an image and copy it into the texture QImage image(bounds.width(), bounds.height(), QImage::Format_ARGB32); if (c == SOLID_BLOCK_CHAR) { - image.fill(QColor(255, 255, 255)); + image.fill(_color); } else { image.fill(0); @@ -180,7 +180,7 @@ const Glyph& TextRenderer::getGlyph(char c) { painter.setRenderHint(QPainter::Antialiasing); painter.drawPath(path); } - painter.setPen(QColor(255, 255, 255)); + painter.setPen(_color); painter.drawText(-bounds.x(), -bounds.y(), ch); } glTexSubImage2D(GL_TEXTURE_2D, 0, _x, _y, bounds.width(), bounds.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.constBits()); diff --git a/interface/src/ui/TextRenderer.h b/interface/src/ui/TextRenderer.h index 813f15a5ac..2daba79c8f 100644 --- a/interface/src/ui/TextRenderer.h +++ b/interface/src/ui/TextRenderer.h @@ -12,6 +12,7 @@ #ifndef hifi_TextRenderer_h #define hifi_TextRenderer_h +#include #include #include #include @@ -41,7 +42,8 @@ public: enum EffectType { NO_EFFECT, SHADOW_EFFECT, OUTLINE_EFFECT }; TextRenderer(const char* family, int pointSize = -1, int weight = -1, bool italic = false, - EffectType effect = NO_EFFECT, int effectThickness = 1); + EffectType effect = NO_EFFECT, int effectThickness = 1, + QColor color = QColor(255, 255, 255)); ~TextRenderer(); const QFontMetrics& metrics() const { return _metrics; } @@ -85,6 +87,9 @@ private: // the list of all texture ids for which we're responsible QVector _allTextureIDs; + + // text color + QColor _color; }; class Glyph { diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index e26c772b06..797d0be1a2 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -19,7 +19,8 @@ TextOverlay::TextOverlay() : _leftMargin(DEFAULT_MARGIN), - _topMargin(DEFAULT_MARGIN) + _topMargin(DEFAULT_MARGIN), + _fontSize(DEFAULT_FONTSIZE) { } @@ -32,7 +33,7 @@ void TextOverlay::render() { } const float MAX_COLOR = 255; - glColor4f(_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR, _alpha); + glColor4f(0 / MAX_COLOR, 0 / MAX_COLOR, 0 / MAX_COLOR, _alpha); glBegin(GL_QUADS); glVertex2f(_bounds.left(), _bounds.top()); @@ -43,8 +44,9 @@ void TextOverlay::render() { //TextRenderer(const char* family, int pointSize = -1, int weight = -1, bool italic = false, // EffectType effect = NO_EFFECT, int effectThickness = 1); - - TextRenderer textRenderer(SANS_FONT_FAMILY, 11, 50); + TextRenderer textRenderer(SANS_FONT_FAMILY, _fontSize, 50, false, TextRenderer::NO_EFFECT, 1, + QColor(_color.red, _color.green, _color.blue)); + const int leftAdjust = -1; // required to make text render relative to left edge of bounds const int topAdjust = -2; // required to make text render relative to top edge of bounds int x = _bounds.left() + _leftMargin + leftAdjust; @@ -67,6 +69,13 @@ void TextOverlay::render() { void TextOverlay::setProperties(const QScriptValue& properties) { Overlay2D::setProperties(properties); + + QScriptValue font = properties.property("font"); + if (font.isObject()) { + if (font.property("size").isValid()) { + setFontSize(font.property("size").toInt32()); + } + } QScriptValue text = properties.property("text"); if (text.isValid()) { diff --git a/interface/src/ui/overlays/TextOverlay.h b/interface/src/ui/overlays/TextOverlay.h index fc04966d07..78a037762e 100644 --- a/interface/src/ui/overlays/TextOverlay.h +++ b/interface/src/ui/overlays/TextOverlay.h @@ -29,6 +29,7 @@ #include "Overlay2D.h" const int DEFAULT_MARGIN = 10; +const int DEFAULT_FONTSIZE = 11; class TextOverlay : public Overlay2D { Q_OBJECT @@ -47,6 +48,7 @@ public: void setText(const QString& text) { _text = text; } void setLeftMargin(int margin) { _leftMargin = margin; } void setTopMargin(int margin) { _topMargin = margin; } + void setFontSize(int fontSize) { _fontSize = fontSize; } virtual void setProperties(const QScriptValue& properties); @@ -55,7 +57,7 @@ private: QString _text; int _leftMargin; int _topMargin; - + int _fontSize; }; From 976b76ac852a0303107a6ef43cc74dcd38a08b31 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sat, 7 Jun 2014 22:29:06 +0200 Subject: [PATCH 03/11] myBalance new layout changes --- examples/myBalance.js | 59 ++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/examples/myBalance.js b/examples/myBalance.js index 8cfad159e5..df47bad3a9 100644 --- a/examples/myBalance.js +++ b/examples/myBalance.js @@ -20,44 +20,43 @@ var AccountManager = AccountManager || {}; "use strict"; var iconUrl = 'http://localhost/~stojce/', overlayWidth = 150, - overlayHeight = 150, - redColor = { - red: 255, + overlayHeight = 50, + overlayTopOffset = 15, + overlayRightOffset = 100, + textRightOffset = 75, + downColor = { + red: 0, green: 0, - blue: 0 + blue: 255 }, - greenColor = { + upColor = { red: 0, green: 255, blue: 0 }, - whiteColor = { - red: 255, - green: 255, - blue: 255 + normalColor = { + red: 204, + green: 204, + blue: 204 }, balance = 0, voxelTool = Overlays.addOverlay("image", { x: 0, - y: 0, - width: 50, - height: 50, - subImage: { - x: 0, - y: 50, - width: 50, - height: 50 - }, + y: overlayTopOffset, + width: 92, + height: 32, imageURL: iconUrl + "wallet.svg", alpha: 1 }), textOverlay = Overlays.addOverlay("text", { x: 0, - y: 0, - width: 55, - height: 13, - topMargin: 5, - text: balance, + y: overlayTopOffset, + topMargin: 9, + text: balance.toFixed(4), + font: { + size: 15 + }, + color: normalColor, alpha: 0 }); @@ -69,11 +68,11 @@ var AccountManager = AccountManager || {}; function update(deltaTime) { var xPos = Controller.getViewportDimensions().x; Overlays.editOverlay(voxelTool, { - x: xPos - 150 + x: xPos - overlayRightOffset }); Overlays.editOverlay(textOverlay, { - x: xPos - 100 + x: xPos - textRightOffset }); } @@ -82,18 +81,20 @@ var AccountManager = AccountManager || {}; return; } - var change = balance - newBalance, - textColor = change > 0 ? redColor : greenColor; + var change = newBalance - balance, + textColor = change < 0 ? downColor : upColor, + integers = balance.toFixed(0).length, + decimals = integers > 4 ? 0 : integers - 4; balance = newBalance; Overlays.editOverlay(textOverlay, { - text: balance, + text: balance.toFixed(decimals), color: textColor }); Script.setTimeout(function () { Overlays.editOverlay(textOverlay, { - color: whiteColor + color: normalColor }); }, 1000); } From 8de2bdfb995d58e757576eebf1efa343a1a4124b Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sat, 7 Jun 2014 23:17:49 +0200 Subject: [PATCH 04/11] expose account details via AccountScriptingInterface --- examples/myBalance.js | 19 ++++++---- interface/src/Application.cpp | 3 +- .../scripting/AccountScriptingInterface.cpp | 37 +++++++++++++++++++ .../src/scripting/AccountScriptingInterface.h | 35 ++++++++++++++++++ 4 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 interface/src/scripting/AccountScriptingInterface.cpp create mode 100644 interface/src/scripting/AccountScriptingInterface.h diff --git a/examples/myBalance.js b/examples/myBalance.js index df47bad3a9..433967c25d 100644 --- a/examples/myBalance.js +++ b/examples/myBalance.js @@ -14,7 +14,7 @@ var Controller = Controller || {}; var Overlays = Overlays || {}; var Script = Script || {}; -var AccountManager = AccountManager || {}; +var Account = Account || {}; (function () { "use strict"; @@ -24,6 +24,7 @@ var AccountManager = AccountManager || {}; overlayTopOffset = 15, overlayRightOffset = 100, textRightOffset = 75, + maxDecimals = 5, downColor = { red: 0, green: 0, @@ -39,7 +40,7 @@ var AccountManager = AccountManager || {}; green: 204, blue: 204 }, - balance = 0, + balance = -1, voxelTool = Overlays.addOverlay("image", { x: 0, y: overlayTopOffset, @@ -52,7 +53,6 @@ var AccountManager = AccountManager || {}; x: 0, y: overlayTopOffset, topMargin: 9, - text: balance.toFixed(4), font: { size: 15 }, @@ -68,11 +68,13 @@ var AccountManager = AccountManager || {}; function update(deltaTime) { var xPos = Controller.getViewportDimensions().x; Overlays.editOverlay(voxelTool, { - x: xPos - overlayRightOffset + x: xPos - overlayRightOffset, + visible: Account.isLoggedIn() }); Overlays.editOverlay(textOverlay, { - x: xPos - textRightOffset + x: xPos - textRightOffset, + visible: Account.isLoggedIn() }); } @@ -83,8 +85,8 @@ var AccountManager = AccountManager || {}; var change = newBalance - balance, textColor = change < 0 ? downColor : upColor, - integers = balance.toFixed(0).length, - decimals = integers > 4 ? 0 : integers - 4; + integers = newBalance.toFixed(0).length, + decimals = integers > maxDecimals ? 0 : maxDecimals - integers; balance = newBalance; Overlays.editOverlay(textOverlay, { @@ -99,7 +101,8 @@ var AccountManager = AccountManager || {}; }, 1000); } - AccountManager.balanceChanged.connect(updateBalance); + updateBalance(Account.getBalance()); + Account.balanceChanged.connect(updateBalance); Script.scriptEnding.connect(scriptEnding); Script.update.connect(update); }()); \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2df6103c74..1f6f1a2c92 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -73,6 +73,7 @@ #include "devices/TV3DManager.h" #include "renderer/ProgramObject.h" +#include "scripting/AccountScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" #include "scripting/ClipboardScriptingInterface.h" #include "scripting/MenuScriptingInterface.h" @@ -3469,7 +3470,7 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("AnimationCache", &_animationCache); scriptEngine->registerGlobalObject("AudioReflector", &_audioReflector); - scriptEngine->registerGlobalObject("AccountManager", &AccountManager::getInstance()); + scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance()); QThread* workerThread = new QThread(this); diff --git a/interface/src/scripting/AccountScriptingInterface.cpp b/interface/src/scripting/AccountScriptingInterface.cpp new file mode 100644 index 0000000000..5c41298800 --- /dev/null +++ b/interface/src/scripting/AccountScriptingInterface.cpp @@ -0,0 +1,37 @@ +// +// AccountScriptingInterface.cpp +// interface/src/scripting +// +// Created by Stojce Slavkovski on 6/07/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "AccountScriptingInterface.h" + +AccountScriptingInterface::AccountScriptingInterface() { + AccountManager& accountManager = AccountManager::getInstance(); + connect(&accountManager, &AccountManager::balanceChanged, this, + &AccountScriptingInterface::updateBalance); +} + +AccountScriptingInterface* AccountScriptingInterface::getInstance() { + static AccountScriptingInterface sharedInstance; + return &sharedInstance; +} + +qint64 AccountScriptingInterface::getBalance() { + AccountManager& accountManager = AccountManager::getInstance(); + return accountManager.getAccountInfo().getBalance(); +} + +bool AccountScriptingInterface::isLoggedIn() { + AccountManager& accountManager = AccountManager::getInstance(); + return accountManager.isLoggedIn(); +} + +void AccountScriptingInterface::updateBalance(qint16 newBalance) { + emit balanceChanged(newBalance); +} diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h new file mode 100644 index 0000000000..de9a7727cd --- /dev/null +++ b/interface/src/scripting/AccountScriptingInterface.h @@ -0,0 +1,35 @@ +// +// AccountScriptingInterface.h +// interface/src/scripting +// +// Created by Stojce Slavkovski on 6/07/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_AccountScriptingInterface_h +#define hifi_AccountScriptingInterface_h + +#include +#include +#include + +#include "Application.h" + +class AccountScriptingInterface : public QObject { + Q_OBJECT + AccountScriptingInterface(); + +signals: + void balanceChanged(qint64 newBalance); + +public slots: + static AccountScriptingInterface* getInstance(); + qint64 getBalance(); + bool isLoggedIn(); + void updateBalance(qint16 newBalance); +}; + +#endif // hifi_AccountScriptingInterface_h From b3279e03ca08bd64d6db36adb94a963d1ba75ea2 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sat, 7 Jun 2014 23:27:51 +0200 Subject: [PATCH 05/11] references fix --- interface/src/scripting/AccountScriptingInterface.cpp | 2 ++ interface/src/scripting/AccountScriptingInterface.h | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/interface/src/scripting/AccountScriptingInterface.cpp b/interface/src/scripting/AccountScriptingInterface.cpp index 5c41298800..f09e2d0890 100644 --- a/interface/src/scripting/AccountScriptingInterface.cpp +++ b/interface/src/scripting/AccountScriptingInterface.cpp @@ -9,6 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "AccountManager.h" + #include "AccountScriptingInterface.h" AccountScriptingInterface::AccountScriptingInterface() { diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h index de9a7727cd..69d8ca4004 100644 --- a/interface/src/scripting/AccountScriptingInterface.h +++ b/interface/src/scripting/AccountScriptingInterface.h @@ -12,11 +12,7 @@ #ifndef hifi_AccountScriptingInterface_h #define hifi_AccountScriptingInterface_h -#include #include -#include - -#include "Application.h" class AccountScriptingInterface : public QObject { Q_OBJECT From 939f8c49defe7ce848b66f231ce7891c98be52fd Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sun, 8 Jun 2014 15:55:16 +0200 Subject: [PATCH 06/11] return balance in satoshis --- interface/src/scripting/AccountScriptingInterface.cpp | 9 +++++---- interface/src/scripting/AccountScriptingInterface.h | 6 +++--- libraries/networking/src/DataServerAccountInfo.h | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/interface/src/scripting/AccountScriptingInterface.cpp b/interface/src/scripting/AccountScriptingInterface.cpp index f09e2d0890..c7b47c7866 100644 --- a/interface/src/scripting/AccountScriptingInterface.cpp +++ b/interface/src/scripting/AccountScriptingInterface.cpp @@ -24,9 +24,9 @@ AccountScriptingInterface* AccountScriptingInterface::getInstance() { return &sharedInstance; } -qint64 AccountScriptingInterface::getBalance() { +float AccountScriptingInterface::getBalance() { AccountManager& accountManager = AccountManager::getInstance(); - return accountManager.getAccountInfo().getBalance(); + return accountManager.getAccountInfo().getBalanceInSatoshis(); } bool AccountScriptingInterface::isLoggedIn() { @@ -34,6 +34,7 @@ bool AccountScriptingInterface::isLoggedIn() { return accountManager.isLoggedIn(); } -void AccountScriptingInterface::updateBalance(qint16 newBalance) { - emit balanceChanged(newBalance); +void AccountScriptingInterface::updateBalance(qint64 newBalance) { + AccountManager& accountManager = AccountManager::getInstance(); + emit balanceChanged(accountManager.getAccountInfo().getBalanceInSatoshis()); } diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h index 69d8ca4004..38ce9c1b35 100644 --- a/interface/src/scripting/AccountScriptingInterface.h +++ b/interface/src/scripting/AccountScriptingInterface.h @@ -19,13 +19,13 @@ class AccountScriptingInterface : public QObject { AccountScriptingInterface(); signals: - void balanceChanged(qint64 newBalance); + void balanceChanged(float newBalance); public slots: static AccountScriptingInterface* getInstance(); - qint64 getBalance(); + float getBalance(); bool isLoggedIn(); - void updateBalance(qint16 newBalance); + void updateBalance(qint64 newBalance); }; #endif // hifi_AccountScriptingInterface_h diff --git a/libraries/networking/src/DataServerAccountInfo.h b/libraries/networking/src/DataServerAccountInfo.h index e0209326f9..2846d2a964 100644 --- a/libraries/networking/src/DataServerAccountInfo.h +++ b/libraries/networking/src/DataServerAccountInfo.h @@ -38,6 +38,7 @@ public: void setDiscourseApiKey(const QString& discourseApiKey); qint64 getBalance() const { return _balance; } + float getBalanceInSatoshis() const { return _balance / SATOSHIS_PER_CREDIT; } void setBalance(qint64 balance); bool hasBalance() const { return _hasBalance; } void setHasBalance(bool hasBalance) { _hasBalance = hasBalance; } From 83b096ca1df8169a448c9be3cc930cae2a3f64ca Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sun, 8 Jun 2014 15:56:37 +0200 Subject: [PATCH 07/11] myBalance - balance formatting - symbol layout changes --- examples/myBalance.js | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/examples/myBalance.js b/examples/myBalance.js index 433967c25d..2142060f61 100644 --- a/examples/myBalance.js +++ b/examples/myBalance.js @@ -5,7 +5,7 @@ // Created by Stojce Slavkovski on June 5, 2014 // Copyright 2014 High Fidelity, Inc. // -// Show wallet balance +// Show wallet ₵ balance // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -22,9 +22,9 @@ var Account = Account || {}; overlayWidth = 150, overlayHeight = 50, overlayTopOffset = 15, - overlayRightOffset = 100, - textRightOffset = 75, - maxDecimals = 5, + overlayRightOffset = 140, + textRightOffset = 105, + maxIntegers = 5, downColor = { red: 0, green: 0, @@ -41,12 +41,12 @@ var Account = Account || {}; blue: 204 }, balance = -1, - voxelTool = Overlays.addOverlay("image", { + walletBox = Overlays.addOverlay("image", { x: 0, y: overlayTopOffset, - width: 92, + width: 122, height: 32, - imageURL: iconUrl + "wallet.svg", + imageURL: iconUrl + "walletsymbol.svg", alpha: 1 }), textOverlay = Overlays.addOverlay("text", { @@ -54,20 +54,19 @@ var Account = Account || {}; y: overlayTopOffset, topMargin: 9, font: { - size: 15 + size: 16 }, - color: normalColor, - alpha: 0 + color: normalColor }); function scriptEnding() { - Overlays.deleteOverlay(voxelTool); + Overlays.deleteOverlay(walletBox); Overlays.deleteOverlay(textOverlay); } function update(deltaTime) { var xPos = Controller.getViewportDimensions().x; - Overlays.editOverlay(voxelTool, { + Overlays.editOverlay(walletBox, { x: xPos - overlayRightOffset, visible: Account.isLoggedIn() }); @@ -78,19 +77,31 @@ var Account = Account || {}; }); } + function formatedBalance() { + var integers = balance.toFixed(0).length, + decimals = Math.abs(maxIntegers - integers) + 2; + + var x = balance.toFixed(decimals).split('.'), + x1 = x[0], + x2 = x.length > 1 ? '.' + x[1] : ''; + var rgx = /(\d+)(\d{3})/; + while (rgx.test(x1)) { + x1 = x1.replace(rgx, '$1' + ',' + '$2'); + } + return x1 + x2; + } + function updateBalance(newBalance) { if (balance === newBalance) { return; } var change = newBalance - balance, - textColor = change < 0 ? downColor : upColor, - integers = newBalance.toFixed(0).length, - decimals = integers > maxDecimals ? 0 : maxDecimals - integers; + textColor = change < 0 ? downColor : upColor; balance = newBalance; Overlays.editOverlay(textOverlay, { - text: balance.toFixed(decimals), + text: formatedBalance(), color: textColor }); From 2cde2f530395a0c6b2c0b7326e3a24c3ff31432b Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sun, 8 Jun 2014 16:03:43 +0200 Subject: [PATCH 08/11] use worklist for assets --- examples/myBalance.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/myBalance.js b/examples/myBalance.js index 2142060f61..e0dbd7c370 100644 --- a/examples/myBalance.js +++ b/examples/myBalance.js @@ -18,7 +18,7 @@ var Account = Account || {}; (function () { "use strict"; - var iconUrl = 'http://localhost/~stojce/', + var iconUrl = 'http://dev.worklist.net/~stojce/', overlayWidth = 150, overlayHeight = 50, overlayTopOffset = 15, @@ -52,7 +52,7 @@ var Account = Account || {}; textOverlay = Overlays.addOverlay("text", { x: 0, y: overlayTopOffset, - topMargin: 9, + topMargin: 10, font: { size: 16 }, From e25817cd88d3794800fc205fec5142083a2ab29e Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Tue, 10 Jun 2014 00:08:10 +0200 Subject: [PATCH 09/11] switch to amazon image resources --- examples/myBalance.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/myBalance.js b/examples/myBalance.js index e0dbd7c370..bd48e8fd21 100644 --- a/examples/myBalance.js +++ b/examples/myBalance.js @@ -18,7 +18,7 @@ var Account = Account || {}; (function () { "use strict"; - var iconUrl = 'http://dev.worklist.net/~stojce/', + var iconUrl = 'http://highfidelity-public.s3-us-west-1.amazonaws.com/images/tools/', overlayWidth = 150, overlayHeight = 50, overlayTopOffset = 15, @@ -46,7 +46,7 @@ var Account = Account || {}; y: overlayTopOffset, width: 122, height: 32, - imageURL: iconUrl + "walletsymbol.svg", + imageURL: iconUrl + "wallet.svg", alpha: 1 }), textOverlay = Overlays.addOverlay("text", { From 9824072300fcdccf67cea024349e89a2cecde64f Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Tue, 17 Jun 2014 23:51:02 +0200 Subject: [PATCH 10/11] remove unused parameter in `AccountScriptingInterface::updateBalance` --- interface/src/scripting/AccountScriptingInterface.cpp | 5 +++-- interface/src/scripting/AccountScriptingInterface.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/interface/src/scripting/AccountScriptingInterface.cpp b/interface/src/scripting/AccountScriptingInterface.cpp index c7b47c7866..ec52eef416 100644 --- a/interface/src/scripting/AccountScriptingInterface.cpp +++ b/interface/src/scripting/AccountScriptingInterface.cpp @@ -15,8 +15,9 @@ AccountScriptingInterface::AccountScriptingInterface() { AccountManager& accountManager = AccountManager::getInstance(); - connect(&accountManager, &AccountManager::balanceChanged, this, + bool succ = connect(&accountManager, &AccountManager::balanceChanged, this, &AccountScriptingInterface::updateBalance); + } AccountScriptingInterface* AccountScriptingInterface::getInstance() { @@ -34,7 +35,7 @@ bool AccountScriptingInterface::isLoggedIn() { return accountManager.isLoggedIn(); } -void AccountScriptingInterface::updateBalance(qint64 newBalance) { +void AccountScriptingInterface::updateBalance() { AccountManager& accountManager = AccountManager::getInstance(); emit balanceChanged(accountManager.getAccountInfo().getBalanceInSatoshis()); } diff --git a/interface/src/scripting/AccountScriptingInterface.h b/interface/src/scripting/AccountScriptingInterface.h index 38ce9c1b35..e9cf0ede5f 100644 --- a/interface/src/scripting/AccountScriptingInterface.h +++ b/interface/src/scripting/AccountScriptingInterface.h @@ -25,7 +25,7 @@ public slots: static AccountScriptingInterface* getInstance(); float getBalance(); bool isLoggedIn(); - void updateBalance(qint64 newBalance); + void updateBalance(); }; #endif // hifi_AccountScriptingInterface_h From 591ab448a12c58ec1214a65da08f3324505c81a5 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Tue, 17 Jun 2014 23:54:55 +0200 Subject: [PATCH 11/11] remove unused variable --- interface/src/scripting/AccountScriptingInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/scripting/AccountScriptingInterface.cpp b/interface/src/scripting/AccountScriptingInterface.cpp index ec52eef416..87ea3220a4 100644 --- a/interface/src/scripting/AccountScriptingInterface.cpp +++ b/interface/src/scripting/AccountScriptingInterface.cpp @@ -15,7 +15,7 @@ AccountScriptingInterface::AccountScriptingInterface() { AccountManager& accountManager = AccountManager::getInstance(); - bool succ = connect(&accountManager, &AccountManager::balanceChanged, this, + connect(&accountManager, &AccountManager::balanceChanged, this, &AccountScriptingInterface::updateBalance); }