diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 79af620661..b78cff3b25 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -26,7 +26,6 @@ #include "EntityTreeRenderer.h" -const float DPI = 30.47f; const float METERS_TO_INCHES = 39.3701f; static uint32_t _currentWebCount { 0 }; // Don't allow more than 100 concurrent web views @@ -87,7 +86,7 @@ bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) { QTouchEvent::TouchPoint point; point.setId(event.getID()); point.setState(Qt::TouchPointReleased); - glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * DPI); + glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi); QPointF windowPoint(windowPos.x, windowPos.y); point.setPos(windowPoint); QList touchPoints; @@ -125,7 +124,8 @@ void RenderableWebEntityItem::render(RenderArgs* args) { _lastRenderTime = usecTimestampNow(); glm::vec2 dims = glm::vec2(getDimensions()); - dims *= METERS_TO_INCHES * DPI; + + dims *= METERS_TO_INCHES * _dpi; // The offscreen surface is idempotent for resizes (bails early // if it's a no-op), so it's safe to just call resize every frame // without worrying about excessive overhead. @@ -185,7 +185,7 @@ void RenderableWebEntityItem::handlePointerEvent(const PointerEvent& event) { return; } - glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * DPI); + glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi); QPointF windowPoint(windowPos.x, windowPos.y); if (event.getType() == PointerEvent::Move) { diff --git a/libraries/entities/src/WebEntityItem.cpp b/libraries/entities/src/WebEntityItem.cpp index b31e47608f..c97eedc56a 100644 --- a/libraries/entities/src/WebEntityItem.cpp +++ b/libraries/entities/src/WebEntityItem.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -20,8 +21,26 @@ #include "EntityTree.h" #include "EntityTreeElement.h" +const float DEFAULT_DPI = 30.47f; + const QString WebEntityItem::DEFAULT_SOURCE_URL("http://www.google.com"); +static float parseDPIFromUserData(QString str) { + QJsonParseError error; + auto doc = QJsonDocument::fromJson(str.toUtf8(), &error); + if (error.error != QJsonParseError::NoError) { + return DEFAULT_DPI; + } + QJsonObject obj = doc.object(); + + QJsonValue dpiValue = obj.value("dpi"); + if (!dpiValue.isDouble()) { + return DEFAULT_DPI; + } + double dpi = dpiValue.toDouble(); + return (float)dpi; +} + EntityItemPointer WebEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItemPointer entity { new WebEntityItem(entityID) }; entity->setProperties(properties); @@ -30,6 +49,7 @@ EntityItemPointer WebEntityItem::factory(const EntityItemID& entityID, const Ent WebEntityItem::WebEntityItem(const EntityItemID& entityItemID) : EntityItem(entityItemID) { _type = EntityTypes::Web; + _dpi = DEFAULT_DPI; } const float WEB_ENTITY_ITEM_FIXED_DEPTH = 0.01f; @@ -62,6 +82,9 @@ bool WebEntityItem::setProperties(const EntityItemProperties& properties) { setLastEdited(properties._lastEdited); } + // AJT: TODO MAKE THIS A REAL PROPERTY + _dpi = parseDPIFromUserData(getUserData()); + return somethingChanged; } diff --git a/libraries/entities/src/WebEntityItem.h b/libraries/entities/src/WebEntityItem.h index 7c4e9f801a..2179f34e36 100644 --- a/libraries/entities/src/WebEntityItem.h +++ b/libraries/entities/src/WebEntityItem.h @@ -56,6 +56,7 @@ public: protected: QString _sourceUrl; + float _dpi; }; #endif // hifi_WebEntityItem_h diff --git a/scripts/system/libraries/WebBuddy.js b/scripts/system/libraries/WebBuddy.js index d584bcc564..33b6c74c93 100644 --- a/scripts/system/libraries/WebBuddy.js +++ b/scripts/system/libraries/WebBuddy.js @@ -33,7 +33,8 @@ WebBuddy = function (url) { gravity: {x: 0, y: 0, z: 0}, shapeType: "box", userData: JSON.stringify({ - "grabbableKey": {"grabbable": true} + "grabbableKey": {"grabbable": true}, + "dpi": 75 }), parentID: MyAvatar.sessionUUID, parentJointIndex: NEGATIVE_ONE