Added icons
This commit is contained in:
0
sources/scripts/core/Icon
Normal file
0
sources/scripts/core/Icon
Normal file
90
sources/scripts/core/command.js
Normal file
90
sources/scripts/core/command.js
Normal file
@@ -0,0 +1,90 @@
|
||||
function Command(content)
|
||||
{
|
||||
this.content = content;
|
||||
|
||||
// Parser
|
||||
|
||||
this.any = function()
|
||||
{
|
||||
if(this.content.join() === ""){ return null; }
|
||||
return new Any(this.content);
|
||||
}
|
||||
|
||||
this.rect = function()
|
||||
{
|
||||
for (i = 0; i < this.content.length; i++) {
|
||||
if(this.content[i].indexOf("x") >= 0 && this.content[i].indexOf("/") < 0){ return new Rect(this.content[i]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.position = function()
|
||||
{
|
||||
for (i = 0; i < this.content.length; i++) {
|
||||
if(this.content[i].indexOf(",") >= 0){ return new Position(this.content[i]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.color = function()
|
||||
{
|
||||
for (i = 0; i < this.content.length; i++) {
|
||||
if(this.content[i].indexOf("#") >= 0){ return new Color(this.content[i]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.filepath = function()
|
||||
{
|
||||
for (i = 0; i < this.content.length; i++) {
|
||||
if(this.content[i].indexOf("/") >= 0){ return new Filepath(this.content[i]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.value = function()
|
||||
{
|
||||
for (i = 0; i < this.content.length; i++) {
|
||||
var test = /[^$\-\d]/.test(this.content[i]);
|
||||
if(!test && this.content[i] !== ""){ return new Value(this.content[i]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.range = function()
|
||||
{
|
||||
for (i = 0; i < this.content.length; i++) {
|
||||
if(this.content[i].indexOf("..") >= 0){ return new Range(this.content[i]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.bang = function()
|
||||
{
|
||||
for (i = 0; i < this.content.length; i++) {
|
||||
if(this.content[i].indexOf("!") >= 0){ return new Bang(); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.angle = function()
|
||||
{
|
||||
for (i = 0; i < this.content.length; i++) {
|
||||
if(this.content[i].indexOf("'") >= 0){ return new Angle(this.content[i]); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
this.variable = function(name)
|
||||
{
|
||||
for (i = 0; i < this.content.length; i++) {
|
||||
if(this.content[i].indexOf("=") >= 0){
|
||||
var parts = this.content[i].split("=");
|
||||
if(parts[0] == name){
|
||||
return new Variable(parts[0],parts[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
38
sources/scripts/core/commander.hint.js
Normal file
38
sources/scripts/core/commander.hint.js
Normal file
@@ -0,0 +1,38 @@
|
||||
function Hint(element)
|
||||
{
|
||||
Module.call(this);
|
||||
|
||||
this.element = element;
|
||||
|
||||
this.update = function(module,cmd)
|
||||
{
|
||||
if(module){
|
||||
this.element.innerHTML = this.message(module,cmd);
|
||||
this.element.style.display = "block";
|
||||
}
|
||||
else if(commander && commander.element_input.value != ""){
|
||||
this.element.innerHTML = commander.element_input.value;
|
||||
this.element.style.display = "block";
|
||||
}
|
||||
else{
|
||||
this.element.innerHTML = this.default();
|
||||
this.element.style.display = "block";
|
||||
}
|
||||
}
|
||||
|
||||
this.message = function(module,cmd)
|
||||
{
|
||||
return module.hint(cmd);
|
||||
}
|
||||
|
||||
this.default = function()
|
||||
{
|
||||
var s = "<span class='module'>Modules</span>";
|
||||
|
||||
for (var key in ronin.modules){
|
||||
s += "<span> <span class='value'>"+key+"</span> <span class='param'>"+ronin.modules[key].constructor.name.substr(0,2)+" ";
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
99
sources/scripts/core/commander.js
Normal file
99
sources/scripts/core/commander.js
Normal file
@@ -0,0 +1,99 @@
|
||||
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;
|
||||
|
||||
var queue = [];
|
||||
|
||||
this.query = function(input_str)
|
||||
{
|
||||
if(input_str.indexOf(";") > 0){
|
||||
queue = input_str.split(";");
|
||||
}
|
||||
else{
|
||||
queue.push(input_str)
|
||||
}
|
||||
run();
|
||||
this.hide();
|
||||
}
|
||||
|
||||
function run()
|
||||
{
|
||||
console.log("~ "+queue[0].trim());
|
||||
active(queue[0].trim());
|
||||
|
||||
queue.shift();
|
||||
if(queue.length > 0){
|
||||
setTimeout(function(){ run(); }, 100);
|
||||
}
|
||||
}
|
||||
|
||||
function active(content)
|
||||
{
|
||||
var key = content[0];
|
||||
var cmd = new Command(content.substring(1).trim().split(" "));
|
||||
|
||||
if(ronin.modules[key]){
|
||||
ronin.modules[key].active(cmd);
|
||||
}
|
||||
|
||||
ronin.history.add(content);
|
||||
}
|
||||
|
||||
this.passive = function(content)
|
||||
{
|
||||
var key = content[0];
|
||||
var cmd = new Command(content.substring(1).split(" "));
|
||||
|
||||
ronin.module = null;
|
||||
|
||||
if(ronin.modules[key]){
|
||||
ronin.modules[key].passive(cmd);
|
||||
ronin.module = ronin.modules[key];
|
||||
}
|
||||
this.hint.update(ronin.module,cmd);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
this.show = function()
|
||||
{
|
||||
this.element.setAttribute('class','visible');
|
||||
this.element_input.focus();
|
||||
this.element_input.value = "";
|
||||
}
|
||||
|
||||
this.always = function() {
|
||||
this.always_show = !this.always_show;
|
||||
}
|
||||
|
||||
this.hide = function()
|
||||
{
|
||||
if (!this.always_show) {
|
||||
this.element.setAttribute('class','hidden');
|
||||
}
|
||||
this.element_input.value = "";
|
||||
}
|
||||
|
||||
this.clear = function()
|
||||
{
|
||||
this.element_input.value = "";
|
||||
}
|
||||
|
||||
this.next_cmd = function()
|
||||
{
|
||||
this.storage_index += this.storage_index < this.storage.length ? 1 : 0;
|
||||
this.element_input.value = this.storage[this.storage_index] ? this.storage[this.storage_index] : "";
|
||||
}
|
||||
|
||||
this.prev_cmd = function()
|
||||
{
|
||||
this.storage_index -= this.storage_index < 1 ? 0 : 1;
|
||||
this.element_input.value = this.storage[this.storage_index];
|
||||
}
|
||||
|
||||
}
|
||||
45
sources/scripts/core/cursor.js
Normal file
45
sources/scripts/core/cursor.js
Normal file
@@ -0,0 +1,45 @@
|
||||
function Cursor()
|
||||
{
|
||||
this.mode = null;
|
||||
this.position = new Position();
|
||||
|
||||
this.update = function(event)
|
||||
{
|
||||
if(event.ctrltKey === true && event.altKey === true && event.shiftKey === true){ /* */ }
|
||||
else if(event.shiftKey === true && event.ctrlKey === true){ this.set_mode(ronin.eye); }
|
||||
else if(event.shiftKey === true && event.altKey === true){ this.set_mode(ronin.surface.active_layer); }
|
||||
else if(event.ctrltKey === true && event.altKey === true){ this.set_mode(ronin.overlay.compositor); }
|
||||
else if(event.ctrlKey === true){ this.set_mode(ronin.overlay); }
|
||||
else if(event.altKey === true){ this.set_mode(ronin.surface); }
|
||||
else if(event.shiftKey === true){ this.set_mode(ronin.eraser); }
|
||||
else{ this.set_mode(ronin.brush); }
|
||||
}
|
||||
|
||||
this.set_mode = function(mode)
|
||||
{
|
||||
if(this.mode == mode){ return; }
|
||||
this.mode = mode;
|
||||
document.body.setAttribute("class",this.mode.constructor.name);
|
||||
ronin.widget.update();
|
||||
}
|
||||
|
||||
this.mouse_down = function(position)
|
||||
{
|
||||
this.position = position;
|
||||
this.mode.mouse_down(position);
|
||||
ronin.widget.update();
|
||||
}
|
||||
|
||||
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);
|
||||
ronin.widget.update();
|
||||
}
|
||||
}
|
||||
42
sources/scripts/core/init.js
Normal file
42
sources/scripts/core/init.js
Normal file
@@ -0,0 +1,42 @@
|
||||
var ronin = new Ronin();
|
||||
ronin.element = document.getElementById('ronin');
|
||||
ronin.overlay.element = document.getElementById('overlay');
|
||||
ronin.surface.element = 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);
|
||||
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);
|
||||
window.addEventListener('resize', function(){ ronin.on_resize(); }, true);
|
||||
|
||||
// Keyboard
|
||||
|
||||
var keyboard = new Keyboard();
|
||||
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;
|
||||
|
||||
// Clamp
|
||||
|
||||
starting_canvas.width = parseInt(starting_canvas.width/40) * 40;
|
||||
starting_canvas.height = parseInt(starting_canvas.height/40) * 40;
|
||||
|
||||
commander.query("~ "+ronin.timestamp());
|
||||
commander.query("# "+starting_canvas.render());
|
||||
commander.query("# layer=background");
|
||||
commander.query("# #efefef");
|
||||
commander.query("# layer=main");
|
||||
commander.query("> 1 0,0 #000000");
|
||||
commander.query("> 1 1,0 #000000");
|
||||
commander.query("> 1 0,1 #000000");
|
||||
80
sources/scripts/core/keyboard.js
Normal file
80
sources/scripts/core/keyboard.js
Normal file
@@ -0,0 +1,80 @@
|
||||
function Keyboard()
|
||||
{
|
||||
this.listen_onkeyup = function(event)
|
||||
{
|
||||
switch (event.key) {
|
||||
case "Enter": this.key_enter(); break;
|
||||
case "ArrowUp": this.key_arrow_up(); break;
|
||||
case "ArrowDown": this.key_arrow_down(); break;
|
||||
case "ArrowLeft": this.key_arrow_left(); break;
|
||||
case "ArrowRight": this.key_arrow_right(); break;
|
||||
// case ":": this.key_colon(); break;
|
||||
case "Escape": this.key_escape(); break;
|
||||
}
|
||||
|
||||
switch(event.which)
|
||||
{
|
||||
case 13: this.key_enter(); break;
|
||||
case 186: if(event.shiftKey){this.key_colon();} break;
|
||||
case 27: this.key_escape(); break;
|
||||
case 219: ronin.brush.size_up(); break;
|
||||
case 221: ronin.brush.size_down(); break;
|
||||
case 38: ronin.surface.layer_up(); break;
|
||||
case 40: ronin.surface.layer_down(); break;
|
||||
}
|
||||
|
||||
// Passive
|
||||
commander.passive(commander.element_input.value);
|
||||
|
||||
ronin.cursor.set_mode(ronin.brush);
|
||||
ronin.widget.update();
|
||||
};
|
||||
|
||||
this.listen_onkeydown = function(event)
|
||||
{
|
||||
ronin.cursor.update(event);
|
||||
}
|
||||
|
||||
this.key_tab = function()
|
||||
{
|
||||
}
|
||||
|
||||
this.key_enter = function()
|
||||
{
|
||||
commander.query(commander.element_input.value);
|
||||
}
|
||||
|
||||
this.key_space = function()
|
||||
{
|
||||
}
|
||||
|
||||
this.key_arrow_up = function()
|
||||
{
|
||||
commander.prev_cmd();
|
||||
}
|
||||
|
||||
this.key_arrow_down = function()
|
||||
{
|
||||
commander.next_cmd();
|
||||
}
|
||||
|
||||
this.key_arrow_left = function()
|
||||
{
|
||||
}
|
||||
|
||||
this.key_arrow_right = function()
|
||||
{
|
||||
}
|
||||
|
||||
this.key_colon = function()
|
||||
{
|
||||
commander.show();
|
||||
return false;
|
||||
}
|
||||
|
||||
this.key_escape = function()
|
||||
{
|
||||
commander.hide();
|
||||
ronin.overlay.clear();
|
||||
}
|
||||
}
|
||||
66
sources/scripts/core/ronin.js
Normal file
66
sources/scripts/core/ronin.js
Normal file
@@ -0,0 +1,66 @@
|
||||
function Ronin()
|
||||
{
|
||||
this.modules = {};
|
||||
this.element = null;
|
||||
this.widget = new Widget();
|
||||
|
||||
this.surface = new Surface("#");
|
||||
this.fileload = new FileLoad("/");
|
||||
this.filesave = new FileSave("$");
|
||||
this.history = new History("^");
|
||||
this.overlay = new Overlay("|");
|
||||
this.brush = new Brush(">");
|
||||
this.eraser = new Eraser(".");
|
||||
this.eye = new Eye("*");
|
||||
this.render = new Render("%");
|
||||
this.stroke = new Stroke("_");
|
||||
this.vector = new Vector("+");
|
||||
this.help = new Help("?");
|
||||
this.typo = new Typographe("&");
|
||||
|
||||
this.cursor = new Cursor();
|
||||
|
||||
this.modules[this.surface.rune] = this.surface;
|
||||
this.modules[this.fileload.rune] = this.fileload;
|
||||
this.modules[this.filesave.rune] = this.filesave;
|
||||
this.modules[this.history.rune] = this.history;
|
||||
this.modules[this.overlay.rune] = this.overlay;
|
||||
this.modules[this.render.rune] = this.render;
|
||||
this.modules[this.brush.rune] = this.brush;
|
||||
this.modules[this.eraser.rune] = this.eraser;
|
||||
this.modules[this.eye.rune] = this.eye;
|
||||
this.modules[this.typo.rune] = this.typo;
|
||||
this.modules[this.stroke.rune] = this.stroke;
|
||||
this.modules[this.vector.rune] = this.vector;
|
||||
this.modules[this.help.rune] = this.help;
|
||||
|
||||
this.cursors = [];
|
||||
|
||||
this.position_in_canvas = function(e)
|
||||
{
|
||||
var x = e.clientX;
|
||||
x -= (window.innerWidth - this.surface.size.width)/2;
|
||||
x -= parseInt(this.surface.element.style.marginLeft) + (this.surface.size.width/2);
|
||||
var y = e.clientY;
|
||||
y -= (window.innerHeight - this.surface.size.height)/2;
|
||||
y -= parseInt(this.surface.element.style.marginTop) + parseInt(this.surface.size.height/2);
|
||||
return new Position(x,y);
|
||||
}
|
||||
|
||||
this.position_in_window = function(p)
|
||||
{
|
||||
return new Position(p.x + parseInt(this.surface.element.style.marginLeft),p.y + parseInt(this.surface.element.style.marginTop));
|
||||
}
|
||||
|
||||
this.timestamp = function()
|
||||
{
|
||||
var currentdate = new Date();
|
||||
var date = currentdate.getFullYear()+""+(currentdate.getMonth()+1)+""+currentdate.getDate();
|
||||
return date+" "+currentdate.getHours()+":"+currentdate.getMinutes()+":"+currentdate.getSeconds();
|
||||
}
|
||||
|
||||
this.on_resize = function()
|
||||
{
|
||||
this.widget.on_resize();
|
||||
}
|
||||
}
|
||||
26
sources/scripts/core/widget.js
Normal file
26
sources/scripts/core/widget.js
Normal file
@@ -0,0 +1,26 @@
|
||||
function Widget()
|
||||
{
|
||||
this.element = null;
|
||||
|
||||
this.update = function()
|
||||
{
|
||||
var s = "";
|
||||
|
||||
for (var key in ronin.modules){
|
||||
s += ronin.modules[key].widget() ? "<div class='module'>"+ronin.modules[key].widget()+"</div>" : "";
|
||||
}
|
||||
|
||||
s += "<div class='cursor'>"+ronin.cursor.mode.widget_cursor()+"</div>";
|
||||
|
||||
this.element.innerHTML = s;
|
||||
}
|
||||
|
||||
this.on_resize = function()
|
||||
{
|
||||
this.element.style.left = (window.innerWidth/2)-(ronin.surface.size.width/2);
|
||||
this.element.style.top = (window.innerHeight/2)+(ronin.surface.size.height/2);
|
||||
this.element.style.width = ronin.surface.size.width+"px";
|
||||
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user