From 182a3e918cc6680f4eaa9612f26d2e22fd764e37 Mon Sep 17 00:00:00 2001 From: Niraj Venkat Date: Wed, 10 Jun 2015 13:12:18 -0700 Subject: [PATCH] Hyperlink properties now propagate locally and over network --- examples/html/entityProperties.html | 5 + libraries/entities/src/EntityItem.cpp | 16 ++- libraries/entities/src/EntityItem.h | 11 +- .../entities/src/EntityItemProperties.cpp | 17 ++- libraries/entities/src/EntityItemProperties.h | 8 +- .../entities/src/HyperlinkPropertyGroup.cpp | 136 ------------------ .../entities/src/HyperlinkPropertyGroup.h | 88 ------------ 7 files changed, 50 insertions(+), 231 deletions(-) delete mode 100644 libraries/entities/src/HyperlinkPropertyGroup.cpp delete mode 100644 libraries/entities/src/HyperlinkPropertyGroup.h diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index a2387a51bf..37f2d0085f 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -471,6 +471,9 @@ elScriptURL.value = properties.script; elUserData.value = properties.userData; + elHyperlinkHref.value = properties.href; + elHyperlinkDescription.value = properties.description; + for (var i = 0; i < allSections.length; i++) { for (var j = 0; j < allSections[i].length; j++) { allSections[i][j].style.display = 'none'; @@ -616,6 +619,8 @@ elLocked.addEventListener('change', createEmitCheckedPropertyUpdateFunction('locked')); elName.addEventListener('change', createEmitTextPropertyUpdateFunction('name')); + elHyperlinkHref.addEventListener('change', createEmitTextPropertyUpdateFunction('href')); + elHyperlinkDescription.addEventListener('change', createEmitTextPropertyUpdateFunction('description')); elVisible.addEventListener('change', createEmitCheckedPropertyUpdateFunction('visible')); var positionChangeFunction = createEmitVec3PropertyUpdateFunction( diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 4a10aad95d..f64dad0ef4 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -70,7 +70,9 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) : _dirtyFlags(0), _element(nullptr), _physicsInfo(nullptr), - _simulated(false) + _simulated(false), + _href(""), + _description("") { quint64 now = usecTimestampNow(); _lastSimulated = now; @@ -117,6 +119,8 @@ EntityPropertyFlags EntityItem::getEntityProperties(EncodeBitstreamParams& param requestedProperties += PROP_MARKETPLACE_ID; requestedProperties += PROP_NAME; requestedProperties += PROP_SIMULATOR_ID; + requestedProperties += PROP_HREF; + requestedProperties += PROP_DESCRIPTION; return requestedProperties; } @@ -246,6 +250,9 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, getMarketplaceID()); APPEND_ENTITY_PROPERTY(PROP_NAME, getName()); APPEND_ENTITY_PROPERTY(PROP_COLLISION_SOUND_URL, getCollisionSoundURL()); + APPEND_ENTITY_PROPERTY(PROP_HREF, getHref()); + APPEND_ENTITY_PROPERTY(PROP_DESCRIPTION, getDescription()); + appendSubclassData(packetData, params, entityTreeElementExtraEncodeData, requestedProperties, @@ -573,6 +580,9 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef READ_ENTITY_PROPERTY(PROP_NAME, QString, setName); READ_ENTITY_PROPERTY(PROP_COLLISION_SOUND_URL, QString, setCollisionSoundURL); + READ_ENTITY_PROPERTY(PROP_HREF, QString, setHref); + READ_ENTITY_PROPERTY(PROP_DESCRIPTION, QString, setDescription); + bytesRead += readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args, propertyFlags, overwriteLocalData); //////////////////////////////////// @@ -905,6 +915,8 @@ EntityItemProperties EntityItem::getProperties() const { COPY_ENTITY_PROPERTY_TO_PROPERTIES(simulatorID, getSimulatorID); COPY_ENTITY_PROPERTY_TO_PROPERTIES(marketplaceID, getMarketplaceID); COPY_ENTITY_PROPERTY_TO_PROPERTIES(name, getName); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(href, getHref); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(description, getDescription); properties._defaultSettings = false; @@ -963,6 +975,8 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(userData, setUserData); SET_ENTITY_PROPERTY_FROM_PROPERTIES(marketplaceID, setMarketplaceID); SET_ENTITY_PROPERTY_FROM_PROPERTIES(name, setName); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(href, setHref); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(description, setDescription); if (somethingChanged) { uint64_t now = usecTimestampNow(); diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 77a6627853..a145c4c236 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -203,7 +203,14 @@ public: inline const glm::quat& getRotation() const { return _transform.getRotation(); } inline void setRotation(const glm::quat& rotation) { _transform.setRotation(rotation); } - + + // Hyperlink related getters and setters + QString getHref() const { return _href; } + void setHref(QString value) { _href = value; } + + QString getDescription() const { return _description; } + void setDescription(QString value) { _description = value; } + /// Dimensions in meters (0.0 - TREE_SCALE) inline const glm::vec3& getDimensions() const { return _transform.getScale(); } virtual void setDimensions(const glm::vec3& value); @@ -415,6 +422,8 @@ protected: quint64 _simulatorIDChangedTime; // when was _simulatorID last updated? QString _marketplaceID; QString _name; + QString _href; //Hyperlink href + QString _description; //Hyperlink description // NOTE: Damping is applied like this: v *= pow(1 - damping, dt) // diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 90f2b22698..cbb3b1dc31 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -347,6 +347,9 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_VOXEL_SURFACE_STYLE, voxelSurfaceStyle); CHECK_PROPERTY_CHANGE(PROP_LINE_WIDTH, lineWidth); CHECK_PROPERTY_CHANGE(PROP_LINE_POINTS, linePoints); + CHECK_PROPERTY_CHANGE(PROP_HREF, href); + CHECK_PROPERTY_CHANGE(PROP_DESCRIPTION, description); + changedProperties += _stage.getChangedProperties(); changedProperties += _atmosphere.getChangedProperties(); changedProperties += _skybox.getChangedProperties(); @@ -439,7 +442,9 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(voxelSurfaceStyle); COPY_PROPERTY_TO_QSCRIPTVALUE(lineWidth); COPY_PROPERTY_TO_QSCRIPTVALUE(linePoints); - + COPY_PROPERTY_TO_QSCRIPTVALUE(href); + COPY_PROPERTY_TO_QSCRIPTVALUE(description); + // Sitting properties support if (!skipDefaults) { QScriptValue sittingPoints = engine->newObject(); @@ -548,6 +553,9 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelSurfaceStyle, uint16_t, setVoxelSurfaceStyle); COPY_PROPERTY_FROM_QSCRIPTVALUE(lineWidth, float, setLineWidth); COPY_PROPERTY_FROM_QSCRIPTVALUE(linePoints, qVectorVec3, setLinePoints); + COPY_PROPERTY_FROM_QSCRIPTVALUE(href, QString, setHref); + COPY_PROPERTY_FROM_QSCRIPTVALUE(description, QString, setDescription); + if (!honorReadOnly) { // this is used by the json reader to set things that we don't want javascript to able to affect. @@ -712,6 +720,8 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem APPEND_ENTITY_PROPERTY(PROP_LOCKED, properties.getLocked()); APPEND_ENTITY_PROPERTY(PROP_USER_DATA, properties.getUserData()); APPEND_ENTITY_PROPERTY(PROP_SIMULATOR_ID, properties.getSimulatorID()); + APPEND_ENTITY_PROPERTY(PROP_HREF, properties.getHref()); + APPEND_ENTITY_PROPERTY(PROP_DESCRIPTION, properties.getDescription()); if (properties.getType() == EntityTypes::Web) { APPEND_ENTITY_PROPERTY(PROP_SOURCE_URL, properties.getSourceUrl()); @@ -962,6 +972,8 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_LOCKED, bool, setLocked); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_USER_DATA, QString, setUserData); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SIMULATOR_ID, QUuid, setSimulatorID); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_HREF, QString, setHref); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_DESCRIPTION, QString, setDescription); if (properties.getType() == EntityTypes::Web) { READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SOURCE_URL, QString, setSourceUrl); @@ -1147,6 +1159,9 @@ void EntityItemProperties::markAllChanged() { _lineWidthChanged = true; _linePointsChanged = true; + _hrefChanged = true; + _descriptionChanged = true; + } /// The maximum bounding cube for the entity, independent of it's rotation. diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index e7d9a7ad18..068bc98f7e 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -36,7 +36,6 @@ #include "EntityPropertyFlags.h" #include "SkyboxPropertyGroup.h" #include "StagePropertyGroup.h" -#include "HyperlinkPropertyGroup.h" const quint64 UNKNOWN_CREATED_TIME = 0; @@ -56,7 +55,6 @@ class EntityItemProperties { friend class WebEntityItem; // TODO: consider removing this friend relationship and use public methods friend class LineEntityItem; // TODO: consider removing this friend relationship and use public methods friend class PolyVoxEntityItem; // TODO: consider removing this friend relationship and use public methods - friend class HyperlinkEntityItem; // TODO: consider removing this friend relationship and use public methods public: EntityItemProperties(); virtual ~EntityItemProperties(); @@ -150,8 +148,8 @@ public: DEFINE_PROPERTY_REF(PROP_SOURCE_URL, SourceUrl, sourceUrl, QString); DEFINE_PROPERTY(PROP_LINE_WIDTH, LineWidth, lineWidth, float); DEFINE_PROPERTY_REF(LINE_POINTS, LinePoints, linePoints, QVector); - DEFINE_PROPERTY_GROUP(Hyperlink, hyperlink, HyperlinkPropertyGroup) - + DEFINE_PROPERTY_REF(PROP_HREF, Href, href, QString); + DEFINE_PROPERTY_REF(PROP_DESCRIPTION, Description, description, QString); static QString getBackgroundModeString(BackgroundMode mode); @@ -299,6 +297,8 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelVolumeSize, voxelVolumeSize, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelData, voxelData, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelSurfaceStyle, voxelSurfaceStyle, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, Href, href, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, Description, description, ""); properties.getStage().debugDump(); properties.getAtmosphere().debugDump(); diff --git a/libraries/entities/src/HyperlinkPropertyGroup.cpp b/libraries/entities/src/HyperlinkPropertyGroup.cpp deleted file mode 100644 index bc94a8d5d3..0000000000 --- a/libraries/entities/src/HyperlinkPropertyGroup.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// -// HyperlinkPropertyGroup.cpp -// libraries/entities/src -// -// Created by Niraj Venkat on 6/9/15. -// Copyright 2013 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 - -#include "HyperlinkPropertyGroup.h" -#include "EntityItemProperties.h" -#include "EntityItemPropertiesMacros.h" - -HyperlinkPropertyGroup::HyperlinkPropertyGroup() { - const QString DEFAULT_HREF = QString(""); - const QString DEFAULT_DESCRIPTION = QString(""); - - _href = DEFAULT_HREF; - _description = DEFAULT_DESCRIPTION; -} - -void HyperlinkPropertyGroup::copyToScriptValue(QScriptValue& properties, QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const { - COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Hyperlink, hyperlink, Href, href); - COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Hyperlink, hyperlink, Description, description); -} - -void HyperlinkPropertyGroup::copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings) { - COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(Hyperlink, href, QString, setHref); - COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(Hyperlink, description, QString, setDescription); -} - -void HyperlinkPropertyGroup::debugDump() const { - qDebug() << " HyperlinkPropertyGroup: ---------------------------------------------"; - qDebug() << " Href:" << getHref() << " has changed:" << hrefChanged(); - qDebug() << " Description:" << getDescription() << " has changed:" << descriptionChanged(); -} - -bool HyperlinkPropertyGroup::appentToEditPacket(OctreePacketData* packetData, - EntityPropertyFlags& requestedProperties, - EntityPropertyFlags& propertyFlags, - EntityPropertyFlags& propertiesDidntFit, - int& propertyCount, - OctreeElement::AppendState& appendState) const { - - bool successPropertyFits = true; - - APPEND_ENTITY_PROPERTY(PROP_HREF, getHref()); - APPEND_ENTITY_PROPERTY(PROP_DESCRIPTION, getDescription()); - - return true; -} - - -bool HyperlinkPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt, int& processedBytes) { - - int bytesRead = 0; - bool overwriteLocalData = true; - - READ_ENTITY_PROPERTY(PROP_HREF, QString, setHref); - READ_ENTITY_PROPERTY(PROP_DESCRIPTION, QString, setDescription); - - DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_HREF, Href); - DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_DESCRIPTION, Description); - - processedBytes += bytesRead; - - return true; -} - -void HyperlinkPropertyGroup::markAllChanged() { - _hrefChanged = true; - _descriptionChanged = true; -} - -EntityPropertyFlags HyperlinkPropertyGroup::getChangedProperties() const { - EntityPropertyFlags changedProperties; - - CHECK_PROPERTY_CHANGE(PROP_HREF, href); - CHECK_PROPERTY_CHANGE(PROP_DESCRIPTION, description); - - return changedProperties; -} - -void HyperlinkPropertyGroup::getProperties(EntityItemProperties& properties) const { - COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Hyperlink, Href, getHref); - COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Hyperlink, Description, getDescription); -} - -bool HyperlinkPropertyGroup::setProperties(const EntityItemProperties& properties) { - bool somethingChanged = false; - - SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Hyperlink, Href, href, setHref); - SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Hyperlink, Description, description, setDescription); - - return somethingChanged; -} - -EntityPropertyFlags HyperlinkPropertyGroup::getEntityProperties(EncodeBitstreamParams& params) const { - EntityPropertyFlags requestedProperties; - - requestedProperties += PROP_HREF; - requestedProperties += PROP_DESCRIPTION; - - return requestedProperties; -} - -void HyperlinkPropertyGroup::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, - EntityTreeElementExtraEncodeData* entityTreeElementExtraEncodeData, - EntityPropertyFlags& requestedProperties, - EntityPropertyFlags& propertyFlags, - EntityPropertyFlags& propertiesDidntFit, - int& propertyCount, - OctreeElement::AppendState& appendState) const { - - bool successPropertyFits = true; - - APPEND_ENTITY_PROPERTY(PROP_HREF, getHref()); - APPEND_ENTITY_PROPERTY(PROP_DESCRIPTION, getDescription()); -} - -int HyperlinkPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, - ReadBitstreamToTreeParams& args, - EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { - - int bytesRead = 0; - const unsigned char* dataAt = data; - - READ_ENTITY_PROPERTY(PROP_DESCRIPTION, QString, setHref); - READ_ENTITY_PROPERTY(PROP_DESCRIPTION, QString, setDescription); - - return bytesRead; -} diff --git a/libraries/entities/src/HyperlinkPropertyGroup.h b/libraries/entities/src/HyperlinkPropertyGroup.h deleted file mode 100644 index b6bd40c91f..0000000000 --- a/libraries/entities/src/HyperlinkPropertyGroup.h +++ /dev/null @@ -1,88 +0,0 @@ -// -// HyperlinkPropertyGroup.h -// libraries/entities/src -// -// Created by Niraj Venkat on 6/9/15. -// Copyright 2013 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_HyperlinkPropertyGroup_h -#define hifi_HyperlinkPropertyGroup_h - -#include - -#include "PropertyGroup.h" -#include "EntityItemPropertiesMacros.h" - -class EntityItemProperties; -class EncodeBitstreamParams; -class OctreePacketData; -class EntityTreeElementExtraEncodeData; -class ReadBitstreamToTreeParams; - -#include -#include - - - -class HyperlinkPropertyGroup : public PropertyGroup { -public: - HyperlinkPropertyGroup(); - virtual ~HyperlinkPropertyGroup() {} - - // EntityItemProperty related helpers - virtual void copyToScriptValue(QScriptValue& properties, QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const; - virtual void copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings); - virtual void debugDump() const; - - virtual bool appentToEditPacket(OctreePacketData* packetData, - EntityPropertyFlags& requestedProperties, - EntityPropertyFlags& propertyFlags, - EntityPropertyFlags& propertiesDidntFit, - int& propertyCount, - OctreeElement::AppendState& appendState) const; - - virtual bool decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt, int& processedBytes); - virtual void markAllChanged(); - virtual EntityPropertyFlags getChangedProperties() const; - - // EntityItem related helpers - // methods for getting/setting all properties of an entity - virtual void getProperties(EntityItemProperties& propertiesOut) const; - - /// returns true if something changed - virtual bool setProperties(const EntityItemProperties& properties); - - virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const; - - virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, - EntityTreeElementExtraEncodeData* entityTreeElementExtraEncodeData, - EntityPropertyFlags& requestedProperties, - EntityPropertyFlags& propertyFlags, - EntityPropertyFlags& propertiesDidntFit, - int& propertyCount, - OctreeElement::AppendState& appendState) const; - - virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, - ReadBitstreamToTreeParams& args, - EntityPropertyFlags& propertyFlags, bool overwriteLocalData); - - /* - DEFINE_PROPERTY_REF(PROP_Hyperlink_CENTER, Center, center, glm::vec3); - DEFINE_PROPERTY(PROP_Hyperlink_INNER_RADIUS, InnerRadius, innerRadius, float); - DEFINE_PROPERTY(PROP_Hyperlink_OUTER_RADIUS, OuterRadius, outerRadius, float); - DEFINE_PROPERTY(PROP_Hyperlink_MIE_SCATTERING, MieScattering, mieScattering, float); - DEFINE_PROPERTY(PROP_Hyperlink_RAYLEIGH_SCATTERING, RayleighScattering, rayleighScattering, float); - DEFINE_PROPERTY_REF(PROP_Hyperlink_SCATTERING_WAVELENGTHS, ScatteringWavelengths, scatteringWavelengths, glm::vec3); - DEFINE_PROPERTY(PROP_Hyperlink_HAS_STARS, HasStars, hasStars, bool); - */ - - DEFINE_PROPERTY_REF(PROP_HREF, Href, href, QString); - DEFINE_PROPERTY_REF(PROP_DESCRIPTION, Description, description, QString); - -}; - -#endif // hifi_HyperlinkPropertyGroup_h