diff --git a/index.html b/index.html
index c3bc8d9..9b1b5d3 100644
--- a/index.html
+++ b/index.html
@@ -31,11 +31,6 @@
-
-
-
-
-
@@ -52,7 +47,7 @@
diff --git a/scripts/core/commander.js b/scripts/core/commander.js
index 80ac04e..3b000b2 100644
--- a/scripts/core/commander.js
+++ b/scripts/core/commander.js
@@ -2,6 +2,7 @@ function Commander(element,element_input)
{
this.element = element;
this.element_input = element_input;
+ this.hint = new Hint();
this.storage = [];
this.storage_index = 0;
this.always_show = false;
@@ -44,6 +45,7 @@ function Commander(element,element_input)
ronin.modules[key].passive(cmd);
ronin.module = ronin.modules[key];
}
+ this.hint.update(ronin.module,cmd);
}
//
diff --git a/scripts/core/cursor.js b/scripts/core/cursor.js
index 6be0761..1c94482 100644
--- a/scripts/core/cursor.js
+++ b/scripts/core/cursor.js
@@ -1,22 +1,22 @@
function Cursor()
{
- this.mode = new Mode_Paint();
+ this.mode = null;
this.position = new Position();
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()); }
+ if(event.ctrlKey === true){ this.set_mode(ronin.overlay); }
+ else if(event.altKey === true){ this.set_mode(ronin.canvas); }
+ else if(event.shiftKey === true){ this.set_mode(ronin.brush); }
+ else{ this.set_mode(ronin.brush); }
}
this.set_mode = function(mode)
{
- if(this.mode.name == mode.name){ return; }
+ // if(this.mode.constructor.name == mode.constructor.name){ return; }
this.mode = mode;
- document.body.setAttribute("class",this.mode.name);
- ronin.widget.update();
+ document.body.setAttribute("class",this.mode.constructor.name);
+ // ronin.widget.update();
}
this.mouse_down = function(position)
diff --git a/scripts/core/hint.js b/scripts/core/hint.js
index 6fb1d02..aff0579 100644
--- a/scripts/core/hint.js
+++ b/scripts/core/hint.js
@@ -4,12 +4,10 @@ function Hint(element)
this.element = element;
- this.update = function()
+ this.update = function(module,cmd)
{
- return; // TODO
-
- if(ronin.module){
- this.element.innerHTML = this.message(ronin.module,commander.cmd);
+ if(module){
+ this.element.innerHTML = this.message(module,cmd);
this.element.style.display = "block";
}
else{
diff --git a/scripts/core/init.js b/scripts/core/init.js
index db4fb28..f874c04 100644
--- a/scripts/core/init.js
+++ b/scripts/core/init.js
@@ -1,11 +1,12 @@
var ronin = new Ronin();
ronin.canvas.element = document.getElementById('workspace');
ronin.overlay.element = document.getElementById('overlay');
-ronin.hint.element = document.getElementById('commander_hint');
ronin.surface = document.getElementById('surface');
ronin.widget.element = document.getElementById('widget');
+ronin.cursor.mode = ronin.brush;
var commander = new Commander(document.getElementById("commander"),document.getElementById("commander_input"));
+commander.hint.element = document.getElementById('commander_hint');
// Cursor
document.addEventListener('mousedown', function(e){ ronin.cursor.mouse_down(ronin.position_in_canvas(e));}, false);
diff --git a/scripts/core/keyboard.js b/scripts/core/keyboard.js
index d8e8572..6d7a1e4 100644
--- a/scripts/core/keyboard.js
+++ b/scripts/core/keyboard.js
@@ -34,9 +34,8 @@ function Keyboard()
// Passive
commander.passive(commander.element_input.value);
- ronin.hint.update();
- ronin.cursor.set_mode(new Mode_Paint());
+ ronin.cursor.set_mode(ronin.brush);
ronin.widget.update();
};
diff --git a/scripts/core/ronin.js b/scripts/core/ronin.js
index e302ec5..13d0e04 100644
--- a/scripts/core/ronin.js
+++ b/scripts/core/ronin.js
@@ -2,7 +2,6 @@ function Ronin()
{
this.modules = {};
- this.hint = new Hint();
this.widget = new Widget();
this.surface = null;
@@ -34,7 +33,9 @@ function Ronin()
this.position_in_canvas = function(e)
{
- return new Position(e.clientX - parseFloat(ronin.surface.style.left) - parseFloat(ronin.canvas.element.style.left),e.clientY- parseFloat(ronin.surface.style.top) - parseFloat(ronin.canvas.element.style.top));
+ var x = e.clientX - parseFloat(ronin.surface.style.left) - parseFloat(ronin.canvas.element.style.left);
+ var y = e.clientY- parseFloat(ronin.surface.style.top) - parseFloat(ronin.canvas.element.style.top);
+ return new Position(x+","+y);
}
this.position_in_window = function(p)
diff --git a/scripts/core/widget.js b/scripts/core/widget.js
index 4ac841d..48b4df7 100644
--- a/scripts/core/widget.js
+++ b/scripts/core/widget.js
@@ -10,7 +10,7 @@ function Widget()
s += ronin.modules[key].widget();
}
- s += "
"+ronin.cursor.mode.widget()+"";
+ // s += "
"+ronin.cursor.mode.widget()+"";
this.element.innerHTML = s;
}
diff --git a/scripts/modes/mode.drag.js b/scripts/modes/mode.drag.js
deleted file mode 100644
index 581eeaa..0000000
--- a/scripts/modes/mode.drag.js
+++ /dev/null
@@ -1,33 +0,0 @@
-function Mode_Drag()
-{
- Mode.call(this);
-
- this.name = "Drag";
-
- this.drag_from = null;
-
- this.mouse_down = function(position)
- {
- this.drag_from = ronin.position_in_window(position);
- }
-
- 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;
-
- ronin.surface.style.left = ronin.surface.style.left ? parseInt(ronin.surface.style.left) - offset_x : offset_x;
- ronin.surface.style.top = ronin.surface.style.top ? parseInt(ronin.surface.style.top) - offset_y : offset_y;
-
- this.drag_from = new Position(position.x,position.y);
- }
-
- this.mouse_up = function(event)
- {
- this.drag_from = null;
- }
-}
\ No newline at end of file
diff --git a/scripts/modes/mode.guide.js b/scripts/modes/mode.guide.js
deleted file mode 100644
index 524a70d..0000000
--- a/scripts/modes/mode.guide.js
+++ /dev/null
@@ -1,38 +0,0 @@
-function Mode_Guide()
-{
- Mode.call(this);
-
- this.name = "Guide";
-
- this.live_draw_from = null;
-
- this.mouse_down = function(position)
- {
- ronin.overlay.clear();
- ronin.overlay.draw_pointer(position);
- this.live_draw_from = position;
- commander.show();
- commander.element_input.focus();
- commander.element_input.value = "| "+this.live_draw_from.render();
- }
-
- this.mouse_move = function(position)
- {
- if(this.live_draw_from === null){ return; }
-
- ronin.overlay.clear();
-
- var rect = new Rect();
- rect.width = position.x - this.live_draw_from.x;
- rect.height = position.y - this.live_draw_from.y;
-
- ronin.overlay.draw_rect(this.live_draw_from,rect);
- commander.element_input.value = "| "+this.live_draw_from.render()+" "+rect.render();
- }
-
- this.mouse_up = function(position)
- {
- this.live_draw_from = null;
- commander.element_input.focus();
- }
-}
\ No newline at end of file
diff --git a/scripts/modes/mode.js b/scripts/modes/mode.js
deleted file mode 100644
index a42b88d..0000000
--- a/scripts/modes/mode.js
+++ /dev/null
@@ -1,24 +0,0 @@
-function Mode()
-{
- this.name = "Unknown";
-
- this.widget = function()
- {
- return this.name;
- }
-
- this.mouse_down = function(event)
- {
- console.log("??");
- }
-
- 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
deleted file mode 100644
index 387a7e0..0000000
--- a/scripts/modes/mode.paint.js
+++ /dev/null
@@ -1,40 +0,0 @@
-function Mode_Paint()
-{
- Mode.call(this);
-
- this.name = "Paint";
- this.is_drawing = false;
-
- this.mouse_down = function(position)
- {
- this.is_drawing = true;
-
- for (i = 0; i < ronin.brush.pointers.length; i++) {
- ronin.brush.pointers[i].start();
- }
-
- ronin.stroke.new_stroke();
- }
-
- this.mouse_move = function(position)
- {
- if(this.is_drawing === false){ return; }
-
- for (i = 0; i < ronin.brush.pointers.length; i++) {
- ronin.brush.pointers[i].draw();
- }
-
- ronin.stroke.append_stroke(position);
- }
-
- this.mouse_up = function(position)
- {
- this.is_drawing = false;
-
- for (i = 0; i < ronin.brush.pointers.length; i++) {
- ronin.brush.pointers[i].stop();
- }
-
- ronin.stroke.save_stroke();
- }
-}
\ No newline at end of file
diff --git a/scripts/modules/brush.js b/scripts/modules/brush.js
index b0ea0da..bae79d3 100644
--- a/scripts/modules/brush.js
+++ b/scripts/modules/brush.js
@@ -5,7 +5,6 @@ function Brush(rune)
this.parameters = [Position,Rect,Angle,Color,Value,Bang];
this.pointers = [new Pointer(new Position())];
- this.position = new Position();
this.size = 1;
this.opacity = 1;
this.color = new Color();
@@ -63,6 +62,43 @@ function Brush(rune)
this.widget = function()
{
- return "> "+this.size+"
"+this.color.render()+" ";
+ return "> "+this.size+"
"+this.color.render()+" ";
+ }
+
+ // Cursor
+
+ this.is_drawing = false;
+
+ this.mouse_down = function(position)
+ {
+ this.is_drawing = true;
+
+ for (i = 0; i < ronin.brush.pointers.length; i++) {
+ ronin.brush.pointers[i].start();
+ }
+
+ ronin.stroke.new_stroke();
+ }
+
+ this.mouse_move = function(position)
+ {
+ if(this.is_drawing === false){ return; }
+
+ for (i = 0; i < ronin.brush.pointers.length; i++) {
+ ronin.brush.pointers[i].draw();
+ }
+
+ ronin.stroke.append_stroke(position);
+ }
+
+ this.mouse_up = function(position)
+ {
+ this.is_drawing = false;
+
+ for (i = 0; i < ronin.brush.pointers.length; i++) {
+ ronin.brush.pointers[i].stop();
+ }
+
+ ronin.stroke.save_stroke();
}
}
\ No newline at end of file
diff --git a/scripts/modules/canvas.js b/scripts/modules/canvas.js
index bf0725f..6072066 100644
--- a/scripts/modules/canvas.js
+++ b/scripts/modules/canvas.js
@@ -67,4 +67,33 @@ function Canvas(rune)
{
return "@ "+this.element.width+"x"+this.element.height+" ";
}
+
+ // Cursor
+
+ this.drag_from = null;
+
+ this.mouse_down = function(position)
+ {
+ this.drag_from = ronin.position_in_window(position);
+ }
+
+ 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;
+
+ ronin.surface.style.left = ronin.surface.style.left ? parseInt(ronin.surface.style.left) - offset_x : offset_x;
+ ronin.surface.style.top = ronin.surface.style.top ? parseInt(ronin.surface.style.top) - offset_y : offset_y;
+
+ this.drag_from = new Position(position.x,position.y);
+ }
+
+ this.mouse_up = function(event)
+ {
+ this.drag_from = null;
+ }
}
\ No newline at end of file
diff --git a/scripts/modules/module.js b/scripts/modules/module.js
index 7952b96..dbeeb33 100644
--- a/scripts/modules/module.js
+++ b/scripts/modules/module.js
@@ -24,4 +24,17 @@ function Module(rune)
{
return "";
}
+
+
+ this.mouse_down = function(position)
+ {
+ }
+
+ this.mouse_move = function(position)
+ {
+ }
+
+ this.mouse_up = function(position)
+ {
+ }
}
\ No newline at end of file
diff --git a/scripts/modules/overlay.js b/scripts/modules/overlay.js
index 889c1c3..db2e7af 100644
--- a/scripts/modules/overlay.js
+++ b/scripts/modules/overlay.js
@@ -118,4 +118,38 @@ function Overlay(rune)
{
this.context().clearRect(0, 0, ronin.canvas.element.width, ronin.canvas.element.height);
}
+
+ // Cursor
+
+ this.live_draw_from = null;
+
+ this.mouse_down = function(position)
+ {
+ ronin.overlay.clear();
+ ronin.overlay.draw_pointer(position);
+ this.live_draw_from = position;
+ commander.show();
+ commander.element_input.focus();
+ commander.element_input.value = "| "+this.live_draw_from.render();
+ }
+
+ this.mouse_move = function(position)
+ {
+ if(this.live_draw_from === null){ return; }
+
+ ronin.overlay.clear();
+
+ var rect = new Rect();
+ rect.width = position.x - this.live_draw_from.x;
+ rect.height = position.y - this.live_draw_from.y;
+
+ ronin.overlay.draw_rect(this.live_draw_from,rect);
+ commander.element_input.value = "| "+this.live_draw_from.render()+" "+rect.render();
+ }
+
+ this.mouse_up = function(position)
+ {
+ this.live_draw_from = null;
+ commander.element_input.focus();
+ }
}
\ No newline at end of file
diff --git a/scripts/modules/stroke.js b/scripts/modules/stroke.js
index 556c7fd..7a42359 100644
--- a/scripts/modules/stroke.js
+++ b/scripts/modules/stroke.js
@@ -24,8 +24,8 @@ function Stroke(rune)
for (i = 0; i < this.positions.length; i++) {
s += this.positions[i].render()+" ";
}
+ if(this.positions.length > 0){ ronin.history.add(s); }
this.positions = null;
- ronin.history.add(s);
}
// Module