Merge branch 'master' of github.com:jean-emmanuel/open-stage-control

This commit is contained in:
bordun 2021-03-19 18:51:53 +01:00
commit fc78e64bda
10 changed files with 115 additions and 15 deletions

View file

@ -109,9 +109,17 @@ class Editor {
this.widgetDragResize.on('move', (e)=>{
var left = Math.round(e.left / GRIDWIDTH) * GRIDWIDTH,
top = Math.round(e.top / GRIDWIDTH) * GRIDWIDTH
var dX = left - e.initLeft,
dY = top - e.initTop
this.moveWidget(dX, dY)
if (e.copying) {
this.copyWidget()
var index = Math.max(...this.selectedWidgets.map(w=>w.parent.children.indexOf(w)))
this.select(this.selectedWidgets[0].parent)
this.pasteWidget(left, top, e.shiftKey, index + 1)
} else {
var dX = left - e.initLeft,
dY = top - e.initTop
this.moveWidget(dX, dY)
}
})
this.widgetDragResize.on('drag-resize', (e)=>{
var width = Math.round(e.width / GRIDWIDTH) * GRIDWIDTH,
@ -558,7 +566,7 @@ class Editor {
}
pasteWidget(x, y, increment) {
pasteWidget(x, y, increment, index) {
if (!this.selectedWidgets.length || this.clipboard === null) return
if (
@ -625,13 +633,18 @@ class Editor {
var store = this.clipboard[0].type === 'tab' ? 'tabs' : 'widgets'
this.selectedWidgets[0].props[store] = this.selectedWidgets[0].props[store] || []
this.selectedWidgets[0].props[store] = this.selectedWidgets[0].props[store].concat(pastedData)
var indexes = {addedIndexes: []}
var indexes = {addedIndexes: []},
start = index || this.selectedWidgets[0].props[store].length
this.selectedWidgets[0].props[store].splice(start, 0, ...pastedData)
for (let i = 0; i < pastedData.length; i++) {
indexes.addedIndexes.push(this.selectedWidgets[0].props[store].length - 1 - i )
indexes.addedIndexes.push(start + pastedData.length - 1 - i )
}
if (index)indexes.reuseChildren=false
updateWidget(this.selectedWidgets[0], indexes)
this.pushHistory(indexes)

View file

@ -38,11 +38,13 @@ class UiDragResize extends UiWidget {
this.handles = DOM.get(this.container, '.handle')
this.dragging = null
this.copying = null
this.shiftKey = false
this.on('draginit', (event)=>{
var node = event.firstTarget
if (event.shiftKey || !this.handles.includes(node)) return
if ((event.shiftKey && !event.altKey) || !this.handles.includes(node)) return
this.initLeft = this.left
this.initTop = this.top
@ -85,14 +87,19 @@ class UiDragResize extends UiWidget {
this.on('dragend', (event)=>{
if (!this.dragging) return
var node = event.firstTarget
if (!this.handles.includes(node)) return
this.container.classList.remove('dragging')
this.left = Math.max(0, this.left)
this.top = Math.max(0, this.top)
this.shiftKey = event.shiftKey
this.trigger(this.dragging.indexOf('left') > -1 ? 'move' : 'drag-resize', this)
this.dragging = null
this.copying = null
this.shiftKey = false
}, {element: this.container})
@ -108,6 +115,13 @@ class UiDragResize extends UiWidget {
}, (e)=>{
this.handles[0].classList.remove('full')
})
keyboardJS.bind('alt+c', (e)=>{
this.copying = true
this.container.classList.add('copying')
}, (e)=>{
this.copying = false
this.container.classList.remove('copying')
})
})
}

View file

@ -25,7 +25,7 @@ class UiSelectArea {
}
mousedown(e) {
if (!e.shiftKey || event.button === 2) return
if (!e.shiftKey || event.altKey || event.button === 2) return
this.startX = this.curX = e.clientX
this.startY = this.curY = e.clientY
this.down = true

View file

@ -2,6 +2,9 @@
var mod = (navigator.platform || '').match('Mac') ? 'metaKey' : 'ctrlKey'
var localZoom = 1,
mousePos = [0, 0]
document.addEventListener('wheel', function(event) {
if (event.ctrlKey) event.preventDefault()
if (event[mod]) {
@ -10,20 +13,53 @@ document.addEventListener('wheel', function(event) {
if (event.deltaY === 0) return
var d = - event.deltaY / (10 * Math.abs(event.deltaY))
PXSCALE = parseFloat(d) + parseFloat(PXSCALE)
document.documentElement.style.setProperty('font-size', PXSCALE + 'px')
DOM.dispatchEvent(window, 'resize')
let d = - event.deltaY / (10 * Math.abs(event.deltaY))
if (!isNaN(d)) {
PXSCALE = parseFloat(d) + parseFloat(PXSCALE)
document.documentElement.style.setProperty('font-size', PXSCALE + 'px')
DOM.dispatchEvent(window, 'resize')
}
}
if (event.altKey) {
event.preventDefault()
let d = - event.deltaY / (10 * Math.abs(event.deltaY))
if (!isNaN(d)) {
localZoom = Math.max(parseFloat(d) + parseFloat(localZoom), 1)
applylocalZoom()
}
}
}, {passive: false})
document.addEventListener('mousemove', function(event) {
mousePos = [
event.screenX / screen.width * 100,
event.screenY / screen.height * 100
]
if (localZoom !== 1) {
applylocalZoom()
}
}, {passive: false})
function applylocalZoom() {
if (localZoom === 1) {
document.body.style.transformOrigin = ''
document.body.style.transform = ''
} else {
document.body.style.transformOrigin = `${mousePos[0]}% ${mousePos[1]}%`
requestAnimationFrame(()=>{
document.body.style.transform = `scale(${localZoom})`
})
}
}
document.addEventListener('keydown', function(event){
if (event[mod] && (event.keyCode == 96 || event.keyCode == 48)) {
PXSCALE = INITIALZOOM
document.documentElement.style.setProperty('font-size', PXSCALE + 'px')
DOM.dispatchEvent(window, 'resize')
localZoom = 1
applylocalZoom()
}
}, {passive: true})

View file

@ -39,6 +39,8 @@ module.exports = class File extends Widget {
if (this.getProp('align') === 'left') this.widget.classList.add('left')
if (this.getProp('align') === 'right') this.widget.classList.add('right')
if (this.getProp('mode') === 'save') this.widget.classList.add('save')
if (this.getProp('hidePath')) this.widget.classList.add('hide-path')
this.text = DOM.get(this.widget, '.text')[0]
this.widget.addEventListener('fast-click', (e)=>{