From: Tor Norbye Date: Fri, 14 Jan 2011 17:49:12 +0000 (-0800) Subject: Zoom Improvements X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=106c1ead81b9d429f2f403b5bafe1b5569a228cb;p=android-x86%2Fsdk.git Zoom Improvements First, add a new "Zoom to Fit" toolbar action. This will look at the size of the rendered image, as well as the size of the canvas area, and compute the largest possible scale factor that will zoom the rendered image while showing everything. This is particularly useful when working with larger devices, such as WXGA, where typically the rendering comes up showing only the top left portion of the image, and the Zoom Out function often zooms out too much since it does not have fine granularity. Second, add icons to the various zooming functions. The zoom in/out icons are from Eclipse WTP; the other three are minor derivations from these icons (using = for emulate real size, 1 for 100% and an outline for zoom to fit). Third hook up zoom in, zoom out, zoom to 100% and zoom to fit to keyboard shortcuts (applicable to the canvas only). Finally, tweak some labels. (Also updated the ddms screencapture icon, since there was a screen capture icon in the same Eclipse WTP icon folder) Change-Id: Idc118a58f418daeefb5835f40dc1fd518b0f99d1 --- diff --git a/ddms/libs/ddmuilib/src/resources/images/capture.png b/ddms/libs/ddmuilib/src/resources/images/capture.png index d75e7a917..da5c10be4 100644 Binary files a/ddms/libs/ddmuilib/src/resources/images/capture.png and b/ddms/libs/ddmuilib/src/resources/images/capture.png differ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoom100.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoom100.png new file mode 100644 index 000000000..8f49f6dda Binary files /dev/null and b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoom100.png differ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomfit.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomfit.png new file mode 100644 index 000000000..9c53ac8bf Binary files /dev/null and b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomfit.png differ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomminus.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomminus.png new file mode 100644 index 000000000..dd2c92f9e Binary files /dev/null and b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomminus.png differ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomplus.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomplus.png new file mode 100644 index 000000000..466d756b3 Binary files /dev/null and b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomplus.png differ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomreal.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomreal.png new file mode 100644 index 000000000..c787ed664 Binary files /dev/null and b/eclipse/plugins/com.android.ide.eclipse.adt/icons/zoomreal.png differ 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 0e824f1fe..73c8d2a34 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 4f3403e86..e432a5a22 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). *

@@ -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 a97aedd50..dc42b1b43 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).