Implementing cursor managers

This commit is contained in:
Devine Lu Linvega 2017-01-19 10:27:21 -07:00
parent 9d6db2a93c
commit 99f1929618
7 changed files with 61 additions and 7 deletions

View File

@ -2,6 +2,12 @@ function Command(content)
{ {
this.content = content; this.content = content;
this.inject_position = function(injection)
{
console.log("> "+injection);
console.log("- "+content);
}
// Parser // Parser
this.any = function() this.any = function()

View File

@ -4,8 +4,11 @@ function Hint(element)
this.element = element; this.element = element;
this.update = function(module,cmd) this.update = function()
{ {
var module = ronin.module;
var cmd = commander.cmd();
if(module){ if(module){
this.element.innerHTML = this.message(module,cmd); this.element.innerHTML = this.message(module,cmd);
this.element.style.display = "block"; this.element.style.display = "block";

View File

@ -55,8 +55,20 @@ function Commander(element,element_input)
if(ronin.modules[key]){ if(ronin.modules[key]){
ronin.modules[key].passive(cmd); ronin.modules[key].passive(cmd);
ronin.module = ronin.modules[key]; ronin.module = ronin.modules[key];
ronin.cursor.set_mode(ronin.module);
} }
this.hint.update(ronin.module,cmd); else{
ronin.cursor.set_mode(ronin.brush);
}
this.hint.update();
}
this.cmd = function()
{
var content = this.element_input.value.trim();
var key = content[0];
var cmd = new Command(content.substring(1).split(" "));
return cmd;
} }
// //
@ -96,5 +108,4 @@ function Commander(element,element_input)
this.storage_index -= this.storage_index < 1 ? 0 : 1; this.storage_index -= this.storage_index < 1 ? 0 : 1;
this.element_input.value = this.storage[this.storage_index]; this.element_input.value = this.storage[this.storage_index];
} }
} }

View File

@ -12,6 +12,7 @@ function Cursor()
else if(event.ctrlKey === true){ this.set_mode(ronin.overlay); } else if(event.ctrlKey === true){ this.set_mode(ronin.overlay); }
else if(event.altKey === true){ this.set_mode(ronin.surface); } else if(event.altKey === true){ this.set_mode(ronin.surface); }
else if(event.shiftKey === true){ this.set_mode(ronin.eraser); } else if(event.shiftKey === true){ this.set_mode(ronin.eraser); }
else if(ronin.module){ this.set_mode(ronin.module); }
else{ this.set_mode(ronin.brush); } else{ this.set_mode(ronin.brush); }
} }
@ -28,6 +29,7 @@ function Cursor()
this.position = position; this.position = position;
this.mode.mouse_down(position); this.mode.mouse_down(position);
ronin.widget.update(); ronin.widget.update();
// console.log(this.mode);
} }
this.mouse_move = function(position) this.mouse_move = function(position)
@ -41,5 +43,6 @@ function Cursor()
this.position = position; this.position = position;
this.mode.mouse_up(position); this.mode.mouse_up(position);
ronin.widget.update(); ronin.widget.update();
commander.element_input.focus();
} }
} }

View File

@ -26,7 +26,7 @@ ronin.install();
// Canvas // Canvas
var starting_canvas = new Rect(); var starting_canvas = new Rect();
starting_canvas.width = window.innerWidth - 200; starting_canvas.width = window.innerWidth - 200;
starting_canvas.height = window.innerHeight - 400; starting_canvas.height = window.innerHeight - 200;
// Clamp // Clamp

View File

@ -26,7 +26,7 @@ function Keyboard()
// Passive // Passive
commander.passive(commander.element_input.value); commander.passive(commander.element_input.value);
ronin.cursor.set_mode(ronin.brush); // ronin.cursor.set_mode(ronin.brush);
ronin.widget.update(); ronin.widget.update();
}; };

View File

@ -46,4 +46,35 @@ function Typographe(rune)
ctx.fillStyle = color.hex; ctx.fillStyle = color.hex;
ctx.fillText(text,position.x,position.y); ctx.fillText(text,position.x,position.y);
} }
// Mouse
this.click = null;
this.widget_cursor = function()
{
return "&";
}
this.mouse_down = function(position)
{
this.click = true;
ronin.overlay.draw(position);
commander.element_input.value = "& "+position.render();
commander.hint.update();
}
this.mouse_move = function(position)
{
if(!this.click){ return; }
ronin.overlay.draw(position);
commander.element_input.value = "& "+position.render();
}
this.mouse_up = function(position)
{
this.click = null;
ronin.overlay.draw(position);
commander.element_input.value = "& "+position.render();
}
} }