Skip to content

Commit

Permalink
image viewer: pinch to zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Jun 21, 2014
1 parent fa6bc35 commit bb07a8e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions images/src/org/intellij/images/editor/impl/ImageEditorUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.intellij.ui.PopupHandler;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.components.JBLayeredPane;
import com.intellij.ui.components.Magnificator;
import com.intellij.util.ui.UIUtil;
import org.intellij.images.ImagesBundle;
import org.intellij.images.editor.ImageDocument;
Expand Down Expand Up @@ -191,12 +192,24 @@ ImageZoomModel getZoomModel() {
return zoomModel;
}

private static final class ImageContainerPane extends JBLayeredPane {
private final class ImageContainerPane extends JBLayeredPane {
private final ImageComponent imageComponent;

public ImageContainerPane(ImageComponent imageComponent) {
public ImageContainerPane(final ImageComponent imageComponent) {
this.imageComponent = imageComponent;
add(imageComponent);

putClientProperty(Magnificator.CLIENT_PROPERTY_KEY, new Magnificator() {
@Override
public Point magnify(double scale, Point at) {
Point locationBefore = imageComponent.getLocation();
ImageZoomModel model = editor.getZoomModel();
double factor = model.getZoomFactor();
model.setZoomFactor(scale * factor);
return new Point(((int)((at.x - Math.max(scale > 1.0 ? locationBefore.x : 0, 0)) * scale)),
((int)((at.y - Math.max(scale > 1.0 ? locationBefore.y : 0, 0)) * scale)));
}
});
}

private void centerComponents() {
Expand Down

0 comments on commit bb07a8e

Please sign in to comment.