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

@@ -20,19 +20,6 @@ function Brush(rune)
return 1, "ok";
}
this.passive = function(cmd)
{
if(cmd.rect()){
var x = isNaN(cmd.rect().width) ? 0 : cmd.rect().width;
var y = isNaN(cmd.rect().height) ? 0 : cmd.rect().height;
var pos = new Position(x+","+y);
ronin.overlay.draw(pos);
}
if(cmd.angle() && cmd.position()){
ronin.overlay.draw(cmd.position());
}
}
this.size_up = function()
{

View File

@@ -64,7 +64,7 @@ function Pointer(offset = new Position())
ronin.frame.context().lineCap="round";
ronin.frame.context().lineWidth = this.thickness();
ronin.frame.context().strokeStyle = new Color(ronin.brush.settings.color).rgba();
ronin.frame.context().strokeStyle = ronin.brush.settings.color;
ronin.frame.context().stroke();
ronin.frame.context().closePath();

View File

@@ -6,15 +6,95 @@ function Cursor(rune)
this.mode = null;
this.position = new Position();
this.position_in_window = new Position();
this.passive = function(cmd)
document.addEventListener('mousedown', function(e){ ronin.cursor.mouse_down(ronin.position_in_canvas(e),e);}, false);
document.addEventListener('mousemove', function(e){ ronin.cursor.mouse_move(ronin.position_in_canvas(e),e);}, false);
document.addEventListener('mouseup', function(e){ ronin.cursor.mouse_up(ronin.position_in_canvas(e),e);}, false);
this.update = function(event = null)
{
if(event && event.altKey == true && event.shiftKey == true){
this.set_mode(ronin.frame.active_layer);
}
else if(event && event.altKey == true){
this.set_mode(ronin.default);
}
else{
this.set_mode(ronin.brush);
}
}
this.set_mode = function(mode = ronin.brush)
{
if(!mode){ return; }
if(this.mode == mode){ return; }
this.mode = mode;
document.body.setAttribute("class",this.mode.name);
ronin.widget.update();
}
this.mouse_down = function(position,e)
{
if(this.layer){ this.layer.clear(); }
this.position = ronin.magnet.update_mouse(position);
this.position_in_window = new Position(e.clientX,e.clientY);
if(this.mode.constructor.name != Cursor.name){
this.mode.mouse_from = this.position;
this.mode.mouse_held = true;
if(!position.is_outside()){
this.mode.mouse_down(this.position);
}
}
}
this.mouse_move = function(position,e)
{
if(!this.layer){ this.create_layer(); }
this.layer.clear();
this.position = ronin.magnet.update_mouse(position);
this.position_in_window = new Position(e.clientX,e.clientY);
if(this.mode){this.mode.mouse_pointer(this.position);}
else{ this.mouse_pointer(this.position);}
if(this.mode.mouse_from == null){ return; }
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(this.position,rect);
this.mode.mouse_prev = this.position;
}
}
this.mouse_up = function(position,e)
{
this.position = ronin.magnet.update_mouse(position);
this.position_in_window = new Position(e.clientX,e.clientY);
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){ return; }
if(this.mode.constructor.name != Cursor.name){
if(!position.is_outside()){
this.mode.mouse_up(this.position,rect);
}
this.mode.mouse_held = false;
}
this.mode.mouse_from = null;
}
this.active = function(cmd)
{
}
this.draw_pointer_arrow = function(position,size = 1)
{
@@ -135,88 +215,6 @@ function Cursor(rune)
this.pointer_last = position;
}
this.update = function(event)
{
console.log("!")
if(event.altKey == true && event.shiftKey == true){
this.set_mode(ronin.frame.active_layer);
}
else if(event.altKey == true){
this.set_mode(ronin.default);
}
else{
this.set_mode(ronin.brush);
}
}
this.set_mode = function(mode = ronin.brush)
{
if(!mode){ return; }
if(this.mode == mode){ return; }
this.mode = mode;
document.body.setAttribute("class",this.mode.name);
ronin.widget.update();
}
this.mouse_down = function(position)
{
if(this.layer){ this.layer.clear(); }
this.position = ronin.magnet.update_mouse(position);
if(this.mode.constructor.name != Cursor.name){
this.mode.mouse_from = this.position;
this.mode.mouse_held = true;
if(!position.is_outside()){
this.mode.mouse_down(this.position);
}
}
}
this.mouse_move = function(position)
{
if(!this.layer){ this.create_layer(); }
this.layer.clear();
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; }
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(this.position,rect);
this.mode.mouse_prev = this.position;
}
// ronin.terminal.update_hint();
}
this.mouse_up = function(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){ return; }
if(this.mode.constructor.name != Cursor.name){
if(!position.is_outside()){
this.mode.mouse_up(this.position,rect);
}
this.mode.mouse_held = false;
}
this.mode.mouse_from = null;
}
this.release = function()
{
this.mode.mouse_held = false;

View File

@@ -1,11 +1,6 @@
function Default(rune)
{
Module.call(this,rune);
this.hint = function()
{
return "";
}
// Cursor
@@ -25,26 +20,21 @@ function Default(rune)
this.mouse_down = function(position)
{
this.drag_from = ronin.position_in_window(position);
this.drag_from = ronin.cursor.position_in_window;
}
this.mouse_move = function(position)
{
if(this.drag_from === null){ return; }
position = ronin.position_in_window(position);
var offset_x = this.drag_from.x - position.x;
var offset_y = this.drag_from.y - position.y;
this.drag_offset_x -= offset_x;
this.drag_offset_y -= offset_y;
ronin.frame.element.style.marginLeft = -(ronin.frame.settings["size"].width/2) + this.drag_offset_x;
ronin.frame.element.style.marginTop = -(ronin.frame.settings["size"].height/2) + this.drag_offset_y;
ronin.element.style.backgroundPosition = ((this.drag_offset_x/8))-(window.innerWidth % 20)+"px "+((this.drag_offset_y/8)-(window.innerWidth % 20))+"px";
var offset = ronin.cursor.position_in_window.offset(this.drag_from);
ronin.frame.element.style.left = parseInt(ronin.frame.element.style.left) + offset.x;
ronin.frame.element.style.top = parseInt(ronin.frame.element.style.top) + offset.y;
this.drag_from = new Position(position.x,position.y);
ronin.on_drag();
this.drag_from = ronin.cursor.position_in_window;
}
this.mouse_up = function(event)

View File

@@ -2,16 +2,6 @@ function Eye(rune)
{
Module.call(this,rune);
// Module
this.active = function(cmd)
{
}
this.passive = function(cmd)
{
}
// TODO: If a rect is given, return the average color
this.color_picker = function(position,rect = null)
{

View File

@@ -85,7 +85,7 @@ function Frame(rune)
Object.keys(ronin.frame.layers).forEach(function (key) {
ronin.frame.layers[key].blink();
});
setTimeout(function(){ ronin.frame.blink(); }, 30);
setTimeout(function(){ ronin.frame.blink(); }, 300);
}
this.select_layer = function(layer)
@@ -140,12 +140,6 @@ function Frame(rune)
ronin.overlay.draw_pointer(position);
}
this.mouse_move = function(position,rect)
{
// ronin.terminal.input_element.value = "frame."+ronin.terminal.method_name+" "+this.mouse_from.render()+" "+rect.render()+" ";
ronin.terminal.passive();
}
this.mouse_up = function(position,rect)
{
}

View File

@@ -152,12 +152,6 @@ function Layer(name,manager = null)
{
return "Move";
}
this.mouse_down = function(position)
{
// ronin.terminal.input_element.value = "layer."+ronin.terminal.method_name+" 0,0";
ronin.terminal.passive();
}
this.mouse_move = function(position)
{
@@ -167,9 +161,6 @@ function Layer(name,manager = null)
ronin.overlay.draw_cross(this.mouse_from);
ronin.overlay.draw_cross(position);
ronin.overlay.draw_line(this.mouse_from,position);
// ronin.terminal.input_element.value = "layer."+ronin.terminal.method_name+" "+offset.render();
ronin.terminal.passive();
}
this.mouse_up = function(position)
@@ -182,7 +173,6 @@ function Layer(name,manager = null)
ronin.overlay.draw_line(this.mouse_from,position);
// ronin.terminal.input_element.value = "layer."+ronin.terminal.method_name+" "+offset.render();
ronin.terminal.passive();
// if(this.coordinates.length == 0){
// this.coordinates.push("M"+position.render());

View File

@@ -31,14 +31,6 @@ function Module(rune)
return this.layer;
}
this.active = function(cmd)
{
}
this.passive = function(cmd)
{
}
this.update_setting = function(name,value)
{
this.settings[name] = value.content.join(" ");

View File

@@ -6,17 +6,6 @@ function Overlay(rune)
this.color = new Color("#ffffff");
this.passive = function(cmd)
{
this.draw(cmd.position(),cmd.rect());
}
this.active = function(cmd)
{
if(cmd.bang()){ this.guides = []; }
if(cmd.color()){ this.color = cmd.color(); }
}
// draw
this.draw = function(position,rect)

View File

@@ -13,28 +13,6 @@ function Render(rune)
this.collection["saturate"] = new Filter_Saturate();
this.collection["contrast"] = new Filter_Contrast();
this.active = function(cmd)
{
if(!this.layer){ this.create_layer(); }
var name = cmd.content[0];
if(!this.collection[name]){ return; }
return this.collection[name].render(cmd);
}
this.passive = function(cmd)
{
if(!this.layer){ this.create_layer(); }
var name = cmd.content[0];
if(!this.collection[name]){ return; }
return this.collection[name].preview(cmd);
}
this.hint = function(content)
{
var name = content.trim().replace(this.rune,"").trim().split(" ")[0];

View File

@@ -96,7 +96,6 @@ function Source(rune)
this.coordinates = [];
this.last_pos = null;
ronin.terminal.input.value = "";
ronin.terminal.passive();
ronin.overlay.get_layer(true).clear();
}
}

View File

@@ -108,6 +108,6 @@ function Log(host,message,error = false)
this.error = error;
this.element = document.createElement("log");
this.element.setAttribute("class",error ? "error" : "okay");
this.element.innerHTML = "<span class='module'>"+host.name+"</span>: "+message;
this.element.innerHTML = "<span class='module'>"+host.name+"</span> "+message;
console.log(this.host.constructor.name,this.message);
}