All services and controllers are implemented.

This commit is contained in:
Gunther Brunner
2014-02-19 15:46:31 +09:00
parent ffce3d5beb
commit 3a284eca1f
12 changed files with 256 additions and 19 deletions

View File

@@ -3,6 +3,37 @@ module.exports = function ControlServiceFactory($rootScope, socket) {
}
function ControlService(channel) {
var keyCodes = {
8: 8 // backspace
, 13: 13 // enter
, 20: 20 // caps lock
, 27: 27 // esc
, 33: 33 // page up
, 34: 34 // page down
, 35: 35 // end
, 36: 36 // home
, 37: 37 // left arrow
, 38: 38 // up arrow
, 39: 39 // right arrow
, 40: 40 // down arrow
, 45: 45 // insert
, 46: 46 // delete
, 93: 93 // windows menu key
, 112: 112 // f1
, 113: 113 // f2
, 114: 114 // f3
, 115: 115 // f4
, 116: 116 // f5
, 117: 117 // f6
, 118: 118 // f7
, 119: 119 // f8
, 120: 120 // f9
, 121: 121 // f10
, 122: 122 // f11
, 123: 123 // f12
, 144: 144 // num lock
}
function touchSender(type) {
return function (x, y) {
socket.emit(type, channel, {
@@ -11,11 +42,14 @@ module.exports = function ControlServiceFactory($rootScope, socket) {
}
}
function keySender(type) {
function keySender(type, fixedKey) {
return function (key) {
socket.emit(type, channel, {
key: key
})
var mapped = fixedKey || keyCodes[key]
if (mapped) {
socket.emit(type, channel, {
key: mapped
})
}
}
}
@@ -28,17 +62,9 @@ module.exports = function ControlServiceFactory($rootScope, socket) {
this.keyUp = keySender('input.keyUp')
this.keyPress = keySender('input.keyPress')
this.home = function () {
socket.emit('input.home', channel)
}
this.menu = function () {
socket.emit('input.menu', channel)
}
this.back = function () {
socket.emit('input.back', channel)
}
this.home = keySender('input.keyPress', 3)
this.menu = keySender('input.keyPress', 93)
this.back = keySender('input.keyPress', 4)
this.type = function (text) {
socket.emit('input.type', channel, {
@@ -52,4 +78,4 @@ module.exports = function ControlServiceFactory($rootScope, socket) {
}
return controlService
}
}

View File

@@ -1,2 +0,0 @@
module.exports = angular.module('stf/scaling', [])
.factory('ScalingService', require('./scaling-service'))

View File

@@ -1,119 +0,0 @@
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
}