From 6091444e65281cdcdc5e1e80f094648048d397e1 Mon Sep 17 00:00:00 2001 From: neauoire Date: Sun, 10 Nov 2019 11:30:43 -0500 Subject: [PATCH] Fixed issue with window hiding on linux --- desktop/sources/scripts/client.js | 2 +- desktop/sources/scripts/library.js | 9 +++--- desktop/sources/scripts/surface.js | 46 +++++++++++------------------- 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/desktop/sources/scripts/client.js b/desktop/sources/scripts/client.js index 86f997e..39782c2 100644 --- a/desktop/sources/scripts/client.js +++ b/desktop/sources/scripts/client.js @@ -180,7 +180,7 @@ function Client () { if (file.type === 'image/jpeg' || file.type === 'image/png') { const img = new Image() img.onload = () => { - this.cache.set(file.name, img.src) + this.cache.set(file.name, img) this.commander.injectPath(file.name) this.log('Loaded ' + file.name) } diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index 3964f87..187ca84 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -5,11 +5,10 @@ function Library (client) { // IO this.import = async (name, shape, alpha = 1) => { // Imports a graphic file with format. - const src = client.cache.get(name) - if (!src) { client.log('No data for ' + name); return } - const img = new Image() - img.src = src - return client.surface.draw(img, shape, alpha) + const img = client.cache.get(name) + if (!img) { client.log('No data for ' + name); return } + client.surface.draw(img, shape, alpha) + return shape || this.rect(0, 0, img.width, img.height) } this.export = async (name = 'export', type = 'image/png', quality = 1.0) => { // Exports a graphic file with format. diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index 38c3a9e..a1391d4 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -173,43 +173,29 @@ function Surface (client) { // IO - this.open = (path, ratio = 1) => { - return new Promise(resolve => { - const img = new Image() - img.src = path - img.onload = () => { - const rect = { x: 0, y: 0, w: img.width * ratio, h: img.height * ratio } - this.resize(rect, true) - this.context.drawImage(img, rect.x, rect.y, rect.w, rect.h) - resolve() - } - }) - } - this.draw = function (img, shape = this.getFrame(), alpha = 1) { return new Promise(resolve => { - img.onload = () => { - this.context.globalAlpha = alpha - if (isLine(shape)) { - this.context.drawImage(img, shape.a.x, shape.a.y, shape.b.x - shape.a.x, shape.b.y - shape.a.y) - } else if (isRect(shape)) { - const fit = fitRect({ w: img.width, h: img.height }, { w: shape.w, h: shape.h }) - this.context.drawImage(img, shape.x, shape.y, fit.w, fit.h) - } else if (isCircle(shape)) { - const side = Math.sqrt(Math.pow(shape.r, 2) / 2) - const rect = { x: shape.cx - (side), y: shape.cy - (side), w: side * 2, h: side * 2 } - const fit = fitRect({ w: img.width, h: img.height }, { w: rect.w, h: rect.h }) - this.context.drawImage(img, rect.x, rect.y, fit.w, fit.h) - } else { - this.context.drawImage(img, shape.x, shape.y, img.width, img.height) - } - this.context.globalAlpha = 1 - resolve() + this.context.globalAlpha = alpha + if (isLine(shape)) { + this.context.drawImage(img, shape.a.x, shape.a.y, shape.b.x - shape.a.x, shape.b.y - shape.a.y) + } else if (isRect(shape)) { + const fit = fitRect({ w: img.width, h: img.height }, { w: shape.w, h: shape.h }) + this.context.drawImage(img, shape.x, shape.y, fit.w, fit.h) + } else if (isCircle(shape)) { + const side = Math.sqrt(Math.pow(shape.r, 2) / 2) + const rect = { x: shape.cx - (side), y: shape.cy - (side), w: side * 2, h: side * 2 } + const fit = fitRect({ w: img.width, h: img.height }, { w: rect.w, h: rect.h }) + this.context.drawImage(img, rect.x, rect.y, fit.w, fit.h) + } else { + this.context.drawImage(img, shape.x, shape.y, img.width, img.height) } + this.context.globalAlpha = 1 + resolve() }) } this.crop = function (rect) { + if (!isRect(rect)) { return } client.log(`Crop ${rect.w}x${rect.h} from ${rect.x}x${rect.y}`) const crop = this.copy(rect) this.resize(rect, true)