You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by iphar <ma...@googlemail.com> on 2009/05/14 09:42:26 UTC
Re: Zoom on mouse wheel
I thought this code is maybe a little bit faster - but still not optimal. The
problem in both versions is certainly that there is a call to
setRenderingTransform() all the time instead of setPaintingTransform() like
in the default interactors.
----------------------------------------------------
public void mouseWheelMoved(MouseWheelEvent e) {
JGVTComponent c = (JGVTComponent)e.getSource();
xStart = e.getX();
yStart = e.getY();
double s;
if (e.getWheelRotation() < 0) {
s = 1.25;
}
else {
s = 0.8;
}
AffineTransform ot = c.getRenderingTransform();
double tx = -xStart * (s - 1.0);
double ty = -yStart * (s - 1.0);
AffineTransform st = AffineTransform.getTranslateInstance(tx, ty);
AffineTransform at = AffineTransform.getScaleInstance(s,s);
ot.preConcatenate(at);
ot.preConcatenate(st);
c.setRenderingTransform(ot);
}
-----------------------------------------------------
hardc0d3r wrote:
>
> i have this code that uses the mouse wheel to zoom. it does work but its
> slow.. can anyone improve this code?
>
--
View this message in context: http://www.nabble.com/Zoom-on-mouse-wheel-tp18171181p23535839.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Zoom on mouse wheel
Posted by iphar <ma...@googlemail.com>.
Ok, now this version uses PaintingTransform, so it is much faster (but ugly)
and looks like the actions by the default interactors. (this version uses
ctrl-key + mousewheel to zoom)
----------------------------------------------------------
public void mouseWheelMoved(MouseWheelEvent e) {
finished = false;
JGVTComponent c = (JGVTComponent)e.getSource();
c.requestFocus();
xStart = e.getX();
yStart = e.getY();
double s;
if (e.getWheelRotation() < 0) {
s = 1.25;
}
else {
s = 0.8;
}
AffineTransform ot;
double tx = -xStart * (s - 1.0);
double ty = -yStart * (s - 1.0);
if(c.getPaintingTransform() != null) {
ot = c.getPaintingTransform();
AffineTransform st = AffineTransform.getTranslateInstance(tx, ty);
AffineTransform at = AffineTransform.getScaleInstance(s,s);
ot.preConcatenate(at);
ot.preConcatenate(st);
}
else {
ot = AffineTransform.getTranslateInstance(tx, ty);
ot.scale(s, s);
}
c.setPaintingTransform(ot);
}
public void keyReleased(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_CONTROL) {
finished = true;
JGVTComponent c = (JGVTComponent)e.getSource();
AffineTransform pt = c.getPaintingTransform();
if (pt != null) {
AffineTransform rt =
(AffineTransform)c.getRenderingTransform().clone();
rt.preConcatenate(pt);
c.setRenderingTransform(rt);
}
}
}
--------------------------------------------------------
iphar wrote:
>
> I thought this code is maybe a little bit faster - but still not optimal.
> The problem in both versions is certainly that there is a call to
> setRenderingTransform() all the time instead of setPaintingTransform()
> like in the default interactors.
>
--
View this message in context: http://www.nabble.com/Zoom-on-mouse-wheel-tp18171181p23538815.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org