2018-10-03 19:27:40 -04:00
|
|
|
'use strict'
|
2018-08-28 00:34:17 -04:00
|
|
|
|
2019-01-08 22:51:57 -05:00
|
|
|
function Interface (dotgrid) {
|
2018-10-03 19:27:40 -04:00
|
|
|
this.el = document.createElement('div')
|
|
|
|
this.el.id = 'interface'
|
2017-11-14 16:11:09 -05:00
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
this.el.appendChild(this.menu_el = document.createElement('div'))
|
|
|
|
this.menu_el.id = 'menu'
|
2018-03-06 19:50:41 -05:00
|
|
|
|
2019-01-11 23:22:38 -05:00
|
|
|
this.isVisible = true
|
2018-10-03 19:27:40 -04:00
|
|
|
this.zoom = false
|
2018-02-05 18:39:25 -05:00
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
this.install = function (host) {
|
|
|
|
host.appendChild(this.el)
|
2018-09-11 23:27:01 -04:00
|
|
|
}
|
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
this.start = function (host) {
|
|
|
|
let html = ''
|
2018-08-26 15:39:15 -04:00
|
|
|
let options = {
|
2018-10-03 19:27:40 -04:00
|
|
|
cast: {
|
|
|
|
line: { key: 'A', icon: 'M60,60 L240,240' },
|
|
|
|
arc_c: { key: 'S', icon: 'M60,60 A180,180 0 0,1 240,240' },
|
|
|
|
arc_r: { key: 'D', icon: 'M60,60 A180,180 0 0,0 240,240' },
|
|
|
|
bezier: { key: 'F', icon: 'M60,60 Q60,150 150,150 Q240,150 240,240' },
|
|
|
|
close: { key: 'Z', icon: 'M60,60 A180,180 0 0,1 240,240 M60,60 A180,180 0 0,0 240,240' }
|
2018-08-02 20:53:26 -04:00
|
|
|
},
|
2018-10-03 19:27:40 -04:00
|
|
|
toggle: {
|
|
|
|
linecap: { key: 'Q', icon: 'M60,60 L60,60 L180,180 L240,180 L240,240 L180,240 L180,180' },
|
|
|
|
linejoin: { key: 'W', icon: 'M60,60 L120,120 L180,120 M120,180 L180,180 L240,240' },
|
|
|
|
thickness: { key: '', icon: 'M120,90 L120,90 L90,120 L180,210 L210,180 Z M105,105 L105,105 L60,60 M195,195 L195,195 L240,240' },
|
|
|
|
mirror: { key: 'E', icon: 'M60,60 L60,60 L120,120 M180,180 L180,180 L240,240 M210,90 L210,90 L180,120 M120,180 L120,180 L90,210' },
|
|
|
|
fill: { key: 'R', icon: 'M60,60 L60,150 L150,150 L240,150 L240,240 Z' }
|
2018-08-02 20:53:26 -04:00
|
|
|
},
|
2018-10-03 19:27:40 -04:00
|
|
|
misc: {
|
|
|
|
color: { key: 'G', icon: 'M150,60 A90,90 0 0,1 240,150 A-90,90 0 0,1 150,240 A-90,-90 0 0,1 60,150 A90,-90 0 0,1 150,60' }
|
2018-08-03 23:55:08 -04:00
|
|
|
},
|
2018-10-03 19:27:40 -04:00
|
|
|
source: {
|
|
|
|
open: { key: 'c-O', icon: 'M155,65 A90,90 0 0,1 245,155 A90,90 0 0,1 155,245 A90,90 0 0,1 65,155 A90,90 0 0,1 155,65 M155,95 A60,60 0 0,1 215,155 A60,60 0 0,1 155,215 A60,60 0 0,1 95,155 A60,60 0 0,1 155,95 ' },
|
|
|
|
render: { key: 'c-R', icon: 'M155,65 A90,90 0 0,1 245,155 A90,90 0 0,1 155,245 A90,90 0 0,1 65,155 A90,90 0 0,1 155,65 M110,155 L110,155 L200,155 ' },
|
|
|
|
export: { key: 'c-E', icon: 'M155,65 A90,90 0 0,1 245,155 A90,90 0 0,1 155,245 A90,90 0 0,1 65,155 A90,90 0 0,1 155,65 M110,140 L110,140 L200,140 M110,170 L110,170 L200,170' },
|
|
|
|
save: { key: 'c-S', icon: 'M155,65 A90,90 0 0,1 245,155 A90,90 0 0,1 155,245 A90,90 0 0,1 65,155 A90,90 0 0,1 155,65 M110,155 L110,155 L200,155 M110,185 L110,185 L200,185 M110,125 L110,125 L200,125' },
|
|
|
|
grid: { key: 'H', icon: 'M65,155 Q155,245 245,155 M65,155 Q155,65 245,155 M155,125 A30,30 0 0,1 185,155 A30,30 0 0,1 155,185 A30,30 0 0,1 125,155 A30,30 0 0,1 155,125 ' }
|
|
|
|
}
|
2018-02-06 14:04:25 -05:00
|
|
|
}
|
2018-02-05 20:14:23 -05:00
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
for (const type in options) {
|
|
|
|
const tools = options[type]
|
|
|
|
for (const name in tools) {
|
|
|
|
const tool = tools[name]
|
2018-08-03 23:55:08 -04:00
|
|
|
html += `
|
|
|
|
<svg
|
|
|
|
id="option_${name}"
|
|
|
|
title="${name.capitalize()}"
|
2019-01-08 23:46:26 -05:00
|
|
|
onmouseout="DOTGRID.interface.out('${type}','${name}')"
|
|
|
|
onmouseup="DOTGRID.interface.up('${type}','${name}')"
|
|
|
|
onmousedown="DOTGRID.interface.down('${type}','${name}')"
|
|
|
|
onmouseover="DOTGRID.interface.over('${type}','${name}')"
|
2018-08-03 23:55:08 -04:00
|
|
|
viewBox="0 0 300 300"
|
|
|
|
class="icon ${type}">
|
2019-04-21 19:36:12 -04:00
|
|
|
<path id="${name}_path" class="icon_path" d="${tool.icon}"/>${name === 'depth' ? `<path class="icon_path inactive" d=""/>` : ''}
|
2018-08-03 23:55:08 -04:00
|
|
|
<rect ar="${name}" width="300" height="300" opacity="0">
|
2018-10-03 19:27:40 -04:00
|
|
|
<title>${name.capitalize()}${tool.key ? '(' + tool.key + ')' : ''}</title>
|
2018-08-03 23:55:08 -04:00
|
|
|
</rect>
|
|
|
|
</svg>`
|
2018-08-02 20:53:26 -04:00
|
|
|
}
|
2018-02-05 18:39:25 -05:00
|
|
|
}
|
2018-03-06 19:50:41 -05:00
|
|
|
this.menu_el.innerHTML = html
|
2019-01-08 22:51:57 -05:00
|
|
|
this.menu_el.appendChild(dotgrid.picker.el)
|
2017-11-14 16:11:09 -05:00
|
|
|
}
|
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
this.over = function (type, name) {
|
2019-01-08 22:51:57 -05:00
|
|
|
dotgrid.cursor.operation = {}
|
|
|
|
dotgrid.cursor.operation[type] = name
|
2018-10-04 00:24:28 -04:00
|
|
|
this.update(true)
|
2019-01-08 22:51:57 -05:00
|
|
|
dotgrid.renderer.update(true)
|
2018-08-02 19:50:09 -04:00
|
|
|
}
|
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
this.out = function (type, name) {
|
2019-01-08 22:51:57 -05:00
|
|
|
dotgrid.cursor.operation = ''
|
|
|
|
dotgrid.renderer.update(true)
|
2018-08-02 20:53:26 -04:00
|
|
|
}
|
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
this.up = function (type, name) {
|
2019-01-08 22:51:57 -05:00
|
|
|
if (!dotgrid.tool[type]) { console.warn(`Unknown option(type): ${type}.${name}`, dotgrid.tool); return }
|
2018-08-02 20:53:26 -04:00
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
this.update(true)
|
2019-01-08 22:51:57 -05:00
|
|
|
dotgrid.renderer.update(true)
|
2018-08-28 17:41:41 -04:00
|
|
|
}
|
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
this.down = function (type, name) {
|
2019-01-08 22:51:57 -05:00
|
|
|
if (!dotgrid.tool[type]) { console.warn(`Unknown option(type): ${type}.${name}`, dotgrid.tool); return }
|
2018-08-28 17:41:41 -04:00
|
|
|
|
2019-01-08 22:51:57 -05:00
|
|
|
dotgrid.tool[type](name)
|
2018-10-03 19:27:40 -04:00
|
|
|
this.update(true)
|
2019-01-08 22:51:57 -05:00
|
|
|
dotgrid.renderer.update(true)
|
2018-08-28 17:41:41 -04:00
|
|
|
}
|
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
this.prev_operation = null
|
2018-05-10 17:37:47 -04:00
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
this.update = function (force = false, id) {
|
2019-04-21 19:36:12 -04:00
|
|
|
if (this.prev_operation === dotgrid.cursor.operation && force === false) { return }
|
2018-05-10 17:37:47 -04:00
|
|
|
|
2019-01-08 23:53:28 -05:00
|
|
|
let multiVertices = null
|
2019-01-08 22:51:57 -05:00
|
|
|
let segments = dotgrid.tool.layer()
|
2019-01-08 23:53:28 -05:00
|
|
|
const sumSegments = dotgrid.tool.length()
|
2018-08-02 21:48:16 -04:00
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
for (const i in segments) {
|
2019-01-08 23:53:28 -05:00
|
|
|
if (segments[i].vertices.length > 2) { multiVertices = true; break }
|
2018-08-02 21:48:16 -04:00
|
|
|
}
|
|
|
|
|
2019-01-08 22:51:57 -05:00
|
|
|
document.getElementById('option_line').className.baseVal = !dotgrid.tool.canCast('line') ? 'icon inactive' : 'icon'
|
|
|
|
document.getElementById('option_arc_c').className.baseVal = !dotgrid.tool.canCast('arc_c') ? 'icon inactive' : 'icon'
|
|
|
|
document.getElementById('option_arc_r').className.baseVal = !dotgrid.tool.canCast('arc_r') ? 'icon inactive' : 'icon'
|
|
|
|
document.getElementById('option_bezier').className.baseVal = !dotgrid.tool.canCast('bezier') ? 'icon inactive' : 'icon'
|
|
|
|
document.getElementById('option_close').className.baseVal = !dotgrid.tool.canCast('close') ? 'icon inactive' : 'icon'
|
2018-10-03 19:27:40 -04:00
|
|
|
|
2019-01-08 22:51:57 -05:00
|
|
|
document.getElementById('option_thickness').className.baseVal = dotgrid.tool.layer().length < 1 ? 'icon inactive' : 'icon'
|
|
|
|
document.getElementById('option_linecap').className.baseVal = dotgrid.tool.layer().length < 1 ? 'icon inactive' : 'icon'
|
2019-01-08 23:53:28 -05:00
|
|
|
document.getElementById('option_linejoin').className.baseVal = dotgrid.tool.layer().length < 1 || !multiVertices ? 'icon inactive' : 'icon'
|
2019-01-08 22:51:57 -05:00
|
|
|
document.getElementById('option_mirror').className.baseVal = dotgrid.tool.layer().length < 1 ? 'icon inactive' : 'icon'
|
|
|
|
document.getElementById('option_fill').className.baseVal = dotgrid.tool.layer().length < 1 ? 'icon inactive' : 'icon'
|
2018-10-03 19:27:40 -04:00
|
|
|
|
2019-01-08 22:51:57 -05:00
|
|
|
document.getElementById('option_color').children[0].style.fill = dotgrid.tool.style().color
|
|
|
|
document.getElementById('option_color').children[0].style.stroke = dotgrid.tool.style().color
|
2018-10-03 19:27:40 -04:00
|
|
|
document.getElementById('option_color').className.baseVal = 'icon'
|
2018-08-03 23:55:08 -04:00
|
|
|
|
|
|
|
// Source
|
2018-05-10 17:37:47 -04:00
|
|
|
|
2019-01-08 23:53:28 -05:00
|
|
|
document.getElementById('option_save').className.baseVal = sumSegments < 1 ? 'icon inactive source' : 'icon source'
|
|
|
|
document.getElementById('option_export').className.baseVal = sumSegments < 1 ? 'icon inactive source' : 'icon source'
|
|
|
|
document.getElementById('option_render').className.baseVal = sumSegments < 1 ? 'icon inactive source' : 'icon source'
|
2018-10-03 19:27:40 -04:00
|
|
|
|
2019-01-08 22:51:57 -05:00
|
|
|
document.getElementById('option_grid').className.baseVal = dotgrid.renderer.showExtras ? 'icon inactive source' : 'icon source'
|
2018-08-03 23:55:08 -04:00
|
|
|
|
2018-08-28 17:41:41 -04:00
|
|
|
// Grid
|
2019-01-08 22:51:57 -05:00
|
|
|
if (dotgrid.renderer.showExtras) { document.getElementById('grid_path').setAttribute('d', 'M65,155 Q155,245 245,155 M65,155 Q155,65 245,155 M155,125 A30,30 0 0,1 185,155 A30,30 0 0,1 155,185 A30,30 0 0,1 125,155 A30,30 0 0,1 155,125 ') } else { document.getElementById('grid_path').setAttribute('d', 'M65,155 Q155,245 245,155 M65,155 ') }
|
2018-08-28 17:41:41 -04:00
|
|
|
|
2018-05-10 17:37:47 -04:00
|
|
|
// Mirror
|
2019-04-21 19:36:12 -04:00
|
|
|
if (dotgrid.tool.style().mirror_style === 0) { document.getElementById('mirror_path').setAttribute('d', 'M60,60 L60,60 L120,120 M180,180 L180,180 L240,240 M210,90 L210,90 L180,120 M120,180 L120,180 L90,210') } else if (dotgrid.tool.style().mirror_style === 1) { document.getElementById('mirror_path').setAttribute('d', 'M60,60 L240,240 M180,120 L210,90 M120,180 L90,210') } else if (dotgrid.tool.style().mirror_style === 2) { document.getElementById('mirror_path').setAttribute('d', 'M210,90 L210,90 L90,210 M60,60 L60,60 L120,120 M180,180 L180,180 L240,240') } else if (dotgrid.tool.style().mirror_style === 3) { document.getElementById('mirror_path').setAttribute('d', 'M60,60 L60,60 L120,120 L180,120 L210,90 M240,240 L240,240 L180,180 L120,180 L90,210') } else if (dotgrid.tool.style().mirror_style === 4) { document.getElementById('mirror_path').setAttribute('d', 'M120,120 L120,120 L120,120 L180,120 M120,150 L120,150 L180,150 M120,180 L120,180 L180,180 L180,180 L180,180 L240,240 M120,210 L120,210 L180,210 M120,90 L120,90 L180,90 M60,60 L60,60 L120,120 ') }
|
2018-05-10 17:37:47 -04:00
|
|
|
|
2019-01-08 22:51:57 -05:00
|
|
|
this.prev_operation = dotgrid.cursor.operation
|
2017-11-14 16:11:09 -05:00
|
|
|
}
|
2017-11-14 16:57:17 -05:00
|
|
|
|
2018-10-03 19:27:40 -04:00
|
|
|
this.toggle = function () {
|
2019-01-11 23:22:38 -05:00
|
|
|
this.isVisible = !this.isVisible
|
|
|
|
this.el.className = this.isVisible ? 'visible' : 'hidden'
|
|
|
|
}
|
|
|
|
|
|
|
|
document.onkeydown = function (e) {
|
|
|
|
if (e.key === 'Tab') {
|
|
|
|
DOTGRID.interface.toggle()
|
|
|
|
e.preventDefault()
|
|
|
|
}
|
2017-11-14 16:57:17 -05:00
|
|
|
}
|
2017-11-16 03:42:46 -05:00
|
|
|
}
|