Moved magnetism to Magnet()
This commit is contained in:
parent
35438605af
commit
d0d1118d3f
@ -28,6 +28,7 @@
|
|||||||
<script type="text/javascript" src="scripts/modules/eye.js"></script>
|
<script type="text/javascript" src="scripts/modules/eye.js"></script>
|
||||||
<script type="text/javascript" src="scripts/modules/typographe.js"></script>
|
<script type="text/javascript" src="scripts/modules/typographe.js"></script>
|
||||||
<script type="text/javascript" src="scripts/modules/render.js"></script>
|
<script type="text/javascript" src="scripts/modules/render.js"></script>
|
||||||
|
<script type="text/javascript" src="scripts/modules/magnet.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="scripts/filters/filter.js"></script>
|
<script type="text/javascript" src="scripts/filters/filter.js"></script>
|
||||||
<script type="text/javascript" src="scripts/filters/stencil.js"></script>
|
<script type="text/javascript" src="scripts/filters/stencil.js"></script>
|
||||||
|
@ -15,6 +15,7 @@ function Ronin()
|
|||||||
this.typo = new Typographe("&");
|
this.typo = new Typographe("&");
|
||||||
this.cursor = new Cursor(".");
|
this.cursor = new Cursor(".");
|
||||||
this.terminal = new Terminal(">");
|
this.terminal = new Terminal(">");
|
||||||
|
this.magnet = new Magnet("^");
|
||||||
|
|
||||||
this.modules[this.surface.rune] = this.surface;
|
this.modules[this.surface.rune] = this.surface;
|
||||||
this.modules[this.fileload.rune] = this.fileload;
|
this.modules[this.fileload.rune] = this.fileload;
|
||||||
@ -26,6 +27,7 @@ function Ronin()
|
|||||||
this.modules[this.vector.rune] = this.vector;
|
this.modules[this.vector.rune] = this.vector;
|
||||||
this.modules[this.terminal.rune] = this.terminal;
|
this.modules[this.terminal.rune] = this.terminal;
|
||||||
this.modules[this.overlay.rune] = this.overlay;
|
this.modules[this.overlay.rune] = this.overlay;
|
||||||
|
this.modules[this.magnet.rune] = this.magnet;
|
||||||
|
|
||||||
this.modules[this.cursor.rune] = this.cursor;
|
this.modules[this.cursor.rune] = this.cursor;
|
||||||
|
|
||||||
|
@ -2,69 +2,18 @@ function Cursor(rune)
|
|||||||
{
|
{
|
||||||
Module.call(this,rune);
|
Module.call(this,rune);
|
||||||
|
|
||||||
this.settings = {"grid" : new Rect("10x10"), "markers": new Position("4,4"), "reset" : new Bang()};
|
this.settings = {};
|
||||||
|
|
||||||
this.mode = null;
|
this.mode = null;
|
||||||
this.position = new Position();
|
this.position = new Position();
|
||||||
this.magnetism = null;
|
|
||||||
this.grid = new Position(4,4);
|
|
||||||
|
|
||||||
this.passive = function(cmd)
|
this.passive = function(cmd)
|
||||||
{
|
{
|
||||||
if(!cmd.rect()){ return; }
|
|
||||||
|
|
||||||
if(!this.layer){ this.create_layer(); }
|
if(!this.layer){ this.create_layer(); }
|
||||||
|
|
||||||
this.layer.clear();
|
|
||||||
this.draw(cmd.rect(),cmd.position());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.active = function(cmd)
|
this.active = function(cmd)
|
||||||
{
|
{
|
||||||
if(cmd.bang()){
|
|
||||||
this.magnetism = null;
|
|
||||||
if(this.layer){ this.layer.remove(this); }
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!this.layer){ this.create_layer(); }
|
|
||||||
|
|
||||||
this.layer.clear();
|
|
||||||
|
|
||||||
if(cmd.position()){
|
|
||||||
this.grid = cmd.position();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cmd.rect()){
|
|
||||||
this.magnetism = cmd.rect();
|
|
||||||
this.draw(this.magnetism,this.grid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.draw = function(rect,grid)
|
|
||||||
{
|
|
||||||
if(rect.width < 5 || rect.height < 5){ return; }
|
|
||||||
|
|
||||||
var horizontal = ronin.surface.settings["size"].width/rect.width;
|
|
||||||
var vertical = ronin.surface.settings["size"].height/rect.height;
|
|
||||||
|
|
||||||
for (var x = 1; x < horizontal; x++) {
|
|
||||||
for (var y = 1; y < vertical; y++) {
|
|
||||||
var dot_position = new Position(x * rect.width, y * rect.height);
|
|
||||||
var size = 0.5;
|
|
||||||
if(grid && x % grid.x == 0 && y % grid.y == 0){ size = 1; }
|
|
||||||
this.draw_marker(dot_position,size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.draw_marker = function(position,size = 0.5)
|
|
||||||
{
|
|
||||||
var context = this.layer.context();
|
|
||||||
context.beginPath();
|
|
||||||
context.arc(position.x, position.y, size, 0, 2 * Math.PI, false);
|
|
||||||
context.fillStyle = 'white';
|
|
||||||
context.fill();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.draw_pointer_arrow = function(position,size = 1)
|
this.draw_pointer_arrow = function(position,size = 1)
|
||||||
@ -202,26 +151,10 @@ function Cursor(rune)
|
|||||||
document.body.setAttribute("class",this.mode.constructor.name);
|
document.body.setAttribute("class",this.mode.constructor.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
this.magnetic_position = function(position)
|
|
||||||
{
|
|
||||||
var x = parseInt(position.x / this.magnetism.width) * this.magnetism.width;
|
|
||||||
var y = parseInt(position.y / this.magnetism.width) * this.magnetism.width;
|
|
||||||
|
|
||||||
return new Position(x,y);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
this.mouse_down = function(position)
|
this.mouse_down = function(position)
|
||||||
{
|
{
|
||||||
if(this.layer){ this.layer.clear(); }
|
if(this.layer){ this.layer.clear(); }
|
||||||
|
|
||||||
if(this.magnetism){
|
|
||||||
position = this.magnetic_position(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
|
||||||
if(this.mode.constructor.name != Cursor.name){
|
if(this.mode.constructor.name != Cursor.name){
|
||||||
@ -240,14 +173,8 @@ function Cursor(rune)
|
|||||||
if(this.mode){this.mode.mouse_pointer(position);}
|
if(this.mode){this.mode.mouse_pointer(position);}
|
||||||
else{ this.mouse_pointer(position);}
|
else{ this.mouse_pointer(position);}
|
||||||
|
|
||||||
if(this.magnetism){ this.draw(this.magnetism,this.grid); }
|
|
||||||
|
|
||||||
if(this.mode.mouse_from == null){ return; }
|
if(this.mode.mouse_from == null){ return; }
|
||||||
|
|
||||||
if(this.magnetism){
|
|
||||||
position = this.magnetic_position(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
|
||||||
var rect = new Rect();
|
var rect = new Rect();
|
||||||
@ -262,10 +189,6 @@ function Cursor(rune)
|
|||||||
|
|
||||||
this.mouse_up = function(position)
|
this.mouse_up = function(position)
|
||||||
{
|
{
|
||||||
if(this.magnetism){
|
|
||||||
position = this.magnetic_position(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
|
||||||
var rect = new Rect();
|
var rect = new Rect();
|
||||||
|
69
scripts/modules/magnet.js
Normal file
69
scripts/modules/magnet.js
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
function Magnet(rune)
|
||||||
|
{
|
||||||
|
Module.call(this,rune);
|
||||||
|
|
||||||
|
this.settings = {"grid" : new Rect("0x0"), "marker": new Position("4,4"), "reset" : new Bang()};
|
||||||
|
|
||||||
|
this.passive = function(cmd)
|
||||||
|
{
|
||||||
|
if(!this.layer){ this.create_layer(); }
|
||||||
|
|
||||||
|
this.layer.clear();
|
||||||
|
this.draw(cmd.setting("grid"),cmd.setting("marker"));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.active = function(cmd)
|
||||||
|
{
|
||||||
|
if(cmd.bang()){
|
||||||
|
if(this.layer){ this.layer.remove(this); }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!this.layer){ this.create_layer(); }
|
||||||
|
|
||||||
|
this.layer.clear();
|
||||||
|
this.draw(this.setting("grid"),this.setting("marker"));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.draw = function(rect,grid)
|
||||||
|
{
|
||||||
|
if(!rect){ rect = new Rect("20x20"); }
|
||||||
|
if(!grid){ grid = new Position("4,4"); }
|
||||||
|
|
||||||
|
if(rect.width < 5 || rect.height < 5){ return; }
|
||||||
|
|
||||||
|
var horizontal = ronin.surface.settings["size"].width/rect.width;
|
||||||
|
var vertical = ronin.surface.settings["size"].height/rect.height;
|
||||||
|
|
||||||
|
for (var x = 1; x < horizontal; x++) {
|
||||||
|
for (var y = 1; y < vertical; y++) {
|
||||||
|
var dot_position = new Position(x * rect.width, y * rect.height);
|
||||||
|
var size = 0.5;
|
||||||
|
if(grid && x % grid.x == 0 && y % grid.y == 0){ size = 1; }
|
||||||
|
this.draw_marker(dot_position,size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.draw_marker = function(position,size = 0.5)
|
||||||
|
{
|
||||||
|
var context = this.layer.context();
|
||||||
|
context.beginPath();
|
||||||
|
context.arc(position.x, position.y, size, 0, 2 * Math.PI, false);
|
||||||
|
context.fillStyle = 'white';
|
||||||
|
context.fill();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.magnetic_position = function(position)
|
||||||
|
{
|
||||||
|
var x = parseInt(position.x / this.settings["grid"].width) * this.settings["grid"].width;
|
||||||
|
var y = parseInt(position.y / this.settings["grid"].width) * this.settings["grid"].width;
|
||||||
|
|
||||||
|
return new Position(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.key_escape = function()
|
||||||
|
{
|
||||||
|
if(this.layer){ this.layer.remove(this); }
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user