Saving RIN file

This commit is contained in:
Devine Lu Linvega
2017-03-11 15:00:52 -07:00
parent 52a044b78e
commit 4040964505
14 changed files with 103 additions and 269 deletions

View File

@@ -17,29 +17,48 @@ function Eye(rune)
return "Eye";
}
this.color_picker = function(position)
// TODO: If a rect is given, return the average color
this.color_picker = function(position,rect = null)
{
var imgData = ronin.surface.context().getImageData(position.x, position.y, 1, 1).data;
var imgData = ronin.surface.context().getImageData(position.x*2, position.y*2, 1, 1).data;
var c = new Color();
commander.show();
commander.element_input.focus();
commander.element_input.value = "> "+(c.rgb_to_hex(imgData));
ronin.terminal.input_element.value = "* "+(c.rgb_to_hex(imgData));
ronin.terminal.update_hint();
}
// Cursor
this.live_draw_from = null;
this.mouse_down = function(position)
{
this.click = true;
this.live_draw_from = position;
ronin.overlay.draw(position);
this.color_picker(position);
}
this.mouse_move = function(position)
{
this.color_picker(position);
if(!this.click){ return; }
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(this.live_draw_from,rect);
this.color_picker(position,rect);
}
this.mouse_up = function(position)
{
this.color_picker(position);
this.click = null;
var rect = new Rect();
rect.width = position.x - this.live_draw_from.x;
rect.height = position.y - this.live_draw_from.y;
this.color_picker(position,rect);
}
}

View File

@@ -3,7 +3,7 @@ function FileSave(rune)
Module.call(this,rune);
this.parameters = [];
this.variables = {"format" : "[png/jpg/svg]"};
this.variables = {"format" : "[png/jpg/svg/rin]"};
this.docs = "Creates a new window with a image of the resulting canvas in the specified format.";
@@ -21,6 +21,12 @@ function FileSave(rune)
else if(cmd.variable("format") && cmd.variable("format").value == "jpg"){
w.document.write("<title>Untitled</title><body><img src='"+this.merge().element.toDataURL('image/jpeg')+"' width='"+ronin.surface.size.width+"px' height='"+ronin.surface.size.height+"px'/></body>");
}
else if(cmd.variable("format") && cmd.variable("format").value == "rin"){
var w = window.open('about:blank','source');
var html = "";
for (i = 0; i < ronin.terminal.history.length; i++) { html += ronin.terminal.history[i]+";<br />"; }
w.document.write("<title>Source</title><pre>"+html+"</pre>");
}
else{
w.document.write("<title>Untitled</title><body><img src='"+this.merge().element.toDataURL('image/png')+"' width='"+ronin.surface.size.width+"px' height='"+ronin.surface.size.height+"px'/></body>");
}

View File

@@ -1,30 +0,0 @@
function History(rune)
{
Module.call(this,rune);
this.cmds = [];
this.active = function(cmd)
{
var w = window.open('about:blank','source');
var html = "";
for (i = 0; i < this.cmds.length; i++) {
if(this.cmds[i][0] == this.rune){ continue; }
html += this.cmds[i]+";<br />";
}
w.document.write("<title>Source</title><style>body { font-family:courier}</style>"+html+"");
}
this.add = function(content)
{
this.cmds.push(content);
}
this.widget = function()
{
if(this.cmds.length === 0){ return "";}
return "^ "+this.cmds.length+" ";
}
}

View File

@@ -102,4 +102,22 @@ function Module(rune)
this.key_delete = function()
{
}
this.key_arrow_up = function()
{
ronin.surface.layer_up();
}
this.key_arrow_down = function()
{
ronin.surface.layer_down();
}
this.key_arrow_left = function()
{
}
this.key_arrow_right = function()
{
}
}

View File

@@ -62,10 +62,14 @@ function Overlay(rune)
{
this.context().beginPath();
this.context().moveTo(position.x,position.y);
this.context().lineTo(position.x + 10,position.y);
this.context().lineTo(position.x,position.y + 10);
this.context().lineTo(position.x,position.y);
this.context().moveTo(position.x + 2,position.y);
this.context().lineTo(position.x + 5,position.y);
this.context().moveTo(position.x,position.y + 2);
this.context().lineTo(position.x,position.y + 5);
this.context().moveTo(position.x - 2,position.y);
this.context().lineTo(position.x - 5,position.y);
this.context().moveTo(position.x,position.y - 2);
this.context().lineTo(position.x,position.y - 5);
this.context().lineCap="round";
this.context().lineWidth = 1;

View File

@@ -1,62 +0,0 @@
function Stroke(rune)
{
Module.call(this,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(mode)
{
// TODO
// s = "_ module="+mode+" ";
// 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;
}
// Module
this.passive = function(cmd)
{
}
this.active = function(cmd)
{
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.surface.context().beginPath();
ronin.surface.context().moveTo(pos1.x,pos1.y);
ronin.surface.context().lineTo(pos2.x,pos2.y);
ronin.surface.context().lineCap="round";
ronin.surface.context().lineWidth = 10;
ronin.surface.context().strokeStyle = ronin.brush.color.rgba();
ronin.surface.context().stroke();
ronin.surface.context().closePath();
}
}

View File

@@ -6,6 +6,9 @@ function Terminal(rune)
this.input_element = document.createElement("input");
this.hint_element = document.createElement("hint");
this.logs_element = document.createElement("logs");
this.menu_element = document.createElement("menu");
this.history = [];
// Module
this.install = function(cmd)
@@ -13,6 +16,7 @@ function Terminal(rune)
this.element.appendChild(this.input_element);
this.element.appendChild(this.hint_element);
this.element.appendChild(this.logs_element);
this.element.appendChild(this.menu_element);
this.hint_element.innerHTML = "_";
@@ -26,7 +30,7 @@ function Terminal(rune)
this.passive = function(content)
{
var key = content[0];
var cmd = new Command(content.substring(1).trim().split(" "));
var cmd = this.cmd();
ronin.module = null;
this.hint_element.innerHTML = "";
@@ -85,7 +89,9 @@ function Terminal(rune)
if(ronin.modules[key]){
ronin.modules[key].active(cmd);
ronin.history.add(content);
ronin.terminal.history.push(content);
ronin.terminal.history_index = ronin.terminal.history.length-1;
ronin.terminal.update_menu();
}
else{
ronin.terminal.log(new Log(ronin.terminal,"Unknown module: "+key));
@@ -134,7 +140,10 @@ function Terminal(rune)
}
}
else{
var h = padding+" ";
var h = "";
for(module in ronin.modules){
h += module+" ";
}
}
this.hint_element.innerHTML = h;
@@ -142,11 +151,33 @@ function Terminal(rune)
ronin.terminal.input_element.setAttribute("style","color:"+ronin.brush.color.hex);
}
this.update_menu = function()
{
this.menu_element.innerHTML = ronin.terminal.history.length;
}
this.key_escape = function()
{
this.input_element.value = "";
}
this.key_arrow_up = function()
{
this.history_index -= 1;
if(this.history_index < 0){ this.history_index = 0; }
ronin.terminal.input_element.value = "> "+ronin.terminal.history[this.history_index];
}
this.key_arrow_down = function()
{
this.history_index += 1;
if(this.history_index >= this.history.length){ this.history_index = this.history.length-1; }
ronin.terminal.input_element.value = "> "+ronin.terminal.history[this.history_index];
}
}
// Log