@turbox3d/graphic-component-pixi
Version:
Graphic component library based on pixi
104 lines (103 loc) • 4.92 kB
JavaScript
"use strict";
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 PIXI = _interopRequireWildcard(require("pixi.js"));
var _rendererPixi = require("@turbox3d/renderer-pixi");
var _index = _interopRequireDefault(require("../draw-utils/index"));
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 Rect2d = exports["default"] = /*#__PURE__*/function (_Mesh2D) {
function Rect2d() {
var _this;
(0, _classCallCheck2["default"])(this, Rect2d);
_this = _callSuper(this, Rect2d, arguments);
_this.view = new PIXI.Graphics();
_this.reactivePipeLine = [_this.updateGeometry, _this.updateMaterial, _this.updatePosition, _this.updateRotation, _this.updateScale];
return _this;
}
(0, _inherits2["default"])(Rect2d, _Mesh2D);
return (0, _createClass2["default"])(Rect2d, [{
key: "updateGeometry",
value: function updateGeometry() {
this.view.clear();
var _this$props = this.props,
_this$props$x = _this$props.x,
x = _this$props$x === void 0 ? 0 : _this$props$x,
_this$props$y = _this$props.y,
y = _this$props$y === void 0 ? 0 : _this$props$y,
width = _this$props.width,
height = _this$props.height,
_this$props$central = _this$props.central,
central = _this$props$central === void 0 ? false : _this$props$central,
radius = _this$props.radius,
lineWidth = _this$props.lineWidth,
lineColor = _this$props.lineColor,
lineAlpha = _this$props.lineAlpha,
fillColor = _this$props.fillColor,
fillAlpha = _this$props.fillAlpha,
alpha = _this$props.alpha,
backgroundImage = _this$props.backgroundImage,
fit = _this$props.fit,
alignment = _this$props.alignment,
_native = _this$props["native"];
_index["default"].drawRect(this.view, {
x: x,
y: y,
width: width,
height: height,
central: central,
radius: radius,
lineWidth: lineWidth,
lineColor: lineColor,
lineAlpha: lineAlpha,
fillColor: fillColor,
fillAlpha: fillAlpha,
alpha: alpha,
backgroundImage: backgroundImage,
fit: fit,
alignment: alignment,
"native": _native
});
}
}, {
key: "updateMaterial",
value: function updateMaterial() {
var _this$props$zIndex = this.props.zIndex,
zIndex = _this$props$zIndex === void 0 ? 0 : _this$props$zIndex;
this.view.zIndex = zIndex;
}
}, {
key: "updatePosition",
value: function updatePosition() {
//
}
}, {
key: "updateRotation",
value: function updateRotation() {
var _this$props$rotation = this.props.rotation,
rotation = _this$props$rotation === void 0 ? 0 : _this$props$rotation;
this.view.rotation = rotation;
}
}, {
key: "updateScale",
value: function updateScale() {
var _this$props$scale = this.props.scale,
scale = _this$props$scale === void 0 ? {
x: 1,
y: 1
} : _this$props$scale;
this.view.scale.set(scale.x, scale.y);
}
}]);
}(_rendererPixi.Mesh2D);