Getting back to normality

This commit is contained in:
Devine Lu Linvega
2017-05-21 09:26:25 -10:00
parent 84244c1437
commit de175e12e7
11 changed files with 188 additions and 163 deletions

View File

@@ -3,20 +3,19 @@ function Frame(rune)
Module.call(this,rune);
this.element = null;
this.settings = {"size":new Rect("200x200")};
this.settings = {size:new Rect("200x200")};
this.layers = {};
this.active_layer = null;
this.render_layer = null;
this.add_method(new Method("resize",[new Rect().name]));
this.add_method(new Method("crop",[new Position().name,new Rect().name]));
this.add_method(new Method("select",["text"]));
this.install = function()
{
this.blink();
this.select(new Command(["background"]));
this.select(new Command("background"));
// Canvas
var starting_canvas = new Rect();
@@ -28,44 +27,37 @@ function Frame(rune)
starting_canvas.width = parseInt(starting_canvas.width/40) * 40;
starting_canvas.height = parseInt(starting_canvas.height/40) * 40;
this.resize(new Command([starting_canvas.width+"x"+starting_canvas.height]));
this.resize(new Command(starting_canvas.width+"x"+starting_canvas.height));
}
// Methods
this.resize = function(params, preview = false)
this.resize = function(cmd, preview = false)
{
if(preview){ return; }
var rect = cmd.rect();
var position = cmd.position() ? cmd.position() : new Position(0,0);
this.settings["size"] = params.rect();
if(preview){ ronin.overlay.draw(position,rect); return; }
for(layer_name in ronin.frame.layers){
ronin.frame.layers[layer_name].resize(this.settings["size"]);
ronin.frame.layers[layer_name].resize(rect);
}
ronin.frame.element.width = this.settings["size"].width * 2;
ronin.frame.element.height = this.settings["size"].height * 2;
ronin.frame.element.style.width = this.settings["size"].width+"px";
ronin.frame.element.style.height = this.settings["size"].height+"px";
ronin.frame.element.width = rect.width * 2;
ronin.frame.element.height = rect.height * 2;
ronin.frame.element.style.width = rect.width+"px";
ronin.frame.element.style.height = rect.height+"px";
ronin.frame.element.style.left = (window.innerWidth - this.settings["size"].width)/2;
ronin.frame.element.style.top = (window.innerHeight - this.settings["size"].height)/2;
ronin.frame.element.style.left = (window.innerWidth - rect.width)/2;
ronin.frame.element.style.top = (window.innerHeight - rect.height)/2;
ronin.on_resize();
this.settings.size = rect;
return 1, "ok";
}
this.crop = function(params, preview = false)
{
if(!params.position() || !params.rect()){ return; }
this.settings["size"] = params.rect();
ronin.overlay.get_layer(true).clear();
if(preview){ronin.overlay.draw_rect(params.position(),params.rect());}
}
this.select = function(params, preview = false)
{
if(preview){ return; }

View File

@@ -1,5 +1,6 @@
function Module(rune)
{
this.name = this.constructor.name.toLowerCase();
this.rune = rune;
this.element = null;
this.settings = {};
@@ -46,30 +47,22 @@ function Module(rune)
this.add_method = function(method)
{
method.host = this;
this.methods[method.name] = method;
}
this.hint = function(content)
{
var s = "";
var html = "";
ronin.terminal.hint_element.innerHTML = "";
var method_name = content.split(" ")[0];
if(this.methods[method_name]){
s = this.methods[method_name].params;
s += this.methods[method_name].mouse_event ? " <i>"+this.methods[method_name].mouse_event+"</i> " : "";
for(method in this.methods){
html += ".<b>"+method+"</b> ";
}
else{
for(method in this.methods){
s += ".<b>"+method+"</b> ";
}
for(setting in this.settings){
s += setting+"="+this.settings[setting]+" ";
}
for(setting in this.settings){
html += setting+"="+this.settings[setting]+" ";
}
return s;
return html;
}
this.pad = function(input)

View File

@@ -21,7 +21,7 @@ function Overlay(rune)
this.draw = function(position,rect)
{
this.clear();
this.get_layer().clear();
if(!position){ position = new Position("0,0"); }
@@ -39,10 +39,12 @@ function Overlay(rune)
}
}
this.draw_rect = function(position,rect)
this.draw_rect = function(position = new Position(0,0),rect)
{
if(!position || !rect){ return; }
this.context().beginPath();
position.normalize(rect);
this.context().moveTo(position.x,position.y);

View File

@@ -26,68 +26,42 @@ function Terminal(rune)
this.run = function()
{
var command = this.cmd();
var module = command.module();
var method = command.method();
if(method){
method.run(command);
}
this.hint_element.innerHTML = "";
this.run_line(this.input.value,false);
this.input.value = "";
}
this.run_line = function(line,is_preview)
{
var content = line;
if(content.trim() == ""){ ronin.cursor.set_mode(ronin.brush); return "~"; }
if(content.trim()[0] == "~"){ return "~"; }
if(content.indexOf(".") > -1){
var module_name = content.split(" ")[0].split(".")[0]
}
else if(content.indexOf(":") > -1){
var module_name = content.split(" ")[0].split(":")[0]
}
else{
var module_name = content.split(" ")[0];
}
var method_name = content.indexOf(".") > -1 ? content.split(" ")[0].split(".")[1] : "default";
var setting_name = content.indexOf(":") > -1 ? content.split(" ")[0].split(":")[1] : null;
var parameters = content.split(" "); parameters.shift();
var parameters = new Command(parameters);
ronin.cursor.set_mode(ronin[module_name]);
if(ronin[module_name] && ronin[module_name][method_name]){
return ronin[module_name][method_name](parameters,is_preview);
}
else if(ronin[module_name] && ronin[module_name].settings[setting_name]){
return ronin[module_name].update_setting(setting_name,parameters);
}
else if(ronin["render"].collection[method_name]){
return ronin["render"].collection[method_name].render(parameters);
}
else if(setting_name){
return 0, "Unknown Setting";
}
else if(ronin[module_name]){
return 0, "Unknown Method";
}
else if(module_name == "render"){
return 0, "Unknown Filter";
}
else{
return 0, "Unknown Module";
}
return 0, "Unknown";
}
this.log = function(log)
{
}
this.update = function()
{
this.hint_element.innerHTML = "<span class='input'>"+this.input.value+"</span> "+this.run_line(this.input.value,true);
var command = this.cmd();
var module = command.module();
var method = command.method();
if(method){
method.preview(command);
}
this.hint_element.innerHTML = "<span class='input'>"+this.input.value+"</span> "+(module ? module.hint() : this.hint());
}
this.hint = function()
{
var html = "";
for(id in ronin.modules){
html += ronin.modules[id].name+" ";
}
return html;
}
this.cmd = function()
{
return new Command(this.input.value);
}
this.filename = "default.rin";
@@ -113,11 +87,30 @@ function Terminal(rune)
ronin.widget.update();
}
this.cmd = function()
this.parsed_input = function()
{
var lines = ronin.terminal.input.value.split("\n");
var last = lines[lines.length-1];
return new Command(last.split(" "));
var content = this.input.value;
if(content.trim() == ""){ ronin.cursor.set_mode(ronin.brush); return "~"; }
if(content.trim()[0] == "~"){ return "~"; }
if(content.indexOf(".") > -1){
var module_name = content.split(" ")[0].split(".")[0]
}
else if(content.indexOf(":") > -1){
var module_name = content.split(" ")[0].split(":")[0]
}
else{
var module_name = content.split(" ")[0];
}
var method_name = content.indexOf(".") > -1 ? content.split(" ")[0].split(".")[1] : "default";
var setting_name = content.indexOf(":") > -1 ? content.split(" ")[0].split(":")[1] : null;
var parameters = content.split(" "); parameters.shift();
var parameters = new Command(parameters);
return {module_name: module_name, method_name: method_name, setting_name: setting_name, parameters: parameters};
}
}