123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import Ponto from '../objetos/Ponto.js';
- export default class AreaDeDesenho {
-
- constructor(app) {
- this.app = app;
- this._area = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
- this._area.setAttribute('id', 'main-svg');
- this._area.setAttribute('preserveAspectRatio', 'none');
- this._areaTop = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
- this._areaTop.setAttribute('id', 'top-svg');
- this._areaTop.setAttribute('preserveAspectRatio', 'none');
-
- this._areaTop.onmouseup = (e) => this.mouseup(e);
- this._areaTop.onmousedown = (e) => this.mousedown(e);
- this._areaTop.onmousemove = (e) => this.mousemove(e);
- let div = document.getElementById('app');
- div.append(this._area);
- div.append(this._areaTop);
- this.resizeArea();
- window.addEventListener('resize', this.resizeArea.bind(this));
- this._selecionado = null;
-
- }
-
- resizeArea() {
- let offset = this.area.getBoundingClientRect();
- this._area.setAttribute('width', window.innerWidth - offset.left + 'px');
- this._area.setAttribute('height', window.innerHeight - offset.top + 'px');
- this._areaTop.setAttribute('width', window.innerWidth - offset.left + 'px');
- this._areaTop.setAttribute('height', window.innerHeight - offset.top + 'px');
- }
-
- mousedown(e) {
- e.preventDefault();
- e.stopPropagation();
-
- if (this.app.menuSuperior.selecionado == this.app.menuSuperior.CODE_PONTO) {
- let offset = this.area.getBoundingClientRect();
- let x = e.clientX - offset.left;
- let y = e.clientY - offset.top;
- this.adicionaObjetos(new Ponto(x, y));
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
- mouseup(e) {
-
- }
-
- mousemove(e) {
- if (this.selecionado) {
- let offset = this.area.getBoundingClientRect();
- let x = e.clientX - offset.left;
- let y = e.clientY - offset.top;
- this.selecionado.mover(x, y);
- }
- }
-
- adicionaObjetos(objeto) {
- this.app.objetos.push(objeto);
- this._area.append(objeto.draw());
- }
-
- get area() {
- return this._area;
- }
-
- get selecionado() {
- return this._selecionado;
- }
-
- set selecionado(selecionado) {
- this._selecionado = selecionado;
- }
-
- }
|