1 /*global areasDefinitions, onFrameClick, centerPoint */
4 * @module HomescreenApplication
8 * Compute distance between two points in 2D.
9 * @method pointsDistance
12 * @param pointA {object} Contains X and Y coordinate of first point.
13 * @param pointB {object} Contains X and Y coordinate of second point.
14 * @return float distance in points
16 var pointsDistance = function (pointA, pointB) {
18 return Math.sqrt(Math.pow(Math.abs(pointA.y - pointB.y), 2) + Math.pow(Math.abs(pointA.x - pointB.x), 2));
22 * Compute angle of click point from zero angle (zero angle has a line, which is horizontal and starts in the center point).
26 * @param point {object} Contains X and Y coordinate of clicked/touched point.
27 * @param centerPoint {object} Contains X and Y coordinate of center point.
28 * @return float angle in degrees
30 var pointAngle = function (point, centerPoint) {
33 tmpPoint.x = centerPoint.x + 200; //to define zero vector
34 tmpPoint.y = centerPoint.y;
35 var u1 = tmpPoint.x - centerPoint.x,
36 u2 = tmpPoint.y - centerPoint.y,
37 v1 = point.x - centerPoint.x,
38 v2 = point.y - centerPoint.y,
39 su = pointsDistance(centerPoint, tmpPoint),
40 sv = pointsDistance(centerPoint, point),
41 angle = Math.acos((u1 * v1 + u2 * v2) / (su * sv)) * (180 / Math.PI);
42 if (point.y > centerPoint.y) {
49 * Gets app sector from click based on predefAppModel, clickDistance from center and click angle.
50 * @method getClickedItem
53 * @param touchPoint {object} Contains X and Y coordinate of clicked/touched point.
55 var getClickedItem = function (touchPoint) {
57 var dst = pointsDistance(touchPoint, centerPoint),
58 angle = pointAngle(touchPoint, centerPoint),
60 for (i = 0; i < areasDefinitions.length; i++) {
61 switch (areasDefinitions[i].shape) {
63 if (dst < areasDefinitions[i].lc) {
64 return areasDefinitions[i];
67 case 'pieWithoutCenter':
68 if ((areasDefinitions[i].sc < dst) && (areasDefinitions[i].lc > dst) && (areasDefinitions[i].sa < angle) && (areasDefinitions[i].la > angle)) {
69 return areasDefinitions[i];
79 * Provides functions for catching mouse events and translating them to correct calls for launching applications displayed in radial menu. Applications and locations
80 * which should be displayed are defined in class [predefAppModel](../classes/predefAppModel.html). Reading applications from Tizen system is handled by class
81 * [installedApps](../classes/installedApps.html). As alternative method to launching applicatins with mouse events applications can be launched by key events which are
82 * processed by class [keyControl](../classes/keyControl.html).
83 * @class actionCatcher
88 * Holds clicked item Object.
89 * @property clickedItem
95 * Indicates if mouse button is pressed.
103 * Provides highlighting sectors if mouse cursor is over.
109 if (!actionCatcher.mouseDown) {
110 var mousePosition = {x: window.event.pageX, y: window.event.pageY};
111 var overItem = getClickedItem(mousePosition);
112 if (overItem !== actionCatcher.clickedItem) {
113 for (i = 0; i < areasDefinitions.length; i++) {
114 if (areasDefinitions[i].sectorId !== null) {
115 $('.sector' + areasDefinitions[i].sectorId).removeClass('selected');
118 if (overItem !== null) {
119 $('.sector' + overItem.sectorId).addClass('selected');
121 actionCatcher.clickedItem = overItem;
126 * Sets mouseDown property to true and sets clickedItem property if click to some sector.
129 touchStart: function () {
131 actionCatcher.mouseDown = true;
132 var mousePosition = {x: window.event.pageX, y: window.event.pageY};
133 actionCatcher.clickedItem = getClickedItem(mousePosition);
136 * Sets mouseDown property to false and starts app if click to some sector.
139 touchEnd: function () {
141 actionCatcher.mouseDown = false;
142 if (actionCatcher.clickedItem !== null) {
143 switch (actionCatcher.clickedItem.shape) {
145 actionCatcher.clickedItem.action();
147 case 'pieWithoutCenter':
148 if (actionCatcher.clickedItem.id !== null) {
149 onFrameClick(actionCatcher.clickedItem);