Implemented export format

This commit is contained in:
Devine Lu Linvega 2017-11-09 21:42:04 +13:00
parent 563fe93571
commit 5d878cfc21
3 changed files with 25 additions and 14 deletions

View File

@ -43,17 +43,17 @@ function Keyboard()
if(e.key == "o" && (e.ctrlKey || e.metaKey)){
e.preventDefault();
ronin.io.methods.import();
ronin.io.methods.load.run();
}
if(e.key == "s" && (e.ctrlKey || e.metaKey)){
e.preventDefault();
ronin.io.save();
ronin.io.methods.save.run();
}
if(e.key == "r" && (e.ctrlKey || e.metaKey)){
e.preventDefault();
ronin.io.render();
ronin.io.methods.save.run();
}
if(e.key == "H" && (e.ctrlKey || e.metaKey) && e.shiftKey){

View File

@ -5,7 +5,6 @@ function IO()
this.image = null;
this.methods.load = new Method("load","browser","Press enter to open the file browser.",function(q){
var filepath = q ? [q] : dialog.showOpenDialog({properties: ['openFile']});
if(!filepath){ console.log("Nothing to load"); return; }
@ -31,14 +30,15 @@ function IO()
ronin.preview.clear();
});
this.methods.save = new Method("save","name","Export canvas.",function(q){
this.methods.save = new Method("save","jpg/png","Export canvas.",function(q){
var ext = q ? q : "jpg";
var fs = require('fs');
var data = ronin.render.to_base64('jpg').replace(/^data:image\/\w+;base64,/, "");
var data = ronin.render.to_base64(ext).replace(/^data:image\/\w+;base64,/, "");
var buf = new Buffer(data, 'base64');
dialog.showSaveDialog((fileName) => {
if (fileName === undefined){ return; }
fs.writeFile(fileName+'.jpg', buf);
fs.writeFile(fileName+'.'+ext, buf);
});
});

View File

@ -2,8 +2,19 @@ function Path()
{
Module.call(this,"path","Trace lines and to draw shapes.");
this.settings = {thickness:30,color:"black",cap:"square"};
this.settings = {thickness:4,color:"white",cap:"square"};
this.methods.svg = new Method("svg","M0,0 L100,100","",function(q){
var path = ronin.commander.query().raw.replace("svg:","").trim();
var ctx = ronin.render.context();
ctx.beginPath();
ctx.lineCap = ronin.path.settings.cap;
ctx.lineWidth = ronin.path.settings.thickness;
ctx.strokeStyle = ronin.path.settings.color;
ctx.stroke(new Path2D(path));
ctx.closePath();
});
this.methods.stroke = new Method("stroke","x,y&","",function(q){
ronin.preview.clear();
@ -12,9 +23,9 @@ function Path()
var ctx = ronin.render.context();
ctx.beginPath();
ctx.lineCap = "butt";
ctx.lineWidth = 30;
ctx.strokeStyle = "black";
ctx.lineCap = r.path.settings.cap;
ctx.lineWidth = r.path.settings.thickness;
ctx.strokeStyle = r.path.settings.color;
ctx.stroke(new Path2D(path));
ctx.closePath();
});
@ -27,9 +38,9 @@ function Path()
var ctx = ronin.render.context();
ctx.beginPath();
ctx.lineCap = "butt";
ctx.lineWidth = 30;
ctx.fillStyle = "black";
ctx.lineCap = r.path.settings.cap;
ctx.lineWidth = r.path.settings.thickness;
ctx.strokeStyle = r.path.settings.color;
ctx.fill(new Path2D(path));
ctx.closePath();
});