From 748fec89f42217216156fdd74bc59160f4544dab Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sun, 21 May 2017 14:37:04 -1000 Subject: [PATCH] Improved Terminal --- presets/default.rin | 3 ++- scripts/core/ronin.js | 1 + scripts/modules/cursor.js | 5 ++++- scripts/modules/frame.js | 4 ++-- scripts/modules/overlay.js | 41 ++----------------------------------- scripts/modules/path.js | 2 +- scripts/modules/source.js | 17 +++++++-------- scripts/modules/terminal.js | 5 +++-- scripts/modules/type.js | 2 +- 9 files changed, 23 insertions(+), 57 deletions(-) diff --git a/presets/default.rin b/presets/default.rin index 34965bf..932f70b 100644 --- a/presets/default.rin +++ b/presets/default.rin @@ -1,4 +1,3 @@ - frame.resize 300x300 frame.select main layer.fill #ff0000 @@ -12,3 +11,5 @@ type.write 38,262 "RONIN" type.write 38,252 "B08" brush:color #000000 brush:size 10 +path:line_width 20 +path:line_color #999999 \ No newline at end of file diff --git a/scripts/core/ronin.js b/scripts/core/ronin.js index f86a334..64d4ced 100644 --- a/scripts/core/ronin.js +++ b/scripts/core/ronin.js @@ -117,5 +117,6 @@ function Ronin() } rawFile.send(null); ronin.widget.update(); + ronin.terminal.update(); } } \ No newline at end of file diff --git a/scripts/modules/cursor.js b/scripts/modules/cursor.js index 9dba183..050eb89 100644 --- a/scripts/modules/cursor.js +++ b/scripts/modules/cursor.js @@ -14,7 +14,10 @@ function Cursor(rune) this.update = function(event = null) { - if(event && event.altKey == true && event.shiftKey == true){ + if(ronin.terminal.cmd().module()){ + this.set_mode(ronin.terminal.cmd().module()); + } + else if(event && event.altKey == true && event.shiftKey == true){ this.set_mode(ronin.frame.active_layer); } else if(event && event.altKey == true){ diff --git a/scripts/modules/frame.js b/scripts/modules/frame.js index db22be4..17924e2 100644 --- a/scripts/modules/frame.js +++ b/scripts/modules/frame.js @@ -15,7 +15,7 @@ function Frame(rune) this.install = function() { this.blink(); - this.select(new Command("background")); + this.select(new Command("frame.select main")); // Canvas var starting_canvas = new Rect(); @@ -62,7 +62,7 @@ function Frame(rune) { if(preview){ return; } - var layer_name = params.content; + var layer_name = "main"; if(!ronin.frame.layers[layer_name]){ this.add_layer(new Layer(layer_name)); } diff --git a/scripts/modules/overlay.js b/scripts/modules/overlay.js index 02e4cdd..ba9710d 100644 --- a/scripts/modules/overlay.js +++ b/scripts/modules/overlay.js @@ -11,7 +11,6 @@ function Overlay(rune) this.draw = function(position,rect) { if(!this.layer){ this.create_layer(); this.layer.is_blinking = true; } - this.get_layer().clear(); if(!position){ position = new Position("0,0"); } @@ -162,46 +161,10 @@ function Overlay(rune) this.context().stroke(); this.context().closePath(); } - - // Cursor - - this.live_draw_from = null; - this.mouse_down = function(position) + this.clear = function() { - ronin.overlay.clear(); - ronin.overlay.draw_pointer(position); - this.live_draw_from = position; - // ronin.terminal.input_element.value = "| "+this.live_draw_from.render(); - } - - this.mouse_move = function(position) - { - if(this.live_draw_from === null){ return; } - - ronin.overlay.clear(); - - var rect = new Rect(); - rect.width = position.x - this.live_draw_from.x; - rect.height = position.y - this.live_draw_from.y; - - ronin.overlay.draw_rect(this.live_draw_from,rect); - // ronin.terminal.input_element.value = "| "+this.live_draw_from.render()+" "+rect.render(); - - ronin.terminal.update_hint(); - } - - this.mouse_up = function(position) - { - this.live_draw_from = null; - // ronin.terminal.input_element.focus(); - } - - // Widget - - this.widget_cursor = function() - { - return "Guide"; + this.layer.remove(this); } this.key_escape = function() diff --git a/scripts/modules/path.js b/scripts/modules/path.js index 3e882c6..5a9b4f7 100644 --- a/scripts/modules/path.js +++ b/scripts/modules/path.js @@ -27,7 +27,7 @@ function Path(rune) context.stroke(new Path2D(cmd.values())); context.closePath(); - if(!preview){ this.coordinates = []; this.last_pos = null; } + if(!preview){ this.coordinates = []; this.last_pos = null; if(!preview){ this.layer.remove(this); } } return 1, preview ? "preview" : "ok"; } diff --git a/scripts/modules/source.js b/scripts/modules/source.js index a12a47f..e0bebad 100644 --- a/scripts/modules/source.js +++ b/scripts/modules/source.js @@ -7,20 +7,17 @@ function Source(rune) this.add_method(new Method("save",["name","rect","format"])); this.add_method(new Method("load",["path","position","rect"]),"Add point"); - this.load = function(params,preview = false) // source.load ../assets/todo.jpg 200x200 40,40 + this.load = function(params,preview = false) // source.load /01.jpg 0,0 100x100 { if(!params.filepath()){ return 0, "Path?"; } if(!params.rect()){ return 0,"Rect?"; } - this.get_layer(true).clear(); + ronin.overlay.draw_rect(position,params.rect()); - var target_layer = preview ? this.get_layer(true) : ronin.frame.active_layer; - - ronin.overlay.get_layer(true).clear(); + if(preview){ return; } var position = params.position() ? params.position() : new Position("0,0"); - ronin.overlay.draw_rect(position,params.rect()); - + base_image = new Image(); base_image.src = "../assets/"+params.filepath().path; base_image.src += '?'+new Date().getTime(); @@ -38,12 +35,12 @@ function Source(rune) width = isNaN(width) && height > 0 ? (height*base_image.naturalWidth)/base_image.naturalHeight : width; height = isNaN(height) && width > 0 ? (width*base_image.naturalHeight)/base_image.naturalWidth : height; - target_layer.context().drawImage(base_image, position.x, position.y, width, height); + ronin.frame.active_layer.context().drawImage(base_image, position.x, position.y, width, height); } - if(!preview){ ronin.overlay.get_layer(true).clear(); } + ronin.overlay.clear(); - return 1,"ok"; + return 1,"Loaded "+params.filepath().path+" at "+position.render(); } this.save = function(params,preview = false) diff --git a/scripts/modules/terminal.js b/scripts/modules/terminal.js index 124fce7..ffa5699 100644 --- a/scripts/modules/terminal.js +++ b/scripts/modules/terminal.js @@ -41,6 +41,7 @@ function Terminal(rune) } if(setting){ module.settings[setting] = command.values(); + this.log(new Log(module,setting+" = "+command.values())); } this.hint_element.innerHTML = ""; this.input.value = ""; @@ -48,7 +49,8 @@ function Terminal(rune) this.update = function(value = null) { - this.input.value = value ? value : this.input.value; + if(value){ this.input.value = value; this.input.focus(); } + var command = this.cmd(); var module = command.module(); var method = command.method(); @@ -58,7 +60,6 @@ function Terminal(rune) } this.hint_element.innerHTML = ""+this.input.value+""+(this.input.value ? " " : "")+(module ? module.hint(method) : this.hint(method)); ronin.cursor.set_mode(module); - this.input.focus(); } this.run_multi = function(lines) diff --git a/scripts/modules/type.js b/scripts/modules/type.js index c712d9d..8e89e1b 100644 --- a/scripts/modules/type.js +++ b/scripts/modules/type.js @@ -23,7 +23,7 @@ function Type(rune) target_layer.context().fillStyle = color; target_layer.context().fillText(text,position.x,position.y); - if(!preview){ this.layer.clear(); } + if(!preview){ this.layer.remove(this); } return 1, "Wrote "+text+" at "+position.render(); }