From e5d6a66ca9dd354b8d4b15ae80b293c02b5b9beb Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 16 May 2014 13:21:10 -0700 Subject: [PATCH] Use char array instead of QString in NodeBounds --- interface/src/ui/NodeBounds.cpp | 24 ++++++++++++------------ interface/src/ui/NodeBounds.h | 4 +++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index 40ae606733..a7d3ae062d 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -23,7 +23,7 @@ NodeBounds::NodeBounds(QObject* parent) : _showVoxelNodes(false), _showModelNodes(false), _showParticleNodes(false), - _overlayText("") { + _overlayText() { } @@ -143,12 +143,17 @@ void NodeBounds::draw() { glPopMatrix(); HifiSockAddr addr = selectedNode->getPublicSocket(); - _overlayText = QString("%1:%2 %3ms") + QString overlay = QString("%1:%2 %3ms") .arg(addr.getAddress().toString()) .arg(addr.getPort()) - .arg(selectedNode->getPingMs()); + .arg(selectedNode->getPingMs()) + .left(MAX_OVERLAY_TEXT_LENGTH); + + // Ideally we'd just use a QString, but I ran into weird blinking issues using + // constData() directly, as if the data was being overwritten. + strcpy(_overlayText, overlay.toLocal8Bit().constData()); } else { - _overlayText = QString(); + _overlayText[0] = '\0'; } } @@ -210,7 +215,7 @@ void NodeBounds::getColorForNodeType(NodeType_t nodeType, float& red, float& gre } void NodeBounds::drawOverlay() { - if (!_overlayText.isNull() && !_overlayText.isEmpty()) { + if (strlen(_overlayText) > 0) { Application* application = Application::getInstance(); const float TEXT_COLOR[] = { 0.90f, 0.90f, 0.90f }; @@ -223,17 +228,12 @@ void NodeBounds::drawOverlay() { const int BACKGROUND_OFFSET_Y = -20; const int BACKGROUND_BEVEL = 3; - int textLength = _overlayText.length(); - char textData[textLength + 1]; - strcpy(textData, _overlayText.toLatin1().constData()); - textData[textLength] = '\0'; - int mouseX = application->getMouseX(), mouseY = application->getMouseY(), - textWidth = widthText(TEXT_SCALE, 0, textData); + textWidth = widthText(TEXT_SCALE, 0, _overlayText); glColor4f(0.4, 0.4, 0.4, 0.6); renderBevelCornersRect(mouseX + MOUSE_OFFSET, mouseY - TEXT_HEIGHT - PADDING, textWidth + (2 * PADDING), TEXT_HEIGHT + (2 * PADDING), BACKGROUND_BEVEL); - drawText(mouseX + MOUSE_OFFSET + PADDING, mouseY, TEXT_SCALE, ROTATION, FONT, textData, TEXT_COLOR); + drawText(mouseX + MOUSE_OFFSET + PADDING, mouseY, TEXT_SCALE, ROTATION, FONT, _overlayText, TEXT_COLOR); } } diff --git a/interface/src/ui/NodeBounds.h b/interface/src/ui/NodeBounds.h index ae2be5f2c1..bd54b84e98 100644 --- a/interface/src/ui/NodeBounds.h +++ b/interface/src/ui/NodeBounds.h @@ -16,6 +16,8 @@ #include +const int MAX_OVERLAY_TEXT_LENGTH = 64; + class NodeBounds : public QObject { Q_OBJECT public: @@ -41,7 +43,7 @@ private: bool _showVoxelNodes; bool _showModelNodes; bool _showParticleNodes; - QString _overlayText; + char _overlayText[MAX_OVERLAY_TEXT_LENGTH + 1]; };