Ignore:
Timestamp:
2017-02-15T12:27:30+01:00 (8 years ago)
Author:
bastik
Message:

[piclayer] more natural mouse handling for scale: stick to mouse pointer

Location:
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleXPictureAction.java

    r32675 r33148  
    2323import static org.openstreetmap.josm.tools.I18n.tr;
    2424
     25import java.awt.event.MouseEvent;
     26
     27import org.openstreetmap.josm.Main;
    2528import org.openstreetmap.josm.gui.MapFrame;
     29import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction;
     30import org.openstreetmap.josm.tools.ImageProvider;
    2631
    2732/**
     
    2934 */
    3035@SuppressWarnings("serial")
    31 public class ScaleXPictureAction extends ScalePictureActionAbstract {
     36public class ScaleXPictureAction extends GenericPicTransformAction {
    3237
    3338    /**
     
    3540     */
    3641    public ScaleXPictureAction(MapFrame frame) {
    37         super(tr("PicLayer scale X"), tr("Scaled by X"), "scale_x", tr("Drag to scale the picture in the X Axis"), frame);
     42        super(tr("PicLayer scale X"), tr("Scaled by X"), "scale_x", tr("Drag to scale the picture in the X Axis"), frame, ImageProvider.getCursor("crosshair", null));
    3843    }
    3944
    4045    @Override
    41     public void doTheScale(double scale) {
    42         currentLayer.scalePictureBy(scale, 1.0);
     46    protected void doAction(MouseEvent e) {
     47        double centerX = Main.map.mapView.getWidth()/2;
     48        double dx0 = Math.max(Math.abs(prevMousePoint.getX() - centerX), 10);
     49        double dx = Math.abs(e.getX() - centerX);
     50        double scaleX = Math.max(dx / dx0, 0.9);
     51        currentLayer.scalePictureBy(scaleX, 1.0);
    4352    }
    4453}
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleXYPictureAction.java

    r32675 r33148  
    2323import static org.openstreetmap.josm.tools.I18n.tr;
    2424
     25import java.awt.Point;
     26import java.awt.event.MouseEvent;
     27import java.awt.geom.Point2D;
     28
     29import org.openstreetmap.josm.Main;
    2530import org.openstreetmap.josm.gui.MapFrame;
     31import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction;
     32import org.openstreetmap.josm.tools.ImageProvider;
    2633
    2734/**
     
    2936 */
    3037@SuppressWarnings("serial")
    31 public class ScaleXYPictureAction extends ScalePictureActionAbstract {
     38public class ScaleXYPictureAction extends GenericPicTransformAction {
    3239
    3340    /**
     
    3542     */
    3643    public ScaleXYPictureAction(MapFrame frame) {
    37         super(tr("PicLayer scale"), tr("Scaled"), "scale", tr("Drag to scale the picture in the X and Y Axis"), frame);
     44        super(tr("PicLayer scale"), tr("Scaled"), "scale", tr("Drag to scale the picture in the X and Y Axis"), frame, ImageProvider.getCursor("crosshair", null));
    3845    }
    3946
    4047    @Override
    41     public void doTheScale(double scale) {
     48    protected void doAction(MouseEvent e) {
     49        double centerX = Main.map.mapView.getWidth()/2;
     50        double centerY = Main.map.mapView.getHeight()/2;
     51        double d0 = Math.max(prevMousePoint.distance(centerX, centerY), 10);
     52        Point2D mousePoint = new Point(e.getX(), e.getY());
     53        double d = mousePoint.distance(centerX, centerY);
     54        double scale = Math.max(d / d0, 0.9);
    4255        currentLayer.scalePictureBy(scale, scale);
    4356    }
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/actions/transform/ScaleYPictureAction.java

    r32675 r33148  
    2323import static org.openstreetmap.josm.tools.I18n.tr;
    2424
     25import java.awt.event.MouseEvent;
     26
     27import org.openstreetmap.josm.Main;
    2528import org.openstreetmap.josm.gui.MapFrame;
     29import org.openstreetmap.josm.plugins.piclayer.actions.GenericPicTransformAction;
     30import org.openstreetmap.josm.tools.ImageProvider;
    2631
    2732/**
     
    2934 */
    3035@SuppressWarnings("serial")
    31 public class ScaleYPictureAction extends ScalePictureActionAbstract {
     36public class ScaleYPictureAction extends GenericPicTransformAction {
    3237
    3338    /**
     
    3540     */
    3641    public ScaleYPictureAction(MapFrame frame) {
    37         super(tr("PicLayer scale Y"), tr("Scaled by Y"), "scale_y", tr("Drag to scale the picture in the Y Axis"), frame);
     42        super(tr("PicLayer scale Y"), tr("Scaled by Y"), "scale_y", tr("Drag to scale the picture in the Y Axis"), frame, ImageProvider.getCursor("crosshair", null));
    3843    }
    3944
    4045    @Override
    41     public void doTheScale(double scale) {
    42         currentLayer.scalePictureBy(1.0, scale);
     46    protected void doAction(MouseEvent e) {
     47        double centerY = Main.map.mapView.getHeight()/2;
     48        double dy0 = Math.max(Math.abs(prevMousePoint.getY() - centerY), 10);
     49        double dy = Math.abs(e.getY() - centerY);
     50        double scaleY = Math.max(dy / dy0, 0.9);
     51        currentLayer.scalePictureBy(1.0, scaleY);
    4352    }
    4453}
Note: See TracChangeset for help on using the changeset viewer.