Disable scrolling when speed is set to zero mspp.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1019 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-02-18 06:05:59 +00:00
parent f497a93541
commit 06f9ac0c31
2 changed files with 34 additions and 16 deletions
@@ -1,5 +1,5 @@
// //
// $Id: AnimatedPanel.java,v 1.7 2002/02/17 23:40:43 mdb Exp $ // $Id: AnimatedPanel.java,v 1.8 2002/02/18 06:05:58 mdb Exp $
package com.threerings.media.animation; package com.threerings.media.animation;
@@ -84,7 +84,8 @@ public class AnimatedPanel extends Canvas implements AnimatedView
/** /**
* Instructs the view to begin scrolling with the specified velocities * Instructs the view to begin scrolling with the specified velocities
* in milliseconds per pixel. * in milliseconds per pixel. A setting of zero indicates that
* scrolling should be deactivated in that direction.
*/ */
public void setScrolling (int msppx, int msppy) public void setScrolling (int msppx, int msppy)
{ {
@@ -98,12 +99,21 @@ public class AnimatedPanel extends Canvas implements AnimatedView
if (msppx == 0 && msppy == 0) { if (msppx == 0 && msppy == 0) {
_stime = 0; _stime = 0;
_animmgr.setScrolling(0); _animmgr.setScrolling(0);
} else { } else {
_stime = System.currentTimeMillis(); _stime = System.currentTimeMillis();
// set our scrolling speed to the (absolute value of the) // set our scrolling speed to the (absolute value of the)
// lower of the two velocities // lower of the two velocities (but not to zero if either one
int scrollvel = Math.min(Math.abs(_msppx), Math.abs(_msppy)); // is zero)
_animmgr.setScrolling(scrollvel); if (_msppx == 0) {
_animmgr.setScrolling(msppy);
} else if (_msppy == 0) {
_animmgr.setScrolling(msppx);
} else {
_animmgr.setScrolling(
Math.min(Math.abs(msppx), Math.abs(msppy)));
}
} }
} }
@@ -168,16 +178,19 @@ public class AnimatedPanel extends Canvas implements AnimatedView
// compute the total distance scrolled since we started (to // compute the total distance scrolled since we started (to
// avoid rounding errors) // avoid rounding errors)
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
int xdist = (int)((now - _stime) / _msppx);
int ydist = (int)((now - _stime) / _msppy);
// determine how many pixels further along we've moved
dx = (xdist - _lastx);
dy = (ydist - _lasty);
// determine how many pixels further along we've moved and
// make a note of our latest position // make a note of our latest position
_lastx = xdist; if (_msppx != 0) {
_lasty = ydist; int xdist = (int)((now - _stime) / _msppx);
dx = (xdist - _lastx);
_lastx = xdist;
}
if (_msppy != 0) {
int ydist = (int)((now - _stime) / _msppy);
dy = (ydist - _lasty);
_lasty = ydist;
}
// let our derived classes do whatever they need to do to // let our derived classes do whatever they need to do to
// prepare to be scrolled // prepare to be scrolled
@@ -1,5 +1,5 @@
// //
// $Id: AnimationManager.java,v 1.5 2002/02/17 23:38:18 mdb Exp $ // $Id: AnimationManager.java,v 1.6 2002/02/18 06:05:59 mdb Exp $
package com.threerings.media.animation; package com.threerings.media.animation;
@@ -189,8 +189,13 @@ public class AnimationManager
// start out assuming that we can refresh for every pixel // start out assuming that we can refresh for every pixel
_refreshInterval = _scrollvel; _refreshInterval = _scrollvel;
// if the interval is too quick, bump it up a bit // if they've disabled scrolling, go back to the default refresh
if (_refreshInterval < lowerTarget) { // interval
if (_scrollvel == 0) {
_refreshInterval = DEFAULT_REFRESH_INTERVAL;
// if the interval is too quick, bump it up a bit
} else if (_refreshInterval < lowerTarget) {
// keep adding a pixel at a time until we're above our minimum // keep adding a pixel at a time until we're above our minimum
// refresh interval // refresh interval
while (_refreshInterval < lowerTarget) { while (_refreshInterval < lowerTarget) {