UNPKG

ami-cjs.js

Version:

<p align="center"> <img src="https://cloud.githubusercontent.com/assets/214063/23213764/78ade038-f90c-11e6-8208-4fcade5f3832.png" width="60%"> </p>

182 lines (159 loc) 5.61 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * */ var WidgetsBase = function (_THREE$Object3D) { _inherits(WidgetsBase, _THREE$Object3D); function WidgetsBase(container) { _classCallCheck(this, WidgetsBase); // is widget enabled? var _this = _possibleConstructorReturn(this, (WidgetsBase.__proto__ || Object.getPrototypeOf(WidgetsBase)).call(this)); // init THREE Object 3D _this._enabled = true; // STATE, ENUM might be better _this._selected = false; _this._hovered = false; _this._active = false; _this._colors = { default: '#00B0FF', active: '#FFEB3B', hover: '#F50057', select: '#76FF03' }; _this._color = _this._colors.default; _this._dragged = false; // can not call it visible because it conflicts with THREE.Object3D _this._displayed = true; _this._container = container; return _this; } _createClass(WidgetsBase, [{ key: 'initOffsets', value: function initOffsets() { var box = this._container.getBoundingClientRect(); var body = document.body; var docEl = document.documentElement; var scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop; var scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft; var clientTop = docEl.clientTop || body.clientTop || 0; var clientLeft = docEl.clientLeft || body.clientLeft || 0; var top = box.top + scrollTop - clientTop; var left = box.left + scrollLeft - clientLeft; this._offsets = { top: Math.round(top), left: Math.round(left) }; } }, { key: 'offsetChanged', value: function offsetChanged() { this.initOffsets(); this.update(); } }, { key: 'getMouseOffsets', value: function getMouseOffsets(event, container) { this.initOffsets(); return { x: (event.clientX - this._offsets.left) / container.offsetWidth * 2 - 1, y: -((event.clientY - this._offsets.top) / container.offsetHeight) * 2 + 1, screenX: event.clientX - this._offsets.left, screenY: event.clientY - this._offsets.top }; } }, { key: 'update', value: function update() { // to be overloaded window.console.log('update() should be overloaded!'); } }, { key: 'free', value: function free() { this._container = null; } }, { key: 'updateColor', value: function updateColor() { if (this._active) { this._color = this._colors.active; } else if (this._hovered) { this._color = this._colors.hover; } else if (this._selected) { this._color = this._colors.select; } else { this._color = this._colors.default; } } }, { key: 'enabled', get: function get() { return this._enabled; }, set: function set(enabled) { this._enabled = enabled; this.update(); } }, { key: 'selected', get: function get() { return this._selected; }, set: function set(selected) { this._selected = selected; this.update(); } }, { key: 'hovered', get: function get() { return this._hovered; }, set: function set(hovered) { this._hovered = hovered; this.update(); } }, { key: 'dragged', get: function get() { return this._dragged; }, set: function set(dragged) { this._dragged = dragged; this.update(); } }, { key: 'displayed', get: function get() { return this._displayed; }, set: function set(displayed) { this._displayed = displayed; this.update(); } }, { key: 'active', get: function get() { return this._active; }, set: function set(active) { this._active = active; this.update(); } }, { key: 'color', get: function get() { return this._color; }, set: function set(color) { this._color = color; this.update(); } }]); return WidgetsBase; }(THREE.Object3D); exports.default = WidgetsBase; module.exports = exports['default'];