diff --git a/pd/nw/css/default.css b/pd/nw/css/default.css index 5abd5f15e8170544e966dc688e68a73c4c922c38..b58290b90e7d76f6f8dc1d771f21e7c3182b807b 100644 --- a/pd/nw/css/default.css +++ b/pd/nw/css/default.css @@ -189,11 +189,11 @@ mark { mark.console_find_current.console_find_highlighted, mark.console_find_current { - background: yellow; + background: #e87216; } mark.console_find_highlighted { - background: red; + background: yellow; } #console_find { @@ -521,6 +521,18 @@ text { fill: gray !important; } +#console_find { + width: 100%; + height: 1em; + padding-top: 2px; + padding-left: 2px; + padding-bottom: 8px; + background: silver; + position: fixed; + bottom: 0; + left: 0; +} + #canvas_find { width: 100%; height: 1em; diff --git a/pd/nw/index.html b/pd/nw/index.html index 32da532bc10216281b13124ef8e17e571715f6b8..d96e25ef000800b9d94428955fe8ec156131db85 100644 --- a/pd/nw/index.html +++ b/pd/nw/index.html @@ -30,20 +30,19 @@ </div> </div> <div id="console_find" style="display:none;"> - <div> - <label><input type="text" - id="console_find_text" - name="console_find_text" - defaultValue="Search in Console" - style="width:10em;"/> - </label> - <label>Highlight All - <input type="checkbox" - id="console_find_highlight" - name="console_find_highlight" - onchange="console_find_highlight_all(this);"/> - </label> - </div> + <label><input type="text" + id="console_find_text" + name="console_find_text" + defaultValue="Search in Console" + style="width:10em"/> + </label> + <label style="margin-left: 7px; margin-right: -3px;">Highlight All + <input type="checkbox" + id="console_find_highlight" + name="console_find_highlight" + onchange="console_find_highlight_all(this);" + style="position: relative; top: 2px; margin-right: 5px;"/> + </label> </div> <script src="./console_search.js"></script> <script type="text/javascript" src="index.js"></script> diff --git a/pd/nw/index.js b/pd/nw/index.js index 8c777871fede74fd90718c7b19d7aaba3885f72c..2a168e27bd2de1456d4856a3b48e5de00388ebee 100644 --- a/pd/nw/index.js +++ b/pd/nw/index.js @@ -383,7 +383,7 @@ function nw_close_window(window) { // 0.46+ seems to be required for "null" to work. TODO: Bisect to get the // actual minimum required version for this. -var null_pos = pdgui.check_nwjs_version("0.46") ? "null" : "center"; +var null_pos = pdgui.check_nw_version("0.46") ? "null" : "center"; function nw_create_window(cid, type, width, height, xpos, ypos, attr_array) { // todo: make a separate way to format the title for OSX @@ -409,7 +409,20 @@ function nw_create_window(cid, type, width, height, xpos, ypos, attr_array) { pos = "center"; } else { pos = null_pos; + //pdgui.post("check_os=" + pdgui.check_os("win32")); + if (pdgui.nw_os_is_linux == 1) { + ypos = ypos - pdgui.nw_menu_offset - 3; + } } + + //pdgui.post("nw_create_window w=" + width + " h=" + height); + + // ico@vt.edu 2020-08-13: + // why does Windows have different innerWidth and innerHeight from other OSs? + // See pdgui.js' canvas_params for the explanation... + width -= 16 * pdgui.nw_os_is_windows; + height -= 8 * pdgui.nw_os_is_windows; + gui.Window.open(my_file, { title: my_title, // ico@vt.edu: position in 0.46.2 overrides x and y below @@ -421,7 +434,7 @@ function nw_create_window(cid, type, width, height, xpos, ypos, attr_array) { // altogether to simplify things. But we'd have to add some kind of // widget for the "Put" menu. // ico@vt.edu: on 0.46.2 this is now 25, go figure... - height: height + 25, + height: height + (pdgui.nw_menu_offset * !pdgui.nw_os_is_osx), x: xpos, y: ypos }, function (new_win) { @@ -597,7 +610,7 @@ function nw_create_pd_window_menus(gui, w) { if (state === "none") { text_container.style.setProperty("bottom", "1.6em"); find_bar.style.setProperty("display", "inline"); - find_bar.style.setProperty("height", "1.2em"); + //find_bar.style.setProperty("height", "1.2em"); // Don't do the following in logical time so that the // console_find keypress event won't receive this shortcut key window.setTimeout(function() { diff --git a/pd/nw/locales/en/translation.json b/pd/nw/locales/en/translation.json index e7a8510191e040baa874336b085caaf65711450b..2cabcff0acfd3082066a2193330adfde20a0a74b 100644 --- a/pd/nw/locales/en/translation.json +++ b/pd/nw/locales/en/translation.json @@ -270,7 +270,8 @@ }, "pd_window": { "find": { - "placeholder": "Search in Console" + "placeholder": "Search in Console", + "highlight": "Highlight All" } }, "canvas": { diff --git a/pd/nw/pd_canvas.html b/pd/nw/pd_canvas.html index cd95e36555fd8078a6025e9faf3d7648768262e2..27bdbd0ac1fe5cf2a5f90ed1b77f9995be23116e 100644 --- a/pd/nw/pd_canvas.html +++ b/pd/nw/pd_canvas.html @@ -78,8 +78,8 @@ </button> </div> </dialog> - <div id="hscroll" style="background-color: rgba(0, 0, 0, 0.267); position: fixed; left: 2px; bottom: 2px; border-radius: 0px; width: 10px; height: 5px; visibility: hidden;"></div> - <div id="vscroll" style="background-color: rgba(0, 0, 0, 0.267); position: fixed; right: 2px; top: 2px; border-radius: 0px; width: 5px; height: 10px; visibility: hidden;"></div> + <div id="hscroll" style="background-color: rgba(0, 0, 0, 0.267); position: fixed; left: 0px; bottom: 0px; border-radius: 0px; width: 10px; height: 5px; visibility: hidden;"></div> + <div id="vscroll" style="background-color: rgba(0, 0, 0, 0.267); position: fixed; right: 0px; top: 0px; border-radius: 0px; width: 5px; height: 10px; visibility: hidden;"></div> <script type="text/javascript" src="./pd_canvas.js"></script> </body> </html> diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index d172ee900234dc5778b1ac7590106589c139a152..4c0b269f706dac7a08e23f263049f0e144b05d39 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -795,7 +795,7 @@ function pd_geo_string(w, h, x, y) { // ico@vt.edu: we moved this from index.js, so that we can use the versioning // to also deal with weird offsets between nwjs 0.14/0.24 and 0.46 and upwards -function check_nwjs_version(version) { +function check_nw_version(version) { // aggraef: check that process.versions["nw"] is at least the given version // NOTE: We assume that "0.x.y" > "0.x", and just ignore any -beta // suffixes if present. @@ -813,9 +813,37 @@ function check_nwjs_version(version) { return vers_array.length <= nwjs_array.length; } -exports.check_nwjs_version = check_nwjs_version; +exports.check_nw_version = check_nw_version; -var menu_offset = check_nwjs_version("0.46") ? 25 : 23; +// ico@vt.edu 2020-08-12: check which OS we have since Windows has a different +// windows positioning logic on nw.js 0.14.7 than Linux/OSX. Go figure... +function check_os(name) { + + var os = require('os'); + //post("os=" + os.platform()); + return os.platform() === name ? 1 : 0; +} + +exports.check_os = check_os; + +// ico@vt.edu 2020-08-14: used to speed-up window size consistency and other +// OS-centric operations by avoiding constant calls to string comparisons. +// Most pertinent calls can be found in index.js' nw_create_window and pdgui.js' +// canvas_check_geometry +var nw_os_is_linux = check_os("linux"); +var nw_os_is_osx = check_os("darwin"); +var nw_os_is_windows = check_os("win32"); + +exports.nw_os_is_linux = nw_os_is_linux; +exports.nw_os_is_osx = nw_os_is_osx; +exports.nw_os_is_windows = nw_os_is_windows; + +// ico@vt.edu 2020-08-11: this appears to have to be 25 at all times +// we will leave this here for later if we encounter issues with inconsistencies +// across different nw.js versions... +var nw_menu_offset = check_nw_version("0.46") ? 25 : 25; + +exports.nw_menu_offset = nw_menu_offset; // quick hack so that we can paste pd code from clipboard and // have it affect an empty canvas' geometry @@ -823,8 +851,8 @@ var menu_offset = check_nwjs_version("0.46") ? 25 : 23; function gui_canvas_change_geometry(cid, w, h, x, y) { gui(cid).get_nw_window(function(nw_win) { nw_win.width = w; - // menu_offset is a kludge to account for menubar - nw_win.height = h + menu_offset; + // nw_menu_offset is a kludge to account for menubar + nw_win.height = h + nw_menu_offset; nw_win.x = x; nw_win.y = y; }); @@ -841,21 +869,31 @@ function canvas_check_geometry(cid) { // in nw_create_window of index.js // ico@vt.edu in 0.46.2 this is now 25 pixels, so I guess // it is now officially kludge^2 - win_h = patchwin[cid].height - menu_offset, + win_h = patchwin[cid].height - + (nw_menu_offset * !nw_os_is_osx), win_x = patchwin[cid].x, win_y = patchwin[cid].y, cnv_width = patchwin[cid].window.innerWidth, - cnv_height = patchwin[cid].window.innerHeight - menu_offset; + cnv_height = patchwin[cid].window.innerHeight; + //post("canvas_check_geometry w=" + win_w + " h=" + win_h + + // " x=" + win_x + " y=" + win_y + "cnv_w=" + cnw_width + " cnv_h=" + cnv_height); + + // ico@vt.edu 2020-08-31: + // why does Windows have different innerWidth and innerHeight from other OSs? + // See canvas_params for the explanation... + win_w += 16 * nw_os_is_windows; + win_h += 8 * nw_os_is_windows; + // We're reusing win_x and win_y below, as it // shouldn't make a difference to the bounds - // algorithm in Pd (ico@vt.edu: this is not true anymore) + // algorithm in Pd (ico@vt.edu: this is not true anymore for nw 0.46+) //post("relocate " + pd_geo_string(cnv_width, cnv_height, win_x, win_y) + " " + // pd_geo_string(cnv_width, cnv_height, win_x, win_y)); - // ico@vt.edu: replaced first pd_geo_string's first two args (originally - // win_x and win_y with cnv_width and cnv_height + 25 to ensure the window - // reopens exactly how it was saved) + // IMPORTANT! ico@vt.edu: for nw 0.46+ we will need to replace first pd_geo_string's + // first two args (win_w and win_h with cnv_width and cnv_height + nw_menu_offset + // to ensure the window reopens exactly how it was saved) pdsend(cid, "relocate", - pd_geo_string(cnv_width, cnv_height + menu_offset, win_x, win_y), + pd_geo_string(win_w, win_h, win_x, win_y), pd_geo_string(cnv_width, cnv_height, win_x, win_y) ); } @@ -2410,6 +2448,8 @@ function gui_canvas_line(cid,tag,type,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) { frag.appendChild(path); return frag; }); + // ico@vt.edu 2020-08-12: update scroll when cord is drawn + gui_canvas_get_scroll(cid); } function gui_canvas_select_line(cid, tag) { @@ -2429,6 +2469,8 @@ function gui_canvas_delete_line(cid, tag) { gui(cid).get_elem(tag, function(e) { e.parentNode.removeChild(e); }); + // ico@vt.edu 2020-08-12: update scroll when cord is deleted + gui_canvas_get_scroll(cid); } function gui_canvas_update_line(cid, tag, x1, y1, x2, y2, yoff) { @@ -2667,7 +2709,7 @@ function gui_canvas_emphasize(cid) { // We *really* have to update all platforms to the same most recent // stable version. Otherwise the entire codebase is going to become // conditional branches... - if (check_nwjs_version("0.15")) { + if (check_nw_version("0.15")) { e.animate([ {"backgroundColor": "white"}, {"backgroundColor": "#ff9999"}, @@ -2685,7 +2727,7 @@ function gui_gobj_emphasize(cid, tag) { e.scrollIntoView(); // quick and dirty, plus another check because Windows and old OSX // versions of nwjs are ancient and don't include web animations API... - if (border && check_nwjs_version("0.15")) { + if (border && check_nw_version("0.15")) { border.animate([ {fill: "white"}, {fill: "#ff9999"}, @@ -6014,27 +6056,38 @@ function canvas_params(nw_win) var bbox, width, height, min_width, min_height, x, y, svg_elem; svg_elem = nw_win.window.document.getElementById("patchsvg"); bbox = svg_elem.getBBox(); + //post("canvas_params calculated bbox: " + bbox.width + " " + bbox.height); // We try to do Pd-extended style canvas origins. That is, coord (0, 0) // should be in the top-left corner unless there are objects with a // negative x or y. // To implement the Pd-l2ork behavior, the top-left of the canvas should // always be the topmost, leftmost object. width = bbox.x > 0 ? bbox.x + bbox.width : bbox.width; - height = bbox.y > 0 ? bbox.y + bbox.height : bbox.height; + // ico@vt.edu 2020-08-12: we add 1 due to an unknown nw.js discrapancy, + // perhaps because of rounding taking place further below? + height = bbox.y > 0 ? bbox.y + bbox.height + 1 : bbox.height + 1; x = bbox.x > 0 ? 0 : bbox.x, y = bbox.y > 0 ? 0 : bbox.y; // ico@vt.edu: adjust body width and height to match patchsvg to ensure // scrollbars only come up when we are indeed inside svg and not before // with extra margins around. This is accurate to a pixel on nw 0.47.0. - // This is also needed when maximizing and restoring the window in order - // to trigger resizing of scrollbars. + // This is needed when maximizing and restoring the window in order + // to trigger resizing of scrollbars. This value reflects the pre-zoom + // size but this is good enough for detecting window resizing changes. + + // ico @vt.edu 2020-08-13 UPDATE: I tracked down the inconsistency in + // measuring window size between Windows and OSX/Linux and it boils down + // to innerWidth and innerHeight for some reason giving out inconsistent + // values. For this reason, I have added the checks in the index.js' + // nw_create_window, and the pdgui.js' canvas_check_geometry. min_width = nw_win.window.innerWidth; min_height = nw_win.window.innerHeight; var body_elem = nw_win.window.document.body; body_elem.style.width = min_width + "px"; body_elem.style.height = min_height + "px"; + //post("canvas_params min_w=" + min_width + " min_h=" + min_height); // Since we don't do any transformations on the patchsvg, // let's try just using ints for the height/width/viewBox @@ -6061,11 +6114,12 @@ function canvas_params(nw_win) // so if it drops below 1, that means we need our scrollbars if (yScrollSize < 1) { var yHeight = Math.floor(yScrollSize * (min_height + 3 + nw_version_bbox_offset)); - vscroll.style.setProperty("height", (yHeight - 6 + nw_version_bbox_offset) + "px"); - vscroll.style.setProperty("top", (yScrollTopOffset + 2) + "px"); + vscroll.style.setProperty("height", (yHeight - 1 + nw_version_bbox_offset) + "px"); + // was (yScrollTopOffset + 2) to make it peel away from the edge + vscroll.style.setProperty("top", (yScrollTopOffset + 0) + "px"); vscroll.style.setProperty("-webkit-clip-path", - "polygon(0px 0px, 5px 0px, 5px " + (yHeight - 6 + nw_version_bbox_offset) + - "px, 0px " + (yHeight - 11 + nw_version_bbox_offset) + "px, 0px 5px)"); + "polygon(0px 0px, 5px 0px, 5px " + (yHeight - 1 + nw_version_bbox_offset) + + "px, 0px " + (yHeight - 6 + nw_version_bbox_offset) + "px, 0px 5px)"); // ico@vt.edu: this could go either way. We can zoom here to compensate for // the zoom and keep the scrollbars the same size, or, as is the case with // this new commit, we enlarge them together with the patch since one of the @@ -6086,11 +6140,12 @@ function canvas_params(nw_win) if (xScrollSize < 1) { var xWidth = Math.floor(xScrollSize * (min_width + 3)); - hscroll.style.setProperty("width", (xWidth - 6) + "px"); - hscroll.style.setProperty("left", (xScrollLeftOffset + 2) + "px"); + hscroll.style.setProperty("width", (xWidth - 1) + "px"); + // was (xScrollTopOffset + 2) to make it peel away from the edge + hscroll.style.setProperty("left", (xScrollLeftOffset + 0) + "px"); hscroll.style.setProperty("-webkit-clip-path", - "polygon(0px 0px, " + (xWidth - 11) + "px 0px, " + - (xWidth - 6) + "px 5px, 0px 5px)"); + "polygon(0px 0px, " + (xWidth - 6) + "px 0px, " + + (xWidth - 1) + "px 5px, 0px 5px)"); // ico@vt.edu: this could go either way. We can zoom here to compensate for // the zoom and keep the scrollbars the same size, or, as is the case with // this new commit, we enlarge them together with the patch since one of the @@ -6105,6 +6160,8 @@ function canvas_params(nw_win) } //post("x=" + xScrollSize + " y=" + yScrollSize); + //post("canvas_params final: x=" + x + " y=" + y + "w=" + width + + // " h=" + height + " min_w=" + min_width + " min_h=" + min_height); return { x: x, y: y, w: width, h: height, mw: min_width, mh: min_height }; @@ -6128,7 +6185,9 @@ function pd_do_getscroll(cid) { exports.pd_do_getscroll = pd_do_getscroll;*/ -var nw_version_bbox_offset = check_nwjs_version("0.46") ? 0 : -4; +// ico@vt.edu: we need this because of inconsistent canvas size between +// nw <=0.24 and >=0.46 +var nw_version_bbox_offset = check_nw_version("0.46") ? 0 : -4; function do_getscroll(cid, checkgeom) { // Since we're throttling these getscroll calls, they can happen after @@ -6148,7 +6207,10 @@ function do_getscroll(cid, checkgeom) { var { x: x, y: y, w: width, h: height, mw: min_width, mh: min_height } = canvas_params(nw_win); + //post("nw_version_bbox_offset=" + nw_version_bbox_offset + + // " min_height=" + min_height); min_height += nw_version_bbox_offset; + //post("post-calc min_height=" + min_height); if (width < min_width) { width = min_width; @@ -6278,7 +6340,7 @@ var optimalzoom_var = {}; // 100 msec are enough for do_optimalzoom to finish. function gui_canvas_optimal_zoom(cid, h, v) { clearTimeout(optimalzoom_var[cid]); - optimalzoom_var[cid] = setTimeout(do_optimalzoom, 10, cid, h, v); + optimalzoom_var[cid] = setTimeout(do_optimalzoom, 50, cid, h, v); } exports.gui_canvas_optimal_zoom = gui_canvas_optimal_zoom; @@ -6423,11 +6485,11 @@ function gui_update_scrollbars(cid) { if (yScrollSize < 1) { var yHeight = Math.floor(yScrollSize * min_height); - vscroll.style.setProperty("height", (yHeight - 6 + nw_version_bbox_offset) + "px"); - vscroll.style.setProperty("top", (yScrollTopOffset + 2) + "px"); + vscroll.style.setProperty("height", (yHeight - 1 + nw_version_bbox_offset) + "px"); + vscroll.style.setProperty("top", (yScrollTopOffset + 0) + "px"); vscroll.style.setProperty("-webkit-clip-path", - "polygon(0px 0px, 5px 0px, 5px " + (yHeight - 6 + nw_version_bbox_offset) + - "px, 0px " + (yHeight - 11 + nw_version_bbox_offset) + "px, 0px 5px)"); + "polygon(0px 0px, 5px 0px, 5px " + (yHeight - 1 + nw_version_bbox_offset) + + "px, 0px " + (yHeight - 6 + nw_version_bbox_offset) + "px, 0px 5px)"); vscroll.style.setProperty("visibility", "visible"); } else { vscroll.style.setProperty("visibility", "hidden"); @@ -6449,11 +6511,11 @@ function gui_update_scrollbars(cid) { if (xScrollSize < 1) { var xWidth = Math.floor(xScrollSize * min_width); - hscroll.style.setProperty("width", (xWidth - 6) + "px"); - hscroll.style.setProperty("left", (xScrollTopOffset + 2) + "px"); + hscroll.style.setProperty("width", (xWidth - 1) + "px"); + hscroll.style.setProperty("left", (xScrollTopOffset + 0) + "px"); hscroll.style.setProperty("-webkit-clip-path", - "polygon(0px 0px, " + (xWidth - 11) + "px 0px, " + - (xWidth - 6) + "px 5px, 0px 5px)"); + "polygon(0px 0px, " + (xWidth - 6) + "px 0px, " + + (xWidth - 1) + "px 5px, 0px 5px)"); hscroll.style.setProperty("visibility", "visible"); } else { hscroll.style.setProperty("visibility", "hidden");