1 goog.provide('lime.Circle');
  2 goog.provide('lime.Renderer.CANVAS.CIRCLE');
  3 goog.provide('lime.Renderer.DOM.CIRCLE');
  4 
  5 
  6 goog.require('lime.Renderer.CANVAS.SPRITE');
  7 goog.require('lime.Renderer.DOM.SPRITE');
  8 goog.require('lime.Sprite');
  9 goog.require('lime.style');
 10 
 11 /**
 12  * Circle or ellipse shaped tectured object
 13  * @constructor
 14  * @extends lime.Sprite
 15  */
 16 lime.Circle = function() {
 17     lime.Sprite.call(this);
 18 
 19 
 20 };
 21 goog.inherits(lime.Circle, lime.Sprite);
 22 
 23 /**
 24  * Common name for circle objects
 25  * @type {string}
 26  */
 27 lime.Circle.prototype.id = 'circle';
 28 
 29 /** @inheritDoc */
 30 lime.Circle.prototype.supportedRenderers = [
 31     lime.Renderer.DOM.SPRITE.makeSubRenderer(lime.Renderer.DOM.CIRCLE),
 32     lime.Renderer.CANVAS.SPRITE.makeSubRenderer(lime.Renderer.CANVAS.CIRCLE)
 33 ];
 34 
 35 /**
 36  * @inheritDoc
 37  */
 38 lime.Circle.prototype.hitTest = function(e) {
 39     var coord = this.screenToLocal(e.screenPosition);
 40     var s = this.size_, ap = this.anchorPoint_,
 41         a = s.width * .5, b = s.height * .5,
 42         x = coord.x - s.width * (.5 - ap.x),
 43         y = coord.y - s.height * (.5 - ap.y);
 44 
 45     if ((x * x) / (a * a) + (y * y) / (b * b) < 1) {
 46         e.position = coord;
 47         return true;
 48     }
 49     return false;
 50 };
 51 
 52 /**
 53  * @inheritDoc
 54  * @this {lime.Circle}
 55  */
 56 lime.Renderer.DOM.CIRCLE.draw = function(el) {
 57     var size = this.getSize();
 58 
 59     lime.Renderer.DOM.SPRITE.draw.call(this, el);
 60 
 61     lime.style.setBorderRadius(el, size.width * .5, size.height * .5);
 62   //  el.style['-webkit-border-radius'] = el.style['MozBorderRadius'] =
 63   //      size.width*.5+'px / '+size.height*.5+'px';
 64 
 65 };
 66 
 67 /**
 68  * @inheritDoc
 69  * @this {lime.Circle}
 70  */
 71 lime.Renderer.CANVAS.CIRCLE.draw = function(context) {
 72    // console.log('draw');
 73     var size = this.getSize(), fill = this.fill_,ap = this.getAnchorPoint();
 74     var frame = this.getFrame();
 75     var cx = (frame.right - frame.left) * .5;
 76     var cy = (frame.bottom - frame.top) * .5;
 77     context.save();
 78     context.save();
 79     context.scale(cx, cy);
 80     context.translate(1-2*ap.x,1-2*ap.y);
 81     context.beginPath();
 82     context.arc(0, 0, 1, 0, 2 * Math.PI, false);
 83     context.closePath();
 84     context.restore();
 85     context.clip();
 86 
 87     lime.Renderer.CANVAS.SPRITE.draw.call(this, context);
 88     
 89     if(this.stroke_){
 90         context.lineWidth*=2;
 91         context.stroke();
 92     }
 93     
 94     context.restore();
 95 };
 96