Started to migrate methods to the new systems
This commit is contained in:
		
							
								
								
									
										2
									
								
								main.js
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.js
									
									
									
									
									
								
							| @@ -56,7 +56,7 @@ app.on('ready', () => | |||||||
|     is_shown = true; |     is_shown = true; | ||||||
|   }) |   }) | ||||||
|   // Open the DevTools. |   // Open the DevTools. | ||||||
|   // win.webContents.openDevTools() |   win.webContents.openDevTools() | ||||||
| }) | }) | ||||||
|  |  | ||||||
| app.on('window-all-closed', () =>  | app.on('window-all-closed', () =>  | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| <html> | <html> | ||||||
|   <head> |   <head> | ||||||
|     <script type="text/javascript" src="scripts/core/module.js"></script> |     <script type="text/javascript" src="scripts/core/module.js"></script> | ||||||
|  |     <script type="text/javascript" src="scripts/core/method.js"></script> | ||||||
|     <script type="text/javascript" src="scripts/modules/frame.js"></script> |     <script type="text/javascript" src="scripts/modules/frame.js"></script> | ||||||
|     <script type="text/javascript" src="scripts/modules/brush.js"></script> |     <script type="text/javascript" src="scripts/modules/brush.js"></script> | ||||||
|     <script type="text/javascript" src="scripts/modules/line.js"></script> |     <script type="text/javascript" src="scripts/modules/line.js"></script> | ||||||
|   | |||||||
| @@ -16,4 +16,5 @@ yu { display:block; } | |||||||
| #commander { z-index: 9000 } | #commander { z-index: 9000 } | ||||||
| #commander input { background: transparent;width: calc(100vw - 30px);display: block;line-height: 40px;font-size: 11px;color: white; margin-left:20px; } | #commander input { background: transparent;width: calc(100vw - 30px);display: block;line-height: 40px;font-size: 11px;color: white; margin-left:20px; } | ||||||
| #hint { background:black; color:#666; padding-left:20px;} | #hint { background:black; color:#666; padding-left:20px;} | ||||||
| #hint b { font-family: 'input_mono_regular' } | #hint b { font-family: 'input_mono_regular'; color:#999;} | ||||||
|  | #hint i { font-style: italic; } | ||||||
| @@ -30,7 +30,7 @@ function Commander() | |||||||
|     for(method_id in q.methods){ |     for(method_id in q.methods){ | ||||||
|       var method_param = q.methods[method_id]; |       var method_param = q.methods[method_id]; | ||||||
|       if(!ronin.modules[q.module].methods[method_id]){ console.log("Missing method",method_id); return; } |       if(!ronin.modules[q.module].methods[method_id]){ console.log("Missing method",method_id); return; } | ||||||
|       ronin.modules[q.module].methods[method_id](method_param); |       ronin.modules[q.module].methods[method_id].run(method_param); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     ronin.commander.input_el.value = ""; |     ronin.commander.input_el.value = ""; | ||||||
|   | |||||||
| @@ -19,10 +19,14 @@ function Hint() | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     var target_module = ronin.commander.query().module; |     var target_module = ronin.commander.query().module; | ||||||
|  |     var target_method = Object.keys(ronin.commander.query().methods).length > 0 ? Object.keys(ronin.commander.query().methods)[0] : null | ||||||
|  |  | ||||||
|     if(ronin.commander.input_el.value == ""){ |     if(ronin.commander.input_el.value == ""){ | ||||||
|       this.el.innerHTML = html; |       this.el.innerHTML = html; | ||||||
|     } |     } | ||||||
|  |     else if(ronin.modules[target_module] && ronin.modules[target_module].methods[target_method]){ | ||||||
|  |       this.el.innerHTML = this.pad(ronin.commander.input_el.value)+ronin.modules[target_module].methods[target_method].docs(); | ||||||
|  |     } | ||||||
|     else if(ronin.modules[target_module]){ |     else if(ronin.modules[target_module]){ | ||||||
|       this.el.innerHTML = this.pad(ronin.commander.input_el.value)+ronin.modules[target_module].hint(); |       this.el.innerHTML = this.pad(ronin.commander.input_el.value)+ronin.modules[target_module].hint(); | ||||||
|     } |     } | ||||||
|   | |||||||
							
								
								
									
										18
									
								
								sources/scripts/core/method.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								sources/scripts/core/method.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | |||||||
|  | function Method(name,params,info = "Missing documentation") | ||||||
|  | { | ||||||
|  |   this.name = name; | ||||||
|  |   this.params = params; | ||||||
|  |   this.info = info; | ||||||
|  |  | ||||||
|  |   this.run = null; | ||||||
|  |  | ||||||
|  |   this.hint = function() | ||||||
|  |   { | ||||||
|  |     return "<b>"+this.name+"</b>:"+this.params+" "; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   this.docs = function() | ||||||
|  |   { | ||||||
|  |     return "["+this.params+"] <i>"+this.info+"</i>"; | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -13,7 +13,7 @@ function Module(name,docs = "Missing documentation.") | |||||||
|  |  | ||||||
|     for(id in this.methods){ |     for(id in this.methods){ | ||||||
|       var v = this.methods[id]; |       var v = this.methods[id]; | ||||||
|       html += id+": "; |       html += v.hint(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     for(setting_id in this.settings){ |     for(setting_id in this.settings){ | ||||||
| @@ -26,6 +26,6 @@ function Module(name,docs = "Missing documentation.") | |||||||
|       html += route_id+"->"+route_val+" "; |       html += route_id+"->"+route_val+" "; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return html.trim() != "" ? "<b>"+this.name+"</b> "+html.trim() : ""; |     return html.trim() != "" ? " "+html.trim() : ""; | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @@ -6,7 +6,9 @@ function Frame() | |||||||
|  |  | ||||||
|   this.methods = {}; |   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); |     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); |     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 |     // Create a canvas copy | ||||||
|     var copy_canvas = document.createElement("canvas"); |     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); |     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); |     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); |     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"); |     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); |     ronin.render.fill(q); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -5,28 +5,12 @@ function IO() | |||||||
|   this.settings = {anchor:{x:0,y:0,width:200,height:200}}; |   this.settings = {anchor:{x:0,y:0,width:200,height:200}}; | ||||||
|  |  | ||||||
|   this.methods = {}; |   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.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']}); |     var filepath = dialog.showOpenDialog({properties: ['openFile']}); | ||||||
|  |  | ||||||
| @@ -34,10 +18,8 @@ function IO() | |||||||
|  |  | ||||||
|     fs.readFile(filepath[0], 'utf-8', (err, data) => { |     fs.readFile(filepath[0], 'utf-8', (err, data) => { | ||||||
|       if(err){ alert("An error ocurred reading the file :" + err.message); return; } |       if(err){ alert("An error ocurred reading the file :" + err.message); return; } | ||||||
|        |  | ||||||
|       var img = new Image(); |       var img = new Image(); | ||||||
|       img.src = filepath[0]; |       img.src = filepath[0]; | ||||||
|  |  | ||||||
|       img.onload = function() { |       img.onload = function() { | ||||||
|         ronin.io.image = img; |         ronin.io.image = img; | ||||||
|         ronin.commander.inject("io draw:20,20|100x100"); |         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.draw_image(ronin.render.context(),ronin.io.image,ronin.commander.query().methods.draw); | ||||||
|     ronin.io.image = null; |     ronin.io.image = null; | ||||||
|     ronin.preview.clear(); |     ronin.preview.clear(); | ||||||
|   } |   } | ||||||
|    |    | ||||||
|   this.methods.save = function(q) |   this.methods.save = new Method("save","name"); | ||||||
|  |  | ||||||
|  |   this.methods.save.run = function(q) | ||||||
|   { |   { | ||||||
|     // TODO |     // TODO | ||||||
|     ronin.io.render(); |     ronin.io.render(); | ||||||
| @@ -130,13 +118,10 @@ function IO() | |||||||
|  |  | ||||||
|   this.draw_image = function(ctx = ronin.preview.context(),img,params) |   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 width = parseInt(img.naturalWidth * 0.5); | ||||||
|     var height = parseInt(img.naturalHeight * 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."); |   Module.call(this,"path","Trace lines and to draw shapes."); | ||||||
|  |  | ||||||
|   this.settings = {thickness:30,color:"black",cap:"square"}; |   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(); |     ronin.preview.clear(); | ||||||
|  |  | ||||||
| @@ -20,7 +21,8 @@ function Path() | |||||||
|     ctx.closePath(); |     ctx.closePath(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   this.methods.fill = function(q) |   this.methods.fill = new Method("fill","x,y&"); | ||||||
|  |   this.methods.fill.run = function(q) | ||||||
|   { |   { | ||||||
|     ronin.preview.clear(); |     ronin.preview.clear(); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user