Sorting out the cursor functionalities.

This commit is contained in:
Devine Lu Linvega 2016-12-18 21:23:53 -07:00
parent f80699271f
commit 87881159af
13 changed files with 151 additions and 24 deletions

BIN
assets/render.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

View File

@ -1,6 +1,6 @@
<html>
<head>
<script type="text/javascript" src="scripts/unit.js"></script>
<script type="text/javascript" src="scripts/units/unit.js"></script>
<script type="text/javascript" src="scripts/units/rect.js"></script>
<script type="text/javascript" src="scripts/units/color.js"></script>
<script type="text/javascript" src="scripts/units/position.js"></script>
@ -12,7 +12,7 @@
<script type="text/javascript" src="scripts/units/variable.js"></script>
<script type="text/javascript" src="scripts/units/range.js"></script>
<script type="text/javascript" src="scripts/module.js"></script>
<script type="text/javascript" src="scripts/modules/module.js"></script>
<script type="text/javascript" src="scripts/modules/canvas.js"></script>
<script type="text/javascript" src="scripts/modules/stroke.js"></script>
<script type="text/javascript" src="scripts/modules/vector.js"></script>
@ -30,7 +30,13 @@
<script type="text/javascript" src="scripts/modules/filter.eval.js"></script>
<script type="text/javascript" src="scripts/modules/filter.balance.js"></script>
<script type="text/javascript" src="scripts/modes/mode.js"></script>
<script type="text/javascript" src="scripts/modes/mode.paint.js"></script>
<script type="text/javascript" src="scripts/modes/mode.drag.js"></script>
<script type="text/javascript" src="scripts/modes/mode.guide.js"></script>
<script type="text/javascript" src="scripts/keyboard.js"></script>
<script type="text/javascript" src="scripts/cursor.js"></script>
<script type="text/javascript" src="scripts/command.js"></script>
<script type="text/javascript" src="scripts/commander.js"></script>
<script type="text/javascript" src="scripts/ronin.js"></script>

34
scripts/cursor.js Normal file
View File

@ -0,0 +1,34 @@
function Cursor()
{
this.mode = new Mode_Paint();
this.update = function(event)
{
if(event.ctrlKey === true){ this.set_mode(new Mode_Guide()); }
else if(event.altKey === true){ this.set_mode(new Mode_Drag()); }
else if(event.shiftKey === true){ this.set_mode(new Mode_Paint()); }
else{ this.set_mode(new Mode_Paint()); }
}
this.set_mode = function(mode)
{
if(this.mode.name == mode.name){ return; }
this.mode = mode;
ronin.widget.update();
}
this.mouse_down = function(event)
{
}
this.mouse_move = function(event)
{
}
this.mouse_up = function(event)
{
}
}

View File

@ -7,32 +7,21 @@ ronin.widget.element = document.getElementById('widget');
var commander = new Commander(document.getElementById("commander"),document.getElementById("commander_input"));
// Interactive
document.addEventListener('mousedown', function(e) {
// Canvas Live Draw
if(e.which == 1 && e.ctrlKey === true){ ronin.overlay.live_draw_start(e); }
else if(e.which == 1){ ronin.brush.draw_start(e); ronin.brush.draw(e); }
else if(e.which == 2){ ronin.drag_start(e); ronin.drag(e); }
}, false);
document.addEventListener('mousemove', function(e) {
// Canvas Live Draw
if(e.which == 1 && e.ctrlKey === true){ ronin.overlay.live_draw(e); }
else if(e.which == 1){ ronin.brush.draw(e); }
else if(e.which == 2){ ronin.drag(e); }
}, false);
document.addEventListener('mouseup', function(e) {
if(e.which == 1){ ronin.brush.draw_stop(e); }
else if(e.which == 2){ ronin.drag_stop(e) }
document.getElementById("commander_input").focus();
}, false);
// Cursor
document.addEventListener('mousedown', function(e){ ronin.cursor.mode.mouse_down(e);}, false);
document.addEventListener('mousemove', function(e){ ronin.cursor.mode.mouse_move(e);}, false);
document.addEventListener('mouseup', function(e){ ronin.cursor.mode.mouse_up(e);}, false);
document.addEventListener('contextmenu', function(ev){ ev.preventDefault(); return false;}, false);
// Keyboard
var keyboard = new Keyboard();
document.onkeyup = function myFunction(){ keyboard.listen(event); };
document.onkeyup = function myFunction(){ keyboard.listen_onkeyup(event); };
document.onkeydown = function myFunction(){ keyboard.listen_onkeydown(event); };
// Canvas
var starting_canvas = new Rect();
starting_canvas.width = window.innerWidth - 200;
starting_canvas.height = window.innerHeight - 200;
ronin.canvas.resize(starting_canvas);
ronin.overlay.resize(starting_canvas);
ronin.overlay.resize(starting_canvas);

View File

@ -32,7 +32,7 @@ function Keyboard()
interface.actions_panel.style.color = "black";
}
this.listen = function(event)
this.listen_onkeyup = function(event)
{
if(this.is_locked === true){ return; }
@ -54,7 +54,14 @@ function Keyboard()
var cmd = commander.element_input.value;
commander.passive(cmd.split(" "));
ronin.hint.update();
ronin.cursor.set_mode(new Mode_Paint());
};
this.listen_onkeydown = function(event)
{
ronin.cursor.update(event);
}
this.key_tab = function()
{

View File

@ -0,0 +1,21 @@
function Mode_Drag()
{
Mode.call(this);
this.name = "Drag";
this.mouse_down = function(event)
{
ronin.drag_start(event); ronin.drag(event);
}
this.mouse_move = function(event)
{
ronin.drag(event);
}
this.mouse_up = function(event)
{
ronin.drag_stop(event);
}
}

View File

@ -0,0 +1,21 @@
function Mode_Guide()
{
Mode.call(this);
this.name = "Guide";
this.mouse_down = function(event)
{
ronin.overlay.live_draw_start(event);
}
this.mouse_move = function(event)
{
ronin.overlay.live_draw(event);
}
this.mouse_up = function(event)
{
}
}

24
scripts/modes/mode.js Normal file
View File

@ -0,0 +1,24 @@
function Mode()
{
this.name = "Unknown";
this.widget = function()
{
return this.name;
}
this.mouse_down = function(event)
{
}
this.mouse_move = function(event)
{
}
this.mouse_up = function(event)
{
}
}

View File

@ -0,0 +1,21 @@
function Mode_Paint()
{
Mode.call(this);
this.name = "Paint";
this.mouse_down = function(event)
{
ronin.brush.draw_start(event); ronin.brush.draw(event);
}
this.mouse_move = function(event)
{
ronin.brush.draw(event);
}
this.mouse_up = function(event)
{
ronin.brush.draw_stop(event);
}
}

View File

@ -16,6 +16,8 @@ function Ronin()
this.vector = new Vector("+");
this.help = new Help("?");
this.cursor = new Cursor();
this.modules[this.canvas.rune] = this.canvas;
this.modules[this.overlay.rune] = this.overlay;
this.modules[this.brush.rune] = this.brush;

View File

@ -9,6 +9,8 @@ function Widget()
for (var key in ronin.modules){
s += ronin.modules[key].widget();
}
s += ronin.cursor.mode.widget();
this.element.innerHTML = s;
}