From cf6ef637b76f34b51a21c92601818981d7029f01 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 27 Sep 2017 19:27:47 +1300 Subject: [PATCH] Improved import --- sources/scripts/docs.js | 5 +---- sources/scripts/io.js | 16 ++++++++++------ sources/scripts/layer.js | 9 ++++++++- sources/scripts/modules/frame.js | 21 ++++++++++----------- sources/scripts/ronin.js | 2 ++ 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/sources/scripts/docs.js b/sources/scripts/docs.js index 65d496c..ee3f5d9 100644 --- a/sources/scripts/docs.js +++ b/sources/scripts/docs.js @@ -10,11 +10,9 @@ function Docs() html += this.print_license(); - var str = html; - dialog.showSaveDialog((fileName) => { if (fileName === undefined){ return; } - fs.writeFile(fileName+".md", str, (err) => { + fs.writeFile(fileName, html, (err) => { if(err){ alert("An error ocurred creating the file "+ err.message); return; } }); }); @@ -72,7 +70,6 @@ function Docs() for(port_name in ports){ var port = ports[port_name]; - console.log(ports); html += "- `"+(port.input ? '->' : '')+""+port.name+""+(port.output ? '->' : '')+"` **("+port.value+"/"+port.max+")** "+port.docs+".\n"; } return html; diff --git a/sources/scripts/io.js b/sources/scripts/io.js index 2275810..e0b0752 100644 --- a/sources/scripts/io.js +++ b/sources/scripts/io.js @@ -3,8 +3,7 @@ function IO() this.render = function() { var fs = require('fs'); - var img = ronin.render.image(); - var data = img.replace(/^data:image\/\w+;base64,/, ""); + var data = ronin.render.to_data().replace(/^data:image\/\w+;base64,/, ""); var buf = new Buffer(data, 'base64'); dialog.showSaveDialog((fileName) => { @@ -36,11 +35,16 @@ function IO() base_image = new Image(); base_image.src = event.target.result; - var width = base_image.naturalWidth; - var height = base_image.naturalHeight; + var width = parseInt(base_image.naturalWidth * 0.5); + var height = parseInt(base_image.naturalHeight * 0.5); - ronin.frame.resize_to({width:width * 0.5,height:height * 0.5}); - ronin.render.context().drawImage(base_image, 0,0,width,height); + if(height > 900){ + width *= 0.5; + height *= 0.5; + } + + ronin.frame.resize_to({width:width,height:height}); + ronin.render.context().drawImage(base_image, 0,0,width * 2,height * 2); } reader.readAsDataURL(file); } diff --git a/sources/scripts/layer.js b/sources/scripts/layer.js index c700e79..8cc3f1e 100644 --- a/sources/scripts/layer.js +++ b/sources/scripts/layer.js @@ -33,11 +33,18 @@ function Layer() return this.context().getImageData(x, y, width * 2, height * 2); } - this.image = function() + this.to_data = function() { return this.el.toDataURL('image/png'); } + this.to_img = function() + { + var img = new Image(); + img.src = this.to_data(); + return img; + } + this.clear = function() { console.log("Clear") diff --git a/sources/scripts/modules/frame.js b/sources/scripts/modules/frame.js index cfe3314..c1793f2 100644 --- a/sources/scripts/modules/frame.js +++ b/sources/scripts/modules/frame.js @@ -2,7 +2,7 @@ function Frame() { Module.call(this,"frame"); - this.settings = {width:200,height:200}; + this.settings = {width:400,height:400}; this.methods = {}; @@ -17,20 +17,19 @@ function Frame() this.methods.rescale = function(p) { - var img = new Image(); - var data = ronin.render.image(); - - img.src = data; + // Create a canvas copy var copy_canvas = document.createElement("canvas"); + copy_canvas.width = ronin.frame.settings.width * 2; + copy_canvas.height = ronin.frame.settings.height * 2; var copy_ctx = copy_canvas.getContext("2d"); + copy_ctx.drawImage(ronin.render.to_img(), 0, 0); - copy_canvas.width = ronin.frame.settings.width; - copy_canvas.height = ronin.frame.settings.height; - copy_ctx.drawImage(img, 0, 0); + var new_size = {width:ronin.frame.settings.width * p,height:ronin.frame.settings.height * p}; - // ronin.render.clear(); - // ronin.frame.resize_to(p); - ronin.render.context().drawImage(copy_ctx.canvas,0,0,ronin.frame.settings.width * 0.5,ronin.frame.settings.height * 0.5); + // Paste + ronin.render.clear(); + ronin.frame.resize_to(new_size); + ronin.render.context().drawImage(copy_ctx.canvas,0,0,new_size.width * 2,new_size.height * 2); } this.methods.crop = function(p) diff --git a/sources/scripts/ronin.js b/sources/scripts/ronin.js index 68711d9..22c276b 100644 --- a/sources/scripts/ronin.js +++ b/sources/scripts/ronin.js @@ -63,5 +63,7 @@ function Ronin() this.render.update(); this.grid.update(); this.guide.update(); + + this.commander.input_el.value = "frame rescale:0.5"; } } \ No newline at end of file