diff options
author | Tor Norbye <tnorbye@google.com> | 2011-01-14 11:56:45 -0800 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2011-01-14 11:56:45 -0800 |
commit | 237c2225ac68ada36d900513a84ad416485ba951 (patch) | |
tree | 776b0552f5e2aabf72b3e705912dc1d66f4f6990 | |
parent | 787c87badd6f5e06ebd9aa58796e8a3f8285e500 (diff) | |
parent | 106c1ead81b9d429f2f403b5bafe1b5569a228cb (diff) | |
download | sdk-237c2225ac68ada36d900513a84ad416485ba951.zip sdk-237c2225ac68ada36d900513a84ad416485ba951.tar.gz sdk-237c2225ac68ada36d900513a84ad416485ba951.tar.bz2 |
Merge "Zoom Improvements" into tools_r9
-rw-r--r-- | ddms/libs/ddmuilib/src/resources/images/capture.png | bin | 696 -> 691 bytes | |||
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/icons/zoom100.png | bin | 0 -> 584 bytes | |||
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomfit.png | bin | 0 -> 542 bytes | |||
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomminus.png | bin | 0 -> 559 bytes | |||
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomplus.png | bin | 0 -> 559 bytes | |||
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomreal.png | bin | 0 -> 578 bytes | |||
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java | 4 | ||||
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java | 74 | ||||
-rwxr-xr-x | eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java | 33 |
9 files changed, 90 insertions, 21 deletions
diff --git a/ddms/libs/ddmuilib/src/resources/images/capture.png b/ddms/libs/ddmuilib/src/resources/images/capture.png Binary files differindex d75e7a9..da5c10b 100644 --- a/ddms/libs/ddmuilib/src/resources/images/capture.png +++ b/ddms/libs/ddmuilib/src/resources/images/capture.png diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoom100.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoom100.png Binary files differnew file mode 100644 index 0000000..8f49f6d --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoom100.png diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomfit.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomfit.png Binary files differnew file mode 100644 index 0000000..9c53ac8 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomfit.png diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomminus.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomminus.png Binary files differnew file mode 100644 index 0000000..dd2c92f --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomminus.png diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomplus.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomplus.png Binary files differnew file mode 100644 index 0000000..466d756 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomplus.png diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomreal.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomreal.png Binary files differnew file mode 100644 index 0000000..c787ed6 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomreal.png diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java index 0e824f1..73c8d2a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java @@ -455,6 +455,10 @@ public class ConfigurationComposite extends Composite { }); } + public boolean isEnabled() { + return mButton != null && mButton.isEnabled(); + } + public void setEnabled(boolean enabledState) { if (mButton != null) { mButton.setEnabled(enabledState); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java index 4f3403e..e432a5a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java @@ -237,7 +237,7 @@ public class GraphicalEditorPart extends EditorPart private CustomButton mZoomOutButton; private CustomButton mZoomResetButton; private CustomButton mZoomInButton; - + private CustomButton mZoomFitButton; private CustomButton mClippingButton; public GraphicalEditorPart(LayoutEditor layoutEditor) { @@ -286,12 +286,13 @@ public class GraphicalEditorPart extends EditorPart gl.marginHeight = gl.marginWidth = 0; // create the top part for the configuration control + IconFactory iconFactory = IconFactory.getInstance(); CustomButton[][] customButtons = new CustomButton[][] { new CustomButton[] { mZoomRealSizeButton = new CustomButton( - "*", - null, //image - "Emulate real size", + null, // label + iconFactory.getIcon("zoomreal"), //$NON-NLS-1$ + "Emulate Real Size", true /*isToggle*/, false /*defaultValue*/ ) { @@ -301,35 +302,49 @@ public class GraphicalEditorPart extends EditorPart mZoomOutButton.setEnabled(!newState); mZoomResetButton.setEnabled(!newState); mZoomInButton.setEnabled(!newState); + mZoomFitButton.setEnabled(!newState); } else { mZoomRealSizeButton.setSelection(!newState); } } }, - mZoomOutButton = new CustomButton( - "-", - null, //image - "Canvas zoom out." + mZoomFitButton = new CustomButton( + null, // label + iconFactory.getIcon("zoomfit"), //$NON-NLS-1$ + "Zoom to Fit (0)" ) { @Override public void onSelected(boolean newState) { - rescale(-1); + rescaleToFit(); } }, mZoomResetButton = new CustomButton( - "100%", - null, //image - "Reset Canvas to 100%" + null, // label + iconFactory.getIcon("zoom100"), //$NON-NLS-1$ + "Reset Zoom to 100% (1)" ) { @Override public void onSelected(boolean newState) { resetScale(); } + } + }, + // Group zoom in/out separately + new CustomButton[] { + mZoomOutButton = new CustomButton( + null, // label + iconFactory.getIcon("zoomminus"), //$NON-NLS-1$ + "Zoom Out (-)" + ) { + @Override + public void onSelected(boolean newState) { + rescale(-1); + } }, mZoomInButton = new CustomButton( - "+", - null, //image - "Canvas zoom in." + null, // label + iconFactory.getIcon("zoomplus"), //$NON-NLS-1$ + "Zoom In (+)" ) { @Override public void onSelected(boolean newState) { @@ -340,8 +355,8 @@ public class GraphicalEditorPart extends EditorPart new CustomButton[] { new CustomButton( null, //text - IconFactory.getInstance().getIcon("explode"), //$NON-NLS-1$ - "Displays extra margins in the layout.", + iconFactory.getIcon("explode"), //$NON-NLS-1$ + "Displays extra margins in the layout", true /*toggle*/, false /*defaultValue*/ ) { @@ -353,8 +368,8 @@ public class GraphicalEditorPart extends EditorPart }, new CustomButton( null, //text - IconFactory.getInstance().getIcon("outline"), //$NON-NLS-1$ - "Shows the outline of all views in the layout.", + iconFactory.getIcon("outline"), //$NON-NLS-1$ + "Shows the outline of all views in the layout", true /*toggle*/, false /*defaultValue*/ ) { @@ -365,7 +380,7 @@ public class GraphicalEditorPart extends EditorPart }, mClippingButton = new CustomButton( null, //text - IconFactory.getInstance().getIcon("clipping"), //$NON-NLS-1$ + iconFactory.getIcon("clipping"), //$NON-NLS-1$ "Toggles screen clipping on/off", true /*toggle*/, true /*defaultValue*/ @@ -437,6 +452,16 @@ public class GraphicalEditorPart extends EditorPart } /** + * Returns true if zooming in/out/to-fit/etc is allowed (which is not the case while + * emulating real size) + * + * @return true if zooming is allowed + */ + boolean isZoomingAllowed() { + return mZoomInButton.isEnabled(); + } + + /** * Listens to workbench selections that does NOT come from {@link LayoutEditor} * (those are generated by ourselves). * <p/> @@ -466,7 +491,7 @@ public class GraphicalEditorPart extends EditorPart * Rescales canvas. * @param direction +1 for zoom in, -1 for zoom out */ - private void rescale(int direction) { + void rescale(int direction) { double s = mCanvasViewer.getCanvas().getScale(); if (direction > 0) { @@ -497,6 +522,13 @@ public class GraphicalEditorPart extends EditorPart mCanvasViewer.getCanvas().setScale(1, true /*redraw*/); } + /** + * Reset the canvas scale to best fit (so content is as large as possible without scrollbars) + */ + private void rescaleToFit() { + mCanvasViewer.getCanvas().setFitScale(); + } + private boolean rescaleToReal(boolean real) { if (real) { return computeAndSetRealScale(true /*redraw*/); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java index a97aedd..dc42b1b 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java @@ -70,6 +70,7 @@ import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; @@ -266,6 +267,19 @@ public class LayoutCanvas extends Canvas { // handle backspace for other platforms as well. if (e.keyCode == SWT.BS) { mDeleteAction.run(); + } else { + // Zooming actions + char c = e.character; + GraphicalEditorPart editor = mLayoutEditor.getGraphicalEditor(); + if (c == '1' && editor.isZoomingAllowed()) { + setScale(1, true); + } else if (c == '0' && editor.isZoomingAllowed()) { + setFitScale(); + } else if (c == '+' && editor.isZoomingAllowed()) { + editor.rescale(1); + } else if (c == '-' && editor.isZoomingAllowed()) { + editor.rescale(-1); + } } } @@ -536,6 +550,25 @@ public class LayoutCanvas extends Canvas { } } + /** Scales the canvas to best fit */ + void setFitScale() { + Rectangle canvasSize = getClientArea(); + int canvasWidth = canvasSize.width - 2 * ICanvasTransform.IMAGE_MARGIN; + int canvasHeight = canvasSize.height - 2 * ICanvasTransform.IMAGE_MARGIN; + + Image image = getImageOverlay().getImage(); + if (image != null) { + ImageData imageData = image.getImageData(); + int sceneWidth = imageData.width; + int sceneHeight = imageData.height; + double hScale = canvasWidth / (double) sceneWidth; + double vScale = canvasHeight / (double) sceneHeight; + + double scale = Math.min(hScale, vScale); + setScale(scale, true); + } + } + /** * Transforms a point, expressed in layout coordinates, into "client" coordinates * relative to the control (and not relative to the display). |