TJ Teegan wrote:
I have a feeling I am making this harder than it needs to be.
I don't think you are ;)
Here is what I am trying to accomplish. I would like to create a method by
which I can increase or decrease the scale on the root element while
maintaining the drawings current position on the screen.
For example, If in the user coordinate system the point -300,400 is in
the center of my monitor after I change the scale I would like the point
-300,400 to still be in the center of the monitor.
This is the code to do this from the JSVGComponent, this is
a bit more complex than what you _really_ need because you
probably aren't concerned about rotation or shear, just scale
and translate, but the basic technique is similar.
// Here we map the old center of the component down to
// the user coodinate system with the old viewing
// transform and then back to the screen with the
// new viewing transform. We then adjust the rendering
// transform so it lands in the same place.
Point2D pt = new Point2D.Float(oldD.width/2.0f,
oldD.height/2.0f);
AffineTransform rendAT = getRenderingTransform();
if (rendAT != null) {
try {
AffineTransform invRendAT = rendAT.createInverse();
pt = invRendAT.transform(pt, null);
} catch (NoninvertibleTransformException e) { }
}
if (vt != null) {
try {
AffineTransform invVT = vt.createInverse();
pt = invVT.transform(pt, null);
} catch (NoninvertibleTransformException e) { }
}
if (at != null)
pt = at.transform(pt, null);
if (rendAT != null)
pt = rendAT.transform(pt, null);
// Now figure out how far we need to shift things
// to get the center point to line up again.
float dx = (float)((d.width/2.0f) -pt.getX());
float dy = (float)((d.height/2.0f)-pt.getY());
// Round the values to nearest integer.
dx = (int)((dx < 0)?(dx - .5):(dx + .5));
dy = (int)((dy < 0)?(dy - .5):(dy + .5));
if ((dx != 0) || (dy != 0)) {
rendAT.preConcatenate
(AffineTransform.getTranslateInstance(dx, dy));
setRenderingTransform(rendAT, false);
}
This works fine, except the position of the drawing on the screen is
changed. I should note - I have setRecenterOnResize set to false and
the JSVGCanvas is contained in a JSVGScrollPane.
You will need to adjust the translate portion to componsate for
the change caused by the scale change.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]