diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/AbstractScaleFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/AbstractScaleFigure.java index 84d1714d2..60575caf5 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/AbstractScaleFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/AbstractScaleFigure.java @@ -33,14 +33,14 @@ public abstract class AbstractScaleFigure extends JPanel { // Number of pixels to leave at edges when fitting figure private static final int DEFAULT_BORDER_PIXELS_WIDTH = 30; private static final int DEFAULT_BORDER_PIXELS_HEIGHT = 20; - - // constant factor that scales screen real-estate to rocket-space - private final double baseScale; - private double userScale = 1.0; - protected double scale = -1; - protected static final Dimension borderThickness_px = new Dimension(DEFAULT_BORDER_PIXELS_WIDTH, DEFAULT_BORDER_PIXELS_HEIGHT); - // pixel offset from the the subject's origin to the canvas's upper-left-corner. + + // constant factor that scales screen real-estate to rocket-space + protected final double baseScale; + protected double userScale = 1.0; + protected double scale = -1; + + // pixel offset from the the subject's origin to the canvas's upper-left-corner. protected Point originLocation_px = new Point(0,0); // size of the visible region @@ -109,10 +109,15 @@ public abstract class AbstractScaleFigure extends JPanel { * @param visibleBounds the visible bounds upon the Figure */ public void scaleTo(final double newScaleRequest, final Dimension visibleBounds) { - if (MathUtil.equals(this.userScale, newScaleRequest, 0.01)){ +// System.err.println(String.format(" ::scaleTo: %6.4f ==>> %6.4f, %d x %d", userScale, newScaleRequest, visibleBounds.width, visibleBounds.height)); + if (MathUtil.equals(this.userScale, newScaleRequest, 0.01) && + (visibleBounds_px.width == visibleBounds.width) && + (visibleBounds_px.height == visibleBounds.height) ) + { return;} if (Double.isInfinite(newScaleRequest) || Double.isNaN(newScaleRequest) || 0 > newScaleRequest) { return;} +// System.err.println(String.format(" => continue")); this.userScale = MathUtil.clamp( newScaleRequest, MINIMUM_ZOOM, MAXIMUM_ZOOM); this.scale = baseScale * userScale; @@ -128,22 +133,19 @@ public abstract class AbstractScaleFigure extends JPanel { * @param visibleBounds the visible bounds to scale this figure to. */ public void scaleTo(Dimension visibleBounds) { - if( 0 == visibleBounds.getWidth() || 0 == visibleBounds.getHeight()) +// System.err.println(String.format(" ::scaleTo: %d x %d", visibleBounds.width, visibleBounds.height)); + if( 0 >= visibleBounds.getWidth() || 0 >= visibleBounds.getHeight()) return; updateSubjectDimensions(); + updateCanvasSize(); + updateCanvasOrigin(); - // dimensions within the viewable area, which are available to draw - final int drawable_width_px = visibleBounds.width - 2 * borderThickness_px.width; - final int drawable_height_px = visibleBounds.height - 2 * borderThickness_px.height; + final double width_scale = (visibleBounds.width) / ((subjectBounds_m.getWidth() * baseScale) + 2 * borderThickness_px.width); + final double height_scale = (visibleBounds.height) / ((subjectBounds_m.getHeight() * baseScale) + 2 * borderThickness_px.height); + final double newScale = Math.min(height_scale, width_scale); - if(( 0 < drawable_width_px ) && ( 0 < drawable_height_px)) { - final double width_scale = (drawable_width_px) / ( subjectBounds_m.getWidth() * baseScale); - final double height_scale = (drawable_height_px) / ( subjectBounds_m.getHeight() * baseScale); - final double minScale = Math.min(height_scale, width_scale); - - scaleTo(minScale, visibleBounds); - } + scaleTo(newScale, visibleBounds); } /** diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/FinPointFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/FinPointFigure.java index 333ed702a..d2d6fda78 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/FinPointFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/FinPointFigure.java @@ -73,18 +73,15 @@ public class FinPointFigure extends AbstractScaleFigure { @Override public Point getAutoZoomPoint(){ - final int finFrontLocationPx = originLocation_px.x + (int)(subjectBounds_m.getX()*scale); - // from canvas top/left - final Point zoomPointPx = new Point( Math.max(0, originLocation_px.x + (int)(subjectBounds_m.getX()*scale)), - 0 ); + final Point zoomPointPx = new Point( Math.max(0, (originLocation_px.x - borderThickness_px.width)), 0); - System.err.println("==>> FinPointFigure.getAutoZoomPoint ==>> " + finset.getName() ); - System.err.println(String.format(" ::ContentBounds: %6.4f, %6.4f", contentBounds_m.getX(), contentBounds_m.getY())); - System.err.println(String.format(" ::SubjectBounds: %6.4f, %6.4f", subjectBounds_m.getX(), subjectBounds_m.getY())); -// System.err.println(String.format(" ::finRootOffset: %d, %d", finFrontOffsetPx, finBottomOffsetPx)); -// System.err.println(String.format(" ::finRootLocation: %d, %d", finFrontLocationPx, 0)); - System.err.println(String.format(" ::ZoomPoint: %d, %d", zoomPointPx.x, zoomPointPx.y)); +// System.err.println("==>> FinPointFigure.getAutoZoomPoint ==>> " + finset.getName() ); +// System.err.println(String.format(" ::scale(overall): %6.4f == %6.4f x %6.4f", scale, userScale, baseScale)); +// System.err.println(String.format(" ::ContentBounds(px): @ %d, %d [ %d x %d ]", (int)(contentBounds_m.getX()*scale), (int)(contentBounds_m.getY()*scale), (int)(contentBounds_m.getWidth()*scale), (int)(contentBounds_m.getHeight()*scale))); +// System.err.println(String.format(" ::SubjectBounds(px): @ %d, %d [ %d x %d ]", (int)(subjectBounds_m.getX()*scale), (int)(subjectBounds_m.getY()*scale), (int)(subjectBounds_m.getWidth()*scale), (int)(subjectBounds_m.getHeight()*scale))); +// System.err.println(String.format(" ::origin: @ %d, %d", originLocation_px.x, originLocation_px.y)); +// System.err.println(String.format(" ::ZoomPoint: @ %d, %d", zoomPointPx.x, zoomPointPx.y)); return zoomPointPx; } @@ -401,12 +398,12 @@ public class FinPointFigure extends AbstractScaleFigure { // this is non-intuitive: it's an offset _from_ the origin(0,0) _to_ the lower-left of the content -- // because the canvas is drawn from that lower-left corner of the content, and the fin-front // is fixed-- by definition-- to the origin. - final int finFrontPx = (int)(contentBounds_m.getX()*scale); + final int finFrontPx = -(int)(contentBounds_m.getX()*scale); // pixels from left-border to fin-front final int contentHeightPx = (int)(contentBounds_m.getHeight()*scale); - originLocation_px.x = borderThickness_px.width - finFrontPx; + originLocation_px.x = borderThickness_px.width + finFrontPx; - if( visibleBounds_px.height > (contentHeightPx + 2*borderThickness_px.height)) { + if( visibleBounds_px.height > (contentHeightPx + 2*borderThickness_px.height)){ originLocation_px.y = getHeight() - mountHeightPx - borderThickness_px.height; }else { originLocation_px.y = borderThickness_px.height + finHeightPx; diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/ScaleScrollPane.java b/swing/src/net/sf/openrocket/gui/scalefigure/ScaleScrollPane.java index 76a78d658..e5d665889 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/ScaleScrollPane.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/ScaleScrollPane.java @@ -159,11 +159,11 @@ public class ScaleScrollPane extends JScrollPane figure.scaleTo(view); final Point zoomPoint = figure.getAutoZoomPoint(); + final Rectangle zoomRectangle = new Rectangle(zoomPoint.x, zoomPoint.y, (int)(view.getWidth()), (int)(view.getHeight())); +// System.err.println(String.format("::zoom: @ %d, %d [ %d x %d ]", zoomRectangle.x, zoomRectangle.y, zoomRectangle.width, zoomRectangle.height)); + figure.scrollRectToVisible(zoomRectangle); - viewport.scrollRectToVisible( new Rectangle( - zoomPoint.x, zoomPoint.y, (int)(view.getWidth()), (int)(view.getHeight()))); - - this.firePropertyChange( USER_SCALE_PROPERTY, 1.0, figure.getUserScale()); + figure.invalidate(); revalidate(); } } @@ -177,13 +177,13 @@ public class ScaleScrollPane extends JScrollPane if( MathUtil.equals(newScale, figure.getUserScale(), 0.01)){ return; } - + // if explicitly setting a zoom level, turn off fitting - this.fit = false; + this.fit = false; Dimension view = viewport.getExtentSize(); - figure.scaleTo(newScale, view); - - revalidate(); + figure.scaleTo(newScale, view); + + revalidate(); } @@ -244,7 +244,7 @@ public class ScaleScrollPane extends JScrollPane dragStartX = e.getX(); dragStartY = e.getY(); - + viewport.scrollRectToVisible(dragRectangle); }