All files / js/display DisplayObject.js

33.33% Statements 20/60
36.36% Branches 8/22
41.67% Functions 5/12
33.93% Lines 19/56
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 2401x 1x 1x 1x   1x 1x 1x             1x                         1x 1x                                                                                                                                                                                                                                                                                                                           1x                         1x                               1x         1x     1x               1x     1x   1x 1x    
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
(function (factory) {
    Eif (typeof module === 'object' && typeof module.exports === 'object') {
        var v = factory(require, exports); Iif (v !== undefined) module.exports = v;
    }
    else if (typeof define === 'function' && define.amd) {
        define(["require", "exports", '../event/EventDispatcher'], factory);
    }
})(function (require, exports) {
    "use strict";
    var EventDispatcher_1 = require('../event/EventDispatcher');
    /**
     * The {{#crossLink "DisplayObject"}}{{/crossLink}} class is the base class for all objects that can be placed on the display list.
     *
     * @class DisplayObject
     * @extends EventDispatcher
     * @module StructureJS
     * @submodule view
     * @requires Extend
     * @requires EventDispatcher
     * @constructor
     * @author Robert S. (www.codeBelt.com)
     */
    var DisplayObject = (function (_super) {
        __extends(DisplayObject, _super);
        function DisplayObject() {
            _super.call(this);
            /**
             * The Stage of the display object.
             *
             * @property stage
             * @type {any}
             * @public
             */
            this.stage = null;
            /**
             * The CanvasRenderingContext2D interface provides the 2D rendering context for the drawing surface of a canvas element.
             * This property is only used with the canvas specific display objects.
             *
             * @property ctx
             * @type {CanvasRenderingContext2D}
             * @public
             */
            this.ctx = null;
            /**
             * A property providing access to the x position.
             *
             * @property x
             * @type {number}
             * @default 0
             * @public
             */
            this.x = 0;
            /**
             * A property providing access to the y position.
             *
             * @property y
             * @type {number}
             * @default 0
             * @public
             */
            this.y = 0;
            /**
             * Indicates the width of the display object, in pixels.
             *
             * @property width
             * @type {number}
             * @default 0
             * @public
             */
            this.width = 0;
            /**
             * Indicates the height of the display object, in pixels.
             *
             * @property height
             * @type {number}
             * @default 0
             * @public
             */
            this.height = 0;
            /**
             * A property providing access to the unscaledWidth.
             *
             * @property unscaledWidth
             * @type {number}
             * @default 100
             * @public
             */
            this.unscaledWidth = 100;
            /**
             * A property providing access to the unscaledHeight.
             *
             * @property unscaledHeight
             * @type {number}
             * @default 100
             * @public
             */
            this.unscaledHeight = 100;
            /**
             * Indicates the horizontal scale (percentage) of the object as applied from the registration point.
             *
             * @property scaleX
             * @type {number}
             * @public
             */
            this.scaleX = 1;
            /**
             * Indicates the vertical scale (percentage) of an object as applied from the registration point of the object.
             *
             * @property scaleY
             * @type {number}
             * @public
             */
            this.scaleY = 1;
            /**
             * Indicates the rotation of the DisplayObject instance, in degrees, from its original orientation.
             *
             * @property rotation
             * @type {number}
             * @public
             */
            this.rotation = 0;
            /**
             * Indicates the alpha transparency value of the object specified.
             *
             * @property alpha
             * @type {number}
             * @public
             */
            this.alpha = 1;
            /**
             * Whether or not the display object is visible.
             *
             * @property visible
             * @type {boolean}
             * @public
             */
            this.visible = true;
            /**
             * Specifies whether this object receives mouse
             *
             * @property mouseEnabled
             * @type {boolean}
             * @public
             */
            this.mouseEnabled = false;
            /**
             * A Boolean value that indicates whether the pointing hand (hand cursor) appears when the pointer rolls over a display object.
             *
             * @property useHandCursor
             * @type {boolean}
             * @public
             */
            this.useHandCursor = false;
            /**
             * The isCreated property is used to keep track if it is the first time this DisplayObject is created.
             *
             * @property isCreated
             * @type {boolean}
             * @default false
             * @public
             */
            this.isCreated = false;
            /**
             * Indicates the instance name of the DisplayObject.
             *
             * @property name
             * @type {string}
             * @public
             */
            this.name = null;
        }
        /**
         * The create function is intended to provide a consistent place for the creation or initializing the view.
         * It will automatically be called the first time that the view is added to a DisplayObjectContainer.
         * It is critical that all subclasses call the super for this function in their overridden methods.
         *
         * @method create
         * @returns {DisplayObject} Returns an instance of itself.
         * @public
         * @chainable
         */
        DisplayObject.prototype.create = function () {
            this.isCreated = true;
            return this;
        };
        /**
         * The layout method provides a common function to handle updating objects in the view.
         *
         * @method layout
         * @param ...rest {Array<any>}
         * @returns {DisplayObject} Returns an instance of itself.
         * @public
         * @chainable
         */
        DisplayObject.prototype.layout = function () {
            var rest = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                rest[_i - 0] = arguments[_i];
            }
            return this;
        };
        /**
         * The setSize method sets the bounds within which the containing DisplayObject would like that component to lay itself out.
         *
         * @param unscaledWidth {number} The width within which the component should lay itself out.
         * @param unscaledHeight {number} The height within which the component should lay itself out.
         * @returns {DisplayObject} Returns an instance of itself.
         * @public
         * @chainable
         */
        DisplayObject.prototype.setSize = function (unscaledWidth, unscaledHeight) {
            this.unscaledWidth = unscaledWidth;
            this.unscaledHeight = unscaledHeight;
            return this;
        };
        DisplayObject.prototype._readerStart = function () {
            this.ctx.save();
        };
        DisplayObject.prototype.renderCanvas = function () {
            if (this.ctx === null || this.alpha <= 0 || this.visible === false)
                return false;
            this._readerStart();
            this.ctx.globalAlpha = this.alpha;
            this.layout();
            this._renderEnd();
        };
        DisplayObject.prototype._renderEnd = function () {
            this.ctx.restore();
        };
        return DisplayObject;
    }(EventDispatcher_1.default));
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.default = DisplayObject;
});