Changeset 32592 in osm
- Timestamp:
- 2016-07-06T16:00:52+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java
r32374 r32592 77 77 this.mouseIsDragging = false; 78 78 MapillaryImageDisplay.this.selectedRect = null; 79 if (image == null)80 return;81 // Calculate the mouse cursor position in image coordinates, so that82 // we can center the zoom83 // on that mouse position.84 // To avoid issues when the user tries to zoom in on the image85 // borders, this point is not calculated86 // again if there was less than 1.5seconds since the last event.87 if (e.getWhen() - this.lastTimeForMousePoint > 1500 || this.mousePointInImg == null) {88 this.lastTimeForMousePoint = e.getWhen();89 this.mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY());90 }91 // Set the zoom to the visible rectangle in image coordinates92 if (e.getWheelRotation() > 0) {93 visibleRect.width = visibleRect.width* 3 / 2;94 visibleRect.height = visibleRect.height * 3 / 2;95 } else {96 visibleRect.width = visibleRect.width* 2 / 3;97 visibleRect.height = visibleRect.height * 2 / 3;98 }99 // Check that the zoom doesn't exceed 2:1100 if (visibleRect.width < getSize().width / 2) {101 visibleRect.width = getSize().width / 2;102 }103 if (visibleRect.height < getSize().height / 2) {104 visibleRect.height = getSize().height / 2;105 }106 // Set the same ratio for the visible rectangle and the display area107 int hFact = visibleRect.height * getSize().width;108 int wFact = visibleRect.width * getSize().height;109 if (hFact > wFact) {110 visibleRect.width = hFact / getSize().height;111 } else {112 visibleRect.height = wFact / getSize().width;113 }114 // The size of the visible rectangle is limited by the image size.115 checkVisibleRectSize(image, visibleRect);116 // Set the position of the visible rectangle, so that the mouse117 // cursor doesn't move on the image.118 Rectangle drawRect = calculateDrawImageRectangle(visibleRect);119 visibleRect.x = this.mousePointInImg.x120 + ((drawRect.x - e.getX()) * visibleRect.width) / drawRect.width;121 visibleRect.y = this.mousePointInImg.y122 + ((drawRect.y - e.getY()) * visibleRect.height) / drawRect.height;123 // The position is also limited by the image size124 checkVisibleRectPos(image, visibleRect);125 synchronized (MapillaryImageDisplay.this) {126 MapillaryImageDisplay.this.visibleRect = visibleRect;127 }128 MapillaryImageDisplay.this.repaint();79 if (image != null && Math.min(getSize().getWidth(), getSize().getHeight()) > 0) { 80 // Calculate the mouse cursor position in image coordinates, so that 81 // we can center the zoom 82 // on that mouse position. 83 // To avoid issues when the user tries to zoom in on the image 84 // borders, this point is not calculated 85 // again if there was less than 1.5seconds since the last event. 86 if (e.getWhen() - this.lastTimeForMousePoint > 1500 || this.mousePointInImg == null) { 87 this.lastTimeForMousePoint = e.getWhen(); 88 this.mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY()); 89 } 90 // Set the zoom to the visible rectangle in image coordinates 91 if (e.getWheelRotation() > 0) { 92 visibleRect.width = visibleRect.width * 3 / 2; 93 visibleRect.height = visibleRect.height * 3 / 2; 94 } else { 95 visibleRect.width = visibleRect.width * 2 / 3; 96 visibleRect.height = visibleRect.height * 2 / 3; 97 } 98 // Check that the zoom doesn't exceed 2:1 99 if (visibleRect.width < getSize().width / 2) { 100 visibleRect.width = getSize().width / 2; 101 } 102 if (visibleRect.height < getSize().height / 2) { 103 visibleRect.height = getSize().height / 2; 104 } 105 // Set the same ratio for the visible rectangle and the display area 106 int hFact = visibleRect.height * getSize().width; 107 int wFact = visibleRect.width * getSize().height; 108 if (hFact > wFact) { 109 visibleRect.width = hFact / getSize().height; 110 } else { 111 visibleRect.height = wFact / getSize().width; 112 } 113 // The size of the visible rectangle is limited by the image size. 114 checkVisibleRectSize(image, visibleRect); 115 // Set the position of the visible rectangle, so that the mouse 116 // cursor doesn't move on the image. 117 Rectangle drawRect = calculateDrawImageRectangle(visibleRect); 118 visibleRect.x = this.mousePointInImg.x 119 + ((drawRect.x - e.getX()) * visibleRect.width) / drawRect.width; 120 visibleRect.y = this.mousePointInImg.y 121 + ((drawRect.y - e.getY()) * visibleRect.height) / drawRect.height; 122 // The position is also limited by the image size 123 checkVisibleRectPos(image, visibleRect); 124 synchronized (MapillaryImageDisplay.this) { 125 MapillaryImageDisplay.this.visibleRect = visibleRect; 126 } 127 MapillaryImageDisplay.this.repaint(); 128 } 129 129 } 130 130 … … 139 139 visibleRect = MapillaryImageDisplay.this.visibleRect; 140 140 } 141 if (image == null) { 142 return; 143 } 144 if (e.getButton() == OPTION_BUTTON) { 145 if (!MapillaryImageDisplay.this.visibleRect.equals(new Rectangle(0, 0, image.getWidth(null), image.getHeight(null)))) { 146 // Zooms to 1:1 147 MapillaryImageDisplay.this.visibleRect = new Rectangle(0, 0, 148 image.getWidth(null), image.getHeight(null)); 149 } else { 150 // Zooms to best fit. 151 MapillaryImageDisplay.this.visibleRect = new Rectangle( 152 0, 153 (image.getHeight(null) - (image.getWidth(null) * getHeight()) / getWidth()) / 2, 154 image.getWidth(null), 155 (image.getWidth(null) * getHeight()) / getWidth() 156 ); 141 if (image != null && Math.min(getSize().getWidth(), getSize().getHeight()) > 0) { 142 if (e.getButton() == OPTION_BUTTON) { 143 if (!MapillaryImageDisplay.this.visibleRect.equals(new Rectangle(0, 0, image.getWidth(null), image.getHeight(null)))) { 144 // Zooms to 1:1 145 MapillaryImageDisplay.this.visibleRect = new Rectangle(0, 0, 146 image.getWidth(null), image.getHeight(null)); 147 } else { 148 // Zooms to best fit. 149 MapillaryImageDisplay.this.visibleRect = new Rectangle( 150 0, 151 (image.getHeight(null) - (image.getWidth(null) * getHeight()) / getWidth()) / 2, 152 image.getWidth(null), 153 (image.getWidth(null) * getHeight()) / getWidth() 154 ); 155 } 156 MapillaryImageDisplay.this.repaint(); 157 return; 158 } else if (e.getButton() != DRAG_BUTTON) { 159 return; 160 } 161 // Calculate the translation to set the clicked point the center of 162 // the view. 163 Point click = comp2imgCoord(visibleRect, e.getX(), e.getY()); 164 Point center = getCenterImgCoord(visibleRect); 165 visibleRect.x += click.x - center.x; 166 visibleRect.y += click.y - center.y; 167 checkVisibleRectPos(image, visibleRect); 168 synchronized (MapillaryImageDisplay.this) { 169 MapillaryImageDisplay.this.visibleRect = visibleRect; 157 170 } 158 171 MapillaryImageDisplay.this.repaint(); 159 return; 160 } else if (e.getButton() != DRAG_BUTTON) { 161 return; 162 } 163 // Calculate the translation to set the clicked point the center of 164 // the view. 165 Point click = comp2imgCoord(visibleRect, e.getX(), e.getY()); 166 Point center = getCenterImgCoord(visibleRect); 167 visibleRect.x += click.x - center.x; 168 visibleRect.y += click.y - center.y; 169 checkVisibleRectPos(image, visibleRect); 170 synchronized (MapillaryImageDisplay.this) { 171 MapillaryImageDisplay.this.visibleRect = visibleRect; 172 } 173 MapillaryImageDisplay.this.repaint(); 172 } 174 173 } 175 174
Note:
See TracChangeset
for help on using the changeset viewer.