This commit is contained in:
Stephen Birarda 2015-02-06 14:20:03 -08:00
commit bde0f0ef73
5 changed files with 109 additions and 16 deletions

View file

@ -23,6 +23,7 @@
// include this before QGLWidget, which includes an earlier version of OpenGL // include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h" #include "InterfaceConfig.h"
#include <QAbstractNativeEventFilter>
#include <QActionGroup> #include <QActionGroup>
#include <QColorDialog> #include <QColorDialog>
#include <QDesktopWidget> #include <QDesktopWidget>
@ -144,6 +145,37 @@ const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::D
const QString DEFAULT_SCRIPTS_JS_URL = "http://s3.amazonaws.com/hifi-public/scripts/defaultScripts.js"; const QString DEFAULT_SCRIPTS_JS_URL = "http://s3.amazonaws.com/hifi-public/scripts/defaultScripts.js";
#ifdef Q_OS_WIN
class MyNativeEventFilter : public QAbstractNativeEventFilter {
public:
static MyNativeEventFilter& getInstance() {
static MyNativeEventFilter staticInstance;
return staticInstance;
}
bool nativeEventFilter(const QByteArray &eventType, void* msg, long* result) Q_DECL_OVERRIDE {
if (eventType == "windows_generic_MSG") {
MSG* message = (MSG*)msg;
if (message->message == UWM_IDENTIFY_INSTANCES) {
*result = UWM_IDENTIFY_INSTANCES;
return true;
}
if (message->message == WM_SHOWWINDOW) {
Application::getInstance()->getWindow()->showNormal();
}
if (message->message == WM_COPYDATA) {
COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)(message->lParam);
QUrl url = QUrl((const char*)(pcds->lpData));
if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) {
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
}
}
}
return false;
}
};
#endif
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message); QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message);
@ -244,6 +276,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_aboutToQuit(false), _aboutToQuit(false),
_notifiedPacketVersionMismatchThisDomain(false) _notifiedPacketVersionMismatchThisDomain(false)
{ {
#ifdef Q_OS_WIN
installNativeEventFilter(&MyNativeEventFilter::getInstance());
#endif
_logger = new FileLogger(this); // After setting organization name in order to get correct directory _logger = new FileLogger(this); // After setting organization name in order to get correct directory
qInstallMessageHandler(messageHandler); qInstallMessageHandler(messageHandler);

View file

@ -114,6 +114,11 @@ static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS
static const QString INFO_HELP_PATH = "html/interface-welcome-allsvg.html"; static const QString INFO_HELP_PATH = "html/interface-welcome-allsvg.html";
static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-entities-commands.html"; static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-entities-commands.html";
#ifdef Q_OS_WIN
static const UINT UWM_IDENTIFY_INSTANCES =
RegisterWindowMessage("UWM_IDENTIFY_INSTANCES_{8AB82783-B74A-4258-955B-8188C22AA0D6}");
#endif
class Application; class Application;
#if defined(qApp) #if defined(qApp)
#undef qApp #undef qApp

View file

@ -15,9 +15,53 @@
#include <SharedUtil.h> #include <SharedUtil.h>
#include "AddressManager.h"
#include "Application.h" #include "Application.h"
#ifdef Q_OS_WIN
static BOOL CALLBACK enumWindowsCallback(HWND hWnd, LPARAM lParam) {
const UINT TIMEOUT = 200; // ms
DWORD response;
LRESULT result = SendMessageTimeout(hWnd, UWM_IDENTIFY_INSTANCES, 0, 0, SMTO_BLOCK | SMTO_ABORTIFHUNG, TIMEOUT, &response);
if (result == 0) { // Timeout; continue search.
return TRUE;
}
if (response == UWM_IDENTIFY_INSTANCES) {
HWND* target = (HWND*)lParam;
*target = hWnd;
return FALSE; // Found; terminate search.
}
return TRUE; // Not found; continue search.
}
#endif
int main(int argc, const char * argv[]) { int main(int argc, const char * argv[]) {
#ifdef Q_OS_WIN
// Run only one instance of Interface at a time.
HANDLE mutex = CreateMutex(NULL, FALSE, "High Fidelity Interface");
DWORD result = GetLastError();
if (result == ERROR_ALREADY_EXISTS || result == ERROR_ACCESS_DENIED) {
// Interface is already running.
HWND otherInstance = NULL;
EnumWindows(enumWindowsCallback, (LPARAM)&otherInstance);
if (otherInstance) {
ShowWindow(otherInstance, SW_RESTORE);
SetForegroundWindow(otherInstance);
QUrl url = QUrl(argv[1]);
if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) {
COPYDATASTRUCT cds;
cds.cbData = strlen(argv[1]) + 1;
cds.lpData = (PVOID)argv[1];
SendMessage(otherInstance, WM_COPYDATA, 0, (LPARAM)&cds);
}
}
return 0;
}
#endif
QElapsedTimer startupTime; QElapsedTimer startupTime;
startupTime.start(); startupTime.start();
@ -44,6 +88,11 @@ int main(int argc, const char * argv[]) {
qDebug( "Created QT Application."); qDebug( "Created QT Application.");
exitCode = app.exec(); exitCode = app.exec();
} }
#ifdef Q_OS_WIN
ReleaseMutex(mutex);
#endif
qDebug("Normal exit."); qDebug("Normal exit.");
return exitCode; return exitCode;
} }

