@turbox3d/graphic-component-pixi
Version:
Graphic component library based on pixi
81 lines • 3.15 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(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; })(); }
import * as PIXI from 'pixi.js';
import { Mesh2D } from '@turbox3d/renderer-pixi';
import DrawUtils from '../draw-utils/index';
/** 正方形 */
var Circle2d = /*#__PURE__*/function (_Mesh2D) {
function Circle2d() {
var _this;
_classCallCheck(this, Circle2d);
_this = _callSuper(this, Circle2d, arguments);
_this.view = new PIXI.Graphics();
_this.reactivePipeLine = [_this.updateGeometry, _this.updateMaterial, _this.updatePosition, _this.updateRotation, _this.updateScale];
return _this;
}
_inherits(Circle2d, _Mesh2D);
return _createClass(Circle2d, [{
key: "updateGeometry",
value: function updateGeometry() {
this.view.clear();
var _this$props = this.props,
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,
alignment = _this$props.alignment,
_native = _this$props["native"];
DrawUtils.drawCircle(this.view, {
cx: 0,
cy: 0,
radius: radius,
lineWidth: lineWidth,
lineColor: lineColor,
lineAlpha: lineAlpha,
fillColor: fillColor,
fillAlpha: fillAlpha,
alpha: alpha,
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() {
var center = this.props.center;
this.view.position.set(center.x, center.y);
}
}, {
key: "updateRotation",
value: function updateRotation() {
var _a;
this.view.rotation = (_a = this.props.rotation) !== null && _a !== void 0 ? _a : 0;
}
}, {
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);
}
}]);
}(Mesh2D);
export { Circle2d as default };