@turbox3d/graphic-component-pixi
Version:
Graphic component library based on pixi
59 lines (58 loc) • 3.81 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _rendererPixi = require("@turbox3d/renderer-pixi");
var PIXI = _interopRequireWildcard(require("pixi.js"));
var _drawUtils = _interopRequireDefault(require("../draw-utils"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var Line2d = exports["default"] = /*#__PURE__*/function (_Mesh2D) {
function Line2d() {
var _this;
(0, _classCallCheck2["default"])(this, Line2d);
_this = _callSuper(this, Line2d, arguments);
_this.view = new PIXI.Graphics();
return _this;
}
(0, _inherits2["default"])(Line2d, _Mesh2D);
return (0, _createClass2["default"])(Line2d, [{
key: "draw",
value: function draw() {
var _a, _b, _c, _d, _e;
var _this$props = this.props,
_this$props$lineWidth = _this$props.lineWidth,
lineWidth = _this$props$lineWidth === void 0 ? 2 : _this$props$lineWidth,
_this$props$lineColor = _this$props.lineColor,
lineColor = _this$props$lineColor === void 0 ? 0xffffff : _this$props$lineColor,
start = _this$props.start,
end = _this$props.end,
_this$props$alignment = _this$props.alignment,
alignment = _this$props$alignment === void 0 ? 0.5 : _this$props$alignment,
_this$props$zIndex = _this$props.zIndex,
zIndex = _this$props$zIndex === void 0 ? 0 : _this$props$zIndex;
this.view.clear();
this.view.zIndex = zIndex;
_drawUtils["default"].drawLine(this.view, {
x0: start.x,
y0: start.y,
x1: end.x,
y1: end.y,
lineWidth: lineWidth,
lineColor: lineColor,
alignment: alignment
});
this.view.rotation = (_a = this.props.rotation) !== null && _a !== void 0 ? _a : 0;
this.view.scale.set((_c = (_b = this.props.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1, (_e = (_d = this.props.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1);
}
}]);
}(_rendererPixi.Mesh2D);