Debian Codegraph @

src/qml/common/units.js

raw
1 /*
2 * This file is part of unity-2d
3 *
4 * Copyright 2011 Canonical Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 var desktopDistanceToDisplay = 0.5
20 var desktopPixelDensity = 112
21
22 var tvDistanceToDisplay = 2.0
23 var tvPixelDensity = 52 // 1080p on a 42" screen
24
25 /* distanceToDisplay and pixelDensity cannot be global javascript variables
26 because they would not be able to access unity2dConfiguration.formFactor
27 */
28 function dtPx(desktopPixels) {
29 var distanceToDisplay = mediaPlayer.formFactor === "desktop" ? desktopDistanceToDisplay : tvDistanceToDisplay
30 var pixelDensity = mediaPlayer.formFactor === "desktop" ? desktopPixelDensity : tvPixelDensity
31 var factorFromDesktop = pixelDensity / desktopPixelDensity * distanceToDisplay / desktopDistanceToDisplay
32 return desktopPixels * factorFromDesktop
33 }
34
35 function tvPx(tvPixels) {
36 var distanceToDisplay = mediaPlayer.formFactor === "desktop" ? desktopDistanceToDisplay : tvDistanceToDisplay
37 var pixelDensity = mediaPlayer.formFactor === "desktop" ? desktopPixelDensity : tvPixelDensity
38 var factorFromTv = pixelDensity / tvPixelDensity * distanceToDisplay / tvDistanceToDisplay
39 return tvPixels * factorFromTv
40 }