View file

@ -119,7 +119,7 @@ void Circle3DOverlay::render(RenderArgs* args) {
glPushMatrix(); glPushMatrix();
glm::vec3 positionToCenter = center - position; glm::vec3 positionToCenter = center - position;
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
glScalef(dimensions.x, dimensions.y, 1.0f); glScalef(dimensions.x / 2.0f, dimensions.y / 2.0f, 1.0f);
glLineWidth(_lineWidth); glLineWidth(_lineWidth);
@ -417,19 +417,19 @@ bool Circle3DOverlay::findRayIntersection(const glm::vec3& origin,
const glm::vec3& direction, float& distance, BoxFace& face) { const glm::vec3& direction, float& distance, BoxFace& face) {
bool intersects = Planar3DOverlay::findRayIntersection(origin, direction, distance, face); bool intersects = Planar3DOverlay::findRayIntersection(origin, direction, distance, face);
if (intersects) {
glm::vec3 hitAt = origin + (direction * distance);
float distanceToHit = glm::distance(hitAt, _position);
float maxDimension = glm::max(_dimensions.x, _dimensions.y); if (intersects) {
float innerRadius = maxDimension * getInnerRadius(); glm::vec3 hitPosition = origin + (distance * direction);
float outerRadius = maxDimension * getOuterRadius(); glm::vec3 localHitPosition = glm::inverse(_rotation) * (hitPosition - _position);
localHitPosition.y = localHitPosition.y * _dimensions.x / _dimensions.y; // Scale to make circular
// TODO: this really only works for circles, we should be handling the ellipse case as well...
if (distanceToHit < innerRadius || distanceToHit > outerRadius) { float distanceToHit = glm::length(localHitPosition);
intersects = false; float innerRadius = _dimensions.x / 2.0f * _innerRadius;
} float outerRadius = _dimensions.x / 2.0f * _outerRadius;
intersects = innerRadius <= distanceToHit && distanceToHit <= outerRadius;
} }
return intersects; return intersects;
} }

View file

@ -93,7 +93,6 @@ QScriptValue Planar3DOverlay::getProperty(const QString& property) {
bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face) { float& distance, BoxFace& face) {
RayIntersectionInfo rayInfo; RayIntersectionInfo rayInfo;
rayInfo._rayStart = origin; rayInfo._rayStart = origin;
rayInfo._rayDirection = direction; rayInfo._rayDirection = direction;
@ -110,9 +109,13 @@ bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::ve
if (intersects) { if (intersects) {
distance = rayInfo._hitDistance; distance = rayInfo._hitDistance;
// TODO: if it intersects, we want to check to see if the intersection point is within our dimensions
// glm::vec3 hitAt = origin + direction * distance; glm::vec3 hitPosition = origin + (distance * direction);
// _dimensions glm::vec3 localHitPosition = glm::inverse(_rotation) * (hitPosition - _position);
glm::vec2 halfDimensions = _dimensions / 2.0f;
intersects = -halfDimensions.x <= localHitPosition.x && localHitPosition.x <= halfDimensions.x
&& -halfDimensions.y <= localHitPosition.y && localHitPosition.y <= halfDimensions.y;
} }
return intersects; return intersects;
} }