|
@@ -4,6 +4,7 @@ import { label as Label } from "../../../component-registry/label";
|
|
|
import { app as App } from "../../../app";
|
|
|
import { PointModel } from "../models/point-model";
|
|
|
import { DrawerAggragator } from "../../../core/drawers/drawer-aggregator";
|
|
|
+import { stages as Stages } from "../../../core/application/stages";
|
|
|
|
|
|
const HOVER_STYLE = {
|
|
|
fill: "#9bc364",
|
|
@@ -24,56 +25,47 @@ export class PointDrawer extends Drawer {
|
|
|
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) {
|
|
|
super.setState(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);
|
|
|
+ }
|
|
|
+ if (this.state == this.states[0]) {
|
|
|
+ App.setStatus("Selecione o centro do Ponto");
|
|
|
+ const pos = App.pos();
|
|
|
+ if (pos == undefined) return;
|
|
|
+ this.point = PointDrawer.drawAndGetPoint(pos.x, pos.y, true);
|
|
|
super.addAggregator(new DrawerAggragator(this, this.point));
|
|
|
- super.draw(this.group);
|
|
|
super.setState(this.states[0]);
|
|
|
- return this.group;
|
|
|
}
|
|
|
}
|
|
|
- _createGroup() {
|
|
|
- this.group = new Konva.Group({
|
|
|
- draggable: true,
|
|
|
- resizeEnabled: false
|
|
|
- });
|
|
|
- return this.group;
|
|
|
+
|
|
|
+ update() {}
|
|
|
+
|
|
|
+ static drawAndGetPoint(x, y, useLabel) {
|
|
|
+ return PointDrawer.drawPoint(new PointModel(x, y), useLabel);
|
|
|
}
|
|
|
- _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;
|
|
|
+ static drawPoint(point, useLabel) {
|
|
|
+ const group = Drawer.getKonvaGroup();
|
|
|
+ const circle = PointDrawer.getKonvaCircle(point);
|
|
|
+ group.add(circle);
|
|
|
+ if (useLabel != undefined && useLabel) {
|
|
|
+ const label = Label.draw();
|
|
|
+ point.setLabel(label);
|
|
|
+ const text = PointDrawer.getKonvaText(point, label);
|
|
|
+ group.add(text);
|
|
|
+ } else {
|
|
|
+ if (point.label != undefined) {
|
|
|
+ const text = PointDrawer.getKonvaText(point, point.label);
|
|
|
+ group.add(text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PointDrawer.configureCircleEvents(circle);
|
|
|
+ Drawer.drawObject(group);
|
|
|
+ return point;
|
|
|
}
|
|
|
- _getCircle(point) {
|
|
|
+ static getKonvaCircle(point) {
|
|
|
return new Konva.Circle({
|
|
|
x: point.posX,
|
|
|
y: point.posY,
|
|
@@ -91,17 +83,30 @@ export class PointDrawer extends Drawer {
|
|
|
listening: true
|
|
|
});
|
|
|
}
|
|
|
- _configureCircleEvents(circle) {
|
|
|
+ static getKonvaText(point, label) {
|
|
|
+ return new Konva.Text({
|
|
|
+ x: point.posX + 10,
|
|
|
+ y: point.posY - 10,
|
|
|
+ text: label,
|
|
|
+ fontSize: 12,
|
|
|
+ fontFamily: "Calibri",
|
|
|
+ fill: "#434a45",
|
|
|
+ draggable: false,
|
|
|
+ resizeEnabled: false,
|
|
|
+ transformEnabled: false,
|
|
|
+ selectable: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+ static configureCircleEvents(circle) {
|
|
|
circle.on("mouseover", function() {
|
|
|
this.strokeWidth(HOVER_STYLE.strokeWidth);
|
|
|
this.stroke(HOVER_STYLE.stroke);
|
|
|
- App.stage.draw();
|
|
|
+ Stages.getCurrentKonvaStage().draw();
|
|
|
});
|
|
|
circle.on("mouseout", function() {
|
|
|
this.strokeWidth(STYLE.strokeWidth);
|
|
|
this.stroke(STYLE.stroke);
|
|
|
- App.stage.draw();
|
|
|
+ Stages.getCurrentKonvaStage().draw();
|
|
|
});
|
|
|
}
|
|
|
- update() {}
|
|
|
}
|