Skip to content

Commit

Permalink
added setScaleFromCenter; updated moveTo methods
Browse files Browse the repository at this point in the history
added setScaleFromCenter method; updated moveTo methods with implicit
requestRender calls
  • Loading branch information
moagrius committed Jan 14, 2014
1 parent 3f0ca8b commit 9f3acd5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/com/qozix/layouts/ZoomPanLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,30 @@ public void frameViewport( Rect rect ) {
smoothScaleTo( minimumScale, SLIDE_DURATION );

}

/**
* Set the scale of the ZoomPanLayout while maintaining the current center point
* @param scale (double) The new value of the ZoomPanLayout scale
*/
public void setScaleFromCenter( double s ) {

int centerOffsetX = (int) ( getWidth() * 0.5f );
int centerOffsetY = (int) ( getHeight() * 0.5f );

Point offset = new Point( centerOffsetX, centerOffsetY );
Point scroll = new Point( getScrollX(), getScrollY() );
scroll.offset( offset.x, offset.y );

double deltaScale = s / getScale();

int x = (int) ( scroll.x * deltaScale ) - offset.x;
int y = (int) ( scroll.y * deltaScale ) - offset.y;
Point destination = new Point( x, y );

setScale( s );
scrollToPoint( destination );

}

/**
* Adds a View to the intermediary ViewGroup that manages layout for the ZoomPanLayout.
Expand Down
2 changes: 2 additions & 0 deletions src/com/qozix/tileview/TileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ public double unscale( double value ) {
public void moveTo( double x, double y ) {
Point point = positionManager.translate( x, y, getScale() );
scrollToPoint( point );
requestRender();
}

/**
Expand All @@ -412,6 +413,7 @@ public void moveTo( double x, double y ) {
public void moveToAndCenter( double x, double y ) {
Point point = positionManager.translate( x, y, getScale() );
scrollToAndCenter( point );
requestRender();
}

/**
Expand Down

0 comments on commit 9f3acd5

Please sign in to comment.