Added support for centering the media panel on a region of interest when
it is displaying in a space smaller than its desired view size. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1345 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: MediaPanel.java,v 1.5 2002/04/27 22:40:09 mdb Exp $
|
// $Id: MediaPanel.java,v 1.6 2002/05/07 00:53:56 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.media;
|
package com.threerings.media;
|
||||||
|
|
||||||
@@ -151,6 +151,20 @@ public class MediaPanel extends JComponent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures a region of interest which will be displayed in the
|
||||||
|
* center of the viewport in situations where the media panel's actual
|
||||||
|
* size is smaller than its view size.
|
||||||
|
*
|
||||||
|
* @param region the region of interest or null if there is to be no
|
||||||
|
* region of interest (in which case the view will simply be
|
||||||
|
* centered).
|
||||||
|
*/
|
||||||
|
public void setRegionOfInterest (Rectangle region)
|
||||||
|
{
|
||||||
|
_interest = region;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a reference to the region manager that is used to
|
* Returns a reference to the region manager that is used to
|
||||||
* accumulate dirty regions each frame.
|
* accumulate dirty regions each frame.
|
||||||
@@ -199,13 +213,39 @@ public class MediaPanel extends JComponent
|
|||||||
|
|
||||||
// figure out our viewport offsets
|
// figure out our viewport offsets
|
||||||
Dimension size = getSize(), vsize = getViewSize();
|
Dimension size = getSize(), vsize = getViewSize();
|
||||||
_tx = (vsize.width - size.width)/2;
|
|
||||||
_ty = (vsize.height - size.height)/2;
|
// we need to compute one dimension at a time to make things work;
|
||||||
|
// if we have a region of interest (and our actual size is smaller
|
||||||
|
// than our view size), use that to compute our offset
|
||||||
|
if (_interest != null && size.width < vsize.width) {
|
||||||
|
_tx = centerWithInterest(size.width, vsize.width,
|
||||||
|
_interest.x, _interest.width);
|
||||||
|
} else {
|
||||||
|
// otherwise just center the display
|
||||||
|
_tx = (vsize.width - size.width)/2;
|
||||||
|
}
|
||||||
|
if (_interest != null && size.height < vsize.height) {
|
||||||
|
_ty = centerWithInterest(size.height, vsize.height,
|
||||||
|
_interest.y, _interest.height);
|
||||||
|
} else {
|
||||||
|
_ty = (vsize.height - size.height)/2;
|
||||||
|
}
|
||||||
|
|
||||||
// Log.info("Size: " + size + ", vsize: " + vsize +
|
// Log.info("Size: " + size + ", vsize: " + vsize +
|
||||||
// ", tx: " + _tx + ", ty: " + _ty + ".");
|
// ", tx: " + _tx + ", ty: " + _ty + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to compute our viewport offsets.
|
||||||
|
*/
|
||||||
|
protected int centerWithInterest (int len, int vlen, int ix, int ilen)
|
||||||
|
{
|
||||||
|
// start out by centering on the region of interest
|
||||||
|
int tx = (ix - (len - ilen)/2);
|
||||||
|
// make sure that didn't push us off of the screen
|
||||||
|
return Math.min(Math.max(tx, 0), vlen-len);
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void invalidate ()
|
public void invalidate ()
|
||||||
{
|
{
|
||||||
@@ -492,6 +532,9 @@ public class MediaPanel extends JComponent
|
|||||||
/** Used to accumulate and merge dirty regions on each tick. */
|
/** Used to accumulate and merge dirty regions on each tick. */
|
||||||
protected RegionManager _remgr;
|
protected RegionManager _remgr;
|
||||||
|
|
||||||
|
/** A region of interest which we'll try to keep visible. */
|
||||||
|
protected Rectangle _interest;
|
||||||
|
|
||||||
/** Our viewport offsets. */
|
/** Our viewport offsets. */
|
||||||
protected int _tx, _ty;
|
protected int _tx, _ty;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user