xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: move shapes in the Canvas
Date Mon, 10 Apr 2006 11:41:36 GMT
Hi Selva,

    The problem is likely that if the mouse moves off the element in one 
mouse move
the dragged element will not recieve the mouse move event (it will recieve 
a mouse 
out event).  Typically the simplest way to fix this is to insert a 'glass 
pane' (an invisible
rect that covers the entire canvas I tend to set fill and stroke to none 
and set
pointer-events to 'fill').   If you append this element to the root SVG 
element it
will capture all mouse events until you remove it - which is exactly what 
you want
(don't forget to add your mouse move listener to the glass-pane element).

    You can also get a similar effect if you register your event listener 
on the root
SVG element, but you must have a 'background' element that is 'under' all 
others
otherwise if your canvas falls off all elements there is no target for the 
mouse event.

news <news@sea.gmane.org> wrote on 04/10/2006 03:01:50 AM:

> Hi All,
> 
> I am trying to move the rectangle element in JSVGcanvas. But it is not 
moving 
> properly when i move the mouse faster. i have referred 
> http://wiki.apache.org/xmlgraphics-batik/DragTutorial. But still i 
couldn't 
> able to move the elements properly. 
> 
> This is code i used in mouse move handler.
> 
> DOMMouseEvent elEvt = (DOMMouseEvent)evt;
> 
> int nowToX = elEvt.getClientX();
> int nowToY = elEvt.getClientY();
> 
> SVGDocument svgDocument = svgCanvas.getSVGDocument();
> SVGPoint trans = svgDocument.getRootElement().getCurrentTranslate();
> float scale = svgDocument.getRootElement().getCurrentScale();
> nowToX = (int)((nowToX - trans.getX()) / scale);
> nowToY = (int)((nowToY - trans.getY()) / scale);
> if (action == DRAG) {
>      ((Element)actionNode).setAttribute("x", "" + (nowToX - dx));
>      ((Element)actionNode).setAttribute("y", "" + (nowToY - dy));
> } else {
> 
>      float cW = 
Float.parseFloat(((Element)actionNode).getAttribute("width"));
>      float cH = 
Float.parseFloat(((Element)actionNode).getAttribute("height"));
>      float ar = cW / cH;
>      float nW = nowToX - dx;
>      float nH = nowToY - dy;
>      if (nW / nH < ar) {
>          nW = ar * nH; } else {
>          nH = nW / ar; }
>          ((Element)actionNode).setAttribute("width", "" + nW);
>          ((Element)actionNode).setAttribute("height", "" + nH);
> }
> 
> Please give the suggestions to handle this situation.
> 
> Thanks,
> Selva
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message