Improved import

This commit is contained in:
Devine Lu Linvega 2017-09-27 19:27:47 +13:00
parent aacde3c26e
commit cf6ef637b7
5 changed files with 31 additions and 22 deletions

View File

@ -10,11 +10,9 @@ function Docs()
html += this.print_license(); html += this.print_license();
var str = html;
dialog.showSaveDialog((fileName) => { dialog.showSaveDialog((fileName) => {
if (fileName === undefined){ return; } 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; } if(err){ alert("An error ocurred creating the file "+ err.message); return; }
}); });
}); });
@ -72,7 +70,6 @@ function Docs()
for(port_name in ports){ for(port_name in ports){
var port = ports[port_name]; var port = ports[port_name];
console.log(ports);
html += "- `"+(port.input ? '->' : '')+""+port.name+""+(port.output ? '->' : '')+"` **("+port.value+"/"+port.max+")** "+port.docs+".\n"; html += "- `"+(port.input ? '->' : '')+""+port.name+""+(port.output ? '->' : '')+"` **("+port.value+"/"+port.max+")** "+port.docs+".\n";
} }
return html; return html;

View File

@ -3,8 +3,7 @@ function IO()
this.render = function() this.render = function()
{ {
var fs = require('fs'); var fs = require('fs');
var img = ronin.render.image(); var data = ronin.render.to_data().replace(/^data:image\/\w+;base64,/, "");
var data = img.replace(/^data:image\/\w+;base64,/, "");
var buf = new Buffer(data, 'base64'); var buf = new Buffer(data, 'base64');
dialog.showSaveDialog((fileName) => { dialog.showSaveDialog((fileName) => {
@ -36,11 +35,16 @@ function IO()
base_image = new Image(); base_image = new Image();
base_image.src = event.target.result; base_image.src = event.target.result;
var width = base_image.naturalWidth; var width = parseInt(base_image.naturalWidth * 0.5);
var height = base_image.naturalHeight; var height = parseInt(base_image.naturalHeight * 0.5);
ronin.frame.resize_to({width:width * 0.5,height:height * 0.5}); if(height > 900){
ronin.render.context().drawImage(base_image, 0,0,width,height); 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); reader.readAsDataURL(file);
} }

View File

@ -33,11 +33,18 @@ function Layer()
return this.context().getImageData(x, y, width * 2, height * 2); return this.context().getImageData(x, y, width * 2, height * 2);
} }
this.image = function() this.to_data = function()
{ {
return this.el.toDataURL('image/png'); return this.el.toDataURL('image/png');
} }
this.to_img = function()
{
var img = new Image();
img.src = this.to_data();
return img;
}
this.clear = function() this.clear = function()
{ {
console.log("Clear") console.log("Clear")

View File

@ -2,7 +2,7 @@ function Frame()
{ {
Module.call(this,"frame"); Module.call(this,"frame");
this.settings = {width:200,height:200}; this.settings = {width:400,height:400};
this.methods = {}; this.methods = {};
@ -17,20 +17,19 @@ function Frame()
this.methods.rescale = function(p) this.methods.rescale = function(p)
{ {
var img = new Image(); // Create a canvas copy
var data = ronin.render.image();
img.src = data;
var copy_canvas = document.createElement("canvas"); 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"); var copy_ctx = copy_canvas.getContext("2d");
copy_ctx.drawImage(ronin.render.to_img(), 0, 0);
copy_canvas.width = ronin.frame.settings.width; var new_size = {width:ronin.frame.settings.width * p,height:ronin.frame.settings.height * p};
copy_canvas.height = ronin.frame.settings.height;
copy_ctx.drawImage(img, 0, 0);
// ronin.render.clear(); // Paste
// ronin.frame.resize_to(p); ronin.render.clear();
ronin.render.context().drawImage(copy_ctx.canvas,0,0,ronin.frame.settings.width * 0.5,ronin.frame.settings.height * 0.5); 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) this.methods.crop = function(p)

View File

@ -63,5 +63,7 @@ function Ronin()
this.render.update(); this.render.update();
this.grid.update(); this.grid.update();
this.guide.update(); this.guide.update();
this.commander.input_el.value = "frame rescale:0.5";
} }
} }