Commit 89bb900c authored by user's avatar user

added scrolling routine for GUI; using shape-rendering attribute instead of drawing on half-pixels

parent 27abfca8
......@@ -10,7 +10,7 @@
<input style="display:none;" id="openpanel_dialog" type="file" />
<input style="display:none;" id="savepanel_dialog" type="file" nwsaveas nwworkingdir />
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" id="patchsvg" height="1000" width="1000" class="noselect">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" id="patchsvg" height="1000" width="1000" overflow="visible" class="noselect">
</svg>
<script>
'use strict';
......@@ -54,6 +54,7 @@ function text_to_fudi(text) {
var canvas_events = (function() {
var name,
state,
svg_view = document.getElementById('patchsvg').viewBox.baseVal,
textbox = function () {
return document.getElementById('new_object_textentry');
},
......@@ -62,8 +63,9 @@ var canvas_events = (function() {
//pdgui.gui_post("x: " + evt.pageX + " y: " + evt.pageY +
// " modifier: " + (evt.shiftKey + (evt.ctrlKey << 1)));
pdgui.pdsend(name +
" motion " + evt.pageX + " " + evt.pageY + " " +
(evt.shiftKey + (evt.ctrlKey << 1)));
" motion " + (evt.pageX + svg_view.x) + " " +
(evt.pageY + svg_view.y) + " " +
(evt.shiftKey + (evt.ctrlKey << 1)));
evt.stopPropagation();
evt.preventDefault();
return false;
......@@ -81,8 +83,9 @@ var canvas_events = (function() {
mod = (evt.shiftKey + (evt.ctrlKey << 1));
}
pdgui.pdsend(name +
" mouse " + evt.pageX + " " + evt.pageY + " " +
b + " " + mod);
" mouse " + (evt.pageX + svg_view.x) + " " +
(evt.pageY + svg_view.y) + " " +
b + " " + mod);
//evt.stopPropagation();
evt.preventDefault();
},
......
......@@ -1886,15 +1886,12 @@ function add_gobj_to_svg(svg, gobj) {
function gui_text_create_gobj(cid, tag, type, xpos, ypos, is_toplevel) {
gui_post("creating a gobj");
var svg = get_item(cid, "patchsvg"); // "patchsvg" is id for the svg element
// Put objects on half-pixels to make them crisp (look in to the
// difference between this and the object-rendering 'crispEdges' attribute)
xpos += 0.5;
ypos += 0.5;
var transform_string = 'matrix(1,0,0,1,' + xpos + ',' + ypos + ')';
var g = create_item(cid, 'g', {
id: tag + 'gobj',
transform: transform_string,
class: type + (is_toplevel !== 0 ? '' : ' gop')
class: type + (is_toplevel !== 0 ? '' : ' gop'),
//'shape-rendering': 'crispEdges'
});
add_gobj_to_svg(svg, g);
// var bluh = svg.getBBox();
......@@ -1919,7 +1916,7 @@ function gui_text_drawborder(cid, tag, bgcolor, isbroken, x1, y1, x2, y2) {
height: y2 - y1,
stroke: 'black',
fill: 'none',
'shape-rendering': 'optimizeSpeed',
'shape-rendering': 'crispEdges',
class: 'border'
});
if (isbroken === 1) {
......@@ -1952,6 +1949,7 @@ function gui_canvas_drawio(cid, parenttag, tag, x1, y1, x2, y2, basex, basey, ty
y: y1 - basey,
id: xlet_id,
class: xlet_class,
'shape-rendering': 'crispEdges'
});
g.appendChild(rect);
gui_post("the tag for this XLET is " + tag);
......@@ -3529,3 +3527,20 @@ function gui_undo_menu(cid, undo_text, redo_text) {
patchwin[cid].window.nw_undo_menu(undo_text, redo_text);
}
}
function gui_canvas_getscroll(cid) {
var svg = get_item(cid, 'patchsvg');
var bbox = svg.getBBox();
configure_item(svg, {
viewBox: [bbox.x > 0 ? 0 : bbox.x,
bbox.y > 0 ? 0 : bbox.y,
bbox.x > 0 ? bbox.x + bbox.width : bbox.width,
bbox.y > 0 ? bbox.y + bbox.height: bbox.height].join(" ")
});
svg.width.baseVal.valueAsString = bbox.x > 0 ? bbox.x + bbox.width : bbox.width;
svg.height.baseVal.valueAsString = bbox.y > 0 ? bbox.y + bbox.height : bbox.height;
console.log("x is " + bbox.x);
console.log("y is " + bbox.x);
console.log("width is " + bbox.width);
console.log("height is " + bbox.height);
}
......@@ -185,6 +185,7 @@ Everything else: (A [x] means we've fixed it)
[ ] abstract out multi-line text loop, use for text_new and text_set
[ ] think about translating the undo/redo actions as they appear in the menu.
(Might be tricky to do)
[ ] set svg viewBox/width/height to the window size when window gets created
Crashers
--------
......
......@@ -173,7 +173,8 @@ static void canvas_nlet_conf (t_canvas *x, int type) {
}*/
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);
gui_vmess("gui_canvas_getscroll", "x", x);
}
/* ---------------- generic widget behavior ------------------------- */
......
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