Fixed issues with exports
This commit is contained in:
parent
dc1b8738ac
commit
e51568f631
@ -3,10 +3,12 @@ function Frame()
|
||||
Module.call(this,"frame","Manager for the canvas size");
|
||||
|
||||
this.el = document.createElement('surface');
|
||||
this.background = "pink";
|
||||
|
||||
this.install = function()
|
||||
{
|
||||
ronin.el.appendChild(this.el);
|
||||
this.el.style.backgroundColor = this.background;
|
||||
}
|
||||
|
||||
this.methods.new = new Method("new","WxH","New Canvas",function(q){
|
||||
@ -19,6 +21,11 @@ function Frame()
|
||||
this.height = 400;
|
||||
this.zoom = {scale:1,offset:{x:0,y:0}};
|
||||
|
||||
this.methods.set_background = new Method("set_background","WxH","Resize canvas to size.",function(q){
|
||||
ronin.frame.background = q;
|
||||
ronin.frame.el.style.backgroundColor = q;
|
||||
});
|
||||
|
||||
this.methods.resize = new Method("resize","WxH","Resize canvas to size.",function(q){
|
||||
var data = ronin.cursor.target.select(0,0,ronin.frame.width,ronin.frame.height);
|
||||
ronin.cursor.target.clear();
|
||||
|
@ -38,15 +38,8 @@ function IO()
|
||||
});
|
||||
});
|
||||
|
||||
this.methods.draw = new Method("draw","X,Y|WxH","Draw the loaded image pixels.",function(q){
|
||||
if(!ronin.io.image){ return; }
|
||||
|
||||
ronin.io.draw_image(ronin.cursor.target.context(),ronin.io.image,ronin.commander.query().methods.draw);
|
||||
ronin.io.image = null;
|
||||
});
|
||||
|
||||
this.methods.save = new Method("save","jpg/png","Export canvas.",function(q){
|
||||
var ext = q ? q : "jpg";
|
||||
this.methods.render = new Method("render","png","Export canvas.",function(q){
|
||||
var ext = "png";
|
||||
var fs = require('fs');
|
||||
var data = ronin.io.render().to_base64(ext).replace(/^data:image\/\w+;base64,/, "");
|
||||
var buf = new Buffer(data, 'base64');
|
||||
@ -57,6 +50,25 @@ function IO()
|
||||
});
|
||||
});
|
||||
|
||||
this.methods.export = new Method("render","jpg","Export canvas.",function(q){
|
||||
var ext = "jpg";
|
||||
var fs = require('fs');
|
||||
var data = ronin.io.render(ronin.frame.background).to_base64(ext).replace(/^data:image\/\w+;base64,/, "");
|
||||
var buf = new Buffer(data, 'base64');
|
||||
|
||||
dialog.showSaveDialog((fileName) => {
|
||||
if (fileName === undefined){ return; }
|
||||
fs.writeFile(fileName+'.'+ext, buf);
|
||||
});
|
||||
});
|
||||
|
||||
this.methods.draw = new Method("draw","X,Y|WxH","Draw the loaded image pixels.",function(q){
|
||||
if(!ronin.io.image){ return; }
|
||||
|
||||
ronin.io.draw_image(ronin.cursor.target.context(),ronin.io.image,ronin.commander.query().methods.draw);
|
||||
ronin.io.image = null;
|
||||
});
|
||||
|
||||
// this.preview = function(q)
|
||||
// {
|
||||
// ronin.preview.clear();
|
||||
@ -66,11 +78,16 @@ function IO()
|
||||
// }
|
||||
// }
|
||||
|
||||
this.render = function()
|
||||
this.render = function(fill = null)
|
||||
{
|
||||
var export_layer = new Layer();
|
||||
|
||||
export_layer.update();
|
||||
export_layer.el.width = ronin.frame.width * 2;
|
||||
export_layer.el.height = ronin.frame.height * 2;
|
||||
|
||||
if(fill){
|
||||
export_layer.fill(fill);
|
||||
}
|
||||
export_layer.context().drawImage(ronin.layers.below.el,0,0)
|
||||
export_layer.context().drawImage(ronin.layers.above.el,0,0)
|
||||
return export_layer;
|
||||
|
@ -75,7 +75,9 @@ function Ronin()
|
||||
this.controller.add("default","File","New Image",() => { ronin.frame.methods.new.run(); },"CmdOrCtrl+N");
|
||||
this.controller.add("default","File","Open Image",() => { ronin.io.methods.open.run(); },"CmdOrCtrl+O");
|
||||
this.controller.add("default","File","Import Image",() => { ronin.io.methods.load.run(); },"CmdOrCtrl+I");
|
||||
this.controller.add("default","File","Export Image",() => { ronin.io.methods.save.run(); },"CmdOrCtrl+R");
|
||||
this.controller.add("default","File","Render Image(PNG)",() => { ronin.io.methods.render.run(); },"CmdOrCtrl+R");
|
||||
this.controller.add("default","File","Save Images(PNGs)",() => { ronin.io.methods.save.run(); },"CmdOrCtrl+S");
|
||||
this.controller.add("default","File","Export Image(JPG)",() => { ronin.io.methods.export.run(); },"CmdOrCtrl+E");
|
||||
|
||||
this.controller.add("default","Layers","Above Layer",() => { ronin.cursor.select_layer(ronin.layers.above); },"c");
|
||||
this.controller.add("default","Layers","Below Layer",() => { ronin.cursor.select_layer(ronin.layers.below); },"z");
|
||||
|
Loading…
x
Reference in New Issue
Block a user