Ticket #5852: shear.patch
| File shear.patch, 17.3 KB (added by , 15 years ago) |
|---|
-
src/org/openstreetmap/josm/plugins/piclayer/ResetPictureShearAction.java
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: images/mapmode/shear.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream
1 /*************************************************************************** 2 * Copyright (C) 2011 by Patrick "Petschge" Kilian, based on code * 3 * Copyright (C) 2009 by Tomasz Stelmach * 4 * http://www.stelmach-online.net/ * 5 * * 6 * This program is free software; you can redistribute it and/or modify * 7 * it under the terms of the GNU General Public License as published by * 8 * the Free Software Foundation; either version 2 of the License, or * 9 * (at your option) any later version. * 10 * * 11 * This program is distributed in the hope that it will be useful, * 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 14 * GNU General Public License for more details. * 15 * * 16 * You should have received a copy of the GNU General Public License * 17 * along with this program; if not, write to the * 18 * Free Software Foundation, Inc., * 19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 20 ***************************************************************************/ 21 22 package org.openstreetmap.josm.plugins.piclayer; 23 24 import static org.openstreetmap.josm.tools.I18n.tr; 25 26 import java.awt.event.ActionEvent; 27 28 import org.openstreetmap.josm.Main; 29 import org.openstreetmap.josm.actions.JosmAction; 30 31 /** 32 * Action for resetting properties of an image. 33 * 34 * TODO Four almost identical classes. Refactoring needed. 35 */ 36 public class ResetPictureShearAction extends JosmAction { 37 38 // Owner layer of the action 39 PicLayerAbstract m_owner = null; 40 41 /** 42 * Constructor 43 */ 44 public ResetPictureShearAction( PicLayerAbstract owner ) { 45 super(tr("Shear"), null, tr("Resets picture shear"), null, false); 46 // Remember the owner... 47 m_owner = owner; 48 } 49 50 /** 51 * Action handler 52 */ 53 public void actionPerformed(ActionEvent arg0) { 54 // Reset 55 m_owner.resetShear(); 56 // Redraw 57 Main.map.mapView.repaint(); 58 } 59 } -
src/org/openstreetmap/josm/plugins/piclayer/MovePictureAction.java
32 32 import org.openstreetmap.josm.tools.ImageProvider; 33 33 import org.openstreetmap.josm.data.coor.EastNorth; 34 34 35 //TODO: Move/Rotate/Scale action classes are similar. Do the redesign!35 //TODO: Move/Rotate/Scale/Shear action classes are similar. Do the redesign! 36 36 37 37 /** 38 38 * This class handles the input during moving the picture. -
src/org/openstreetmap/josm/plugins/piclayer/ScaleXYPictureAction.java
27 27 import org.openstreetmap.josm.gui.MapFrame; 28 28 import org.openstreetmap.josm.tools.ImageProvider; 29 29 30 // TODO: Move/Rotate/Scale action classes are similar. Do the redesign!30 // TODO: Move/Rotate/Scale/Shear action classes are similar. Do the redesign! 31 31 32 32 /** 33 33 * This class handles the input during scaling the picture. -
src/org/openstreetmap/josm/plugins/piclayer/ResetPictureAllAction.java
54 54 m_owner.resetAngle(); 55 55 m_owner.resetPosition(); 56 56 m_owner.resetScale(); 57 m_owner.resetShear(); 57 58 // Redraw 58 59 Main.map.mapView.repaint(); 59 60 } -
src/org/openstreetmap/josm/plugins/piclayer/ScaleXPictureAction.java
27 27 import org.openstreetmap.josm.gui.MapFrame; 28 28 import org.openstreetmap.josm.tools.ImageProvider; 29 29 30 // TODO: Move/Rotate/Scale action classes are similar. Do the redesign!30 // TODO: Move/Rotate/Scale/Shear action classes are similar. Do the redesign! 31 31 32 32 /** 33 33 * This class handles the input during scaling the picture. -
src/org/openstreetmap/josm/plugins/piclayer/ScaleYPictureAction.java
27 27 import org.openstreetmap.josm.gui.MapFrame; 28 28 import org.openstreetmap.josm.tools.ImageProvider; 29 29 30 // TODO: Move/Rotate/Scale action classes are similar. Do the redesign!30 // TODO: Move/Rotate/Scale/Shear action classes are similar. Do the redesign! 31 31 32 32 /** 33 33 * This class handles the input during scaling the picture. -
src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java
49 49 private IconToggleButton m_scalexPictureButton = null; 50 50 private IconToggleButton m_scaleyPictureButton = null; 51 51 private IconToggleButton m_scalexyPictureButton = null; 52 private IconToggleButton m_shearPictureButton = null; 52 53 53 54 // Menu actions 54 55 private NewLayerFromFileAction m_newFromFileAction = null; … … 88 89 ScaleXYPictureAction scaleXYPictureAction = new ScaleXYPictureAction(newFrame); 89 90 ScaleXPictureAction scaleXPictureAction = new ScaleXPictureAction(newFrame); 90 91 ScaleYPictureAction scaleYPictureAction = new ScaleYPictureAction(newFrame); 92 ShearPictureAction shearPictureAction = new ShearPictureAction(newFrame); 91 93 // Create plugin buttons and add them to the toolbar 92 94 m_movePictureButton = new IconToggleButton(movePictureAction); 93 95 m_rotatePictureButton = new IconToggleButton(rotatePictureAction); 94 96 m_scalexyPictureButton = new IconToggleButton(scaleXYPictureAction); 95 97 m_scalexPictureButton = new IconToggleButton(scaleXPictureAction); 96 98 m_scaleyPictureButton = new IconToggleButton(scaleYPictureAction); 99 m_shearPictureButton = new IconToggleButton(shearPictureAction); 97 100 newFrame.addMapMode(m_movePictureButton); 98 101 newFrame.addMapMode(m_rotatePictureButton); 99 102 newFrame.addMapMode(m_scalexyPictureButton); 100 103 newFrame.addMapMode(m_scalexPictureButton); 101 104 newFrame.addMapMode(m_scaleyPictureButton); 105 newFrame.addMapMode(m_shearPictureButton); 102 106 // newFrame.toolGroup.add(m_movePictureButton); 103 107 // newFrame.toolGroup.add(m_rotatePictureButton); 104 108 // newFrame.toolGroup.add(m_scalePictureButton); … … 108 112 m_scalexyPictureButton.setVisible(true); 109 113 m_scalexPictureButton.setVisible(true); 110 114 m_scaleyPictureButton.setVisible(true); 115 m_shearPictureButton.setVisible(true); 111 116 } 112 117 } 113 118 -
src/org/openstreetmap/josm/plugins/piclayer/RotatePictureAction.java
31 31 import org.openstreetmap.josm.gui.MapFrame; 32 32 import org.openstreetmap.josm.tools.ImageProvider; 33 33 34 //TODO: Move/Rotate/Scale action classes are similar. Do the redesign!34 //TODO: Move/Rotate/Scale/Shear action classes are similar. Do the redesign! 35 35 36 36 /** 37 37 * This class handles the input during rotating the picture. -
src/org/openstreetmap/josm/plugins/piclayer/PicLayerAbstract.java
73 73 // Scale of the image 74 74 private double m_scalex = 1.0; 75 75 private double m_scaley = 1.0; 76 // Shear of the image 77 private double m_shearx = 0.0; 78 private double m_sheary = 0.0; 76 79 // The scale that was set on the map during image creation 77 80 private double m_initial_scale = 1.0; 78 81 // Layer icon … … 87 90 private final String INITIAL_SCALE = "INITIAL_SCALE"; 88 91 private final String SCALEX = "SCALEX"; 89 92 private final String SCALEY = "SCALEY"; 93 private final String SHEARX = "SHEARX"; 94 private final String SHEARY = "SHEARY"; 90 95 91 96 /** 92 97 * Constructor … … 214 219 double scalex = m_scalex * m_initial_scale / Main.map.mapView.getDist100Pixel(); 215 220 double scaley = m_scaley * m_initial_scale / Main.map.mapView.getDist100Pixel(); 216 221 g.scale( scalex, scaley ); 222 // Shear 223 g.shear(m_shearx, m_sheary); 217 224 218 225 // Draw picture 219 226 g.drawImage( m_image, -m_image.getWidth() / 2, -m_image.getHeight() / 2, null ); … … 257 264 } 258 265 259 266 /** 267 * Shear the picture. shearx and sheary will separately add to the 268 * corresponding current value 269 */ 270 public void shearPictureBy( double shearx, double sheary ) { 271 m_shearx += shearx; 272 m_sheary += sheary; 273 } 274 275 /** 260 276 * Sets the image position to the initial position 261 277 */ 262 278 public void resetPosition() { … … 278 294 m_angle = 0.0; 279 295 } 280 296 297 298 /** 299 * Sets the image to no shear 300 */ 301 public void resetShear() { 302 m_shearx = 0.0; 303 m_sheary = 0.0; 304 } 281 305 @Override 282 306 /** 283 307 * Computes the (rough) bounding box. … … 329 353 props.put(SCALEX, "" + m_scalex); 330 354 props.put(SCALEY, "" + m_scaley); 331 355 props.put(ANGLE, "" + m_angle); 356 props.put(SHEARX, "" + m_shearx); 357 props.put(SHEARY, "" + m_sheary); 332 358 } 333 359 334 360 /** … … 357 383 double in_scale = Double.valueOf( props.getProperty(INITIAL_SCALE)); 358 384 double scale_x = Double.valueOf( props.getProperty(SCALEX)); 359 385 double scale_y = Double.valueOf( props.getProperty(SCALEY)); 386 double shear_x = Double.valueOf( props.getProperty(SHEARX)); 387 double shear_y = Double.valueOf( props.getProperty(SHEARY)); 360 388 m_position.setLocation(pos_x, pos_y); 361 389 m_initial_position.setLocation(pos_x, pos_y); 362 390 m_angle = angle; 363 391 m_scalex = scale_x; 364 392 m_scaley = scale_y; 393 m_shearx = shear_x; 394 m_sheary = shear_y; 365 395 m_initial_scale = in_scale; 366 396 // Refresh 367 397 Main.map.mapView.repaint(); … … 383 413 reset_submenu.add( new ResetPicturePositionAction( PicLayerAbstract.this ) ); 384 414 reset_submenu.add( new ResetPictureAngleAction( PicLayerAbstract.this ) ); 385 415 reset_submenu.add( new ResetPictureScaleAction( PicLayerAbstract.this ) ); 416 reset_submenu.add( new ResetPictureShearAction( PicLayerAbstract.this ) ); 386 417 return reset_submenu; 387 418 } 388 419 -
src/org/openstreetmap/josm/plugins/piclayer/ShearPictureAction.java
1 /*************************************************************************** 2 * * 3 * Copyright (C) 2011 Patrick "Petschge" Kilian, based on code * 4 * (c) 2009 by Tomasz Stelmach * 5 * http://www.stelmach-online.net/ * 6 * * 7 * This program is free software; you can redistribute it and/or modify * 8 * it under the terms of the GNU General Public License as published by * 9 * the Free Software Foundation; either version 2 of the License, or * 10 * (at your option) any later version. * 11 * * 12 * This program is distributed in the hope that it will be useful, * 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 15 * GNU General Public License for more details. * 16 * * 17 * You should have received a copy of the GNU General Public License * 18 * along with this program; if not, write to the * 19 * Free Software Foundation, Inc., * 20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 21 ***************************************************************************/ 22 23 package org.openstreetmap.josm.plugins.piclayer; 24 25 import static org.openstreetmap.josm.tools.I18n.tr; 26 27 import java.awt.event.MouseEvent; 28 import java.awt.event.MouseListener; 29 import java.awt.event.MouseMotionListener; 30 31 import org.openstreetmap.josm.Main; 32 import org.openstreetmap.josm.actions.mapmode.MapMode; 33 import org.openstreetmap.josm.gui.MapFrame; 34 import org.openstreetmap.josm.tools.ImageProvider; 35 import org.openstreetmap.josm.data.coor.EastNorth; 36 37 //TODO: Move/Rotate/Scale/Shear action classes are similar. Do the redesign! 38 39 /** 40 * This class handles the input during shearing of the picture. 41 */ 42 public class ShearPictureAction extends MapMode implements MouseListener, MouseMotionListener 43 { 44 // Action ongoing? 45 private boolean mb_dragging = false; 46 47 // Last mouse position 48 private EastNorth m_prevEastNorth; 49 50 // The layer we're working on 51 private PicLayerAbstract m_currentLayer = null; 52 53 /** 54 * Constructor 55 */ 56 public ShearPictureAction(MapFrame frame) { 57 super(tr("PicLayer shear"), "shear", tr("Drag to shear the picture"), frame, ImageProvider.getCursor("crosshair", null)); 58 } 59 60 @Override 61 public void enterMode() { 62 super.enterMode(); 63 Main.map.mapView.addMouseListener(this); 64 Main.map.mapView.addMouseMotionListener(this); 65 } 66 67 @Override 68 public void exitMode() { 69 super.exitMode(); 70 Main.map.mapView.removeMouseListener(this); 71 Main.map.mapView.removeMouseMotionListener(this); 72 } 73 74 @Override 75 public void mousePressed(MouseEvent e) { 76 77 // If everything is OK, we start dragging/moving the picture 78 if ( Main.map.mapView.getActiveLayer() instanceof PicLayerAbstract ) { 79 m_currentLayer = (PicLayerAbstract)Main.map.mapView.getActiveLayer(); 80 81 if ( m_currentLayer != null && e.getButton() == MouseEvent.BUTTON1 ) { 82 mb_dragging = true; 83 m_prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY()); 84 } 85 } 86 } 87 88 @Override 89 public void mouseDragged(MouseEvent e) { 90 // Picture moving is ongoing 91 if(mb_dragging) { 92 EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(),e.getY()); 93 m_currentLayer.shearPictureBy( 94 1000* (eastNorth.east()-m_prevEastNorth.east()), 95 1000* (eastNorth.north()-m_prevEastNorth.north()) 96 ); 97 m_prevEastNorth = eastNorth; 98 Main.map.mapView.repaint(); 99 } 100 } 101 102 @Override 103 public void mouseReleased(MouseEvent e) { 104 // Stop moving 105 mb_dragging = false; 106 } 107 108 }
