Progress toward Ronin source files.
This commit is contained in:
parent
53898a5881
commit
29ca5aa5cd
17
index.html
17
index.html
@ -22,6 +22,7 @@
|
||||
<script type="text/javascript" src="scripts/modules/file.load.js"></script>
|
||||
<script type="text/javascript" src="scripts/modules/file.save.js"></script>
|
||||
<script type="text/javascript" src="scripts/modules/help.js"></script>
|
||||
<script type="text/javascript" src="scripts/modules/history.js"></script>
|
||||
|
||||
<script type="text/javascript" src="scripts/modules/filter.js"></script>
|
||||
<script type="text/javascript" src="scripts/modules/filter.saturation.js"></script>
|
||||
@ -35,13 +36,13 @@
|
||||
<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>
|
||||
<script type="text/javascript" src="scripts/hint.js"></script>
|
||||
<script type="text/javascript" src="scripts/widget.js"></script>
|
||||
<script type="text/javascript" src="scripts/core/keyboard.js"></script>
|
||||
<script type="text/javascript" src="scripts/core/cursor.js"></script>
|
||||
<script type="text/javascript" src="scripts/core/command.js"></script>
|
||||
<script type="text/javascript" src="scripts/core/commander.js"></script>
|
||||
<script type="text/javascript" src="scripts/core/ronin.js"></script>
|
||||
<script type="text/javascript" src="scripts/core/hint.js"></script>
|
||||
<script type="text/javascript" src="scripts/core/widget.js"></script>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="links/main.css"/>
|
||||
<title>Ronin</title>
|
||||
@ -58,6 +59,6 @@
|
||||
<input id='commander_input' placeholder='~'/>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="scripts/init.js"></script>
|
||||
<script type="text/javascript" src="scripts/core/init.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -61,6 +61,8 @@ function Commander(element,element_input)
|
||||
break;
|
||||
}
|
||||
this.hide();
|
||||
|
||||
ronin.history.add(content.join(" "));
|
||||
}
|
||||
|
||||
this.passive = function(content)
|
39
scripts/core/cursor.js
Normal file
39
scripts/core/cursor.js
Normal file
@ -0,0 +1,39 @@
|
||||
function Cursor()
|
||||
{
|
||||
this.mode = new Mode_Paint();
|
||||
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()); }
|
||||
}
|
||||
|
||||
this.set_mode = function(mode)
|
||||
{
|
||||
if(this.mode.name == mode.name){ return; }
|
||||
this.mode = mode;
|
||||
document.body.setAttribute("class",this.mode.name);
|
||||
ronin.widget.update();
|
||||
}
|
||||
|
||||
this.mouse_down = function(position)
|
||||
{
|
||||
this.position = position;
|
||||
this.mode.mouse_down(position);
|
||||
}
|
||||
|
||||
this.mouse_move = function(position)
|
||||
{
|
||||
this.position = position;
|
||||
this.mode.mouse_move(position);
|
||||
}
|
||||
|
||||
this.mouse_up = function(position)
|
||||
{
|
||||
this.position = position;
|
||||
this.mode.mouse_up(position);
|
||||
}
|
||||
}
|
@ -8,9 +8,9 @@ ronin.widget.element = document.getElementById('widget');
|
||||
var commander = new Commander(document.getElementById("commander"),document.getElementById("commander_input"));
|
||||
|
||||
// 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('mousedown', function(e){ ronin.cursor.mouse_down(ronin.position_in_canvas(e));}, false);
|
||||
document.addEventListener('mousemove', function(e){ ronin.cursor.mouse_move(ronin.position_in_canvas(e));}, false);
|
||||
document.addEventListener('mouseup', function(e){ ronin.cursor.mouse_up(ronin.position_in_canvas(e));}, false);
|
||||
document.addEventListener('contextmenu', function(ev){ ev.preventDefault(); return false;}, false);
|
||||
|
||||
// Keyboard
|
@ -56,6 +56,7 @@ function Keyboard()
|
||||
ronin.hint.update();
|
||||
|
||||
ronin.cursor.set_mode(new Mode_Paint());
|
||||
ronin.widget.update();
|
||||
};
|
||||
|
||||
this.listen_onkeydown = function(event)
|
@ -15,6 +15,7 @@ function Ronin()
|
||||
this.stroke = new Stroke("_");
|
||||
this.vector = new Vector("+");
|
||||
this.help = new Help("?");
|
||||
this.history = new History(";");
|
||||
|
||||
this.cursor = new Cursor();
|
||||
|
||||
@ -27,6 +28,9 @@ function Ronin()
|
||||
this.modules[this.stroke.rune] = this.stroke;
|
||||
this.modules[this.vector.rune] = this.vector;
|
||||
this.modules[this.help.rune] = this.help;
|
||||
this.modules[this.history.rune] = this.history;
|
||||
|
||||
this.cursors = [];
|
||||
|
||||
this.position_in_canvas = function(e)
|
||||
{
|
@ -1,35 +0,0 @@
|
||||
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;
|
||||
document.body.setAttribute("class",this.mode.name);
|
||||
ronin.widget.update();
|
||||
}
|
||||
|
||||
this.mouse_down = function(event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
this.mouse_move = function(event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
this.mouse_up = function(event)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ function Mode_Guide()
|
||||
|
||||
this.mouse_up = function(event)
|
||||
{
|
||||
this.live_draw_from = null;
|
||||
commander.element_input.focus();
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ function Mode()
|
||||
|
||||
this.mouse_down = function(event)
|
||||
{
|
||||
|
||||
console.log("??");
|
||||
}
|
||||
|
||||
this.mouse_move = function(event)
|
||||
|
@ -3,36 +3,38 @@ function Mode_Paint()
|
||||
Mode.call(this);
|
||||
|
||||
this.name = "Paint";
|
||||
|
||||
this.is_drawing = false;
|
||||
|
||||
this.mouse_down = function(event)
|
||||
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(event)
|
||||
this.mouse_move = function(position)
|
||||
{
|
||||
if(this.is_drawing === false){return;}
|
||||
|
||||
// this.position = new Position(event.clientX - parseFloat(ronin.surface.style.left) - parseFloat(ronin.canvas.element.style.left),event.clientY- parseFloat(ronin.surface.style.top) - parseFloat(ronin.canvas.element.style.top));
|
||||
ronin.brush.position = ronin.position_in_canvas(event);
|
||||
|
||||
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(event)
|
||||
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();
|
||||
}
|
||||
}
|
@ -5,10 +5,7 @@ function Pointer(offset = new Position(), color = new Color('000000'))
|
||||
this.position_prev = null;
|
||||
this.angle = null;
|
||||
this.distance = 0;
|
||||
|
||||
this.osc_scale = null;
|
||||
this.osc_rate = null;
|
||||
|
||||
|
||||
this.draw = function()
|
||||
{
|
||||
if(!this.position_prev){this.position_prev = this.position(); }
|
||||
@ -18,12 +15,6 @@ function Pointer(offset = new Position(), color = new Color('000000'))
|
||||
|
||||
this.distance += position.distance_to(this.position_prev);
|
||||
|
||||
// Osc experiment
|
||||
if(this.osc_rate && this.osc_scale){
|
||||
// position.x += (Math.sin(this.distance/(25 * this.osc_rate)) * this.osc_scale) - (this.osc_scale/2);
|
||||
position.y += (Math.sin(this.distance/(25 * this.osc_rate)) * this.osc_scale) - (this.osc_scale/2);
|
||||
}
|
||||
|
||||
ronin.canvas.context().beginPath();
|
||||
ronin.canvas.context().moveTo(this.position_prev.x,this.position_prev.y);
|
||||
ronin.canvas.context().lineTo(position.x,position.y);
|
||||
@ -50,6 +41,8 @@ function Pointer(offset = new Position(), color = new Color('000000'))
|
||||
|
||||
this.position = function()
|
||||
{
|
||||
return ronin.cursor.position;
|
||||
|
||||
if(this.angle){
|
||||
var angle_radian = this.angle.degrees * Math.PI / 180;
|
||||
var deltaX = ronin.brush.position.x - this.offset.x;
|
||||
@ -66,6 +59,10 @@ function Pointer(offset = new Position(), color = new Color('000000'))
|
||||
else if(this.mirror && this.mirror.height > 0){
|
||||
return new Position((ronin.brush.position.x + this.offset.x), (2 * this.mirror.height) - (ronin.brush.position.y + this.offset.y));
|
||||
}
|
||||
|
||||
console.log(ronin.brush.position);
|
||||
console.log(this.offset);
|
||||
return;
|
||||
return new Position(ronin.brush.position.x + this.offset.x, ronin.brush.position.y + this.offset.y);
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,11 @@ function Help(rune)
|
||||
this.active = function(cmd)
|
||||
{
|
||||
var w = window.open('about:blank','image from canvas');
|
||||
var html = this.view_modules();
|
||||
w.document.write("<title>Help</title><style>body { font-size:11px;background:#555; color:#ccc; padding:50px}</style><pre>"+html+"</pre>");
|
||||
var html = "";
|
||||
html += this.view_modules();
|
||||
html += this.view_cursors();
|
||||
html += "<hr />"
|
||||
w.document.write("<title>Help</title><style>body { font-size:11px;background:#555; color:#ccc; padding:50px} pre { width:300px; float:left} hr { clear:both}</style>"+html+"");
|
||||
}
|
||||
|
||||
//
|
||||
@ -31,7 +34,30 @@ function Help(rune)
|
||||
html += "\n"
|
||||
});
|
||||
|
||||
return html;
|
||||
return "<pre>"+html+"</pre>";
|
||||
}
|
||||
|
||||
this.view_cursors = function()
|
||||
{
|
||||
html = " Cursors\n\n";
|
||||
// Object.keys(ronin.modules).forEach(function (key) {
|
||||
// html += key+" <b>"+ronin.modules[key].constructor.name+"</b>\n";
|
||||
// html += ""
|
||||
// for (i = 0; i < ronin.modules[key].parameters.length; i++) {
|
||||
// html += " "+pad(ronin.modules[key].parameters[i].name,14);
|
||||
// html += pad(new ronin.modules[key].parameters[i]().example,14)+" \n";
|
||||
// }
|
||||
// for (i = 0; i < ronin.modules[key].variables.length; i++) {
|
||||
// html += " "+pad(ronin.modules[key].variables[i].key,14)+"= ";
|
||||
// for (c = 0; c < ronin.modules[key].variables[i].candidates.length; c++) {
|
||||
// html += ronin.modules[key].variables[i].candidates[c]+" ";
|
||||
// }
|
||||
// html += "\n";
|
||||
// }
|
||||
// html += "\n"
|
||||
// });
|
||||
|
||||
return "<pre>"+html+"</pre>";
|
||||
}
|
||||
|
||||
function pad(s,length)
|
||||
|
22
scripts/modules/history.js
Normal file
22
scripts/modules/history.js
Normal file
@ -0,0 +1,22 @@
|
||||
function History(rune)
|
||||
{
|
||||
Module.call(this,rune);
|
||||
|
||||
this.lines = [];
|
||||
|
||||
this.active = function(cmd)
|
||||
{
|
||||
console.log(this.lines);
|
||||
}
|
||||
|
||||
this.add = function(content)
|
||||
{
|
||||
this.lines.push(content);
|
||||
}
|
||||
|
||||
this.widget = function()
|
||||
{
|
||||
if(this.lines.length === 0){ return "";}
|
||||
return "; "+this.lines.length+" ";
|
||||
}
|
||||
}
|
@ -4,6 +4,30 @@ function Stroke(rune)
|
||||
|
||||
this.parameters = [Any];
|
||||
|
||||
// Create a stroke
|
||||
|
||||
this.positions = null;
|
||||
|
||||
this.new_stroke = function()
|
||||
{
|
||||
this.positions = [];
|
||||
}
|
||||
|
||||
this.append_stroke = function(p)
|
||||
{
|
||||
this.positions.push(p);
|
||||
}
|
||||
|
||||
this.save_stroke = function()
|
||||
{
|
||||
s = "_ ";
|
||||
for (i = 0; i < this.positions.length; i++) {
|
||||
s += this.positions[i].render()+" ";
|
||||
}
|
||||
this.positions = null;
|
||||
ronin.history.add(s);
|
||||
}
|
||||
|
||||
// Module
|
||||
|
||||
this.passive = function(cmd)
|
||||
@ -12,23 +36,26 @@ function Stroke(rune)
|
||||
|
||||
this.active = function(cmd)
|
||||
{
|
||||
// TODO
|
||||
|
||||
var origin = new Position(cmd.content[0]);
|
||||
var destination = new Position(cmd.content[1]);
|
||||
|
||||
var e = {};
|
||||
e.clientX = origin.x;
|
||||
e.clientY = origin.y;
|
||||
|
||||
ronin.brush.is_drawing = true;
|
||||
ronin.brush.draw(e);
|
||||
|
||||
e.clientX = destination.x;
|
||||
e.clientY = destination.y;
|
||||
|
||||
ronin.brush.draw(e);
|
||||
ronin.brush.is_drawing = false;
|
||||
var prev = null
|
||||
for (i = 1; i < cmd.content.length; i++) {
|
||||
var p = new Position(cmd.content[i]);
|
||||
if(prev){
|
||||
this.draw(prev,p);
|
||||
}
|
||||
prev = p;
|
||||
}
|
||||
}
|
||||
|
||||
this.draw = function(pos1,pos2)
|
||||
{
|
||||
ronin.canvas.context().beginPath();
|
||||
ronin.canvas.context().moveTo(pos1.x,pos1.y);
|
||||
ronin.canvas.context().lineTo(pos2.x,pos2.y);
|
||||
ronin.canvas.context().lineCap="round";
|
||||
ronin.canvas.context().lineWidth = 1;
|
||||
ronin.canvas.context().strokeStyle = new Color("#ff0000").rgba();
|
||||
ronin.canvas.context().stroke();
|
||||
ronin.canvas.context().closePath();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user