Commit 80fe5356 authored by Jonathan Wilkes's avatar Jonathan Wilkes

fix #312: GOP freezes from Pd messages to non-existant canvases

parent a7cf3b70
...@@ -1427,10 +1427,13 @@ function canvas_map(name) { ...@@ -1427,10 +1427,13 @@ function canvas_map(name) {
} }
function gui_canvas_erase_all_gobjs(cid) { function gui_canvas_erase_all_gobjs(cid) {
var svg_elem = get_item(cid, "patchsvg"), var svg_elem,
elem; elem;
while (elem = svg_elem.firstChild) { if (patchwin[cid]) {
svg_elem.removeChild(elem); svg_elem = get_item(cid, "patchsvg");
while (elem = svg_elem.firstChild) {
svg_elem.removeChild(elem);
}
} }
} }
...@@ -1807,43 +1810,53 @@ function add_gobj_to_svg(svg, gobj) { ...@@ -1807,43 +1810,53 @@ function add_gobj_to_svg(svg, gobj) {
// creation, in which case a flag to toggle the offset would be appropriate. // 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) {
var svg = get_item(cid, "patchsvg"), // id for the svg element var svg,
g, g,
transform_string; transform_string;
xpos += 0.5; if (patchwin[cid]) {
ypos += 0.5; svg = get_item(cid, "patchsvg"), // id for the svg element
transform_string = "matrix(1,0,0,1," + xpos + "," + ypos + ")", xpos += 0.5;
g = create_item(cid, "g", { ypos += 0.5;
transform_string = "matrix(1,0,0,1," + xpos + "," + ypos + ")",
g = create_item(cid, "g", {
id: tag + "gobj", id: tag + "gobj",
transform: transform_string, transform: transform_string,
class: type + (is_toplevel !== 0 ? "" : " gop") class: type + (is_toplevel !== 0 ? "" : " gop")
}); });
add_gobj_to_svg(svg, g); add_gobj_to_svg(svg, g);
// hm... why returning g and not the return value of appendChild? // hm... why returning g and not the return value of appendChild?
return g; return g;
}
} }
function gui_text_draw_border(cid, tag, bgcolor, isbroken, x1, y1, x2, y2) { function gui_text_draw_border(cid, tag, bgcolor, isbroken, x1, y1, x2, y2) {
var g = get_gobj(cid, tag), var g,
rect; rect;
// isbroken means either if (patchwin[cid]) {
// a) the object couldn't create or g = get_gobj(cid, tag),
// b) the box is empty // isbroken means either
rect = create_item(cid, "rect", { // a) the object couldn't create or
width: x2 - x1, // b) the box is empty
height: y2 - y1, rect = create_item(cid, "rect", {
//"shape-rendering": "crispEdges", width: x2 - x1,
class: "border" height: y2 - y1,
}); //"shape-rendering": "crispEdges",
if (isbroken === 1) { class: "border"
rect.classList.add("broken_border"); });
if (isbroken === 1) {
rect.classList.add("broken_border");
}
g.appendChild(rect);
} }
g.appendChild(rect);
} }
function gui_gobj_draw_io(cid, parenttag, tag, x1, y1, x2, y2, basex, basey, function gui_gobj_draw_io(cid, parenttag, tag, x1, y1, x2, y2, basex, basey,
type, i, is_signal, is_iemgui) { type, i, is_signal, is_iemgui) {
var xlet_class, xlet_id, rect, g = get_gobj(cid, parenttag); var xlet_class, xlet_id, rect, g;
if (!patchwin[cid]) {
return;
}
g = get_gobj(cid, parenttag);
if (is_iemgui) { if (is_iemgui) {
xlet_class = "xlet_iemgui"; xlet_class = "xlet_iemgui";
// We have an inconsistency here. We're setting the tag using // We have an inconsistency here. We're setting the tag using
...@@ -1933,8 +1946,12 @@ function message_border_points(width, height) { ...@@ -1933,8 +1946,12 @@ function message_border_points(width, height) {
} }
function gui_message_draw_border(cid, tag, width, height) { function gui_message_draw_border(cid, tag, width, height) {
var g = get_gobj(cid, tag), var g,
polygon; polygon;
if (!patchwin[cid]) {
return;
}
g = get_gobj(cid, tag);
polygon = create_item(cid, "polygon", { polygon = create_item(cid, "polygon", {
points: message_border_points(width, height), points: message_border_points(width, height),
fill: "none", fill: "none",
...@@ -2225,8 +2242,12 @@ function gobj_font_y_kludge(fontsize) { ...@@ -2225,8 +2242,12 @@ function gobj_font_y_kludge(fontsize) {
function gui_text_new(canvasname, myname, type, isselected, left_margin, font_height, text, font) { function gui_text_new(canvasname, myname, type, isselected, left_margin, font_height, text, font) {
var lines, i, len, tspan, var lines, i, len, tspan,
g = get_gobj(canvasname, myname), g,
svg_text; svg_text;
if (!patchwin[canvasname]) {
return;
}
g = get_gobj(canvasname, myname),
svg_text = create_item(canvasname, "text", { svg_text = create_item(canvasname, "text", {
// Maybe it's just me, but the svg spec's explanation of how // Maybe it's just me, but the svg spec's explanation of how
// text x/y and tspan x/y interact is difficult to understand. // text x/y and tspan x/y interact is difficult to understand.
...@@ -2444,8 +2465,12 @@ function gui_canvas_hide_selection(cid) { ...@@ -2444,8 +2465,12 @@ function gui_canvas_hide_selection(cid) {
// iemguis // iemguis
function gui_bng_new(cid, tag, cx, cy, radius) { function gui_bng_new(cid, tag, cx, cy, radius) {
var g = get_gobj(cid, tag), var g, circle;
circle = create_item(cid, "circle", { if (!patchwin[cid]) {
return;
}
g = get_gobj(cid, tag);
circle = create_item(cid, "circle", {
cx: cx, cx: cx,
cy: cy, cy: cy,
r: radius, r: radius,
...@@ -2479,9 +2504,13 @@ function gui_bng_configure(cid, tag, color, cx, cy, r) { ...@@ -2479,9 +2504,13 @@ function gui_bng_configure(cid, tag, color, cx, cy, r) {
} }
function gui_toggle_new(cid, tag, color, width, state, p1,p2,p3,p4,p5,p6,p7,p8,basex,basey) { function gui_toggle_new(cid, tag, color, width, state, p1,p2,p3,p4,p5,p6,p7,p8,basex,basey) {
var g = get_gobj(cid, tag), var g,
points_array, points_array,
cross1, cross2; cross1, cross2;
if (!patchwin[cid]) {
return;
}
g = get_gobj(cid, tag);
points_array = [p1 - basex, p2 - basey, points_array = [p1 - basex, p2 - basey,
p3 - basex, p4 - basey p3 - basex, p4 - basey
]; ];
...@@ -2569,9 +2598,13 @@ function numbox_data_string(w, h) { ...@@ -2569,9 +2598,13 @@ function numbox_data_string(w, h) {
function gui_numbox_new(cid, tag, color, x, y, w, h, is_toplevel) { function gui_numbox_new(cid, tag, color, x, y, w, h, is_toplevel) {
// numbox doesn't have a standard iemgui border, // numbox doesn't have a standard iemgui border,
// so we must create its gobj manually // so we must create its gobj manually
var g = gui_gobj_new(cid, tag, "iemgui", x, y, is_toplevel), var g,
data, data,
border; border;
if (!patchwin[cid]) {
return;
}
g = gui_gobj_new(cid, tag, "iemgui", x, y, is_toplevel);
data = numbox_data_string(w, h); data = numbox_data_string(w, h);
border = create_item(cid, "path", { border = create_item(cid, "path", {
d: data, d: data,
...@@ -2628,8 +2661,12 @@ function gui_numbox_update_text_position(cid, tag, x, y) { ...@@ -2628,8 +2661,12 @@ function gui_numbox_update_text_position(cid, tag, x, y) {
} }
function gui_slider_new(cid, tag, color, p1, p2, p3, p4, basex, basey) { function gui_slider_new(cid, tag, color, p1, p2, p3, p4, basex, basey) {
var g = get_gobj(cid, tag), var g,
indicator; indicator;
if (!patchwin[cid]) {
return;
}
g = get_gobj(cid, tag);
indicator = create_item(cid, "line", { indicator = create_item(cid, "line", {
x1: p1 - basex, x1: p1 - basex,
y1: p2 - basey, y1: p2 - basey,
...@@ -2667,8 +2704,12 @@ function gui_slider_indicator_color(cid, tag, color) { ...@@ -2667,8 +2704,12 @@ function gui_slider_indicator_color(cid, tag, color) {
} }
function gui_radio_new(cid, tag, p1, p2, p3, p4, i, basex, basey) { function gui_radio_new(cid, tag, p1, p2, p3, p4, i, basex, basey) {
var g = get_gobj(cid, tag), var g,
cell; cell;
if (!patchwin[cid]) {
return;
}
g = get_gobj(cid, tag);
cell = create_item(cid, "line", { cell = create_item(cid, "line", {
x1: p1 - basex, x1: p1 - basex,
y1: p2 - basey, y1: p2 - basey,
...@@ -2881,8 +2922,12 @@ function gui_vumeter_update_peak(cid,tag,color,p1,p2,p3,p4,basex,basey) { ...@@ -2881,8 +2922,12 @@ function gui_vumeter_update_peak(cid,tag,color,p1,p2,p3,p4,basex,basey) {
} }
function gui_iemgui_base_color(cid, tag, color) { function gui_iemgui_base_color(cid, tag, color) {
var g = get_gobj(cid, tag), var g,
b; b;
if (!patchwin[cid]) {
return;
}
g = get_gobj(cid, tag);
if (g) { if (g) {
b = g.querySelector(".border"); b = g.querySelector(".border");
configure_item(b, { fill: color }); configure_item(b, { fill: color });
...@@ -2942,8 +2987,12 @@ function iemgui_fontfamily(name) { ...@@ -2942,8 +2987,12 @@ function iemgui_fontfamily(name) {
function gui_iemgui_label_new(cid, tag, x, y, color, text, fontname, fontweight, function gui_iemgui_label_new(cid, tag, x, y, color, text, fontname, fontweight,
fontsize) { fontsize) {
var g = get_gobj(cid, tag), var g,
svg_text, text_node; svg_text, text_node;
if (!patchwin[cid]) {
return;
}
g = get_gobj(cid, tag);
svg_text = create_item(cid, "text", { svg_text = create_item(cid, "text", {
// x and y need to be relative to baseline instead of nw anchor // x and y need to be relative to baseline instead of nw anchor
x: x, x: x,
...@@ -3027,8 +3076,12 @@ function gui_iemgui_label_font(cid, tag, fontname, fontweight, fontsize) { ...@@ -3027,8 +3076,12 @@ function gui_iemgui_label_font(cid, tag, fontname, fontweight, fontsize) {
// Show or hide little handle for dragging around iemgui labels // Show or hide little handle for dragging around iemgui labels
function gui_iemgui_label_show_drag_handle(cid, tag, state, x, y, cnv_resize) { function gui_iemgui_label_show_drag_handle(cid, tag, state, x, y, cnv_resize) {
var gobj = get_gobj(cid, tag), var gobj,
rect; rect;
if (!patchwin[cid]) {
return;
}
gobj = get_gobj(cid, tag);
if (state !== 0) { if (state !== 0) {
// Here we use a "line" shape so that we can control its color // Here we use a "line" shape so that we can control its color
// using the "border" class (for iemguis) or the "gop_rect" class // using the "border" class (for iemguis) or the "gop_rect" class
...@@ -3066,6 +3119,9 @@ function gui_iemgui_label_show_drag_handle(cid, tag, state, x, y, cnv_resize) { ...@@ -3066,6 +3119,9 @@ function gui_iemgui_label_show_drag_handle(cid, tag, state, x, y, cnv_resize) {
function gui_mycanvas_new(cid,tag,color,x1,y1,x2_vis,y2_vis,x2,y2) { function gui_mycanvas_new(cid,tag,color,x1,y1,x2_vis,y2_vis,x2,y2) {
var rect_vis, rect, g; var rect_vis, rect, g;
if (!patchwin[cid]) {
return;
}
rect_vis = create_item(cid, "rect", { rect_vis = create_item(cid, "rect", {
width: x2_vis - x1, width: x2_vis - x1,
height: y2_vis - y1, height: y2_vis - y1,
...@@ -3123,11 +3179,11 @@ function gui_scalar_new(cid, tag, isselected, t1, t2, t3, t4, t5, t6, ...@@ -3123,11 +3179,11 @@ function gui_scalar_new(cid, tag, isselected, t1, t2, t3, t4, t5, t6,
is_toplevel) { is_toplevel) {
// we should probably use gui_gobj_new here, but we"re doing some initial // we should probably use gui_gobj_new here, but we"re doing some initial
// scaling that normal gobjs don't need... // scaling that normal gobjs don't need...
var svg = get_item(cid, "patchsvg"), // id for the svg in the DOM var svg, matrix, transform_string, g, selection_rect;
matrix, if (!patchwin[cid]) {
transform_string, return;
g, }
selection_rect; svg = get_item(cid, "patchsvg"), // id for the svg in the DOM
matrix = [t1,t2,t3,t4,t5,t6]; matrix = [t1,t2,t3,t4,t5,t6];
transform_string = "matrix(" + matrix.join() + ")"; transform_string = "matrix(" + matrix.join() + ")";
g = create_item(cid, "g", { g = create_item(cid, "g", {
...@@ -3192,8 +3248,12 @@ function gui_scalar_draw_select_rect(cid, tag, state, x1, y1, x2, y2, basex, bas ...@@ -3192,8 +3248,12 @@ function gui_scalar_draw_select_rect(cid, tag, state, x1, y1, x2, y2, basex, bas
} }
function gui_scalar_draw_group(cid, tag, parent_tag, attr_array) { function gui_scalar_draw_group(cid, tag, parent_tag, attr_array) {
var parent_elem = get_item(cid, parent_tag), var parent_elem,
g; g;
if (!patchwin[cid]) {
return;
}
parent_elem = get_item(cid, parent_tag);
if (attr_array === undefined) { if (attr_array === undefined) {
attr_array = []; attr_array = [];
} }
...@@ -3314,8 +3374,12 @@ function gui_draw_configure_all(cid, tag, attr_array) { ...@@ -3314,8 +3374,12 @@ function gui_draw_configure_all(cid, tag, attr_array) {
// Plots for arrays and data structures // Plots for arrays and data structures
function gui_plot_vis(cid, basex, basey, data_array, attr_array, tag_array) { function gui_plot_vis(cid, basex, basey, data_array, attr_array, tag_array) {
var g = get_item(cid, tag_array[0]), var g,
p; p;
if (!patchwin[cid]) {
return;
}
g = get_item(cid, tag_array[0]),
p = create_item(cid, "path", { p = create_item(cid, "path", {
d: data_array.join(" "), d: data_array.join(" "),
id: tag_array[1], id: tag_array[1],
...@@ -3430,6 +3494,9 @@ function gui_drawimage_new(obj_tag, file_path, canvasdir, flags) { ...@@ -3430,6 +3494,9 @@ function gui_drawimage_new(obj_tag, file_path, canvasdir, flags) {
files, files,
ext, ext,
img; // dummy image to measure width and height img; // dummy image to measure width and height
if (!patchwin[cid]) {
return;
}
image_seq = flags & drawsprite; image_seq = flags & drawsprite;
if (!path.isAbsolute(file_path)) { if (!path.isAbsolute(file_path)) {
file_path = path.join(canvasdir, file_path); file_path = path.join(canvasdir, file_path);
...@@ -4235,9 +4302,14 @@ function gui_graph_tick_label(cid, tag, x, y, text, font, font_size, font_weight ...@@ -4235,9 +4302,14 @@ function gui_graph_tick_label(cid, tag, x, y, text, font, font_size, font_weight
} }
function gui_canvas_drawredrect(cid, x1, y1, x2, y2) { function gui_canvas_drawredrect(cid, x1, y1, x2, y2) {
var svgelem = get_item(cid, "patchsvg"), var svgelem,
g = gui_gobj_new(cid, cid, "gop_rect", x1, y1, 1), g,
r; r;
if (!patchwin[cid]) {
return;
}
svgelem = get_item(cid, "patchsvg");
g = gui_gobj_new(cid, cid, "gop_rect", x1, y1, 1);
r = create_item(cid, "rect", { r = create_item(cid, "rect", {
width: x2 - x1, width: x2 - x1,
height: y2 - y1, height: y2 - y1,
......
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