Added alternative color and above/under layers.

This commit is contained in:
Devine Lu Linvega 2017-11-22 16:58:48 +13:00
parent 4820e2b2b5
commit 5790481a92
9 changed files with 78 additions and 8 deletions

View File

@ -19,6 +19,7 @@
<script type="text/javascript" src="scripts/layers/guide.js"></script> <script type="text/javascript" src="scripts/layers/guide.js"></script>
<script type="text/javascript" src="scripts/layers/render.js"></script> <script type="text/javascript" src="scripts/layers/render.js"></script>
<script type="text/javascript" src="scripts/layers/preview.js"></script> <script type="text/javascript" src="scripts/layers/preview.js"></script>
<script type="text/javascript" src="scripts/layers/under.js"></script>
<script type="text/javascript" src="scripts/core/docs.js"></script> <script type="text/javascript" src="scripts/core/docs.js"></script>
<script type="text/javascript" src="scripts/core/port.js"></script> <script type="text/javascript" src="scripts/core/port.js"></script>

View File

@ -9,6 +9,7 @@ yu { display:block; }
#guide { z-index:810;position: fixed; } #guide { z-index:810;position: fixed; }
#preview { z-index:805; position: fixed; } #preview { z-index:805; position: fixed; }
#render { z-index:800; position: fixed; } #render { z-index:800; position: fixed; }
#under { z-index:799; position: fixed; }
#grid { z-index:795;position: fixed; } #grid { z-index:795;position: fixed; }
#ronin { background:#eee; height: 100vh; width:100vw; } #ronin { background:#eee; height: 100vh; width:100vw; }

View File

@ -85,6 +85,11 @@ function Commander()
ronin.commander.update(); ronin.commander.update();
} }
this.is_focused = function()
{
return this.input_el === document.activeElement;
}
this.focus = function() this.focus = function()
{ {
this.input_el.focus(); this.input_el.focus();

View File

@ -9,7 +9,9 @@ function Cursor(rune)
this.mode = "vertex"; this.mode = "vertex";
this.color = "#f00" this.color = "#f00"
this.color_alt = "#fff"
this.size = 4; this.size = 4;
this.under = false;
this.draw_cursor = function(pos,touch = false) this.draw_cursor = function(pos,touch = false)
{ {
@ -58,6 +60,12 @@ function Cursor(rune)
} }
else if(e.altKey && e.shiftKey){ else if(e.altKey && e.shiftKey){
ronin.brush.methods.pick.run(pos); ronin.brush.methods.pick.run(pos);
}
else if(e.altKey){
ronin.brush.erase(ronin.cursor.line);
}
else if(e.shiftKey){
} }
else{ else{
ronin.brush.stroke(ronin.cursor.line); ronin.brush.stroke(ronin.cursor.line);
@ -118,6 +126,15 @@ function Cursor(rune)
ronin.cursor.mode = "vertex"; ronin.cursor.mode = "vertex";
ronin.cursor.query = ronin.commander.input_el.value; ronin.cursor.query = ronin.commander.input_el.value;
if(ronin.cursor.under){
var above = ronin.render.to_img();
var under = ronin.under.to_img();
ronin.render.clear();
ronin.under.clear();
ronin.render.context().drawImage(under, 0,0,ronin.frame.width*2,ronin.frame.height*2);
ronin.render.context().drawImage(above, 0,0,ronin.frame.width*2,ronin.frame.height*2);
}
} }
this.drag = function(line) this.drag = function(line)
@ -128,6 +145,20 @@ function Cursor(rune)
ronin.render.context().putImageData(data, offset.x * -2, offset.y * -2); ronin.render.context().putImageData(data, offset.x * -2, offset.y * -2);
} }
this.swap_colors = function()
{
var c = this.color_alt
this.color_alt = this.color;
this.color = c;
ronin.commander.update();
}
this.swap_layer = function()
{
this.under = this.under ? false : true;
ronin.commander.update();
}
function make_offset(a,b) function make_offset(a,b)
{ {
return {x:a.x-b.x,y:a.y-b.y}; return {x:a.x-b.x,y:a.y-b.y};
@ -198,7 +229,7 @@ function Cursor(rune)
mode = "DRAG"; mode = "DRAG";
} }
return "<t class='mode'>"+mode+"</t><t class='size'>"+ronin.cursor.size+"</t> <t class='color' style='color:"+ronin.cursor.color+"'>●</t>"; return "<t class='mode'>"+mode+"</t><t class='size'>"+ronin.cursor.size+"</t> "+(ronin.cursor.under ? "UNDER" : "ABOVE")+" <t class='color' style='color:"+ronin.cursor.color+"'>●</t><t class='color' style='color:"+ronin.cursor.color_alt+"'>●</t>";
} }
function distance_between(a,b) function distance_between(a,b)

View File

