Re-implemented (export)

This commit is contained in:
neauoire
2019-11-02 17:11:41 -04:00
parent 707f056649
commit ff934f9f16
7 changed files with 45 additions and 54 deletions

View File

@@ -10,17 +10,17 @@ function Library (ronin) {
// IO
this.import = async (path, shape, alpha = 1) => { // Imports a graphic file with format.
const img = new Image()
img.src = path
return ronin.surface.draw(img, shape, alpha)
// const img = new Image()
// img.src = path
// return ronin.surface.draw(img, shape, alpha)
}
this.export = (path, quality = 1.0) => { // Exports a graphic file with format.
// if (!path) { console.warn('Missing export path'); return path }
// const dataUrl = ronin.surface.el.toDataURL(path.indexOf('.jpg') > -1 ? 'image/jpeg' : path.indexOf('.png') > -1 ? 'image/png' : format, quality)
// const data = dataUrl.replace(/^data:image\/png;base64,/, '').replace(/^data:image\/jpeg;base64,/, '')
// fs.writeFileSync(path, data, 'base64')
// return path
this.export = (name = 'export', type = 'image/png', quality = 1.0) => { // Exports a graphic file with format.
const base64 = ronin.surface.el.toDataURL(type, quality)
const link = document.createElement('a')
link.setAttribute('href', base64)
link.setAttribute('download', type === 'image/png' ? name + '.png' : name + '.jpg')
link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }))
}
this.open = async (path, ratio = 1) => { // Imports a graphic file and resizes the frame.

View File

@@ -83,11 +83,7 @@ function Ronin () {
requestAnimationFrame(() => this.loop())
}
this.reset = function () {
this.theme.reset()
}
this.log = function (...msg) {
this.log = (...msg) => {
this.commander.setStatus(msg.reduce((acc, val) => {
return acc + JSON.stringify(val).replace(/"/g, '').trim() + ' '
}, ''))

View File

@@ -293,10 +293,11 @@ function Surface (ronin) {
}
this.fitWindow = function (size) {
const win = require('electron').remote.getCurrentWindow()
const pad = { w: ronin.commander.isVisible === true ? 400 : 60, h: 60 }
if (size.w < 10 || size.h < 10) { return }
win.setSize(Math.floor((size.w / this.ratio) + pad.w), Math.floor((size.h / this.ratio) + pad.h), true)
console.log('TODO')
// const win = require('electron').remote.getCurrentWindow()
// const pad = { w: ronin.commander.isVisible === true ? 400 : 60, h: 60 }
// if (size.w < 10 || size.h < 10) { return }
// win.setSize(Math.floor((size.w / this.ratio) + pad.w), Math.floor((size.h / this.ratio) + pad.h), true)
}
this.maximize = () => {