Adding smoother transitions between events
[profile/ivi/webdialer.git] / js / canvasObject.js
1 /*
2  * Copyright (c) 2012, Intel Corporation.
3  *
4  * This program is licensed under the terms and conditions of the 
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 var cancelAudioGlowInterval = undefined;
11
12 function objectsAtLocation(pageObj, xLoc, yLoc)
13 {       
14     var currItem;
15     var prevItem;
16
17     for (i = 0; i < pageObj.canvasObjs.length; i++)
18     {
19         if (pageObj.canvasObjs[i] !== undefined && pageObj.canvasObjs[i].visible !== false)
20         {
21             currItem = pageObj.canvasObjs[i];
22
23             if (currItem.visible)
24             {
25                 if (xLoc > currItem.xLoc && xLoc < (currItem.xLoc + currItem.width))
26                 {
27                     if (yLoc > currItem.yLoc && yLoc < (currItem.yLoc + currItem.height))
28                     {               
29                         if (prevItem === undefined || (Number(currItem.ctx.canvas.style.zIndex) > Number(prevItem.ctx.canvas.style.zIndex)) || 
30                                 ((Number(currItem.ctx.canvas.style.zIndex) === Number(prevItem.ctx.canvas.style.zIndex)) && (currItem.zLoc > prevItem.zLoc)))
31                             prevItem = currItem;
32                     }
33                 }
34             }
35         }
36     }
37     if (prevItem)
38         return prevItem;
39
40     return undefined;
41 }
42
43 function clearCanvas()
44 {
45     buttonCtx.clearRect(0,0, screenWidth, screenHeight);
46     mainCtx.clearRect(0,0, screenWidth, screenHeight);   
47     mouseCtx.clearRect(0,0, screenWidth, screenHeight);
48 }
49
50 function drawRoundedRectangle(ctx, xLoc, yLoc, width, height, cornerRadius, strokeStyle, fillStyle, lineWidth)
51 {
52     ctx.save();
53     ctx.strokeStyle = strokeStyle;
54     ctx.lineWidth = lineWidth;
55     ctx.fillStyle = fillStyle;
56     ctx.beginPath();
57     ctx.moveTo(xLoc + cornerRadius, yLoc);
58     ctx.lineTo(xLoc + width - cornerRadius, yLoc);
59     ctx.quadraticCurveTo(xLoc + width, yLoc, xLoc + width, yLoc + cornerRadius);
60     ctx.lineTo(xLoc + width, yLoc + height - cornerRadius);
61     ctx.quadraticCurveTo(xLoc + width, yLoc + height, xLoc + width - cornerRadius, yLoc + height);
62     ctx.lineTo(xLoc + cornerRadius, yLoc + height);
63     ctx.quadraticCurveTo(xLoc, yLoc + height, xLoc, yLoc + height - cornerRadius);
64     ctx.lineTo(xLoc, yLoc + cornerRadius);
65     ctx.quadraticCurveTo(xLoc, yLoc, xLoc + cornerRadius, yLoc);
66     ctx.closePath();
67     ctx.stroke();
68     ctx.fill();
69     ctx.restore();
70 }