From e6f7f62d0bd7be14548bd27ae7b31bfc3ea71064 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 20 Mar 2017 15:37:27 -0700 Subject: [PATCH] Improved Vector and Magnet --- README.md | 34 ++++++++++++++++++++++++++ scripts/modules/cursor.js | 22 ++++++++--------- scripts/modules/magnet.js | 50 ++++++++++++++++++++++++++++++-------- scripts/modules/overlay.js | 6 ----- scripts/modules/vector.js | 2 +- 5 files changed, 86 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index bb0e7aa..4b236d9 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,40 @@ The repository comes with a script that fires Ronin from within Localhost. Launch Ronin and press **:**(colon) to display the command prompt. Enjoy +## TODOs + General + Splash screen + Hide widget on mouseover + Add locks + Store values in modules, experiment with vector + Give name to settings + Merge layers + Export multiple layers file + % Render + balance auto=true ~ auto color + balance 0.8 ~ equal RGB balance + mirror ,100 ~ mirror + Brush + Texture paint + Save + $ 1280x800 ~ Export with size + Auto saveAs + History + Undo shortcut + > Terminal + Auto Complete + Progress update + Scroll logs + Expand logs + ? Interrog + Inline Help + / Load + Load .rin files, instead of "Presets" + Load default.rin on startup + * Eye + Swatches, handle all colors + + this.collection = {}; this.collection["grid"] = {}; this.collection["grid"]["glyph"] = "@ 300x300; @ layer=background ; @ #A1A1A1 ; . 15x15 4,4 ; @ layer=main"; diff --git a/scripts/modules/cursor.js b/scripts/modules/cursor.js index f83e31b..fd1c13b 100644 --- a/scripts/modules/cursor.js +++ b/scripts/modules/cursor.js @@ -155,12 +155,12 @@ function Cursor(rune) { if(this.layer){ this.layer.clear(); } - this.position = position; + this.position = ronin.magnet.update_mouse(position); if(this.mode.constructor.name != Cursor.name){ - this.mode.mouse_from = position; + this.mode.mouse_from = this.position; this.mode.mouse_held = true; - this.mode.mouse_down(position); + this.mode.mouse_down(this.position); } } @@ -170,33 +170,33 @@ function Cursor(rune) this.layer.clear(); - if(this.mode){this.mode.mouse_pointer(position);} - else{ this.mouse_pointer(position);} + this.position = ronin.magnet.update_mouse(position); + + if(this.mode){this.mode.mouse_pointer(this.position);} + else{ this.mouse_pointer(this.position);} if(this.mode.mouse_from == null){ return; } - this.position = position; - var rect = new Rect(); rect.width = this.position.x - this.mode.mouse_from.x; rect.height = this.position.y - this.mode.mouse_from.y; if(this.mode.constructor.name != Cursor.name){ - this.mode.mouse_move(position,rect); - this.mode.mouse_prev = position; + this.mode.mouse_move(this.position,rect); + this.mode.mouse_prev = this.position; } } this.mouse_up = function(position) { - this.position = position; + this.position = ronin.magnet.update_mouse(position); var rect = new Rect(); rect.width = this.position.x - this.mode.mouse_from.x; rect.height = this.position.y - this.mode.mouse_from.y; if(this.mode.constructor.name != Cursor.name){ - this.mode.mouse_up(position,rect); + this.mode.mouse_up(this.position,rect); this.mode.mouse_held = false; } ronin.terminal.input_element.focus(); diff --git a/scripts/modules/magnet.js b/scripts/modules/magnet.js index 02e75c3..85fe7f3 100644 --- a/scripts/modules/magnet.js +++ b/scripts/modules/magnet.js @@ -2,14 +2,14 @@ function Magnet(rune) { Module.call(this,rune); - this.settings = {"grid" : new Rect("0x0"), "marker": new Position("4,4"), "reset" : new Bang()}; + this.settings = {"grid" : new Rect("1x1"), "marker": new Position("4,4"), "reset" : new Bang()}; this.passive = function(cmd) { if(!this.layer){ this.create_layer(); } this.layer.clear(); - this.draw(cmd.setting("grid"),cmd.setting("marker")); + this.draw_grid(cmd.setting("grid"),cmd.setting("marker")); } this.active = function(cmd) @@ -22,10 +22,17 @@ function Magnet(rune) if(!this.layer){ this.create_layer(); } this.layer.clear(); - this.draw(this.setting("grid"),this.setting("marker")); + this.draw_grid(this.settings["grid"],this.settings["marker"]); + } + + this.context = function() + { + if(!this.layer){ this.create_layer(); } + + return this.layer.context(); } - this.draw = function(rect,grid) + this.draw_grid = function(rect,grid) { if(!rect){ rect = new Rect("20x20"); } if(!grid){ grid = new Position("4,4"); } @@ -45,13 +52,24 @@ function Magnet(rune) } } + this.draw_helper = function(position) + { + var magnetized = this.magnetic_position(position); + this.context().beginPath(); + this.context().arc(magnetized.x, magnetized.y, 4, 0, 2 * Math.PI, false); + this.context().strokeStyle = 'white'; + this.context().stroke(); + this.context().closePath(); + } + + this.draw_marker = function(position,size = 0.5) { - var context = this.layer.context(); - context.beginPath(); - context.arc(position.x, position.y, size, 0, 2 * Math.PI, false); - context.fillStyle = 'white'; - context.fill(); + this.context().beginPath(); + this.context().arc(position.x, position.y, size, 0, 2 * Math.PI, false); + this.context().fillStyle = 'white'; + this.context().fill(); + this.context().closePath(); } this.magnetic_position = function(position) @@ -61,7 +79,19 @@ function Magnet(rune) return new Position(x,y); } - + + this.update_mouse = function(position) + { + if(!this.layer){ this.create_layer(); } + + this.layer.clear(); + + this.draw_helper(position); + this.draw_grid(this.settings["grid"],this.settings["marker"]); + + return this.magnetic_position(position); + } + this.key_escape = function() { if(this.layer){ this.layer.remove(this); } diff --git a/scripts/modules/overlay.js b/scripts/modules/overlay.js index f1f6cab..611fd67 100644 --- a/scripts/modules/overlay.js +++ b/scripts/modules/overlay.js @@ -127,12 +127,6 @@ function Overlay(rune) this.context().closePath(); } - this.context = function() - { - if(!this.layer){ this.create_layer(); this.layer.is_blinking = true; } - return this.layer.context(); - } - this.clear = function() { this.context().clearRect(0, 0, ronin.surface.settings["size"].width, ronin.surface.settings["size"].height); diff --git a/scripts/modules/vector.js b/scripts/modules/vector.js index e416cd6..56f7d0a 100644 --- a/scripts/modules/vector.js +++ b/scripts/modules/vector.js @@ -13,7 +13,7 @@ function Vector(rune) this.passive = function(cmd) { - if(!ronin.vector.layer){ ronin.vector.create_layer(); } + if(!ronin.vector.layer){ ronin.vector.create_layer(); ronin.vector.layer.is_blinking = true; } this.layer.clear(); this.layer.context().lineCap = cmd.setting("line_cap") ? cmd.setting("line_cap").value : "square";