|
@@ -0,0 +1,104 @@
|
|
|
+import { Drawer } from "../../../core/drawers/drawer";
|
|
|
+import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
|
|
|
+import { label as Label } from "../../../component-registry/label";
|
|
|
+import { app as App } from "../../../app";
|
|
|
+import { PointModel } from "../models/point-model";
|
|
|
+const HOVER_STYLE = {
|
|
|
+ fill: "#9bc364",
|
|
|
+ strokeWidth: 2,
|
|
|
+ stroke: "#FF0000"
|
|
|
+};
|
|
|
+const STYLE = {
|
|
|
+ fill: "#9bc364",
|
|
|
+ strokeWidth: 1,
|
|
|
+ stroke: "#9bc364"
|
|
|
+};
|
|
|
+export class PointDrawer extends Drawer {
|
|
|
+ constructor() {
|
|
|
+ super();
|
|
|
+ this.point;
|
|
|
+ this.group;
|
|
|
+ this.label;
|
|
|
+ this.text;
|
|
|
+ this.states = ["center"];
|
|
|
+ }
|
|
|
+ setPoint(point, useLabel) {
|
|
|
+ this.point = point;
|
|
|
+ this.group = this._createGroup();
|
|
|
+ this.circle = this._getCircle(point);
|
|
|
+ this.label = Label.draw();
|
|
|
+ this.text = this._createText(point);
|
|
|
+ this.group.add(this.circle);
|
|
|
+ if (useLabel != undefined && useLabel) {
|
|
|
+ this.group.add(this.text);
|
|
|
+ }
|
|
|
+ this._configureCircleEvents(this.circle);
|
|
|
+ }
|
|
|
+ draw() {
|
|
|
+ if (this.state == undefined) {
|
|
|
+ this.state = this.states[0];
|
|
|
+ App.setStatus("Selecione o centro do Ponto");
|
|
|
+ return;
|
|
|
+ } else if (this.state == this.states[0]) {
|
|
|
+ let pos = App.pos();
|
|
|
+ this.point = new PointModel(pos.x, pos.y);
|
|
|
+ this.setPoint(this.point, true);
|
|
|
+ // super.addAggregator(new DrawerAggregator(this, this.point));
|
|
|
+ super.draw(this.group);
|
|
|
+ this.clear();
|
|
|
+ return this.group;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _createGroup() {
|
|
|
+ this.group = new Konva.Group({
|
|
|
+ draggable: true,
|
|
|
+ resizeEnabled: false
|
|
|
+ });
|
|
|
+ return this.group;
|
|
|
+ }
|
|
|
+ _createText(point) {
|
|
|
+ this.text = new Konva.Text({
|
|
|
+ x: point.posX + 10,
|
|
|
+ y: point.posY - 10,
|
|
|
+ text: this.label,
|
|
|
+ fontSize: 12,
|
|
|
+ fontFamily: "Calibri",
|
|
|
+ fill: "#434a45",
|
|
|
+ draggable: false,
|
|
|
+ resizeEnabled: false,
|
|
|
+ transformEnabled: false,
|
|
|
+ selectable: false
|
|
|
+ });
|
|
|
+ return this.text;
|
|
|
+ }
|
|
|
+ _getCircle(point) {
|
|
|
+ return new Konva.Circle({
|
|
|
+ x: point.posX,
|
|
|
+ y: point.posY,
|
|
|
+ radius: 5,
|
|
|
+ fill: STYLE.fill,
|
|
|
+ stroke: STYLE.fill,
|
|
|
+ strokeWidth: 1,
|
|
|
+ strokeScaleEnabled: false,
|
|
|
+ draggable: false,
|
|
|
+ resizeEnabled: false,
|
|
|
+ transformEnabled: false,
|
|
|
+ style: STYLE,
|
|
|
+ class: ELEMENTS_CLASS.POINT,
|
|
|
+ connections: [],
|
|
|
+ listening: true
|
|
|
+ });
|
|
|
+ }
|
|
|
+ _configureCircleEvents(circle) {
|
|
|
+ circle.on("mouseover", function() {
|
|
|
+ this.strokeWidth(HOVER_STYLE.strokeWidth);
|
|
|
+ this.stroke(HOVER_STYLE.stroke);
|
|
|
+ App.stage.draw();
|
|
|
+ });
|
|
|
+ circle.on("mouseout", function() {
|
|
|
+ this.strokeWidth(STYLE.strokeWidth);
|
|
|
+ this.stroke(STYLE.stroke);
|
|
|
+ App.stage.draw();
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|