mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
All services added back.
This commit is contained in:
parent
347d9e9a55
commit
ffce3d5beb
6 changed files with 204 additions and 0 deletions
119
res/app/components/stf/control/scaling/scaling-service.js
Normal file
119
res/app/components/stf/control/scaling/scaling-service.js
Normal file
|
@ -0,0 +1,119 @@
|
|||
module.exports = function ScalingServiceFactory() {
|
||||
var scalingService = {
|
||||
}
|
||||
|
||||
scalingService.coordinator = function (realWidth, realHeight) {
|
||||
var realRatio = realWidth / realHeight
|
||||
|
||||
return {
|
||||
coords: function (width, height, x, y) {
|
||||
var ratio = width / height
|
||||
, scaledValue
|
||||
|
||||
if (realRatio > ratio) {
|
||||
// covers the area horizontally
|
||||
scaledValue = width / realRatio;
|
||||
|
||||
// adjust y to start from the scaled top edge
|
||||
y -= (height - scaledValue) / 2
|
||||
|
||||
// not touching the screen, but we want to trigger certain events
|
||||
// (like touchup) anyway, so let's do it on the edges.
|
||||
if (y < 0) {
|
||||
y = 0
|
||||
}
|
||||
else if (y > scaledValue) {
|
||||
y = scaledValue
|
||||
}
|
||||
|
||||
// make sure x is within bounds too
|
||||
if (x < 0) {
|
||||
x = 0
|
||||
}
|
||||
else if (x > width) {
|
||||
x = width
|
||||
}
|
||||
|
||||
height = scaledValue
|
||||
}
|
||||
else {
|
||||
// covers the area vertically
|
||||
scaledValue = height * realRatio
|
||||
|
||||
// adjust x to start from the scaled left edge
|
||||
x -= (width - scaledValue) / 2
|
||||
|
||||
// not touching the screen, but we want to trigger certain events
|
||||
// (like touchup) anyway, so let's do it on the edges.
|
||||
if (x < 0) {
|
||||
x = 0
|
||||
}
|
||||
else if (x > scaledValue) {
|
||||
x = scaledValue
|
||||
}
|
||||
|
||||
// make sure y is within bounds too
|
||||
if (y < 0) {
|
||||
y = 0
|
||||
}
|
||||
else if (y > height) {
|
||||
y = height
|
||||
}
|
||||
|
||||
width = scaledValue
|
||||
}
|
||||
|
||||
return {
|
||||
xP: x / width, yP: y / height
|
||||
}
|
||||
}, size: function (width, height) {
|
||||
var ratio = width / height
|
||||
|
||||
if (realRatio > ratio) {
|
||||
// covers the area horizontally
|
||||
|
||||
if (width >= realWidth) {
|
||||
// don't go over max size
|
||||
width = realWidth
|
||||
height = realHeight
|
||||
}
|
||||
else {
|
||||
height = Math.floor(width / realRatio)
|
||||
}
|
||||
}
|
||||
else {
|
||||
// covers the area vertically
|
||||
|
||||
if (height >= realHeight) {
|
||||
// don't go over max size
|
||||
height = realHeight
|
||||
width = realWidth
|
||||
}
|
||||
else {
|
||||
width = Math.floor(height * realRatio)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
width: width, height: height
|
||||
}
|
||||
}, projectedSize: function (width, height) {
|
||||
var ratio = width / height
|
||||
|
||||
if (realRatio > ratio) {
|
||||
// covers the area horizontally
|
||||
height = Math.floor(width / realRatio)
|
||||
}
|
||||
else {
|
||||
width = Math.floor(height * realRatio)
|
||||
}
|
||||
|
||||
return {
|
||||
width: width, height: height
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return scalingService
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue