From 9d3d104ec3aad16415db6edff73edadf4ea707e4 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 25 Aug 2015 16:13:36 -0700 Subject: [PATCH] Add Desktop object to JavaScript with width and height properties --- interface/src/Application.cpp | 4 +++ .../scripting/DesktopScriptingInterface.cpp | 27 +++++++++++++++++ .../src/scripting/DesktopScriptingInterface.h | 29 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 interface/src/scripting/DesktopScriptingInterface.cpp create mode 100644 interface/src/scripting/DesktopScriptingInterface.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c59c24de71..716fd97c78 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -126,6 +126,7 @@ #include "scripting/AccountScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" #include "scripting/ClipboardScriptingInterface.h" +#include "scripting/DesktopScriptingInterface.h" #include "scripting/HMDScriptingInterface.h" #include "scripting/GlobalServicesScriptingInterface.h" #include "scripting/LocationScriptingInterface.h" @@ -284,6 +285,7 @@ bool setupEssentials(int& argc, char** argv) { auto dialogsManager = DependencyManager::set(); auto bandwidthRecorder = DependencyManager::set(); auto resourceCacheSharedItems = DependencyManager::set(); + auto desktopScriptingInterface = DependencyManager::set(); auto entityScriptingInterface = DependencyManager::set(); auto windowScriptingInterface = DependencyManager::set(); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) @@ -3970,6 +3972,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri qScriptRegisterMetaType(scriptEngine, RayToOverlayIntersectionResultToScriptValue, RayToOverlayIntersectionResultFromScriptValue); + scriptEngine->registerGlobalObject("Desktop", DependencyManager::get().data()); + QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", DependencyManager::get().data()); scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, LocationScriptingInterface::locationSetter, windowValue); diff --git a/interface/src/scripting/DesktopScriptingInterface.cpp b/interface/src/scripting/DesktopScriptingInterface.cpp new file mode 100644 index 0000000000..746cdaf36f --- /dev/null +++ b/interface/src/scripting/DesktopScriptingInterface.cpp @@ -0,0 +1,27 @@ +// +// DesktopScriptingInterface.h +// interface/src/scripting +// +// Created by David Rowe on 25 Aug 2015. +// Copyright 2015 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 "DesktopScriptingInterface.h" + +#include +#include + +#include "Application.h" +#include "MainWindow.h" + +int DesktopScriptingInterface::getWidth() { + QSize size = Application::getInstance()->getWindow()->windowHandle()->screen()->virtualSize(); + return size.width(); +} +int DesktopScriptingInterface::getHeight() { + QSize size = Application::getInstance()->getWindow()->windowHandle()->screen()->virtualSize(); + return size.height(); +} diff --git a/interface/src/scripting/DesktopScriptingInterface.h b/interface/src/scripting/DesktopScriptingInterface.h new file mode 100644 index 0000000000..be4eaadbfb --- /dev/null +++ b/interface/src/scripting/DesktopScriptingInterface.h @@ -0,0 +1,29 @@ +// +// DesktopScriptingInterface.h +// interface/src/scripting +// +// Created by David Rowe on 25 Aug 2015. +// Copyright 2015 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_DesktopScriptingInterface_h +#define hifi_DesktopScriptingInterface_h + +#include + +#include + +class DesktopScriptingInterface : public QObject, public Dependency { + Q_OBJECT + Q_PROPERTY(int width READ getWidth) // Physical width of screen(s) including task bars and system menus + Q_PROPERTY(int height READ getHeight) // Physical height of screen(s) including task bars and system menus + +public: + int getWidth(); + int getHeight(); +}; + +#endif // hifi_DesktopScriptingInterface_h