I don't seem to be able to do it right. after the transfor, i get a white
page with nothing in it. it seems it zooms to an area that is different than
what i want.
If you have an example of doing it the right way, I appreciate it if you can
please post here.
or if you can look at the code below, and tell me where did i go wrong...
in this code, i tried to follow what is done in
org.apache.batik.swing.gvt.AbstractZoomInteractor.mouseReleased
double x1= my value
double y1= my value
double x2= my value
double y2= my value
double xCurrent = x2;
double yCurrent = y2;
double xStart = x1;
double yStart = y1;
if ((xCurrent - xStart) != 0 &&
(yCurrent - yStart) != 0) {
int dx = xCurrent - xStart;
int dy = yCurrent - yStart;
if (dx < 0) {
dx = -dx;
xStart = xCurrent;
}
if (dy < 0) {
dy = -dy;
yStart = yCurrent;
}
Dimension size = c.getSize();
// Zoom factor
float scaleX = size.width / (float)dx;
float scaleY = size.height / (float)dy;
float scale = (scaleX < scaleY) ? scaleX : scaleY;
// Zoom translate
AffineTransform at = new AffineTransform();
at.scale(scale, scale);
at.translate(-xStart, -yStart);
at.concatenate(c.getRenderingTransform());
c.setRenderingTransform(at);
Luca Piccarreta schrieb:
Hi Manuel
Why not zooming around the mouse position?
In order to trap mousewheel events I think you should put an invisible
rectangle behind all the other elements in the scene and listen on the
root
(with the capture flag set) for the event you're interested in.
Actually here I'm using SVG 1.2, so perhaps this is not possible in
SVG 1.1
In the following code getElementCoords and getClientCoords (definitely
these
names are not so clear) convert from OS coordinates to SVG scene
coordinates.
I hope everything is clear, and... yes I do understand that the code
could be made
much better!
Luca.
public void handleEvent(Event evt) {
MouseEvent uiEvt = (MouseEvent) evt;
SVGSVGElement root=editor.getRoot();
float scale = root.getCurrentScale();
SVGPoint sceneCoords = editor.getElementCoords(root, uiEvt
.getClientX(), uiEvt.getClientY());
if (uiEvt.getDetail() < 0) {
root.setCurrentScale(scale * 2);
} else {
root.setCurrentScale(scale / 2);
}
SVGPoint newClientCoords = editor.getClientCoords(root,
sceneCoords.getX(), sceneCoords.getY());
SVGPoint t = root.getCurrentTranslate();
t.setX(t.getX() + uiEvt.getClientX() - newClientCoords.getX());
t.setY(t.getY() + uiEvt.getClientY() - newClientCoords.getY());
}
Manuel Brnjic ha scritto:
Hello!
I wrote a simple Application, that displays me a SVG File in a
JSVGCanvas. Now i want to implement a Function for zooming in. But i
want the zoom on a button-click, that means:
1. The user types in the koordinates, for example: x1, y1, x2, y2
(instead of dragging a rect with the mouse)
2. After the user has pressed a button, it should zoom into the
chosen rect
Is this possible? I have no idea how to realize this. It would be
nice if anybody could write me a simple function with 4 parameters
(x1,y2, x2, y2) that i can implement.
MfG Manuel
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]