Started to migrate methods to the new systems
This commit is contained in:
@@ -6,7 +6,9 @@ function Frame()
|
||||
|
||||
this.methods = {};
|
||||
|
||||
this.methods.resize = function(q)
|
||||
this.methods.resize = new Method("resize","WxH");
|
||||
|
||||
this.methods.resize.run = function(q)
|
||||
{
|
||||
var data = ronin.render.select(0,0,ronin.frame.settings.width,ronin.frame.settings.height);
|
||||
|
||||
@@ -15,7 +17,9 @@ function Frame()
|
||||
ronin.render.context().putImageData(data, 0, 0);
|
||||
}
|
||||
|
||||
this.methods.rescale = function(p)
|
||||
this.methods.rescale = new Method("rescale","X,Y|WxH");
|
||||
|
||||
this.methods.rescale.run = function(p)
|
||||
{
|
||||
// Create a canvas copy
|
||||
var copy_canvas = document.createElement("canvas");
|
||||
@@ -32,7 +36,8 @@ function Frame()
|
||||
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 = new Method("crop","X,Y|WxH");
|
||||
this.methods.crop.run = function(p)
|
||||
{
|
||||
var data = ronin.render.select(p.x,p.y,p.width,p.height);
|
||||
|
||||
@@ -41,12 +46,14 @@ function Frame()
|
||||
ronin.render.context().putImageData(data, 0, 0);
|
||||
}
|
||||
|
||||
this.methods.clear = function(q)
|
||||
this.methods.clear = new Method("clear","X,Y|WxH");
|
||||
this.methods.clear.run = function(q)
|
||||
{
|
||||
ronin.render.fill("blue");
|
||||
}
|
||||
|
||||
this.methods.fill = function(q)
|
||||
this.methods.fill = new Method("fill","X,Y|WxH");
|
||||
this.methods.fill.run = function(q)
|
||||
{
|
||||
ronin.render.fill(q);
|
||||
}
|
||||
|
||||
@@ -5,28 +5,12 @@ function IO()
|
||||
this.settings = {anchor:{x:0,y:0,width:200,height:200}};
|
||||
|
||||
this.methods = {};
|
||||
|
||||
this.methods.import = function(q)
|
||||
{
|
||||
var filepath = dialog.showOpenDialog({properties: ['openFile']});
|
||||
|
||||
if(!filepath){ console.log("Nothing to load"); return; }
|
||||
|
||||
fs.readFile(filepath[0], 'utf-8', (err, data) => {
|
||||
if(err){ alert("An error ocurred reading the file :" + err.message); return; }
|
||||
|
||||
var img = new Image();
|
||||
img.src = filepath[0];
|
||||
|
||||
img.onload = function() {
|
||||
ronin.io.draw_image(ronin.render.context(),img,ronin.commander.query());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this.image = null;
|
||||
|
||||
this.methods.load = function(q)
|
||||
this.methods.load = new Method("load","browser","Press enter to open the file browser.");
|
||||
|
||||
this.methods.load.run = function(q)
|
||||
{
|
||||
var filepath = dialog.showOpenDialog({properties: ['openFile']});
|
||||
|
||||
@@ -34,10 +18,8 @@ function IO()
|
||||
|
||||
fs.readFile(filepath[0], 'utf-8', (err, data) => {
|
||||
if(err){ alert("An error ocurred reading the file :" + err.message); return; }
|
||||
|
||||
var img = new Image();
|
||||
img.src = filepath[0];
|
||||
|
||||
img.onload = function() {
|
||||
ronin.io.image = img;
|
||||
ronin.commander.inject("io draw:20,20|100x100");
|
||||
@@ -45,14 +27,20 @@ function IO()
|
||||
});
|
||||
}
|
||||
|
||||
this.methods.draw = function(q)
|
||||
this.methods.draw = new Method("draw","X,Y|WxH","Draw the loaded image pixels.");
|
||||
|
||||
this.methods.draw.run = function(q)
|
||||
{
|
||||
if(!ronin.io.image){ return; }
|
||||
|
||||
ronin.io.draw_image(ronin.render.context(),ronin.io.image,ronin.commander.query().methods.draw);
|
||||
ronin.io.image = null;
|
||||
ronin.preview.clear();
|
||||
}
|
||||
|
||||
this.methods.save = function(q)
|
||||
this.methods.save = new Method("save","name");
|
||||
|
||||
this.methods.save.run = function(q)
|
||||
{
|
||||
// TODO
|
||||
ronin.io.render();
|
||||
@@ -130,13 +118,10 @@ function IO()
|
||||
|
||||
this.draw_image = function(ctx = ronin.preview.context(),img,params)
|
||||
{
|
||||
var anchor = params ? params : ronin.io.settings.anchor;
|
||||
|
||||
console.log("draw",ctx)
|
||||
var width = parseInt(img.naturalWidth * 0.5);
|
||||
var height = parseInt(img.naturalHeight * 0.5);
|
||||
var scale = (anchor.width/width) * 2;
|
||||
var scale = (params.width/width) * 2;
|
||||
|
||||
ctx.drawImage(img, anchor.x * 2,anchor.y * 2,width * scale,height * scale);
|
||||
ctx.drawImage(img, params.x * 2,params.y * 2,width * scale,height * scale);
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,9 @@ function Path()
|
||||
Module.call(this,"path","Trace lines and to draw shapes.");
|
||||
|
||||
this.settings = {thickness:30,color:"black",cap:"square"};
|
||||
|
||||
this.methods.stroke = function(q)
|
||||
|
||||
this.methods.stroke = new Method("stroke","x,y&");
|
||||
this.methods.stroke.run = function(q)
|
||||
{
|
||||
ronin.preview.clear();
|
||||
|
||||
@@ -20,7 +21,8 @@ function Path()
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
this.methods.fill = function(q)
|
||||
this.methods.fill = new Method("fill","x,y&");
|
||||
this.methods.fill.run = function(q)
|
||||
{
|
||||
ronin.preview.clear();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user