Code review

This commit is contained in:
David Rowe 2016-12-13 13:11:21 +13:00
parent 8a399c7cc0
commit efb784f703
7 changed files with 49 additions and 51 deletions

View file

@ -2332,48 +2332,47 @@ bool Application::event(QEvent* event) {
{ {
if (!_keyboardFocusedEntity.get().isInvalidID()) { if (!_keyboardFocusedEntity.get().isInvalidID()) {
switch (event->type()) { switch (event->type()) {
case QEvent::KeyPress: case QEvent::KeyPress:
case QEvent::KeyRelease: { case QEvent::KeyRelease: {
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); //auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
auto entity = getEntities()->getTree()->findEntityByID(_keyboardFocusedEntity.get()); auto entity = getEntities()->getTree()->findEntityByID(_keyboardFocusedEntity.get());
if (entity && entity->getEventHandler()) { if (entity && entity->getEventHandler()) {
event->setAccepted(false); event->setAccepted(false);
QCoreApplication::sendEvent(entity->getEventHandler(), event); QCoreApplication::sendEvent(entity->getEventHandler(), event);
if (event->isAccepted()) { if (event->isAccepted()) {
_lastAcceptedKeyPress = usecTimestampNow(); _lastAcceptedKeyPress = usecTimestampNow();
return true; return true;
}
} }
break;
}
default:
break;
} }
break;
}
default:
break;
}
} }
} }
{ {
if (_keyboardFocusedOverlay.get() != UNKNOWN_OVERLAY_ID) { if (_keyboardFocusedOverlay.get() != UNKNOWN_OVERLAY_ID) {
switch (event->type()) { switch (event->type()) {
case QEvent::KeyPress: case QEvent::KeyPress:
case QEvent::KeyRelease: { case QEvent::KeyRelease: {
// Only Web overlays can have focus. // Only Web overlays can have focus.
auto overlay = auto overlay =
std::dynamic_pointer_cast<Web3DOverlay>(getOverlays().getOverlay(_keyboardFocusedOverlay.get())); std::dynamic_pointer_cast<Web3DOverlay>(getOverlays().getOverlay(_keyboardFocusedOverlay.get()));
if (overlay && overlay->getEventHandler()) { if (overlay && overlay->getEventHandler()) {
event->setAccepted(false); event->setAccepted(false);
QCoreApplication::sendEvent(overlay->getEventHandler(), event); QCoreApplication::sendEvent(overlay->getEventHandler(), event);
if (event->isAccepted()) { if (event->isAccepted()) {
_lastAcceptedKeyPress = usecTimestampNow(); _lastAcceptedKeyPress = usecTimestampNow();
return true; return true;
}
} }
break;
}
default:
break;
} }
break;
}
default:
break;
}
} }
} }
@ -3874,6 +3873,8 @@ void Application::setKeyboardFocusEntity(QUuid id) {
setKeyboardFocusEntity(entityItemID); setKeyboardFocusEntity(entityItemID);
} }
static const float FOCUS_HIGHLIGHT_EXPANSION_FACTOR = 1.05f;
void Application::setKeyboardFocusEntity(EntityItemID entityItemID) { void Application::setKeyboardFocusEntity(EntityItemID entityItemID) {
if (_keyboardFocusedEntity.get() != entityItemID) { if (_keyboardFocusedEntity.get() != entityItemID) {
_keyboardFocusedEntity.set(entityItemID); _keyboardFocusedEntity.set(entityItemID);
@ -3897,7 +3898,8 @@ void Application::setKeyboardFocusEntity(EntityItemID entityItemID) {
} }
_lastAcceptedKeyPress = usecTimestampNow(); _lastAcceptedKeyPress = usecTimestampNow();
setKeyboardFocusHighlight(entity->getPosition(), entity->getRotation(), entity->getDimensions() * 1.05f); setKeyboardFocusHighlight(entity->getPosition(), entity->getRotation(),
entity->getDimensions() * FOCUS_HIGHLIGHT_EXPANSION_FACTOR);
} }
} }
} }
@ -3930,7 +3932,7 @@ void Application::setKeyboardFocusOverlay(unsigned int overlayID) {
} }
_lastAcceptedKeyPress = usecTimestampNow(); _lastAcceptedKeyPress = usecTimestampNow();
auto size = overlay->getSize() * 1.05f; auto size = overlay->getSize() * FOCUS_HIGHLIGHT_EXPANSION_FACTOR;
const float OVERLAY_DEPTH = 0.0105f; const float OVERLAY_DEPTH = 0.0105f;
setKeyboardFocusHighlight(overlay->getPosition(), overlay->getRotation(), glm::vec3(size.x, size.y, OVERLAY_DEPTH)); setKeyboardFocusHighlight(overlay->getPosition(), overlay->getRotation(), glm::vec3(size.x, size.y, OVERLAY_DEPTH));
} }
@ -5508,9 +5510,9 @@ void Application::addAssetToWorldFromURLRequestFinished() {
temporaryDir.setAutoRemove(false); temporaryDir.setAutoRemove(false);
if (temporaryDir.isValid()) { if (temporaryDir.isValid()) {
QString temporaryDirPath = temporaryDir.path(); QString temporaryDirPath = temporaryDir.path();
QString filename = url.section("filename=", 1, 1); QString filename = url.section("filename=", 1, 1); // Filename from trailing "?filename=" URL parameter.
QString downloadPath = temporaryDirPath + "/" + filename; QString downloadPath = temporaryDirPath + "/" + filename;
qInfo() << "Download path:" << downloadPath; qInfo(interfaceapp) << "Download path:" << downloadPath;
QFile tempFile(downloadPath); QFile tempFile(downloadPath);
if (tempFile.open(QIODevice::WriteOnly)) { if (tempFile.open(QIODevice::WriteOnly)) {
@ -5684,7 +5686,7 @@ void Application::addAssetToWorldAddEntity(QString mapping) {
// Inform user. // Inform user.
QString successInfo = "Asset " + mapping.mid(1) + " added to world."; QString successInfo = "Asset " + mapping.mid(1) + " added to world.";
qInfo() << "Downloading asset completed: " + successInfo; qInfo(interfaceapp) << "Downloading asset completed: " + successInfo;
_addAssetToWorldMessageBox->setProperty("text", successInfo); _addAssetToWorldMessageBox->setProperty("text", successInfo);
_addAssetToWorldMessageBox->setProperty("buttons", QMessageBox::Ok); _addAssetToWorldMessageBox->setProperty("buttons", QMessageBox::Ok);
_addAssetToWorldMessageBox->setProperty("defaultButton", QMessageBox::Ok); _addAssetToWorldMessageBox->setProperty("defaultButton", QMessageBox::Ok);
@ -5716,7 +5718,7 @@ void Application::addAssetToWorldCheckModelSize() {
properties.setCollisionless(false); properties.setCollisionless(false);
properties.setLastEdited(usecTimestampNow()); properties.setLastEdited(usecTimestampNow());
entityScriptingInterface->editEntity(entityID, properties); entityScriptingInterface->editEntity(entityID, properties);
qInfo() << "Asset auto-resized"; qInfo(interfaceapp) << "Asset auto-resized";
} }
item = _addAssetToWorldResizeList.erase(item); // Finished with this entity. item = _addAssetToWorldResizeList.erase(item); // Finished with this entity.

View file

@ -202,9 +202,8 @@ bool Image3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec
if (_texture && _texture->isLoaded()) { if (_texture && _texture->isLoaded()) {
// Make sure position and rotation is updated. // Make sure position and rotation is updated.
Transform transform = getTransform(); Transform transform = getTransform();
// XXX this code runs too often for this...
// applyTransformTo(transform, true); // Don't call applyTransformTo() or setTransform() here because this code runs too frequently.
// setTransform(transform);
// Produce the dimensions of the overlay based on the image's aspect ratio and the overlay's scale. // Produce the dimensions of the overlay based on the image's aspect ratio and the overlay's scale.
bool isNull = _fromImage.isNull(); bool isNull = _fromImage.isNull();

View file

@ -305,8 +305,8 @@ private:
PointerEvent calculatePointerEvent(Overlay::Pointer overlay, PickRay ray, RayToOverlayIntersectionResult rayPickResult, PointerEvent calculatePointerEvent(Overlay::Pointer overlay, PickRay ray, RayToOverlayIntersectionResult rayPickResult,
QMouseEvent* event, PointerEvent::EventType eventType); QMouseEvent* event, PointerEvent::EventType eventType);
unsigned int _currentClickingOnOverlayID = UNKNOWN_OVERLAY_ID; unsigned int _currentClickingOnOverlayID { UNKNOWN_OVERLAY_ID };
unsigned int _currentHoverOverOverlayID = UNKNOWN_OVERLAY_ID; unsigned int _currentHoverOverOverlayID { UNKNOWN_OVERLAY_ID };
}; };
#endif // hifi_Overlays_h #endif // hifi_Overlays_h

View file

@ -346,11 +346,7 @@ glm::vec2 Web3DOverlay::getSize() {
bool Web3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face, glm::vec3& surfaceNormal) { bool Web3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face, glm::vec3& surfaceNormal) {
// FIXME - face and surfaceNormal not being returned // FIXME - face and surfaceNormal not being returned
// Make sure position and rotation is updated. // Don't call applyTransformTo() or setTransform() here because this code runs too frequently.
// XXX this code runs too often for this...
//Transform transform = getTransform();
//applyTransformTo(transform, true);
//setTransform(transform);
// Produce the dimensions of the overlay based on the image's aspect ratio and the overlay's scale. // Produce the dimensions of the overlay based on the image's aspect ratio and the overlay's scale.
return findRayRectangleIntersection(origin, direction, getRotation(), getPosition(), getSize(), distance); return findRayRectangleIntersection(origin, direction, getRotation(), getPosition(), getSize(), distance);

View file

@ -34,7 +34,7 @@ QString ResourceRequest::getResultString() const {
case Timeout: return "Timeout"; case Timeout: return "Timeout";
case ServerUnavailable: return "Server Unavailable"; case ServerUnavailable: return "Server Unavailable";
case AccessDenied: return "Access Denied"; case AccessDenied: return "Access Denied";
case InvalidURL: return "Ivalid URL"; case InvalidURL: return "Invalid URL";
case NotFound: return "Not Found"; case NotFound: return "Not Found";
default: return "Unspecified Error"; default: return "Unspecified Error";
} }

View file

@ -309,7 +309,7 @@ function projectOntoOverlayXYPlane(overlayID, worldPos) {
var dpi = Overlays.getProperty(overlayID, "dpi"); var dpi = Overlays.getProperty(overlayID, "dpi");
if (dpi) { if (dpi) {
// Calculate physical dimensions for web3d overlay; "dimensions" property is used as a scale. // Calculate physical dimensions for web3d overlay from resolution and dpi; "dimensions" property is used as a scale.
var resolution = Overlays.getProperty(overlayID, "resolution"); var resolution = Overlays.getProperty(overlayID, "resolution");
resolution.z = 1; // Circumvent divide-by-zero. resolution.z = 1; // Circumvent divide-by-zero.
var scale = Overlays.getProperty(overlayID, "dimensions"); var scale = Overlays.getProperty(overlayID, "dimensions");

View file

@ -47,6 +47,7 @@ WebTablet = function (url, width, dpi, clientOnly) {
var HEIGHT = WIDTH * ASPECT * TABLET_HEIGHT_SCALE; var HEIGHT = WIDTH * ASPECT * TABLET_HEIGHT_SCALE;
var DEPTH = 0.025; var DEPTH = 0.025;
var DPI = dpi || DEFAULT_DPI; var DPI = dpi || DEFAULT_DPI;
var SENSOR_TO_ROOM_MATRIX = -2;
var spawnInfo = calcSpawnInfo(); var spawnInfo = calcSpawnInfo();
var tabletEntityPosition = spawnInfo.position; var tabletEntityPosition = spawnInfo.position;
@ -63,7 +64,7 @@ WebTablet = function (url, width, dpi, clientOnly) {
}), }),
dimensions: {x: WIDTH, y: HEIGHT, z: DEPTH}, dimensions: {x: WIDTH, y: HEIGHT, z: DEPTH},
parentID: MyAvatar.sessionUUID, parentID: MyAvatar.sessionUUID,
parentJointIndex: -1 parentJointIndex: SENSOR_TO_ROOM_MATRIX
}, clientOnly); }, clientOnly);
var WEB_OVERLAY_Z_OFFSET = -0.01; var WEB_OVERLAY_Z_OFFSET = -0.01;