Commit bf1c4cc3 authored by Aayush's avatar Aayush

final UI working fine for pd->diagram to ascii_art

parent 0cdd32db
Pipeline #1667 canceled with stage
...@@ -4,6 +4,7 @@ var gui = require("nw.gui"); ...@@ -4,6 +4,7 @@ var gui = require("nw.gui");
var pdgui = require("./pdgui.js"); var pdgui = require("./pdgui.js");
var pd_menus = require("./pd_menus.js"); var pd_menus = require("./pd_menus.js");
var pd_ascii_art = require("./pd_ascii_art.js"); var pd_ascii_art = require("./pd_ascii_art.js");
var pd_message_parser = require("./pd_message_parser.js");
// Apply gui preset to this canvas // Apply gui preset to this canvas
pdgui.skin.apply(window); pdgui.skin.apply(window);
...@@ -800,6 +801,12 @@ var canvas_events = (function() { ...@@ -800,6 +801,12 @@ var canvas_events = (function() {
document.getElementById("ascii_art_text_area").addEventListener("input", events.check_ascii_art_state); document.getElementById("ascii_art_text_area").addEventListener("input", events.check_ascii_art_state);
state = "ascii_art"; state = "ascii_art";
}, },
create_ascii_art: function(pd_message) {
canvas_events.none();
var selected_ascii_art = pd_message_parser.parse_pd_message(pd_message);
document.getElementById("ascii_art_text_area").value = selected_ascii_art;
canvas_events[canvas_events.get_previous_state()]();
},
register: function(n) { register: function(n) {
name = n; name = n;
}, },
......
//Example message
"use strict"; "use strict";
var pd_message = "#X obj 36 60 inlet;\n#X obj 36 416 outlet;\n#X obj 68 387 send;\n#X obj 93 282 loadbang;\n#X msg 93 308 dollarzero;\n#X obj 93 334 canvasinfo 1;\n#X msg 93 359 symbol \$1-result;\n#X connect 0 0 5 0;\n#X connect 1 0 4 0;\n#X connect 3 0 2 0;\n#X connect 4 0 3 0;\n#X connect 4 1 0 0;"
var x=parse_pd_message(pd_message);
alert(x);
document.getElementById("demo").innerHTML = x;
function makeArray(w, h, val) { function makeArray(w, h, val) {
var arr = []; var arr = [];
for(let i = 0; i < h; i++) { for(let i = 0; i < h; i++) {
arr[i] = []; arr[i] = [];
for(let j = 0; j < w-1; j++) { for(let j = 0; j < w; j++) {
arr[i][j] = val; arr[i][j] = val;
} }
arr[i][h-1]="\n<br>";
} }
return arr; return arr;
} }
...@@ -61,13 +54,16 @@ function parse_pd_message(message) { ...@@ -61,13 +54,16 @@ function parse_pd_message(message) {
counter = 0, counter = 0,
str_count = 0, str_count = 0,
object_msg_index_info = {}, object_msg_index_info = {},
matrix = makeArray(100,100,' '); min_x=Infinity,
min_y=Infinity,
max_x=0,
max_y=0,
matrix;
message.replace("\n" ,"");
lines = message.split(";");
lines = message.split(";");
for ( i = 0 ; i<lines.length-1 ; i++ ) { for ( i = 0 ; i<lines.length-1 ; i++ ) {
lines[i].replace(";\n",""); lines[i].replace(";","");
splitted_str = lines[i].split(" "); splitted_str = lines[i].split(" ");
if ( splitted_str[1] == "connect") { if ( splitted_str[1] == "connect") {
...@@ -78,8 +74,8 @@ function parse_pd_message(message) { ...@@ -78,8 +74,8 @@ function parse_pd_message(message) {
} else { } else {
temp_str = splitted_str.slice(4,splitted_str.length); temp_str = splitted_str.slice(4,splitted_str.length);
obj_msg_info.push({type : splitted_str[1], obj_msg_info.push({type : splitted_str[1],
x : splitted_str[2], x : splitted_str[3],
y : splitted_str[3], y : splitted_str[2],
obj_no : count, obj_no : count,
text : temp_str, text : temp_str,
cell_start_x : 0, cell_start_x : 0,
...@@ -87,17 +83,31 @@ function parse_pd_message(message) { ...@@ -87,17 +83,31 @@ function parse_pd_message(message) {
cell_end_x : 0, cell_end_x : 0,
cell_end_y : 0}); cell_end_y : 0});
count = count+1; count = count+1;
if (min_y > splitted_str[2]) {
min_y = splitted_str[2];
}
if (min_x > splitted_str[3]) {
min_x = splitted_str[3];
}
if (max_y < splitted_str[2]) {
max_y = splitted_str[2];
}
if (max_x < splitted_str[3]) {
max_x = splitted_str[3];
}
} }
} }
matrix = makeArray(max_x/20 + 5,max_y/20 + 5,'*');
obj_msg_info.sort(compare); obj_msg_info.sort(compare);
i=0; i=0;
j=0; j=0;
counter=0; counter=0;
while( counter < obj_msg_info.length ) { while( counter < obj_msg_info.length ) {
if(counter == 0) { obj_msg_info[counter].cell_start_x = Math.floor((obj_msg_info[counter].x - min_x)/20);
obj_msg_info[counter].cell_start_x = i; obj_msg_info[counter].cell_start_y = Math.floor((obj_msg_info[counter].y - min_y)/20);
obj_msg_info[counter].cell_start_y = j; i = obj_msg_info[counter].cell_start_x;
j = obj_msg_info[counter].cell_start_y;
matrix[i][j] = "["; matrix[i][j] = "[";
j++; j++;
str_count=0; str_count=0;
...@@ -114,57 +124,8 @@ function parse_pd_message(message) { ...@@ -114,57 +124,8 @@ function parse_pd_message(message) {
obj_msg_info[counter].cell_end_y = j; obj_msg_info[counter].cell_end_y = j;
counter+=1; counter+=1;
} }
else {
if (obj_msg_info[counter].x == obj_msg_info[counter-1].x) {
j += 5;
j += (obj_msg_info[counter].y - obj_msg_info[counter-1].y)/50;
j = Math.floor(j);
obj_msg_info[counter].cell_start_x = i;
obj_msg_info[counter].cell_start_y = j;
matrix[i][j] = "[";
j++;
str_count=0;
for ( l = j ; l < j + obj_msg_info[counter].text[0].length ; l++ ) {
matrix[i][l] = obj_msg_info[counter].text[0][str_count];
str_count++;
}
j=l;
if (obj_msg_info[counter].type == "obj")
matrix[i][j]="]";
else
matrix[i][j]="(";
obj_msg_info[counter].cell_end_x = i;
obj_msg_info[counter].cell_end_y = j;
}
else {
i += 3;
i += (obj_msg_info[counter].x - obj_msg_info[counter-1].x)/10;
i = Math.floor(i);
j = ( obj_msg_info[counter].y)/50;
j = Math.floor(j);
obj_msg_info[counter].cell_start_x = i;
obj_msg_info[counter].cell_start_y = j;
matrix[i][j] = "[";
j++;
str_count=0;
for ( l = j ; l < j + obj_msg_info[counter].text[0].length ; l++ ) {
matrix[i][l] = obj_msg_info[counter].text[0][str_count];
str_count++;
}
j=l;
if (obj_msg_info[counter].type == "obj")
matrix[i][j]="]";
else
matrix[i][j]="(";
obj_msg_info[counter].cell_end_x = i;
obj_msg_info[counter].cell_end_y = j;
}
counter+=1;
}
}
for ( i = 0 ; i < obj_msg_info.length ; i++ ) { for ( i = 0 ; i < obj_msg_info.length ; i++ ) {
//alert([obj_msg_info[i].obj_no,obj_msg_info[i].cell_start_x,obj_msg_info[i].cell_start_y,obj_msg_info[i].cell_end_x,obj_msg_info[i].cell_end_y]);
object_msg_index_info[obj_msg_info[i].obj_no] = {cell_start_x:obj_msg_info[i].cell_start_x, object_msg_index_info[obj_msg_info[i].obj_no] = {cell_start_x:obj_msg_info[i].cell_start_x,
cell_start_y:obj_msg_info[i].cell_start_y, cell_start_y:obj_msg_info[i].cell_start_y,
cell_end_x:obj_msg_info[i].cell_end_x, cell_end_x:obj_msg_info[i].cell_end_x,
...@@ -197,5 +158,20 @@ function parse_pd_message(message) { ...@@ -197,5 +158,20 @@ function parse_pd_message(message) {
} }
} }
} }
return matrix; var ascii_art='';
for(i=0;i<matrix.length;i++){
for(j=0;j<matrix[i].length;j++) {
if (matrix[i][j] == "*"){
ascii_art = ascii_art + " ";
}
else {
ascii_art = ascii_art + matrix[i][j];
}
}
ascii_art = ascii_art + '\n';
}
return ascii_art;
} }
exports.parse_pd_message = parse_pd_message;
\ No newline at end of file
...@@ -1175,7 +1175,7 @@ function ascii_entry(cid,textarea_state,pd_message,pd_message_length) ...@@ -1175,7 +1175,7 @@ function ascii_entry(cid,textarea_state,pd_message,pd_message_length)
if (textarea_state) { if (textarea_state) {
//Just to check if we are getting the correct pd_message //Just to check if we are getting the correct pd_message
if(pd_message_length>0) { if(pd_message_length>0) {
ascii_art_text_area.value=pd_message; patchwin[cid].window.canvas_events.create_ascii_art(pd_message);
} }
ascii_art.style.setProperty("display", "inline"); ascii_art.style.setProperty("display", "inline");
ascii_art_text_area.focus(); ascii_art_text_area.focus();
......
...@@ -184,6 +184,8 @@ static void canvas_ascii_entry(t_canvas *x, t_floatarg textarea_state) ...@@ -184,6 +184,8 @@ static void canvas_ascii_entry(t_canvas *x, t_floatarg textarea_state)
state, state,
b_string, b_string,
b_length); b_length);
if (b)
binbuf_free(b);
} }
void canvas_getscroll (t_canvas *x) { void canvas_getscroll (t_canvas *x) {
//sys_vgui("pdtk_canvas_getscroll .x%lx.c\n",(long)x); //sys_vgui("pdtk_canvas_getscroll .x%lx.c\n",(long)x);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment