Merge pull request from ctrlaltdavid/20653

Add Desktop object to JavaScript with width and height properties
This commit is contained in:
Brad Hefta-Gaub 2015-08-25 23:18:20 -07:00
commit b19f1e0631
3 changed files with 60 additions and 0 deletions

View file

@ -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<DialogsManager>();
auto bandwidthRecorder = DependencyManager::set<BandwidthRecorder>();
auto resourceCacheSharedItems = DependencyManager::set<ResourceCacheSharedItems>();
auto desktopScriptingInterface = DependencyManager::set<DesktopScriptingInterface>();
auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>();
auto windowScriptingInterface = DependencyManager::set<WindowScriptingInterface>();
#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<DesktopScriptingInterface>().data());
QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", DependencyManager::get<WindowScriptingInterface>().data());
scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
LocationScriptingInterface::locationSetter, windowValue);

View file

@ -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 <QWindow>
#include <QScreen>
#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();
}

View file

@ -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 <QObject>
#include <DependencyManager.h>
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