Commit a1410833 authored by nerrons's avatar nerrons
Browse files

Make hovering xlet tooltips work

parent 9205ac94
Pipeline #1630 failed with stage
in 0 seconds
......@@ -370,8 +370,8 @@ exports.get_k12_demo_dir = function () {
return path.join(lib_dir, "extra/K12/demos");
}
function build_k12_xlet_tt() {
k12_xlet_tt = {}; // after: { "ab1": { "i0": "content", "o0": "content", ...}, "ab2": ... }
var help_patch_files;
k12_xlet_tt = {}; // after: { "add": { "i0": "content", "o0": "content", ...}, "subtract": ... }
try {
help_patch_files = fs.readdirSync("extra/K12")
.filter(function (f) { return f.endsWith("-help.pd"); });
......@@ -385,17 +385,20 @@ function build_k12_xlet_tt() {
k12_xlet_tt[ab_name] = {};
f.split(" META 0;")[1].split(" pd META;")[0] // get content within pd META
.replace(/[\r\n\x0B\x0C\u0085\u2028\u2029]+/g, " ") // normalize the various linebreaks
.replace(/([^\\]);/g, '$1\u000B').split('\u000B') // split by ; but not \;
.replace(/([^\\]);/g, '$1\u000B').split('\u000B') // split to lines by ";" but not "\;"
.slice(0, -1) // remove the last line which is #X restore
// now each element starts with either INLET_, OUTLET_ or DESCRIPTION
// now each element is with either INLET_, OUTLET_ or DESCRIPTION
.map(function (l) {
// do parsing for each line in the extracted .pd content
var line = l.trim()
.replace(/#X text [0-9]+ [0-9]+ /g, "") // remove #X text <number> <number>
.replace(/\\,/g, ",").replace(/ ,/g, ","); // remove the escaping of commas
if (line.endsWith(".")) line = line.slice(0, -1);
if (line.endsWith(".")) line = line.slice(0, -1); // remove trailing periods
// generate tooltip content
if (line.startsWith("INLET_")) {
var parsed_line = line.match(/INLET_(\d+) (.*)/);
var xlet_no = Number(parsed_line[1]),
var parsed_line = line.match(/INLET_(\d+) (.*)/); // split into 2 groups
var xlet_no = Number(parsed_line[1]), // [0] is the whole match
tt_content = parsed_line[2];
k12_xlet_tt[ab_name]["i" + xlet_no] = tt_content;
} else if (line.startsWith("OUTLET_")) {
......@@ -410,13 +413,6 @@ function build_k12_xlet_tt() {
post("err: " + err);
}
});
// Object.keys(k12_xlet_tt).forEach(function (ab) {
// post("----- " + ab);
// Object.keys(k12_xlet_tt[ab]).forEach(function (xlet) {
// post(xlet + ": " + k12_xlet_tt[ab][xlet]);
// });
// });
// post("#####################");
}
popup_coords = [0,0];
......@@ -2180,17 +2176,24 @@ exports.gui = gui;
// In the future, it might make sense to combine the scalar and object
// creation, in which case a flag to toggle the offset would be appropriate.
function gui_gobj_new(cid, tag, type, xpos, ypos, is_toplevel) {
function gui_gobj_new(cid, tag, type, xpos, ypos, is_toplevel, text) {
var g;
xpos += 0.5,
ypos += 0.5,
xpos += 0.5;
ypos += 0.5;
gui(cid).get_elem("patchsvg", function(svg_elem) {
var transform_string = "matrix(1,0,0,1," + xpos + "," + ypos + ")";
g = create_item(cid, "g", {
var transform_string = "matrix(1,0,0,1," + xpos + "," + ypos + ")",
create_item_params = {
id: tag + "gobj",
transform: transform_string,
class: type + (is_toplevel !== 0 ? "" : " gop")
});
};
if (k12_mode === 1 && text && type === "graph") {
var tt_id = text.match(/K12[\/]([A-Za-z0-9_]+)/);
if (tt_id && tt_id.length > 1) {
create_item_params.ttid = tt_id[1];
}
}
g = create_item(cid, "g", create_item_params);
add_gobj_to_svg(svg_elem, g);
});
return g;
......@@ -2296,27 +2299,24 @@ function gui_gobj_configure_io(cid, tag, is_iemgui, is_signal, width) {
});
}
function gui_gobj_highlight_io(cid, tag) {
gui(cid).get_elem(tag, function(e) {
e.classList.add("xlet_selected");
if (k12_mode === 1) {
if (e.classList.contains("xlet_tti") || e.classList.contains("xlet_tto")) {
gui(cid).get_elem("xlet_tt", function(tt) {
var e_rect = e.getBoundingClientRect(),
e_x = e_rect.left,
e_y = e_rect.top;
tt.innerHTML = "placeholder tt";
tt.style.display = "block";
tt.style.left = e_x + 10 + "px";
if (e.classList.contains("xlet_tti")) {
tt.style.top = e_y + 3 + "px";
} else {
tt.style.top = e_y - 10 + "px";
}
});
}
if (k12_mode === 1
&& (e.classList.contains("xlet_tti") || e.classList.contains("xlet_tto"))) {
gui(cid).get_elem("xlet_tt", function(tt) {
var e_rect = e.getBoundingClientRect(),
e_x = e_rect.left,
e_y = e_rect.top;
tt.innerHTML = k12_xlet_tt[e.parentNode.getAttribute("ttid")][tag.slice(-2)];
tt.style.display = "block";
tt.style.left = e_x + 10 + "px";
if (e.classList.contains("xlet_tti")) {
tt.style.top = e_y + 3 + "px";
} else {
tt.style.top = e_y - 10 + "px";
}
});
}
});
}
......
......@@ -900,11 +900,14 @@ static void graph_vis(t_gobj *gr, t_glist *parent_glist, int vis)
if (vis & gobj_shouldvis(gr, parent_glist))
{
int xpix, ypix;
char *textbuf;
int textbufsize;
rtext_gettext(glist_findrtext(parent_glist, &x->gl_obj), &textbuf, &textbufsize);
xpix = text_xpix(&x->gl_obj, parent_glist);
ypix = text_ypix(&x->gl_obj, parent_glist);
gui_vmess("gui_gobj_new", "xssiii",
gui_vmess("gui_gobj_new", "xssiiis",
glist_getcanvas(x->gl_owner),
tag, "graph", xpix, ypix, 1);
tag, "graph", xpix, ypix, 1, textbuf);
if (canvas_showtext(x))
rtext_draw(glist_findrtext(parent_glist, &x->gl_obj));
}
......
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