Began working on methods

This commit is contained in:
Devine Lu Linvega 2017-03-18 15:02:37 -07:00
parent 15e019d455
commit 35438605af
12 changed files with 81 additions and 12 deletions

View File

@ -11,6 +11,7 @@
<script type="text/javascript" src="scripts/units/any.js"></script> <script type="text/javascript" src="scripts/units/any.js"></script>
<script type="text/javascript" src="scripts/units/setting.js"></script> <script type="text/javascript" src="scripts/units/setting.js"></script>
<script type="text/javascript" src="scripts/units/range.js"></script> <script type="text/javascript" src="scripts/units/range.js"></script>
<script type="text/javascript" src="scripts/units/method.js"></script>
<script type="text/javascript" src="scripts/modules/default.js"></script> <script type="text/javascript" src="scripts/modules/default.js"></script>
<script type="text/javascript" src="scripts/modules/cursor.js"></script> <script type="text/javascript" src="scripts/modules/cursor.js"></script>

View File

@ -84,8 +84,8 @@ function Command(content)
this.setting = function(name) this.setting = function(name)
{ {
for (i = 0; i < this.content.length; i++) { for (i = 0; i < this.content.length; i++) {
if(this.content[i].indexOf(":") >= 0){ if(this.content[i].indexOf("=") >= 0){
var parts = this.content[i].split(":"); var parts = this.content[i].split("=");
if(parts[0] == name){ if(parts[0] == name){
return new Setting(parts[0],parts[1]); return new Setting(parts[0],parts[1]);
} }

View File

@ -32,9 +32,9 @@ starting_canvas.width = parseInt(starting_canvas.width/40) * 40;
starting_canvas.height = parseInt(starting_canvas.height/40) * 40; starting_canvas.height = parseInt(starting_canvas.height/40) * 40;
ronin.terminal.query("~ "+ronin.timestamp()); ronin.terminal.query("~ "+ronin.timestamp());
ronin.terminal.query("@ size:"+starting_canvas.render()); ronin.terminal.query("@ size="+starting_canvas.render());
ronin.terminal.query("@ layer:Main"); ronin.terminal.query("@ layer=Main");
ronin.terminal.query("- color:#ff0000"); ronin.terminal.query("- color=#ff0000");
// ronin.terminal.query("# fill=#ff0000"); // ronin.terminal.query("# fill=#ff0000");
// ronin.terminal.query("- 0,0"); // ronin.terminal.query("- 0,0");
// ronin.terminal.query("- 1,1"); // ronin.terminal.query("- 1,1");

View File

@ -19,13 +19,13 @@ function Ronin()
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;
this.modules[this.filesave.rune] = this.filesave; this.modules[this.filesave.rune] = this.filesave;
this.modules[this.overlay.rune] = this.overlay;
this.modules[this.render.rune] = this.render; this.modules[this.render.rune] = this.render;
this.modules[this.brush.rune] = this.brush; this.modules[this.brush.rune] = this.brush;
this.modules[this.eye.rune] = this.eye; this.modules[this.eye.rune] = this.eye;
this.modules[this.typo.rune] = this.typo; this.modules[this.typo.rune] = this.typo;
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.cursor.rune] = this.cursor; this.modules[this.cursor.rune] = this.cursor;

View File

@ -79,7 +79,7 @@ function Brush(rune)
this.mouse_pointer = function(position) this.mouse_pointer = function(position)
{ {
return ronin.cursor.draw_pointer_circle(position,this.settings["size"]); return ronin.cursor.draw_pointer_circle(position,this.settings["size"].float);
} }
this.mouse_mode = function() this.mouse_mode = function()

View File

@ -96,7 +96,40 @@ function Cursor(rune)
this.pointer_last = this.pointer_last ? this.pointer_last : position; this.pointer_last = this.pointer_last ? this.pointer_last : position;
this.layer.context().beginPath(); this.layer.context().beginPath();
this.layer.context().arc(position.x, position.y, 3.5, 0, 2 * Math.PI, false); this.layer.context().moveTo(this.pointer_last.x,this.pointer_last.y);
this.layer.context().lineTo(position.x,position.y);
this.layer.context().lineCap="round";
this.layer.context().lineWidth = 1;
this.layer.context().strokeStyle = "white";
this.layer.context().stroke();
this.layer.context().closePath();
this.layer.context().beginPath();
this.layer.context().arc(position.x, position.y, size+1, 0, 2 * Math.PI, false);
this.layer.context().lineWidth = 1;
this.layer.context().strokeStyle = "white";
this.layer.context().stroke();
this.layer.context().closePath();
this.pointer_last = position;
}
this.draw_pointer_drag = function(position)
{
if(!this.layer){ this.create_layer(); }
this.pointer_last = this.pointer_last ? this.pointer_last : position;
this.layer.context().beginPath();
this.layer.context().moveTo(position.x,position.y - 3);
this.layer.context().lineTo(position.x,position.y + 3);
this.layer.context().moveTo(position.x - 2,position.y - 3);
this.layer.context().lineTo(position.x - 2,position.y + 3);
this.layer.context().moveTo(position.x + 2,position.y - 3);
this.layer.context().lineTo(position.x + 2,position.y + 3);
this.layer.context().lineCap="round";
this.layer.context().lineWidth = 1; this.layer.context().lineWidth = 1;
this.layer.context().strokeStyle = "white"; this.layer.context().strokeStyle = "white";
this.layer.context().stroke(); this.layer.context().stroke();

View File

@ -9,6 +9,11 @@ function Default(rune)
return "Drag"; return "Drag";
} }
this.mouse_pointer = function(position)
{
return ronin.cursor.draw_pointer_drag(position);
}
this.drag_from = null; this.drag_from = null;
this.drag_offset_x = 0; this.drag_offset_x = 0;
this.drag_offset_y = 0; this.drag_offset_y = 0;

View File

@ -3,6 +3,7 @@ function Module(rune)
this.rune = rune; this.rune = rune;
this.element = null; this.element = null;
this.settings = {}; this.settings = {};
this.methods = {};
this.layer = null; this.layer = null;
this.docs = "Missing documentation."; this.docs = "Missing documentation.";
@ -50,7 +51,10 @@ function Module(rune)
var h = "<b>"+ronin.module.constructor.name+"</b> "; var h = "<b>"+ronin.module.constructor.name+"</b> ";
for(setting in ronin.module.settings){ for(setting in ronin.module.settings){
h += setting+":"+ronin.module.settings[setting].render()+" "; h += setting+"="+ronin.module.settings[setting].render()+" ";
}
for(method in ronin.module.methods){
h += ronin.module.methods[method].render()+" ";
} }
h += ronin.module.mouse_mode() ? "<i>"+ronin.module.mouse_mode()+"</i>" : ""; h += ronin.module.mouse_mode() ? "<i>"+ronin.module.mouse_mode()+"</i>" : "";

View File

@ -4,6 +4,7 @@ function Surface(rune)
this.element = null; this.element = null;
this.settings = {"size":new Rect("200x200")}; this.settings = {"size":new Rect("200x200")};
this.methods = {"layer":new Method("layer",["name"])}
this.layers = {}; this.layers = {};
this.active_layer = null; this.active_layer = null;

View File

@ -1,6 +1,7 @@
function Layer(name,manager = null) function Layer(name,manager = null)
{ {
this.rune = "@"; Module.call(this,"#");
this.name = name; this.name = name;
this.manager = manager; this.manager = manager;
this.element = document.createElement("canvas"); this.element = document.createElement("canvas");
@ -68,6 +69,11 @@ function Layer(name,manager = null)
return "<span class='"+e_class+"'>"+e_name+"</span>"; return "<span class='"+e_class+"'>"+e_name+"</span>";
} }
this.mouse_pointer = function(position)
{
return ronin.cursor.draw_pointer_drag(position);
}
this.mouse_mode = function() this.mouse_mode = function()
{ {
return "Move"; return "Move";

View File

@ -2,8 +2,8 @@ function Typographe(rune)
{ {
Module.call(this,rune); Module.call(this,rune);
this.parameters = [Position,Color,Value]; this.settings = {"color":new Color("#ffffff"),"size":new Value(10)};
this.variables = {"text" : null, "font" : "Georgia"}; this.methods = {"draw":new Method("draw",["text","position","font"])}
this.active = function(cmd) this.active = function(cmd)
{ {

19
scripts/units/method.js Normal file
View File

@ -0,0 +1,19 @@
function Method(name,params)
{
Unit.call(this);
this.name = name;
this.params = params;
this.example = "";
this.render = function()
{
var s = name+":";
for(param in this.params){
s += this.params[param]+","
}
s = s.substr(0,s.length-1);
return s;
}
}