diff --git a/src/java/com/threerings/media/MediaPanel.java b/src/java/com/threerings/media/MediaPanel.java index 44c4d8db0..5236f01af 100644 --- a/src/java/com/threerings/media/MediaPanel.java +++ b/src/java/com/threerings/media/MediaPanel.java @@ -1,5 +1,5 @@ // -// $Id: MediaPanel.java,v 1.14 2002/06/18 22:25:33 mdb Exp $ +// $Id: MediaPanel.java,v 1.15 2002/06/19 07:41:37 mdb Exp $ package com.threerings.media; @@ -11,6 +11,7 @@ import java.awt.Shape; import javax.swing.JComponent; import javax.swing.RepaintManager; +import javax.swing.SwingUtilities; import javax.swing.event.AncestorEvent; import com.samskivert.swing.event.AncestorAdapter; @@ -263,10 +264,16 @@ public class MediaPanel extends JComponent for (int ii = 0; ii < dcount; ii++) { Rectangle clip = dirty[ii]; + + // constrain this dirty region to the bounds of the component + constrainToBounds(clip); + // ignore rectangles that were reduced to nothingness if (clip.width == 0 || clip.height == 0) { continue; } + + // clip to this dirty region clipToDirtyRegion(gfx, clip); // paint the behind the scenes stuff @@ -286,6 +293,19 @@ public class MediaPanel extends JComponent } } + /** + * Called by the main rendering code to constrain this dirty rectangle + * to the bounds of the media panel. If a derived class is using dirty + * rectangles that live in some sort of virtual coordinate system, + * they'll want to override this method and constraint the rectangles + * properly. + */ + protected void constrainToBounds (Rectangle dirty) + { + SwingUtilities.computeIntersection( + 0, 0, getWidth(), getHeight(), dirty); + } + /** * This is called to clip the rendering output to the supplied dirty * region. This should use {@link Graphics#setClip} because the diff --git a/src/java/com/threerings/media/VirtualMediaPanel.java b/src/java/com/threerings/media/VirtualMediaPanel.java index e3cf1042b..615ac7653 100644 --- a/src/java/com/threerings/media/VirtualMediaPanel.java +++ b/src/java/com/threerings/media/VirtualMediaPanel.java @@ -1,5 +1,5 @@ // -// $Id: VirtualMediaPanel.java,v 1.3 2002/06/19 02:34:39 mdb Exp $ +// $Id: VirtualMediaPanel.java,v 1.4 2002/06/19 07:41:37 mdb Exp $ package com.threerings.media; @@ -168,11 +168,9 @@ public class VirtualMediaPanel extends MediaPanel // documentation inherited protected void paint (Graphics2D gfx, Rectangle[] dirty) { - int width = getWidth(), height = getHeight(); - int dcount = dirty.length; - // if we're scrolling, go ahead and do the business if (_dx != 0 || _dy != 0) { + int width = getWidth(), height = getHeight(); int cx = (_dx > 0) ? _dx : 0; int cy = (_dy > 0) ? _dy : 0; @@ -190,14 +188,6 @@ public class VirtualMediaPanel extends MediaPanel _dx = 0; _dy = 0; } - // clip the dirty regions to the viewport - for (int ii = 0; ii < dcount; ii++) { - SwingUtilities.computeIntersection( - _tx, _ty, width, height, dirty[ii]); -// Log.info("Intersected [rect=" + StringUtil.toString(dirty[ii]) + -// ", tx=" + _tx + ", ty=" + _ty + "]."); - } - // translate into happy space gfx.translate(-_tx, -_ty); @@ -208,6 +198,13 @@ public class VirtualMediaPanel extends MediaPanel gfx.translate(_tx, _ty); } + // documentation inherited + protected void constrainToBounds (Rectangle dirty) + { + SwingUtilities.computeIntersection( + _tx, _tx, getWidth(), getHeight(), dirty); + } + /** * Used to compute our viewport offsets. */