2
* Copyright (C) 2013 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
// get the element which is selected accordingly to x, the hero of the view
20
function getContinuousIndex(x, tileWidth, gapToMiddlePhase, gapToEndPhase, kGapEnd, kMiddleIndex, kXBeginningEnd) {
21
if (x < gapToMiddlePhase) {
23
return x * kXBeginningEnd
24
} else if (x > gapToEndPhase) {
26
return x * kXBeginningEnd + kGapEnd
30
return x / tileWidth + kMiddleIndex
33
// obtain x position relative to an index, essentially an inverse of getContinuousIndex()
34
function getXFromContinuousIndex(index, viewWidth, contentWidth, tileWidth, gapToMiddlePhase, gapToEndPhase) {
35
var middleX = (index + 0.5) * tileWidth - viewWidth / 2
37
if (middleX < gapToMiddlePhase) {
38
// inverse of 'middleIndex - kGap' of getContinuousIndex()
41
(viewWidth / (2 * tileWidth * gapToMiddlePhase)) -
42
1 / (2 * gapToMiddlePhase))
43
} else if (middleX > gapToEndPhase) {
44
// inverse of 'middleIndex + kGap' of getContinuousIndex()
47
viewWidth / tileWidth +
48
(contentWidth * viewWidth - viewWidth * viewWidth) / (2 * tileWidth * gapToMiddlePhase) +
49
(viewWidth - contentWidth) / (2 * gapToMiddlePhase)) /
51
viewWidth / (2 * tileWidth * gapToMiddlePhase) -
52
1 / (2 * gapToMiddlePhase))
55
// inverse of 'middleIndex' of getContinuousIndex()
59
// get translation of the whole view, adds gaps on sides
60
function getViewTranslation(x, tileWidth, gapToMiddlePhase, gapToEndPhase, translationXViewFactor) {
61
if (x < gapToMiddlePhase) {
63
return (gapToMiddlePhase - x) * translationXViewFactor
64
} else if (x > gapToEndPhase) {
66
return (gapToEndPhase - x) * translationXViewFactor
74
function getItemScale(distance, continuousIndex, end, scaleFactor) {
75
var distanceAbs = Math.abs(distance)
76
var distanceToBounds = Math.min(continuousIndex, end - continuousIndex)
77
var k = Math.max(200 + 100 * (-distanceToBounds / (3 * scaleFactor)), 50)
78
return Math.max(0.01, 1 - Math.pow(distanceAbs, 2.5) / (k * scaleFactor))
82
function getItemTranslation(distance, scale, maxScale, translationFactor) {
83
var sign = distance > 0 ? 1 : -1
84
return sign * (maxScale - scale) * translationFactor