@turbox3d/graphic-component-pixi
Version:
Graphic component library based on pixi
70 lines • 3.03 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 { Mesh2D } from '@turbox3d/renderer-pixi';
import * as PIXI from 'pixi.js';
import { drawText } from '../_utils/utils';
/**
* @description: 半径尺寸线
*/
var RadiusDimension = /*#__PURE__*/function (_Mesh2D) {
function RadiusDimension() {
var _this;
_classCallCheck(this, RadiusDimension);
_this = _callSuper(this, RadiusDimension, arguments);
_this.view = new PIXI.Graphics();
return _this;
}
_inherits(RadiusDimension, _Mesh2D);
return _createClass(RadiusDimension, [{
key: "draw",
value: function draw() {
var _a, _b, _c, _d, _e;
var graphics = this.view;
graphics.clear();
graphics.lineStyle(2, 0x131313);
graphics.line["native"] = true;
var textSize = this.props.textSize;
var dir = {
x: Math.cos(this.props.angle),
y: Math.sin(this.props.angle)
};
var startP = {
x: this.props.center.x + this.props.startP * dir.x,
y: this.props.center.y + this.props.startP * dir.y
};
graphics.moveTo(startP.x, startP.y);
graphics.lineTo(this.props.center.x + (this.props.startP + this.props.length) * dir.x, this.props.center.y + (this.props.startP + this.props.length) * dir.y);
// 先沿径向偏移,然后再沿切线方向偏移
var textOffsetDir = {
x: -dir.y,
y: dir.x
};
// 径向偏移
var a = {
x: 2 * textSize * dir.x,
y: 2 * textSize * dir.y
};
// 切向偏移
var b = {
x: 0.8 * textSize * textOffsetDir.x,
y: 0.8 * textSize * textOffsetDir.y
};
drawText(graphics, this.props.radius, {
offset: {
x: startP.x + a.x + b.x,
y: startP.y + a.y + b.y
},
size: textSize,
rotation: this.props.angle
});
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);
}
}]);
}(Mesh2D);
export { RadiusDimension as default };