diff --git a/assets/render.jpg b/assets/render.jpg new file mode 100644 index 0000000..e50b172 Binary files /dev/null and b/assets/render.jpg differ diff --git a/index.html b/index.html index 3ba768e..f06661d 100644 --- a/index.html +++ b/index.html @@ -1,6 +1,6 @@
- + @@ -12,7 +12,7 @@ - + @@ -30,7 +30,13 @@ + + + + + + diff --git a/scripts/cursor.js b/scripts/cursor.js new file mode 100644 index 0000000..5c14c2c --- /dev/null +++ b/scripts/cursor.js @@ -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) + { + + } +} \ No newline at end of file diff --git a/scripts/init.js b/scripts/init.js index 59a6a29..3195eb6 100644 --- a/scripts/init.js +++ b/scripts/init.js @@ -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); \ No newline at end of file diff --git a/scripts/keyboard.js b/scripts/keyboard.js index b1cdb82..4fac81d 100644 --- a/scripts/keyboard.js +++ b/scripts/keyboard.js @@ -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() { diff --git a/scripts/modes/mode.drag.js b/scripts/modes/mode.drag.js new file mode 100644 index 0000000..5efd9d9 --- /dev/null +++ b/scripts/modes/mode.drag.js @@ -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); + } +} \ No newline at end of file diff --git a/scripts/modes/mode.guide.js b/scripts/modes/mode.guide.js new file mode 100644 index 0000000..9a9b646 --- /dev/null +++ b/scripts/modes/mode.guide.js @@ -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) + { + + } +} \ No newline at end of file diff --git a/scripts/modes/mode.js b/scripts/modes/mode.js new file mode 100644 index 0000000..079e867 --- /dev/null +++ b/scripts/modes/mode.js @@ -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) + { + + } +} \ No newline at end of file diff --git a/scripts/modes/mode.paint.js b/scripts/modes/mode.paint.js new file mode 100644 index 0000000..ad3325c --- /dev/null +++ b/scripts/modes/mode.paint.js @@ -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); + } +} \ No newline at end of file diff --git a/scripts/module.js b/scripts/modules/module.js similarity index 100% rename from scripts/module.js rename to scripts/modules/module.js diff --git a/scripts/ronin.js b/scripts/ronin.js index bec9c17..fb1442b 100644 --- a/scripts/ronin.js +++ b/scripts/ronin.js @@ -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; diff --git a/scripts/unit.js b/scripts/units/unit.js similarity index 100% rename from scripts/unit.js rename to scripts/units/unit.js diff --git a/scripts/widget.js b/scripts/widget.js index eeb0508..346693a 100644 --- a/scripts/widget.js +++ b/scripts/widget.js @@ -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; }