@ -10,8 +10,10 @@ function Docs()
html += "Include `$` in a query and click on the canvas to inject the cursor position in the query.\n"; html += "Include `$` in a query and click on the canvas to inject the cursor position in the query.\n";
html += "- `$ click` inject a **Pos**.\n"; html += "- `$ click` inject a **Pos**.\n";
html += "- `$+ click` inject a **Pos**, and append `$+` for multiple positions.\n"; html += "- `$+ click` inject a **Pos**, and append `$+` for multiple positions.\n";
html += "- `$ shift click` inject a **Rect**.\n\n"; html += "- `$ shift click` inject a **Rect**.\n";
html += "- `#$ click` inject a **Color**.\n"; html += "- `#$ click` inject a **Color**.\n";
html += "- `x` swap **Color** with secondary.\n\n";
html += "- `z` draw under render.\n\n";
html += "## Modules\n"; html += "## Modules\n";
html += this.print_modules(ronin.modules); html += this.print_modules(ronin.modules);

View File

@ -40,6 +40,11 @@ function Keyboard()
return; return;
} }
if(ronin.commander.is_focused()){
ronin.hint.update(e);
return;
}
if(e.key == "]"){ if(e.key == "]"){
e.preventDefault(); e.preventDefault();
ronin.brush.mod_size(1); ronin.brush.mod_size(1);
@ -56,26 +61,33 @@ function Keyboard()
ronin.render.clear(); ronin.render.clear();
} }
// Open
if(e.key == "o" && (e.ctrlKey || e.metaKey)){ if(e.key == "o" && (e.ctrlKey || e.metaKey)){
e.preventDefault(); e.preventDefault();
ronin.io.methods.load.run(); ronin.io.methods.load.run();
} }
// Save
if(e.key == "s" && (e.ctrlKey || e.metaKey)){ if(e.key == "s" && (e.ctrlKey || e.metaKey)){
e.preventDefault(); e.preventDefault();
ronin.io.methods.save.run(); ronin.io.methods.save.run();
} }
if(e.key == "r" && (e.ctrlKey || e.metaKey)){
e.preventDefault();
ronin.io.methods.save.run();
}
if(e.key == "H" && (e.ctrlKey || e.metaKey) && e.shiftKey){ if(e.key == "H" && (e.ctrlKey || e.metaKey) && e.shiftKey){
e.preventDefault(); e.preventDefault();
ronin.docs.export(); ronin.docs.export();
} }
if(e.key == "x"){
e.preventDefault();
ronin.cursor.swap_colors();
}
if(e.key == "z"){
e.preventDefault();
ronin.cursor.swap_layer();
}
ronin.hint.update(e); ronin.hint.update(e);
} }
} }

View File

@ -0,0 +1,6 @@
function Under()
{
Layer.call(this);
this.el.id = "under";
}

View File

@ -53,6 +53,10 @@ function Brush()
{ {
var ctx = ronin.render.context(); var ctx = ronin.render.context();
if(!line.to){
line.to = line.from
}
ctx.beginPath(); ctx.beginPath();
ctx.globalCompositeOperation="destination-out"; ctx.globalCompositeOperation="destination-out";
ctx.moveTo(line.from.x * 2,line.from.y * 2); ctx.moveTo(line.from.x * 2,line.from.y * 2);
@ -65,6 +69,10 @@ function Brush()
this.pick = function(line) this.pick = function(line)
{ {
if(!line.to){
line.to = line.from
}
var pixel = ronin.render.context().getImageData(line.to.x*2, line.to.y*2, 1, 1).data; var pixel = ronin.render.context().getImageData(line.to.x*2, line.to.y*2, 1, 1).data;
} }
@ -100,7 +108,7 @@ function Pointer(options)
this.stroke = function(line) this.stroke = function(line)
{ {
var ctx = ronin.render.context(); var ctx = ronin.cursor.under ? ronin.layers.under.context() : ronin.layers.render.context();
if(this.options.mirror){ if(this.options.mirror){
line.from.x = (this.options.mirror.x *2) - line.from.x; line.from.x = (this.options.mirror.x *2) - line.from.x;

View File

@ -13,6 +13,7 @@ function Ronin()
this.guide = new Guide(); this.guide = new Guide();
this.render = new Render(); this.render = new Render();
this.preview = new Preview(); this.preview = new Preview();
this.under = new Under();
this.io = new IO(); this.io = new IO();
this.brush = new Brush(); this.brush = new Brush();
@ -25,6 +26,7 @@ function Ronin()
this.layers = { this.layers = {
grid : this.grid, grid : this.grid,
guide : this.guide, guide : this.guide,
under : this.under,
render : this.render, render : this.render,
cursor : this.cursor, cursor : this.cursor,
preview : this.preview, preview : this.preview,
@ -50,6 +52,7 @@ function Ronin()
this.grid.install(); this.grid.install();
this.guide.install(); this.guide.install();
this.render.install(); this.render.install();
this.under.install();
this.preview.install(); this.preview.install();
this.cursor.install(); this.cursor.install();
@ -72,6 +75,7 @@ function Ronin()
console.log("Ronin","Started"); console.log("Ronin","Started");
this.render.update(); this.render.update();
this.under.update();
this.grid.update(); this.grid.update();
this.guide.update(); this.guide.update();
this.cursor.update(); this.cursor.update();