diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5f446fcf2f..7c7c455d1d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -1152,8 +1153,7 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { showMouse = false; } - QMouseEvent deviceEvent = getDeviceEvent(event, deviceID); - _controllerScriptingInterface.emitMouseMoveEvent(&deviceEvent, deviceID); // send events to any registered scripts + _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { @@ -1168,13 +1168,12 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { _seenMouseMove = true; } - _mouseX = deviceEvent.x(); - _mouseY = deviceEvent.y(); + _mouseX = event->x(); + _mouseY = event->y(); } void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { - QMouseEvent deviceEvent = getDeviceEvent(event, deviceID); - _controllerScriptingInterface.emitMousePressEvent(&deviceEvent); // send events to any registered scripts + _controllerScriptingInterface.emitMousePressEvent(event); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { @@ -1184,8 +1183,8 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { if (activeWindow() == _window) { if (event->button() == Qt::LeftButton) { - _mouseX = deviceEvent.x(); - _mouseY = deviceEvent.y(); + _mouseX = event->x(); + _mouseY = event->y(); _mouseDragStartedX = _mouseX; _mouseDragStartedY = _mouseY; _mousePressed = true; @@ -1207,8 +1206,7 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { } void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { - QMouseEvent deviceEvent = getDeviceEvent(event, deviceID); - _controllerScriptingInterface.emitMouseReleaseEvent(&deviceEvent); // send events to any registered scripts + _controllerScriptingInterface.emitMouseReleaseEvent(event); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { @@ -1217,8 +1215,8 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { if (activeWindow() == _window) { if (event->button() == Qt::LeftButton) { - _mouseX = deviceEvent.x(); - _mouseY = deviceEvent.y(); + _mouseX = event->x(); + _mouseY = event->y(); _mousePressed = false; checkBandwidthMeterClick(); if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) { @@ -1417,7 +1415,7 @@ void Application::checkBandwidthMeterClick() { if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth) && glm::compMax(glm::abs(glm::ivec2(_mouseX - _mouseDragStartedX, _mouseY - _mouseDragStartedY))) <= BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH - && _bandwidthMeter.isWithinArea(_mouseX, _mouseY, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight())) { + && _bandwidthMeter.isWithinArea(_mouseX, _mouseY, _glWidget->width(), _glWidget->height())) { // The bandwidth meter is visible, the click didn't get dragged too far and // we actually hit the bandwidth meter @@ -1735,8 +1733,8 @@ void Application::init() { _voxelShader.init(); _pointShader.init(); - _mouseX = _glWidget->getDeviceWidth() / 2; - _mouseY = _glWidget->getDeviceHeight() / 2; + _mouseX = _glWidget->width() / 2; + _mouseY = _glWidget->height() / 2; QCursor::setPos(_mouseX, _mouseY); // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager @@ -1891,8 +1889,8 @@ void Application::updateMouseRay() { // if the mouse pointer isn't visible, act like it's at the center of the screen float x = 0.5f, y = 0.5f; if (!_mouseHidden) { - x = _mouseX / (float)_glWidget->getDeviceWidth(); - y = _mouseY / (float)_glWidget->getDeviceHeight(); + x = _mouseX / (float)_glWidget->width(); + y = _mouseY / (float)_glWidget->height(); } _viewFrustum.computePickRay(x, y, _mouseRayOrigin, _mouseRayDirection); @@ -2332,14 +2330,6 @@ int Application::sendNackPackets() { return packetsSent; } -QMouseEvent Application::getDeviceEvent(QMouseEvent* event, unsigned int deviceID) { - if (deviceID > 0) { - return *event; - } - return QMouseEvent(event->type(), QPointF(_glWidget->getDeviceX(event->x()), _glWidget->getDeviceY(event->y())), - event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers()); -} - void Application::queryOctree(NodeType_t serverType, PacketType packetType, NodeToJurisdictionMap& jurisdictions) { //qDebug() << ">>> inside... queryOctree()... _viewFrustum.getFieldOfView()=" << _viewFrustum.getFieldOfView(); @@ -3041,8 +3031,16 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { _mirrorCamera.update(1.0f/_fps); // set the bounds of rear mirror view - glViewport(region.x(), _glWidget->getDeviceHeight() - region.y() - region.height(), region.width(), region.height()); - glScissor(region.x(), _glWidget->getDeviceHeight() - region.y() - region.height(), region.width(), region.height()); + if (billboard) { + glViewport(region.x(), _glWidget->getDeviceHeight() - region.y() - region.height(), region.width(), region.height()); + glScissor(region.x(), _glWidget->getDeviceHeight() - region.y() - region.height(), region.width(), region.height()); + } else { + // if not rendering the billboard, the region is in device independent coordinates; must convert to device + float ratio = QApplication::desktop()->windowHandle()->devicePixelRatio(); + int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio; + glViewport(x, _glWidget->getDeviceHeight() - y - height, width, height); + glScissor(x, _glWidget->getDeviceHeight() - y - height, width, height); + } bool updateViewFrustum = false; updateProjectionMatrix(_mirrorCamera, updateViewFrustum); glEnable(GL_SCISSOR_TEST); @@ -3291,8 +3289,8 @@ void Application::deleteVoxelAt(const VoxelDetail& voxel) { void Application::resetSensors() { - _mouseX = _glWidget->getDeviceWidth() / 2; - _mouseY = _glWidget->getDeviceHeight() / 2; + _mouseX = _glWidget->width() / 2; + _mouseY = _glWidget->height() / 2; _faceplus.reset(); _faceshift.reset(); diff --git a/interface/src/Application.h b/interface/src/Application.h index f46eef881c..f48d88d7a4 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -436,8 +436,6 @@ private: int sendNackPackets(); - QMouseEvent getDeviceEvent(QMouseEvent* event, unsigned int deviceID); - MainWindow* _window; GLCanvas* _glWidget; // our GLCanvas has a couple extra features diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index c4df0f7f2a..4a924b4ec3 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -262,8 +262,8 @@ CameraScriptableObject::CameraScriptableObject(Camera* camera, ViewFrustum* view } PickRay CameraScriptableObject::computePickRay(float x, float y) { - float screenWidth = Application::getInstance()->getGLWidget()->getDeviceWidth(); - float screenHeight = Application::getInstance()->getGLWidget()->getDeviceHeight(); + float screenWidth = Application::getInstance()->getGLWidget()->width(); + float screenHeight = Application::getInstance()->getGLWidget()->height(); PickRay result; if (OculusManager::isConnected()) { result.origin = _camera->getPosition(); diff --git a/interface/src/GLCanvas.cpp b/interface/src/GLCanvas.cpp index e63e79f1f0..108b9ba829 100644 --- a/interface/src/GLCanvas.cpp +++ b/interface/src/GLCanvas.cpp @@ -43,14 +43,6 @@ int GLCanvas::getDeviceHeight() const { return height() * (windowHandle() ? windowHandle()->devicePixelRatio() : 1.0f); } -int GLCanvas::getDeviceX(int x) const { - return x * getDeviceWidth() / width(); -} - -int GLCanvas::getDeviceY(int y) const { - return y * getDeviceHeight() / height(); -} - void GLCanvas::initializeGL() { Application::getInstance()->initializeGL(); setAttribute(Qt::WA_AcceptTouchEvents); diff --git a/interface/src/GLCanvas.h b/interface/src/GLCanvas.h index 22cdaae75f..0d381fa0bf 100644 --- a/interface/src/GLCanvas.h +++ b/interface/src/GLCanvas.h @@ -26,9 +26,6 @@ public: int getDeviceHeight() const; QSize getDeviceSize() const { return QSize(getDeviceWidth(), getDeviceHeight()); } - int getDeviceX(int x) const; - int getDeviceY(int y) const; - protected: QTimer _frameTimer; diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index ca32adb6ba..5c7e89fc37 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -11,6 +11,9 @@ #include +#include +#include + #include #include #include @@ -655,7 +658,8 @@ void Avatar::renderDisplayName() { if (success) { double textWindowHeight = abs(result1[1] - result0[1]); - float scaleFactor = (textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f; + float scaleFactor = QApplication::desktop()->windowHandle()->devicePixelRatio() * + ((textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f); glScalef(scaleFactor, scaleFactor, 1.0); glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index b4a11231ed..d6c74e4a5d 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -209,8 +209,8 @@ void PrioVR::renderCalibrationCountdown() { } static TextRenderer textRenderer(MONO_FONT_FAMILY, 18, QFont::Bold, false, TextRenderer::OUTLINE_EFFECT, 2); QByteArray text = "Assume T-Pose in " + QByteArray::number(secondsRemaining) + "..."; - textRenderer.draw((Application::getInstance()->getGLWidget()->getDeviceWidth() - - textRenderer.computeWidth(text.constData())) / 2, Application::getInstance()->getGLWidget()->getDeviceHeight() / 2, + textRenderer.draw((Application::getInstance()->getGLWidget()->width() - + textRenderer.computeWidth(text.constData())) / 2, Application::getInstance()->getGLWidget()->height() / 2, text); #endif } diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 86c4b17cb2..417b0619f8 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -396,10 +396,10 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) { float yAngle = 0.5f - ((atan2(direction.z, direction.y) + M_PI_2)); // Get the pixel range over which the xAngle and yAngle are scaled - float cursorRange = widget->getDeviceWidth() * getCursorPixelRangeMult(); + float cursorRange = widget->width() * getCursorPixelRangeMult(); - pos.setX(widget->getDeviceWidth() / 2.0f + cursorRange * xAngle); - pos.setY(widget->getDeviceHeight() / 2.0f + cursorRange * yAngle); + pos.setX(widget->width() / 2.0f + cursorRange * xAngle); + pos.setY(widget->height() / 2.0f + cursorRange * yAngle); } diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 0ebcfea987..b58568c365 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -257,7 +257,7 @@ void ControllerScriptingInterface::releaseJoystick(int joystickIndex) { glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { GLCanvas* widget = Application::getInstance()->getGLWidget(); - return glm::vec2(widget->getDeviceWidth(), widget->getDeviceHeight()); + return glm::vec2(widget->width(), widget->height()); } AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) { diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index ccb32e286a..20ed1d9d58 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -99,14 +99,14 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { glPushMatrix(); glLoadIdentity(); - gluOrtho2D(0, glWidget->getDeviceWidth(), glWidget->getDeviceHeight(), 0); + gluOrtho2D(0, glWidget->width(), glWidget->height(), 0); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); renderAudioMeter(); if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)) { - myAvatar->renderHeadMouse(glWidget->getDeviceWidth(), glWidget->getDeviceHeight()); + myAvatar->renderHeadMouse(glWidget->width(), glWidget->height()); } renderStatsAndLogs(); @@ -305,8 +305,8 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { float u = asin(collisionPos.x) / (_textureFov)+0.5f; float v = 1.0 - (asin(collisionPos.y) / (_textureFov)+0.5f); - rv.setX(u * glWidget->getDeviceWidth()); - rv.setY(v * glWidget->getDeviceHeight()); + rv.setX(u * glWidget->width()); + rv.setY(v * glWidget->height()); } } else { //if they did not click on the overlay, just set the coords to INT_MAX @@ -323,8 +323,8 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { ndcSpacePos = glm::vec3(clipSpacePos) / clipSpacePos.w; } - rv.setX(((ndcSpacePos.x + 1.0) / 2.0) * glWidget->getDeviceWidth()); - rv.setY((1.0 - ((ndcSpacePos.y + 1.0) / 2.0)) * glWidget->getDeviceHeight()); + rv.setX(((ndcSpacePos.x + 1.0) / 2.0) * glWidget->width()); + rv.setY((1.0 - ((ndcSpacePos.y + 1.0) / 2.0)) * glWidget->height()); } return rv; } @@ -496,11 +496,11 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as //draw the mouse pointer glBindTexture(GL_TEXTURE_2D, _crosshairTexture); - const float reticleSize = 40.0f / application->getGLWidget()->getDeviceWidth() * quadWidth; + const float reticleSize = 40.0f / application->getGLWidget()->width() * quadWidth; x -= reticleSize / 2.0f; y += reticleSize / 2.0f; - const float mouseX = (application->getMouseX() / (float)application->getGLWidget()->getDeviceWidth()) * quadWidth; - const float mouseY = (1.0 - (application->getMouseY() / (float)application->getGLWidget()->getDeviceHeight())) * quadHeight; + const float mouseX = (application->getMouseX() / (float)application->getGLWidget()->width()) * quadWidth; + const float mouseY = (1.0 - (application->getMouseY() / (float)application->getGLWidget()->height())) * quadHeight; glBegin(GL_QUADS); @@ -671,14 +671,14 @@ void ApplicationOverlay::renderControllerPointers() { float yAngle = 0.5f - ((atan2(direction.z, direction.y) + M_PI_2)); // Get the pixel range over which the xAngle and yAngle are scaled - float cursorRange = glWidget->getDeviceWidth() * application->getSixenseManager()->getCursorPixelRangeMult(); + float cursorRange = glWidget->width() * application->getSixenseManager()->getCursorPixelRangeMult(); - mouseX = (glWidget->getDeviceWidth() / 2.0f + cursorRange * xAngle); - mouseY = (glWidget->getDeviceHeight() / 2.0f + cursorRange * yAngle); + mouseX = (glWidget->width() / 2.0f + cursorRange * xAngle); + mouseY = (glWidget->height() / 2.0f + cursorRange * yAngle); } //If the cursor is out of the screen then don't render it - if (mouseX < 0 || mouseX >= glWidget->getDeviceWidth() || mouseY < 0 || mouseY >= glWidget->getDeviceHeight()) { + if (mouseX < 0 || mouseX >= glWidget->width() || mouseY < 0 || mouseY >= glWidget->height()) { _reticleActive[index] = false; continue; } @@ -709,8 +709,8 @@ void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) { GLCanvas* glWidget = application->getGLWidget(); glm::vec3 cursorVerts[4]; - const int widgetWidth = glWidget->getDeviceWidth(); - const int widgetHeight = glWidget->getDeviceHeight(); + const int widgetWidth = glWidget->width(); + const int widgetHeight = glWidget->height(); const float reticleSize = 50.0f; @@ -850,8 +850,8 @@ void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY, float sizeMult, Application* application = Application::getInstance(); GLCanvas* glWidget = application->getGLWidget(); - const int widgetWidth = glWidget->getDeviceWidth(); - const int widgetHeight = glWidget->getDeviceHeight(); + const int widgetWidth = glWidget->width(); + const int widgetHeight = glWidget->height(); const float magnifyWidth = MAGNIFY_WIDTH * sizeMult; const float magnifyHeight = MAGNIFY_HEIGHT * sizeMult; @@ -968,7 +968,7 @@ void ApplicationOverlay::renderAudioMeter() { float collisionSoundMagnitude = audio->getCollisionSoundMagnitude(); const float VISIBLE_COLLISION_SOUND_MAGNITUDE = 0.5f; if (collisionSoundMagnitude > VISIBLE_COLLISION_SOUND_MAGNITUDE) { - renderCollisionOverlay(glWidget->getDeviceWidth(), glWidget->getDeviceHeight(), + renderCollisionOverlay(glWidget->width(), glWidget->height(), audio->getCollisionSoundMagnitude()); } } @@ -1019,16 +1019,16 @@ void ApplicationOverlay::renderAudioMeter() { if ((audio->getTimeSinceLastClip() > 0.f) && (audio->getTimeSinceLastClip() < CLIPPING_INDICATOR_TIME)) { const float MAX_MAGNITUDE = 0.7f; float magnitude = MAX_MAGNITUDE * (1 - audio->getTimeSinceLastClip() / CLIPPING_INDICATOR_TIME); - renderCollisionOverlay(glWidget->getDeviceWidth(), glWidget->getDeviceHeight(), magnitude, 1.0f); + renderCollisionOverlay(glWidget->width(), glWidget->height(), magnitude, 1.0f); } audio->renderToolBox(MIRROR_VIEW_LEFT_PADDING + AUDIO_METER_GAP, audioMeterY, Menu::getInstance()->isOptionChecked(MenuOption::Mirror)); - audio->renderScope(glWidget->getDeviceWidth(), glWidget->getDeviceHeight()); + audio->renderScope(glWidget->width(), glWidget->height()); - audio->renderStats(WHITE_TEXT, glWidget->getDeviceWidth(), glWidget->getDeviceHeight()); + audio->renderStats(WHITE_TEXT, glWidget->width(), glWidget->height()); glBegin(GL_QUADS); if (isClipping) { @@ -1108,8 +1108,8 @@ void ApplicationOverlay::renderStatsAndLogs() { application->getPacketsPerSecond(), application->getBytesPerSecond(), voxelPacketsToProcess); // Bandwidth meter if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth)) { - Stats::drawBackground(0x33333399, glWidget->getDeviceWidth() - 296, glWidget->getDeviceHeight() - 68, 296, 68); - bandwidthMeter->render(glWidget->getDeviceWidth(), glWidget->getDeviceHeight()); + Stats::drawBackground(0x33333399, glWidget->width() - 296, glWidget->height() - 68, 296, 68); + bandwidthMeter->render(glWidget->width(), glWidget->height()); } } @@ -1122,7 +1122,7 @@ void ApplicationOverlay::renderStatsAndLogs() { (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth)) ? 80 : 20; - drawText(glWidget->getDeviceWidth() - 100, glWidget->getDeviceHeight() - timerBottom, + drawText(glWidget->width() - 100, glWidget->height() - timerBottom, 0.30f, 0.0f, 0, frameTimer, WHITE_TEXT); } nodeBoundsDisplay.drawOverlay(); @@ -1247,8 +1247,8 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { if (nodeList && !nodeList->getDomainHandler().isConnected()) { GLCanvas* glWidget = Application::getInstance()->getGLWidget(); - int right = glWidget->getDeviceWidth(); - int bottom = glWidget->getDeviceHeight(); + int right = glWidget->width(); + int bottom = glWidget->height(); glColor3f(CONNECTION_STATUS_BORDER_COLOR[0], CONNECTION_STATUS_BORDER_COLOR[1], diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index a17aed6c42..e3bd3a5cc3 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -41,8 +41,8 @@ void NodeBounds::draw() { // itself after the cursor disappears. Application* application = Application::getInstance(); GLCanvas* glWidget = application->getGLWidget(); - float mouseX = application->getMouseX() / (float)glWidget->getDeviceWidth(); - float mouseY = application->getMouseY() / (float)glWidget->getDeviceHeight(); + float mouseX = application->getMouseX() / (float)glWidget->width(); + float mouseY = application->getMouseY() / (float)glWidget->height(); glm::vec3 mouseRayOrigin; glm::vec3 mouseRayDirection; application->getViewFrustum()->computePickRay(mouseX, mouseY, mouseRayOrigin, mouseRayDirection); diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 76a803e2b8..6b7d499bf9 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -57,7 +57,7 @@ Stats::Stats(): _metavoxelReceiveTotal(0) { GLCanvas* glWidget = Application::getInstance()->getGLWidget(); - resetWidth(glWidget->getDeviceWidth(), 0); + resetWidth(glWidget->width(), 0); } void Stats::toggleExpanded() { @@ -114,7 +114,7 @@ void Stats::checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseD // top-right stats click lines = _expanded ? 11 : 3; statsHeight = lines * STATS_PELS_PER_LINE + 10; - statsWidth = glWidget->getDeviceWidth() - statsX; + statsWidth = glWidget->width() - statsX; if (mouseX > statsX && mouseX < statsX + statsWidth && mouseY > statsY && mouseY < statsY + statsHeight) { toggleExpanded(); return; @@ -123,7 +123,7 @@ void Stats::checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseD void Stats::resetWidth(int width, int horizontalOffset) { GLCanvas* glWidget = Application::getInstance()->getGLWidget(); - int extraSpace = glWidget->getDeviceWidth() - horizontalOffset -2 + int extraSpace = glWidget->width() - horizontalOffset -2 - STATS_GENERAL_MIN_WIDTH - (Menu::getInstance()->isOptionChecked(MenuOption::TestPing) ? STATS_PING_MIN_WIDTH -1 : 0) - STATS_GEO_MIN_WIDTH @@ -147,7 +147,7 @@ void Stats::resetWidth(int width, int horizontalOffset) { _pingStatsWidth += (int) extraSpace / panels; } _geoStatsWidth += (int) extraSpace / panels; - _voxelStatsWidth += glWidget->getDeviceWidth() - (_generalStatsWidth + _pingStatsWidth + _geoStatsWidth + 3); + _voxelStatsWidth += glWidget->width() - (_generalStatsWidth + _pingStatsWidth + _geoStatsWidth + 3); } } @@ -210,7 +210,7 @@ void Stats::display( std::stringstream voxelStats; if (_lastHorizontalOffset != horizontalOffset) { - resetWidth(glWidget->getDeviceWidth(), horizontalOffset); + resetWidth(glWidget->width(), horizontalOffset); _lastHorizontalOffset = horizontalOffset; } @@ -410,7 +410,7 @@ void Stats::display( } } - drawBackground(backgroundColor, horizontalOffset, 0, glWidget->getDeviceWidth() - horizontalOffset, + drawBackground(backgroundColor, horizontalOffset, 0, glWidget->width() - horizontalOffset, lines * STATS_PELS_PER_LINE + 10); horizontalOffset += 5; diff --git a/interface/src/ui/TextRenderer.cpp b/interface/src/ui/TextRenderer.cpp index 18279d3914..4ced8c1f2e 100644 --- a/interface/src/ui/TextRenderer.cpp +++ b/interface/src/ui/TextRenderer.cpp @@ -9,11 +9,14 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include +#include #include #include #include #include #include +#include #include "InterfaceConfig.h" #include "TextRenderer.h" @@ -25,10 +28,17 @@ Glyph::Glyph(int textureID, const QPoint& location, const QRect& bounds, int wid _textureID(textureID), _location(location), _bounds(bounds), _width(width) { } -TextRenderer::TextRenderer(const char* family, int pointSize, int weight, - 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), _color(color) { +TextRenderer::TextRenderer(const char* family, int pointSize, int weight, 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), + _color(color) { + _font.setKerning(false); } @@ -73,7 +83,7 @@ int TextRenderer::draw(int x, int y, const char* str) { int bottom = y + glyph.bounds().y(); int top = y + glyph.bounds().y() + glyph.bounds().height(); - float scale = 1.0 / IMAGE_SIZE; + float scale = QApplication::desktop()->windowHandle()->devicePixelRatio() / IMAGE_SIZE; float ls = glyph.location().x() * scale; float rs = (glyph.location().x() + glyph.bounds().width()) * scale; float bt = glyph.location().y() * scale; @@ -119,21 +129,25 @@ const Glyph& TextRenderer::getGlyph(char c) { } // we use 'J' as a representative size for the solid block character QChar ch = (c == SOLID_BLOCK_CHAR) ? QChar('J') : QChar(c); - QRect bounds = _metrics.boundingRect(ch); - if (bounds.isEmpty()) { + QRect baseBounds = _metrics.boundingRect(ch); + if (baseBounds.isEmpty()) { glyph = Glyph(0, QPoint(), QRect(), _metrics.width(ch)); return glyph; } // grow the bounds to account for effect, if any if (_effectType == SHADOW_EFFECT) { - bounds.adjust(-_effectThickness, 0, 0, _effectThickness); + baseBounds.adjust(-_effectThickness, 0, 0, _effectThickness); } else if (_effectType == OUTLINE_EFFECT) { - bounds.adjust(-_effectThickness, -_effectThickness, _effectThickness, _effectThickness); + baseBounds.adjust(-_effectThickness, -_effectThickness, _effectThickness, _effectThickness); } // grow the bounds to account for antialiasing - bounds.adjust(-1, -1, 1, 1); + baseBounds.adjust(-1, -1, 1, 1); + + // adjust bounds for device pixel scaling + float ratio = QApplication::desktop()->windowHandle()->devicePixelRatio(); + QRect bounds(baseBounds.x() * ratio, baseBounds.y() * ratio, baseBounds.width() * ratio, baseBounds.height() * ratio); if (_x + bounds.width() > IMAGE_SIZE) { // we can't fit it on the current row; move to next @@ -162,9 +176,16 @@ const Glyph& TextRenderer::getGlyph(char c) { } else { image.fill(0); QPainter painter(&image); - painter.setFont(_font); + QFont font = _font; + if (ratio == 1.0f) { + painter.setFont(_font); + } else { + QFont enlargedFont = _font; + enlargedFont.setPointSize(_font.pointSize() * ratio); + painter.setFont(enlargedFont); + } if (_effectType == SHADOW_EFFECT) { - for (int i = 0; i < _effectThickness; i++) { + for (int i = 0; i < _effectThickness * ratio; i++) { painter.drawText(-bounds.x() - 1 - i, -bounds.y() + 1 + i, ch); } } else if (_effectType == OUTLINE_EFFECT) { @@ -173,7 +194,7 @@ const Glyph& TextRenderer::getGlyph(char c) { font.setStyleStrategy(QFont::ForceOutline); path.addText(-bounds.x() - 0.5, -bounds.y() + 0.5, font, ch); QPen pen; - pen.setWidth(_effectThickness); + pen.setWidth(_effectThickness * ratio); pen.setJoinStyle(Qt::RoundJoin); pen.setCapStyle(Qt::RoundCap); painter.setPen(pen); @@ -185,7 +206,7 @@ const Glyph& TextRenderer::getGlyph(char c) { } glTexSubImage2D(GL_TEXTURE_2D, 0, _x, _y, bounds.width(), bounds.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.constBits()); - glyph = Glyph(_currentTextureID, QPoint(_x, _y), bounds, _metrics.width(ch)); + glyph = Glyph(_currentTextureID, QPoint(_x / ratio, _y / ratio), baseBounds, _metrics.width(ch)); _x += bounds.width(); _rowHeight = qMax(_rowHeight, bounds.height());