Added guides to file load.

This commit is contained in:
Devine Lu Linvega 2016-11-14 14:23:13 -08:00
parent 2afe59883d
commit 0dc4e53685
9 changed files with 68 additions and 116 deletions

View File

@ -10,6 +10,7 @@
<script type="text/javascript" src="scripts/ronin.module.js"></script>
<script type="text/javascript" src="scripts/ronin.canvas.js"></script>
<script type="text/javascript" src="scripts/ronin.overlay.js"></script>
<script type="text/javascript" src="scripts/ronin.file.js"></script>
<script type="text/javascript" src="scripts/ronin.brush.js"></script>
<script type="text/javascript" src="scripts/ronin.brush.pointer.js"></script>

View File

@ -29,16 +29,13 @@ function Commander(element,element_input)
ronin.history.active(cmd);
break;
case "$":
ronin.save.active(cmd);
ronin.file.save(cmd);
break;
case "/":
ronin.load.active(cmd);
break;
case "&":
ronin.brush.active(cmd);
ronin.file.active(cmd);
break;
case ">":
ronin.pointer.active(cmd);
ronin.brush.active(cmd);
break;
case "|":
ronin.overlay.active(cmd);
@ -116,13 +113,10 @@ function Commander(element,element_input)
ronin.history.passive(cmd);
break;
case "/":
ronin.load.passive(cmd);
break;
case "&":
ronin.brush.passive(cmd);
ronin.file.passive(cmd);
break;
case ">":
ronin.pointer.passive(cmd);
ronin.brush.passive(cmd);
break;
case "|":
ronin.overlay.passive(cmd);
@ -142,11 +136,6 @@ function Commander(element,element_input)
}
/*
// Guides
if(parts[0] == "|"){
parts.shift();
ronin.guide(parts);
}
// Draw
if(parts[0] == "/"){

View File

@ -114,6 +114,6 @@ function Keyboard()
this.key_escape = function()
{
commander.hide();
ronin.draw_guides();
ronin.overlay.clear();
}
}

View File

@ -6,6 +6,7 @@ function Brush()
this.is_drawing = false;
this.size = 1;
this.opacity = 1;
this.color = new Color();
// Module
@ -15,6 +16,9 @@ function Brush()
var pointer = new Pointer(cmd.position());
this.add_pointer(pointer);
}
if(cmd.color()){
this.color = cmd.color();
}
}
this.passive = function(cmd)

View File

@ -14,7 +14,7 @@ function Pointer(offset = new Position(), color = new Color('000000'))
context.lineTo(this.position().x,this.position().y);
context.lineCap="round";
context.lineWidth = this.thickness();
context.strokeStyle = "rgba("+this.color.rgb().r+","+this.color.rgb().g+","+this.color.rgb().b+","+1+")";
context.strokeStyle = ronin.brush.color.rgba();
context.stroke();
context.closePath();

24
scripts/ronin.file.js Normal file
View File

@ -0,0 +1,24 @@
function File()
{
Module.call(this);
this.active = function()
{
console.log("Nothing to do.");
ronin.overlay.clear();
}
this.passive = function(cmd)
{
if(!cmd.path()){ return; }
var position = cmd.position() ? cmd.position() : new Position();
if(position && cmd.rect()){
ronin.overlay.draw(position,cmd.rect());
}
else if(position){
ronin.overlay.draw(position);
}
}
}

View File

@ -4,6 +4,7 @@ function Ronin()
this.canvas = new Canvas();
this.overlay = new Overlay();
this.brush = new Brush();
this.file = new File();
this.load_image = function(p)
{
@ -38,86 +39,4 @@ function Ronin()
context.drawImage(imgObj,0,0);
}
// Guides
this.guides_element = null;
this.guides_context = null;
this.guides = [];
this.clear_guides = function()
{
this.guides = [];
this.draw_guides();
}
this.draw_guides = function()
{
this.guides_context.clearRect(0, 0, canvas.width, canvas.height);
for (i = 0; i < this.guides.length; i++) {
this.guides[i].draw(this.guides_context);
}
}
this.guide = function(p)
{
this.guides_context.clearRect(0, 0, canvas.width, canvas.height);
this.draw_guides();
var x = p[0] ? p[0] : 0 ;
var y = p[1] ? p[1] : 0 ;
var w = p[2] ? p[2] : 0 ;
var h = p[3] ? p[3] : 0 ;
if(x < -10 && w === 0 && h === 0){
x = Math.abs(x);
for (i = 0; i < canvas.width/x; i++) {
var g = new Guide(new Position(x * i,y), new Rect(w,h), new Color('ff0000'));
g.draw(this.guides_context);
}
}
else if(y < -10 && w === 0 && h === 0){
y = Math.abs(y);
for (i = 0; i < canvas.width/y; i++) {
var g = new Guide(new Position(x,y* i), new Rect(w,h), new Color('ff0000'));
g.draw(this.guides_context);
}
}
else{
var g = new Guide(new Position(x,y), new Rect(w,h), new Color('ff0000'));
g.draw(this.guides_context);
return g;
}
}
this.add_guide = function(p)
{
if(p[0] == "?"){ this.guides = []; this.draw_guides(); return; }
var x = p[0] ? p[0] : 0 ;
var y = p[1] ? p[1] : 0 ;
var w = p[2] ? p[2] : 0 ;
var h = p[3] ? p[3] : 0 ;
if(x < -10 && w === 0 && h === 0){
x = Math.abs(x);
for (i = 0; i < canvas.width/x; i++) {
var g = new Guide(new Position(x * i,y), new Rect(w,h), new Color('000000'));
this.guides.push(g);
}
}
else if(y < -10 && w === 0 && h === 0){
y = Math.abs(y);
for (i = 0; i < canvas.width/y; i++) {
var g = new Guide(new Position(x,y* i), new Rect(w,h), new Color('000000'));
this.guides.push(g);
}
}
else{
var g = new Guide(new Position(x,y), new Rect(w,h), new Color('000000'));
this.guides.push(g);
}
this.draw_guides();
}
}

View File

@ -8,22 +8,7 @@ function Overlay(element)
this.passive = function(cmd)
{
this.clear();
if(!cmd.position()){ return; }
if(cmd.rect()){
this.draw_rect(cmd.position(),cmd.rect());
}
else if(cmd.position().x > 0 && cmd.position().y > 0){
this.draw_pointer(cmd.position());
}
else if(cmd.position().x > 0 ){
this.draw_vertical_line(cmd.position());
}
else if(cmd.position().y > 0 ){
this.draw_horizontal_line(cmd.position());
}
this.draw(cmd.position(),cmd.rect());
}
this.active = function(cmd)
@ -31,6 +16,28 @@ function Overlay(element)
}
// draw
this.draw = function(position,rect)
{
this.clear();
if(!position){ return; }
if(rect){
this.draw_rect(position,rect);
}
else if(position.x > 0 && position.y > 0){
this.draw_pointer(position);
}
else if(position.x > 0 ){
this.draw_vertical_line(position);
}
else if(position.y > 0 ){
this.draw_horizontal_line(position);
}
}
this.draw_rect = function(position,rect)
{
this.context().beginPath();

View File

@ -25,4 +25,12 @@ function Command(cmd_array)
}
return null;
}
this.path = function()
{
for (i = 0; i < this.cmd_array.length; i++) {
if(this.cmd_array[i].indexOf("/") >= 0){ return this.cmd_array[i]; }
}
return null;
}
}