Fixed issues with cursor

This commit is contained in:
Devine Lu Linvega
2017-05-21 14:12:51 -10:00
parent 8ded549ae8
commit a9f76f6100
19 changed files with 137 additions and 235 deletions

View File

@@ -1,27 +0,0 @@
var ronin = new Ronin();
ronin.element = document.getElementById('ronin');
ronin.frame.element = document.getElementById('frame');
ronin.cursor.element = document.getElementById('cursor');
ronin.terminal.element = document.getElementById('terminal');
ronin.cursor.mode = ronin.brush;
// Cursor
document.addEventListener('mousedown', function(e){ ronin.cursor.mouse_down(ronin.position_in_canvas(e));}, false);
document.addEventListener('mousemove', function(e){ ronin.cursor.mouse_move(ronin.position_in_canvas(e));}, false);
document.addEventListener('mouseup', function(e){ ronin.cursor.mouse_up(ronin.position_in_canvas(e));}, false);
// document.addEventListener('contextmenu', function(ev){ ev.preventDefault(); return false;}, false);
window.addEventListener('resize', function(){ ronin.on_resize(); }, true);
// Keyboard
var keyboard = new Keyboard();
document.onkeyup = function myFunction(){ keyboard.listen_onkeyup(event); };
document.onkeydown = function myFunction(){ keyboard.listen_onkeydown(event); };
ronin.install();
var target_file = window.location.hash ? window.location.hash : "default";
target_file = target_file.substr(1,target_file.length-1);
ronin.start(window.location.hash ? target_file+".rin" : "default.rin");

View File

@@ -3,6 +3,9 @@ function Keyboard()
this.shift_held = false;
this.alt_held = false;
document.onkeyup = function myFunction(){ keyboard.listen_onkeyup(event); };
document.onkeydown = function myFunction(){ keyboard.listen_onkeydown(event); };
this.listen_onkeydown = function(event)
{
if(event.shiftKey == true){
@@ -44,6 +47,7 @@ function Keyboard()
// Passive
ronin.widget.update();
ronin.terminal.update();
ronin.cursor.update();
};
this.key_tab = function()

View File

@@ -35,20 +35,29 @@ function Ronin()
this.modules[this.cursor.name] = this.cursor;
this.modules[this.terminal.name] = this.terminal;
//
// document.addEventListener('contextmenu', function(ev){ ev.preventDefault(); return false;}, false);
window.addEventListener('resize', function(){ ronin.on_resize(); }, true);
this.install = function()
{
ronin.element = document.getElementById('ronin');
ronin.frame.element = document.getElementById('frame');
ronin.cursor.element = document.getElementById('cursor');
ronin.terminal.element = document.getElementById('terminal');
for(var key in this.modules){
this.modules[key].install();
}
// this.terminal.install();
this.widget.install();
ronin.cursor.mode = ronin.brush;
this.on_drag();
}
this.start = function(target_file)
this.start = function(hash = null)
{
var target_file = hash.length > 2 ? hash.substr(1,hash.length-1)+".rin" : "default.rin"
ronin.terminal.update();
ronin.widget.update();
ronin.terminal.input.focus();
@@ -59,19 +68,12 @@ function Ronin()
this.position_in_canvas = function(e)
{
var x = e.clientX;
var y = e.clientY;
// Canvas Size
x += (-window.innerWidth/2) + (parseInt(this.frame.element.style.width)/2);
y += (-window.innerHeight/2) + (parseInt(this.frame.element.style.height)/2);
// x -= parseInt(this.frame.element.style.left) - parseInt(this.frame.element.style.width/2);
var x = e.clientX - parseInt(this.frame.element.style.left);
var y = e.clientY - parseInt(this.frame.element.style.top);
return new Position(x,y);
}
this.position_in_window = function(p)
{
return new Position(p.x + parseInt(this.frame.element.style.marginLeft),p.y + parseInt(this.frame.element.style.marginTop));
}
this.timestamp = function()
{
var currentdate = new Date();
@@ -83,6 +85,17 @@ function Ronin()
{
}
this.on_drag = function()
{
// Position Background
var bg_offset_parts = ronin.element.style.backgroundPosition == "" ? [0,0] : ronin.element.style.backgroundPosition.split(" ");
var x = parseInt(ronin.frame.element.style.left)/4;
var y = parseInt(ronin.frame.element.style.top)/4;
ronin.element.style.backgroundPosition = x+"px "+y+"px";
}
this.filename = "default.rin";
this.load = function readTextFile(name)