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()) {
switch (event->type()) {
case QEvent::KeyPress:
case QEvent::KeyRelease: {
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
auto entity = getEntities()->getTree()->findEntityByID(_keyboardFocusedEntity.get());
if (entity && entity->getEventHandler()) {
event->setAccepted(false);
QCoreApplication::sendEvent(entity->getEventHandler(), event);
if (event->isAccepted()) {
_lastAcceptedKeyPress = usecTimestampNow();
return true;
case QEvent::KeyPress:
case QEvent::KeyRelease: {
//auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
auto entity = getEntities()->getTree()->findEntityByID(_keyboardFocusedEntity.get());
if (entity && entity->getEventHandler()) {
event->setAccepted(false);
QCoreApplication::sendEvent(entity->getEventHandler(), event);
if (event->isAccepted()) {
_lastAcceptedKeyPress = usecTimestampNow();
return true;
}
}
break;
}
default:
break;
}
break;
}
default:
break;
}
}
}
{
if (_keyboardFocusedOverlay.get() != UNKNOWN_OVERLAY_ID) {
switch (event->type()) {
case QEvent::KeyPress:
case QEvent::KeyRelease: {
// Only Web overlays can have focus.
auto overlay =
std::dynamic_pointer_cast<Web3DOverlay>(getOverlays().getOverlay(_keyboardFocusedOverlay.get()));
if (overlay && overlay->getEventHandler()) {
event->setAccepted(false);
QCoreApplication::sendEvent(overlay->getEventHandler(), event);
if (event->isAccepted()) {
_lastAcceptedKeyPress = usecTimestampNow();
return true;
case QEvent::KeyPress:
case QEvent::KeyRelease: {
// Only Web overlays can have focus.
auto overlay =
std::dynamic_pointer_cast<Web3DOverlay>(getOverlays().getOverlay(_keyboardFocusedOverlay.get()));
if (overlay && overlay->getEventHandler()) {
event->setAccepted(false);
QCoreApplication::sendEvent(overlay->getEventHandler(), event);
if (event->isAccepted()) {
_lastAcceptedKeyPress = usecTimestampNow();
return true;
}
}
break;
}
default:
break;
}
break;
}
default:
break;
}
}
}
@ -3874,6 +3873,8 @@ void Application::setKeyboardFocusEntity(QUuid id) {
setKeyboardFocusEntity(entityItemID);
}
static const float FOCUS_HIGHLIGHT_EXPANSION_FACTOR = 1.05f;
void Application::setKeyboardFocusEntity(EntityItemID entityItemID) {
if (_keyboardFocusedEntity.get() != entityItemID) {
_keyboardFocusedEntity.set(entityItemID);
@ -3897,7 +3898,8 @@ void Application::setKeyboardFocusEntity(EntityItemID entityItemID) {
}
_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();
auto size = overlay->getSize() * 1.05f;
auto size = overlay->getSize() * FOCUS_HIGHLIGHT_EXPANSION_FACTOR;
const float OVERLAY_DEPTH = 0.0105f;
setKeyboardFocusHighlight(overlay->getPosition(), overlay->getRotation(), glm::vec3(size.x, size.y, OVERLAY_DEPTH));
}
@ -5508,9 +5510,9 @@ void Application::addAssetToWorldFromURLRequestFinished() {
temporaryDir.setAutoRemove(false);
if (temporaryDir.isValid()) {
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;
qInfo() << "Download path:" << downloadPath;
qInfo(interfaceapp) << "Download path:" << downloadPath;
QFile tempFile(downloadPath);
if (tempFile.open(QIODevice::WriteOnly)) {
@ -5684,7 +5686,7 @@ void Application::addAssetToWorldAddEntity(QString mapping) {
// Inform user.
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("buttons", QMessageBox::Ok);
_addAssetToWorldMessageBox->setProperty("defaultButton", QMessageBox::Ok);
@ -5716,7 +5718,7 @@ void Application::addAssetToWorldCheckModelSize() {
properties.setCollisionless(false);
properties.setLastEdited(usecTimestampNow());
entityScriptingInterface->editEntity(entityID, properties);
qInfo() << "Asset auto-resized";
qInfo(interfaceapp) << "Asset auto-resized";
}
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()) {
// Make sure position and rotation is updated.
Transform transform = getTransform();
// XXX this code runs too often for this...
// applyTransformTo(transform, true);
// setTransform(transform);
// Don't call applyTransformTo() or setTransform() here because this code runs too frequently.
// Produce the dimensions of the overlay based on the image's aspect ratio and the overlay's scale.
bool isNull = _fromImage.isNull();

View file

@ -305,8 +305,8 @@ private:
PointerEvent calculatePointerEvent(Overlay::Pointer overlay, PickRay ray, RayToOverlayIntersectionResult rayPickResult,
QMouseEvent* event, PointerEvent::EventType eventType);
unsigned int _currentClickingOnOverlayID = UNKNOWN_OVERLAY_ID;
unsigned int _currentHoverOverOverlayID = UNKNOWN_OVERLAY_ID;
unsigned int _currentClickingOnOverlayID { UNKNOWN_OVERLAY_ID };
unsigned int _currentHoverOverOverlayID { UNKNOWN_OVERLAY_ID };
};
#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) {
// FIXME - face and surfaceNormal not being returned
// Make sure position and rotation is updated.
// XXX this code runs too often for this...
//Transform transform = getTransform();
//applyTransformTo(transform, true);
//setTransform(transform);
// Don't call applyTransformTo() or setTransform() here because this code runs too frequently.
// 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);

View file

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

View file

@ -309,7 +309,7 @@ function projectOntoOverlayXYPlane(overlayID, worldPos) {
var dpi = Overlays.getProperty(overlayID, "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");
resolution.z = 1; // Circumvent divide-by-zero.
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 DEPTH = 0.025;
var DPI = dpi || DEFAULT_DPI;
var SENSOR_TO_ROOM_MATRIX = -2;
var spawnInfo = calcSpawnInfo();
var tabletEntityPosition = spawnInfo.position;
@ -63,7 +64,7 @@ WebTablet = function (url, width, dpi, clientOnly) {
}),
dimensions: {x: WIDTH, y: HEIGHT, z: DEPTH},
parentID: MyAvatar.sessionUUID,
parentJointIndex: -1
parentJointIndex: SENSOR_TO_ROOM_MATRIX
}, clientOnly);
var WEB_OVERLAY_Z_OFFSET = -0.01;